forked from divvun/ck-ospell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
126 lines (100 loc) · 3.31 KB
/
test.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const test = require("ava");
const request = require("supertest-as-promised");
const express = require("express");
const { response } = require("express");
const app = express();
app.use(require("./server/index"));
const API = "/spellcheck/script/ssrv.cgi";
const cmd = (name) =>
({ 'cmd': name, 'run_mode': "web_service", 'format': "json" });
const spellCmd = () => ({
'cmd': "check_spelling",
'run_mode': "web_service",
'format': "json",
'version': "1.0",
'out_type': "words",
});
test.serial("Get Banner", async t => {
const response = await request(app)
.get(API)
.query(cmd("getbanner"));
t.is(response.status, 200);
t.deepEqual(response.body, { banner: false })
});
test("Get Lang List", async t => {
const response = await request(app)
.get(API)
.query(cmd("get_lang_list"));
t.is(response.status, 200)
t.deepEqual(
response.body,
{
langList: {
ltr: {
sma: 'Giellatekno/Divvun/UiT fst-based speller for Southern Sami',
},
rtl: {},
},
verLang: 6,
})
});
test("Check Spelling: Correct Word", async t => {
const response = await request(app)
.get(API)
.query(spellCmd())
.query({ slang: "sma", text: "akkusatijvh" })
t.is(response.status, 200)
t.deepEqual(response.body, [])
});
test("Check Spelling: Suggestions", async t => {
const response = await request(app)
.get(API)
.query(spellCmd())
.query({ slang: "sma", text: "akkusativa" })
t.is(response.status, 200)
t.truthy(Array.isArray(response.body))
const s = response.body[0];
t.deepEqual(s.word, 'akkusativa');
t.deepEqual(s.ud, false);
// Only check the values are all present but ignore the order. (For some
// reason, the order of suggestions is different on Linux and OS X...)
t.deepEqual(s.suggestions.sort(), ['akkusatijve', 'akkusatijvh', 'akkusatijvi', 'akkusativ-C', 'akkusativ-D', 'akkusativ-I', 'akkusativ-L', 'akkusativ-M', 'akkusativ-V', 'akkusativ-X'].sort());
});
test("Check Spelling: Empty Suggestions", async t => {
const response = await request(app)
.get(API)
.query(spellCmd())
.query({ slang: "sma", text: "apfelkuchen" })
t.is(response.status, 200)
const expected = [{
word: 'apfelkuchen',
suggestions: [],
ud: false,
}];
t.deepEqual(response.body, expected)
});
test("Check Spelling: Suggestions for multiple words", async t => {
const response = await request(app)
.get(API)
.query(spellCmd())
.query({ slang: "sma", text: "lorem,ipsum" })
t.is(response.status, 200)
t.truthy(Array.isArray(response.body));
const s0 = response.body[0];
t.deepEqual(s0.word, 'lorem');
t.deepEqual(s0.ud, false);
t.deepEqual(s0.suggestions.sort(), ['Borem', 'Doram', 'Floram', 'Florem', 'Morem', 'Norem', 'Torem', 'lorvem', 'lovrem', 'låvrem'].sort());
// Check ipsum
const s1 = response.body[1];
t.deepEqual(s1.word, 'ipsum');
t.deepEqual(s1.ud, false);
t.deepEqual(s1.suggestions.sort(), ['Aksum', 'Epsom', 'Hasum', 'Husum', 'Pesum', 'Sippum', 'Sisum', 'gipsem', 'gipsim', 'jipsem'].sort());
});
test("Check Spelling: Remove quote marks", async t => {
const response = await request(app)
.get(API)
.query(spellCmd())
.query({ slang: "sma", text: "«akkusatijvh»«»“”‘’" })
t.is(response.status, 200)
t.deepEqual(response.body, [])
});