-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.js
193 lines (172 loc) · 5.79 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import assert from 'node:assert/strict'
import test from 'node:test'
import {retext} from 'retext'
import retextReadability from 'retext-readability'
test('retext-readability', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('retext-readability')).sort(), [
'default'
])
})
await t.test('should emit a message w/ metadata', async function () {
const file = await retext()
.use(retextReadability)
.process(
[
'Oberon, also designated Uranus IV, is the outermost ',
'major moon of the planet Uranus and quite large',
'and massive for a Uranian moon.',
''
].join('\n')
)
assert.deepEqual(
JSON.parse(JSON.stringify({...file.messages[0], ancestors: []})),
{
ancestors: [],
column: 1,
fatal: false,
message:
'Unexpected hard to read sentence, according to 4 out of 7 algorithms',
line: 1,
name: '1:1-3:32',
place: {
start: {line: 1, column: 1, offset: 0},
end: {line: 3, column: 32, offset: 132}
},
reason:
'Unexpected hard to read sentence, according to 4 out of 7 algorithms',
ruleId: 'readability',
source: 'retext-readability',
actual:
'Oberon, also designated Uranus IV, is the outermost \nmajor moon of the planet Uranus and quite large\nand massive for a Uranian moon.',
expected: [],
url: 'https://github.com/retextjs/retext-readability#readme'
}
)
})
await t.test(
'should not warn when a sentence is easy to read',
async function () {
const file = await retext()
.use(retextReadability)
.process('The cat sat on the mat')
assert.deepEqual(file.messages.map(String), [])
}
)
await t.test(
'should warn when low confidence that a sentence is hard to read',
async function () {
const file = await retext()
.use(retextReadability)
.process(
[
'Oberon, also designated Uranus IV, is the outermost ',
'major moon of the planet Uranus and quite large',
'and massive for a Uranian moon.',
''
].join('\n')
)
assert.deepEqual(file.messages.map(String), [
'1:1-3:32: Unexpected hard to read sentence, according to 4 out of 7 algorithms'
])
}
)
await t.test('should support a threshold', async function () {
const file = await retext()
.use(retextReadability, {threshold: 5 / 7})
.process(
[
'Oberon, also designated Uranus IV, is the outermost ',
'major moon of the planet Uranus and quite large',
'and massive for a Uranian moon.',
''
].join('\n')
)
assert.deepEqual(file.messages.map(String), [])
})
await t.test(
'should support a given age (removing the warning)',
async function () {
const file = await retext()
.use(retextReadability, {age: 18})
.process(
[
'Oberon, also designated Uranus IV, is the outermost ',
'major moon of the planet Uranus and quite large',
'and massive for a Uranian moon.',
''
].join('\n')
)
assert.deepEqual(file.messages.map(String), [])
}
)
await t.test(
'should support a given age (upping the warning)',
async function () {
const file = await retext()
.use(retextReadability, {age: 14})
.process(
[
'Oberon, also designated Uranus IV, is the outermost ',
'major moon of the planet Uranus and quite large',
'and massive for a Uranian moon.',
''
].join('\n')
)
assert.deepEqual(file.messages.map(String), [
'1:1-3:32: Unexpected hard to read sentence, according to 5 out of 7 algorithms'
])
}
)
await t.test(
'should warn when moderately confident that a sentence is hard to read',
async function () {
const file = await retext()
.use(retextReadability)
.process(
[
'Oberon, also designated Uranus IV, is the outermost ',
'major moon of the planet Uranus and the second-largest ',
'and second most massive of the Uranian moons.',
''
].join('\n')
)
assert.deepEqual(file.messages.map(String), [
'1:1-3:46: Unexpected hard to read sentence, according to 5 out of 7 algorithms'
])
}
)
await t.test(
'should warn when highly confident that a sentence is hard to read',
async function () {
const file = await retext()
.use(retextReadability, {age: 6})
.process(
[
'Oberon, also designated Uranus IV, is the outermost ',
'major moon of the planet Uranus and the second-largest ',
'and second most massive of the Uranian moons, and the ',
'ninth most massive moon in the Solar System.',
''
].join('\n')
)
assert.deepEqual(file.messages.map(String), [
'1:1-4:45: Unexpected hard to read sentence, according to all 7 algorithms'
])
}
)
await t.test('should support minWords (default)', async function () {
const file = await retext()
.use(retextReadability)
.process('Honorificabilitudinitatibus.')
assert.deepEqual(file.messages.map(String), [])
})
await t.test('should support `minWords` (config)', async function () {
const file = await retext()
.use(retextReadability, {minWords: 0})
.process('Honorificabilitudinitatibus.')
assert.deepEqual(file.messages.map(String), [
'1:1-1:29: Unexpected hard to read sentence, according to 4 out of 7 algorithms'
])
})
})