-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
50 lines (42 loc) · 1.34 KB
/
test.ts
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
import { expandGlobSync } from "https://deno.land/[email protected]/fs/mod.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { Joss } from './joss.ts';
const decoder = new TextDecoder();
function *get_tests() {
for (const file of expandGlobSync("tests/*.session")) {
let expected = '';
let lineno = 0;
let command = '';
let command_lineno = 0;
for (const line of Deno.readTextFileSync(file.path).split('\n')) {
lineno += 1;
if (line.startsWith('#')) {
continue;
}
if (!line.startsWith('> ')) {
expected += line + '\n';
continue;
}
if (command !== '') {
yield {fname: file.name, command_lineno, command, expected};
}
command = line.slice(2);
command_lineno = lineno;
expected = '';
}
yield {fname: file.name, command_lineno, command, expected};
}
}
let old_fname: string|null = null;
const output = new Deno.Buffer();
let joss = new Joss(Deno.stdin, output);
for (const {fname, command_lineno, command, expected} of get_tests()) {
if (old_fname && old_fname !== fname) {
joss = new Joss(Deno.stdin, output);
old_fname = fname;
}
Deno.test(`${fname}: ${command_lineno}: ${command}`, () => {
joss.eval(command);
assertEquals(decoder.decode(Deno.readAllSync(output)), expected);
});
}