-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
84 lines (76 loc) · 2.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const nextText = require('..')
const {ok, equal, notStrictEqual} = require('assert')
test('nextText', () => {
test('returns an object with `.toString()`', () => {
let text = nextText('Lorem')
ok(text.toString)
equal(typeof text.toString, 'function')
})
test('is not coerced into string', () => {
let text = nextText('Lorem')
notStrictEqual(text, '')
})
test('`.toString()` returns each letter in sequence', () => {
let text = nextText('Lorem')
equal(text.toString(), '')
text = text.next()
equal(text.toString(), 'L')
text = text.next()
equal(text.toString(), 'Lo')
text = text.next()
equal(text.toString(), 'Lor')
text = text.next()
equal(text.toString(), 'Lore')
text = text.next()
equal(text.toString(), 'Lorem')
})
test('`.toString()` can also be omitted when coercing to string', () => {
let text = nextText('Lorem')
equal(text, '')
equal(text = text.next(), 'L')
equal(text = text.next(), 'Lo')
equal(text = text.next(), 'Lor')
equal(text = text.next(), 'Lore')
equal(text = text.next(), 'Lorem')
})
test('when the string has been iterated', () => {
test('returns always the original text', () => {
let text = nextText('test')
equal(text, '')
equal(text = text.next(), 't')
equal(text = text.next(), 'te')
equal(text = text.next(), 'tes')
equal(text = text.next(), 'test')
equal(text = text.next(), 'test')
equal(text = text.next(), 'test')
equal(text = text.next(), 'test')
})
test('can be specified if the string should be iterated from the start', () => {
let text = nextText('test', {restart: true})
equal(text, '')
equal(text = text.next(), 't')
equal(text = text.next(), 'te')
equal(text = text.next(), 'tes')
equal(text = text.next(), 'test')
equal(text = text.next(), '')
equal(text = text.next(), 't')
equal(text = text.next(), 'te')
equal(text = text.next(), 'tes')
equal(text = text.next(), 'test')
})
})
test('resets a nextText instance', () => {
let text = nextText('Lorem')
equal(text, '')
equal(text = text.next(), 'L')
equal(text = text.next(), 'Lo')
equal(text = text.reset(), '')
equal(text = text.next(), 'L')
equal(text = text.next(), 'Lo')
})
// test('can be resumed', () => {
// let text = nextText('Lorem')
// equal(text, '')
// equal(text = text.next(), 'L')
// })
})