test/Lexer/Input.spec.js   A
last analyzed

Complexity

Total Complexity 12
Complexity/F 1

Size

Lines of Code 65
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 12
c 1
b 0
f 0
nc 1
mnd 0
bc 12
fnc 12
dl 0
loc 65
rs 10
bpm 1
cpm 1
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A Input.spec.js ➔ ??? 0 58 1
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