-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
63 lines (62 loc) · 2.25 KB
/
index.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
const remark = require('remark');
const vfile = require('to-vfile');
const rule = require('.');
describe('no-repeat-punctuation', () => {
function process(markdown, config) {
return new Promise((resolve, reject) => {
remark()
.use(rule, config)
.process(vfile({ path: 'input.md', contents: markdown }), (error, file) => {
if (error) reject(error);
else resolve(file.messages.map(String));
});
});
}
it('should pass when punctuation not repeat', () => {
const markdown = '好好学习,天天向上。';
return process(markdown).then((messages) => {
expect(messages).toEqual([]);
});
});
['!', '!', '~', '~', '.', '。', ',', ',', '·', '?', '?'].forEach((punctuation) => {
it(`should fail when ${punctuation} repeat`, () => {
const markdown = `好好学习,天天向上${punctuation}${punctuation}${punctuation}`;
return process(markdown).then((messages) => {
expect(messages).toEqual([
`input.md:1:11: Should not repeat "${punctuation}"`,
`input.md:1:12: Should not repeat "${punctuation}"`,
]);
});
});
});
it('should use provided puncutation list', () => {
const markdown = '好好学习!!!天天向上。。。';
return process(markdown, '。').then((messages) => {
expect(messages).toEqual([
'input.md:1:13: Should not repeat "。"',
'input.md:1:14: Should not repeat "。"',
]);
});
});
it('should not handle text inside inline code', () => {
const markdown = 'correct: `../` wrong: ...';
return process(markdown).then((messages) => {
expect(messages).toEqual([
'input.md:1:24: Should not repeat "."',
'input.md:1:25: Should not repeat "."',
]);
});
});
it('should handle series of inline blocks with punctuation inside correctly', () => {
const markdown = [
'HTML 的标签有:`div`,`span`,`img`,`a` 等。',
'HTML 的标签还有:`main`,`article`,`aside`,`footer` 等。。。',
].join('\n');
return process(markdown).then((messages) => {
expect(messages).toEqual([
'input.md:2:48: Should not repeat "。"',
'input.md:2:49: Should not repeat "。"',
]);
});
});
});