1
|
|
|
'use strict'; |
2
|
|
|
|
3
|
|
|
import { assert } from 'chai'; |
4
|
|
|
import Input from '../../src/Lexer/Input'; |
5
|
|
|
import pkg from '../../package.json'; |
6
|
|
|
|
7
|
|
|
/** @test {Input} */ |
8
|
|
|
describe(`${pkg.name}/Lexer/Input`, () => { |
9
|
|
|
/** @test {Input#constructor} */ |
10
|
|
|
describe('#constructor', () => { |
11
|
|
|
it('Create a new instance of type Input', () => { |
12
|
|
|
assert.instanceOf(new Input(''), Input); |
13
|
|
|
}); |
14
|
|
|
}); |
15
|
|
|
|
16
|
|
|
/** @test {Input#eof} */ |
17
|
|
|
describe('#eof', () => { |
18
|
|
|
it('Determine whether or not there are no more values in the stream.', () => { |
19
|
|
|
const stream = new Input(''); |
20
|
|
|
assert.isTrue(stream.eof()); |
21
|
|
|
}); |
22
|
|
|
}); |
23
|
|
|
|
24
|
|
|
/** @test {Input#error} */ |
25
|
|
|
describe('#error', () => { |
26
|
|
|
it('Throw a new Error.', () => { |
27
|
|
|
const stream = new Input(''); |
28
|
|
|
|
29
|
|
|
assert.throws(() => { |
30
|
|
|
stream.error('Parse error'); |
31
|
|
|
}, Error, 'Parse error (Line: 1, Column: 0)'); |
32
|
|
|
}); |
33
|
|
|
}); |
34
|
|
|
|
35
|
|
|
/** @test {Input#next} */ |
36
|
|
|
describe('#next', () => { |
37
|
|
|
it('Return the next value from the stream.', () => { |
38
|
|
|
const stream = new Input('> hello botlang'); |
39
|
|
|
|
40
|
|
|
assert.strictEqual(stream.next(), ' '); |
41
|
|
|
assert.strictEqual(stream.next(), 'h'); |
42
|
|
|
assert.strictEqual(stream.next(), 'e'); |
43
|
|
|
assert.strictEqual(stream.next(), 'l'); |
44
|
|
|
assert.strictEqual(stream.next(), 'l'); |
45
|
|
|
assert.strictEqual(stream.next(), 'o'); |
46
|
|
|
assert.strictEqual(stream.next(), ' '); |
47
|
|
|
assert.strictEqual(stream.next(), 'b'); |
48
|
|
|
assert.strictEqual(stream.next(), 'o'); |
49
|
|
|
assert.strictEqual(stream.next(), 't'); |
50
|
|
|
assert.strictEqual(stream.next(), 'l'); |
51
|
|
|
assert.strictEqual(stream.next(), 'a'); |
52
|
|
|
assert.strictEqual(stream.next(), 'n'); |
53
|
|
|
assert.strictEqual(stream.next(), 'g'); |
54
|
|
|
}); |
55
|
|
|
}); |
56
|
|
|
|
57
|
|
|
/** @test {Input#peek} */ |
58
|
|
|
describe('#peek', () => { |
59
|
|
|
it('Return the value from the current position.', () => { |
60
|
|
|
const stream = new Input('> hello botlang'); |
61
|
|
|
|
62
|
|
|
assert.strictEqual(stream.peek(), '>'); |
63
|
|
|
}); |
64
|
|
|
}); |
65
|
|
|
}); |
66
|
|
|
|