-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstd.test.js
More file actions
86 lines (72 loc) · 2.3 KB
/
std.test.js
File metadata and controls
86 lines (72 loc) · 2.3 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import fs from 'node:fs';
import { describe, it } from 'node:test';
import { deepEqual, notDeepEqual, throws } from 'node:assert/strict';
import {
FILE_LOCATION,
NUMERIC_INPUT,
ANALLIFY_INPUT,
STRINGIFY_INPUT,
RUN_WRONG_OUTPUT,
ANAL_FILE_LOCATION,
EMPTY_STRING_INPUT,
NOT_ACCEPTED_INPUT,
RUN_CORRECT_OUTPUT,
ANALLIFY_WRONG_OUTPUT,
STRINGIFY_WRONG_OUTPUT,
COMPILE_CORRECT_OUTPUT,
COMPILED_FILE_LOCATION,
ANALLIFY_CORRECT_OUTPUT,
STRINGIFY_CORRECT_OUTPUT,
} from './seeds.js';
import {
run,
anallify,
stringify,
compile,
} from '../lib/std.js';
import { ERROR } from '../lib/dictionary.js';
describe('Anallify', () => {
it('Encode string to anal', () => {
deepEqual(anallify(ANALLIFY_INPUT), ANALLIFY_CORRECT_OUTPUT);
notDeepEqual(anallify(ANALLIFY_INPUT), ANALLIFY_WRONG_OUTPUT);
});
it('Throw error if argument is not a string', () => {
throws(() => anallify(1), Error(ERROR.notString));
});
it('Throw error if argument is missing', () => {
throws(() => anallify(EMPTY_STRING_INPUT), Error(ERROR.missingArgument));
});
});
describe('Stringify', () => {
it('Decode anal to string', () => {
deepEqual(stringify(STRINGIFY_INPUT), STRINGIFY_CORRECT_OUTPUT);
notDeepEqual(stringify(STRINGIFY_INPUT), STRINGIFY_WRONG_OUTPUT);
});
it('Throw error if argument is not a string', () => {
throws(() => stringify(1), Error(ERROR.notString));
});
it('Throw error if argument is missing', () => {
throws(() => stringify(EMPTY_STRING_INPUT), Error(ERROR.missingArgument));
});
it('Throw error if there are grammar-refused characters', () => {
throws(() => stringify(NOT_ACCEPTED_INPUT), Error(ERROR.notAcceptedByGrammar));
});
});
describe('Run', () => {
it('Run .anal file', () => {
deepEqual(run(ANAL_FILE_LOCATION), RUN_CORRECT_OUTPUT);
notDeepEqual(run(ANAL_FILE_LOCATION), RUN_WRONG_OUTPUT);
});
it('Throw error if file is not found', () => {
throws(() => run(NUMERIC_INPUT), Error(ERROR.fileNotFound));
});
});
describe('Compile', () => {
it('Compile file to .anal', (t) => {
t.after(() => fs.rmSync(COMPILED_FILE_LOCATION));
deepEqual(compile(FILE_LOCATION), COMPILE_CORRECT_OUTPUT);
});
it('Throw error if file is not found', () => {
throws(() => compile(NUMERIC_INPUT), Error(ERROR.fileNotFound));
});
});