1
|
|
|
'use strict'; |
2
|
|
|
|
3
|
|
|
import * as fs from 'fs'; |
4
|
|
|
import * as path from 'path'; |
5
|
|
|
import { assert } from 'chai'; |
6
|
|
|
import Botlang from '../src/Botlang'; |
7
|
|
|
import pkg from '../package.json'; |
8
|
|
|
|
9
|
|
|
/** @test {Botlang} */ |
10
|
|
|
describe(`${pkg.name}/Botlang`, () => { |
11
|
|
|
/** @test {Botlang#constructor} */ |
12
|
|
|
describe('#constructor', () => { |
13
|
|
|
it('Create a new instance of type Botlang', () => { |
14
|
|
|
const sourceCode = fs.readFileSync(path.join(__dirname, 'Data', 'hello_world.bot'), { |
15
|
|
|
encoding : 'utf8', |
16
|
|
|
flag : 'r' |
17
|
|
|
}), |
18
|
|
|
botlang = new Botlang(sourceCode); |
19
|
|
|
|
20
|
|
|
assert.instanceOf(botlang, Botlang); |
21
|
|
|
}); |
22
|
|
|
}); |
23
|
|
|
|
24
|
|
|
/** @test {Botlang#reply} */ |
25
|
|
|
describe('#reply', () => { |
26
|
|
|
const sourceCode = fs.readFileSync(path.join(__dirname, 'Data', 'hello_world.bot'), { |
27
|
|
|
encoding : 'utf8', |
28
|
|
|
flag : 'r' |
29
|
|
|
}), |
30
|
|
|
botlang = new Botlang(sourceCode); |
31
|
|
|
|
32
|
|
|
it('Should return an empty string', () => { |
33
|
|
|
assert.match(botlang.reply(''), /^$/); |
34
|
|
|
}); |
35
|
|
|
|
36
|
|
|
it('Should return "Hi, how is it going?"', () => { |
37
|
|
|
assert.match(botlang.reply('Hey'), /Hi, how is it going?/); |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
it('Should return "I think Botlang is freakin awesome!"', () => { |
41
|
|
|
assert.match( |
42
|
|
|
botlang.reply('What do you think about Botlang?'), |
43
|
|
|
/(I think Botlang is freakin awesome!|I think Botlang is great!|I think Botlang is the coolest thing on Earth!)/ |
44
|
|
|
); |
45
|
|
|
}); |
46
|
|
|
|
47
|
|
|
it('Should return "Hi, how are you?" or "Hey, how are you?"', () => { |
48
|
|
|
assert.match(botlang.reply('Hello there'), /Hi, how are you?|Hey, how are you?/); |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
it('Should return "Sorry, I do not know the answer to that question."', () => { |
52
|
|
|
assert.match(botlang.reply('Yay ...'), /Sorry, I do not know the answer to that question./); |
53
|
|
|
}); |
54
|
|
|
|
55
|
|
|
it('Should return "I love you too"', () => { |
56
|
|
|
assert.match(botlang.reply('I love you'), /I love you too./); |
57
|
|
|
}); |
58
|
|
|
|
59
|
|
|
it('Should return "Can you think of why you might forget names?"', () => { |
60
|
|
|
assert.match(botlang.reply('Sometimes I forget names'), /Can you think of why you might forget names?/); |
61
|
|
|
}); |
62
|
|
|
|
63
|
|
|
it('Should return "Im you too"', () => { |
64
|
|
|
assert.match(botlang.reply('I am good'), /Glad to hear that you are good./); |
65
|
|
|
}); |
66
|
|
|
}); |
67
|
|
|
|
68
|
|
|
/** @test {Botlang#version} */ |
69
|
|
|
describe('#version', () => { |
70
|
|
|
it('Should return the current version', () => { |
71
|
|
|
assert.equal(Botlang.version(), pkg.version); |
72
|
|
|
}); |
73
|
|
|
}); |
74
|
|
|
}); |
75
|
|
|
|