-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession-rules.test.cjs
More file actions
72 lines (67 loc) · 1.93 KB
/
session-rules.test.cjs
File metadata and controls
72 lines (67 loc) · 1.93 KB
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
/**
* Table-driven checks for frontend/session-rules.js (run: npm run test:session-rules).
*/
'use strict';
const assert = require('assert');
const path = require('path');
const rules = require(path.join(__dirname, '..', 'frontend', 'session-rules.js'));
const cases = [
{
raw: 'Please export PDF now.',
writeIntent: false,
answerStated: false,
exportIntent: true,
questionNum: null,
},
{
raw: 'Save this as PDF please.',
writeIntent: false,
answerStated: false,
exportIntent: true,
questionNum: null,
},
{
raw: 'Write my answer for question 2.',
writeIntent: true,
answerStated: false,
exportIntent: false,
questionNum: 2,
},
{
raw: 'My answer is 42 for question 3.',
writeIntent: false,
answerStated: true,
exportIntent: false,
questionNum: 3,
},
{
raw: 'I think it is the Civil War.',
writeIntent: false,
answerStated: true,
exportIntent: false,
questionNum: null,
},
{
raw: 'Let me write that for question 1',
writeIntent: true,
answerStated: false,
exportIntent: false,
questionNum: 1,
clarosWriteQ: 1,
},
];
for (const c of cases) {
const norm = rules.normalizeTranscript(c.raw);
assert.strictEqual(rules.WRITE_INTENT_RE.test(norm), c.writeIntent, `writeIntent ${c.raw}`);
assert.strictEqual(rules.ANSWER_STATED_RE.test(norm), c.answerStated, `answerStated ${c.raw}`);
assert.strictEqual(rules.hasExportIntent(norm), c.exportIntent, `exportIntent ${c.raw}`);
const qm = rules.QUESTION_NUM_RE.exec(norm);
const num = qm ? parseInt(qm[1], 10) : null;
assert.strictEqual(num, c.questionNum, `questionNum ${c.raw}`);
if (c.clarosWriteQ != null) {
const m = rules.CLAROS_WRITE_PHRASE_RE.exec(norm);
assert.ok(m, `claros phrase should match: ${c.raw}`);
assert.strictEqual(parseInt(m[1], 10), c.clarosWriteQ);
}
}
console.log('session-rules.test.cjs: all', cases.length, 'cases passed.');