-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
169 lines (144 loc) · 5.23 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
import assert from 'node:assert/strict'
import test from 'node:test'
import {retext} from 'retext'
import retextContractions from 'retext-contractions'
test('retextContractions', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('retext-contractions')).sort(), [
'default'
])
})
await t.test(
'should message for missing smart apostrophes',
async function () {
const file = await retext().use(retextContractions).process('Yall.')
assert.deepEqual(
JSON.parse(JSON.stringify({...file.messages[0], ancestors: []})),
{
ancestors: [],
column: 1,
fatal: false,
message: 'Unexpected missing apostrophe in `Yall`, expected `Y’all`',
line: 1,
name: '1:1-1:5',
place: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 5, offset: 4}
},
reason: 'Unexpected missing apostrophe in `Yall`, expected `Y’all`',
ruleId: 'missing-smart-apostrophe',
source: 'retext-contractions',
actual: 'Yall',
expected: ['Y’all'],
url: 'https://github.com/retextjs/retext-contractions#readme'
}
)
}
)
await t.test(
'should message for missing straight apostrophes',
async function () {
const file = await retext()
.use(retextContractions, {straight: true})
.process('Dont.')
assert.deepEqual(file.messages.map(String), [
"1:1-1:5: Unexpected missing apostrophe in `Dont`, expected `Don't`"
])
}
)
await t.test(
'should message for an expected smart apostrophe',
async function () {
const file = await retext().use(retextContractions).process("Don't.")
assert.deepEqual(file.messages.map(String), [
"1:1-1:6: Unexpected straight apostrophe in `Don't`, expected `Don’t`"
])
}
)
await t.test(
'should message for an expected straight apostrophe',
async function () {
const file = await retext()
.use(retextContractions, {straight: true})
.process('Don’t.')
assert.deepEqual(file.messages.map(String), [
"1:1-1:6: Unexpected smart apostrophe in `Don’t`, expected `Don't`"
])
}
)
await t.test(
'should catch contractions without apostrophes',
async function () {
const file = await retext()
.use(retextContractions)
.process('Well, it doesnt have to be so bad, yall.')
assert.deepEqual(file.messages.map(String), [
'1:10-1:16: Unexpected missing apostrophe in `doesnt`, expected `doesn’t`',
'1:36-1:40: Unexpected missing apostrophe in `yall`, expected `y’all`'
])
}
)
await t.test(
'should catch contractions with incorrect apostrophes',
async function () {
const file = await retext()
.use(retextContractions)
.process("Well, it does’nt have to be so bad, ya'll.")
assert.deepEqual(file.messages.map(String), [
'1:10-1:17: Unexpected straight apostrophe in `does’nt`, expected `doesn’t`',
"1:37-1:42: Unexpected straight apostrophe in `ya'll`, expected `y’all`"
])
}
)
await t.test('should catch initial elisions', async function () {
const file = await retext()
.use(retextContractions)
.process('twas tis twere')
assert.deepEqual(file.messages.map(String), [
'1:1-1:5: Unexpected missing apostrophe in `twas`, expected `’twas`',
'1:6-1:9: Unexpected missing apostrophe in `tis`, expected `’tis`',
'1:10-1:15: Unexpected missing apostrophe in `twere`, expected `’twere`'
])
})
await t.test('should ignore decades (GH-7)', async function () {
const file = await retext()
.use(retextContractions)
.process('It was acceptable in the 80s, I mean 80’s, no wait?')
assert.deepEqual(file.messages.map(String), [])
})
await t.test(
'should catch contractions without apostrophes',
async function () {
const file = await retext()
.use(retextContractions, {straight: true})
.process('Well, it does’nt have to be so bad, y’all.')
assert.deepEqual(file.messages.map(String), [
"1:10-1:17: Unexpected smart apostrophe in `does’nt`, expected `doesn't`",
"1:37-1:42: Unexpected smart apostrophe in `y’all`, expected `y'all`"
])
}
)
await t.test('should ignore literals by default', async function () {
const file = await retext()
.use(retextContractions)
.process('“Twas” is misspelt.')
assert.deepEqual(file.messages.map(String), [])
})
await t.test(
'should allow literals when `allowLiterals: true`',
async function () {
const file = await retext()
.use(retextContractions, {allowLiterals: true})
.process('“Twas” is misspelt.')
assert.deepEqual(file.messages.map(String), [
'1:2-1:6: Unexpected missing apostrophe in `Twas`, expected `’twas`'
])
}
)
await t.test('should work', async function () {
const file = await retext()
.use(retextContractions)
.process('Well, it doesn’t have to be so bad, y’all.')
assert.deepEqual(file.messages.map(String), [])
})
})