test/Parser/Parser.spec.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 1

Size

Lines of Code 54
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
B Parser.spec.js ➔ ??? 0 43 1
1
'use strict';
2
3
import * as fs from 'fs';
4
import * as path from 'path';
5
import { assert } from 'chai';
6
import Parser from '../../src/Parser';
7
import { Input, Lexer } from '../../src/Lexer';
8
import helloWorldAst from '../Data/hello_world.ast.json';
9
import pkg from '../../package.json';
10
11
/** @test {Parser} */
12
describe(`${pkg.name}/Parser/Parser`, () => {
13
  /** @test {Parser#constructor} */
14
  describe('#constructor', () => {
15
    it('Create a new instance of type Parser', () => {
16
      const input = new Input('+Hello World'),
17
            lexer = new Lexer(input),
18
            parser = new Parser(lexer);
19
20
      assert.instanceOf(parser, Parser);
21
    });
22
  });
23
24
  /** @test {Parser#parse} */
25
  describe('#parse', () => {
26
    it('Parse program', () => {
27
      const sourceCode = fs.readFileSync(path.join(__dirname, '..', 'Data', 'hello_world.bot'), {
28
              encoding : 'utf8',
29
              flag     : 'r'
30
            }),
31
            input = new Input(sourceCode),
32
            lexer = new Lexer(input),
33
            parser = new Parser(lexer),
34
            code = parser.parse();
35
36
      assert.isObject(code);
37
      assert.deepEqual(code, helloWorldAst);
38
    });
39
  });
40
41
  /** @test {Parser#replaceStringSubstitution} */
42
  describe('#replaceStringSubstitution', () => {
43
    it('Should replace the string substitution character in a given string', () => {
44
      assert.notInclude(Parser.replaceStringSubstitution('I $ you because you are so $!'), '$');
45
    });
46
  });
47
48
  /** @test {Parser#replaceWildcard} */
49
  describe('#replaceWildcard', () => {
50
    it('Should replace the wildcard substitution character in a given string', () => {
51
      assert.notInclude(Parser.replaceWildcard('What do you think about * and *?'), '*');
52
    });
53
  });
54
});
55