|
| 1 | +import { substr } from '../../../helpers/substr'; |
| 2 | +import { module, test } from 'qunit'; |
| 3 | + |
| 4 | +module('Unit | Helper | substr'); |
| 5 | + |
| 6 | + |
| 7 | +// Replace this with your real tests. |
| 8 | +test('number', function(assert) { |
| 9 | + let result = substr([42]); |
| 10 | + assert.equal(result, 42); |
| 11 | +}); |
| 12 | + |
| 13 | +test('string', function(assert) { |
| 14 | + let result = substr(['substr'], {}); |
| 15 | + assert.equal(result, 'substr'); |
| 16 | +}); |
| 17 | + |
| 18 | +test('empty object', function(assert) { |
| 19 | + let result = substr([{}]); |
| 20 | + assert.deepEqual(result, {}); |
| 21 | +}); |
| 22 | + |
| 23 | +test('object with properties', function(assert) { |
| 24 | + let result = substr([{a: 1, b: 2 }]); |
| 25 | + assert.deepEqual(result, {a: 1, b: 2 }); |
| 26 | +}); |
| 27 | + |
| 28 | +test('start >= length', function(assert) { |
| 29 | + let result = substr(['abcdefghij'], {start: 20, length: 2}); |
| 30 | + assert.equal(result, ''); |
| 31 | +}); |
| 32 | + |
| 33 | +test('start <= -1', function(assert) { |
| 34 | + let result = substr(['abcdefghij'], {start: -3, length: 2}); |
| 35 | + assert.equal(result, 'hi'); |
| 36 | +}); |
| 37 | + |
| 38 | +test('start == 1, length ommited ', function(assert) { |
| 39 | + let result = substr(['abcdefghij'], {start: 1}); |
| 40 | + assert.equal(result, 'bcdefghij'); |
| 41 | +}); |
| 42 | + |
| 43 | +test('start == 1, length 0 ', function(assert) { |
| 44 | + let result = substr(['abcdefghij'], {start: 1, length: 0}); |
| 45 | + assert.equal(result, ''); |
| 46 | +}); |
| 47 | + |
| 48 | +test('start == 1, length is negative ', function(assert) { |
| 49 | + let result = substr(['abcdefghij'], {start: 1, length: -1}); |
| 50 | + assert.equal(result, ''); |
| 51 | +}); |
0 commit comments