-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
160 lines (154 loc) · 3.12 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
const TextLintTester = require('textlint-tester');
const rule = require('./index');
const { getText, updateCase } = rule.test;
const tester = new TextLintTester();
describe('getText', () => {
test('ATX style headers', () => {
expect(getText({
type: 'Header',
depth: 1,
raw: '# This Is a Title',
range: [0, 17],
children: [{
type: 'Str',
value: 'This Is a Title',
range: [1, 17],
}],
})).toBe('This Is a Title');
expect(getText({
type: 'Header',
depth: 2,
raw: '## This Is a Subtitle',
range: [0, 21],
children: [{
type: 'Str',
value: 'This Is a Subtitle',
range: [2, 21],
}],
})).toBe('This Is a Subtitle');
});
});
describe('updateCase', () => {
test('exclude', () => {
expect(updateCase('what is an npm package', ['npm'])).toBe('What Is an npm Package');
});
test('ignore case', () => {
expect(updateCase('new webpack version', ['webpack'])).toBe('New webpack Version');
expect(updateCase('foo a bar', ['A'])).toBe('Foo A Bar');
});
});
tester.run('textlint-rule-terminology', rule, {
valid: [
{
text: '# This Is a Title\n\n## This Is a Subtitle',
},
{
text: 'This Is a Title\n===\n\nThis Is a Subtitle\n---',
},
{
text: '# This **Is a** Title',
},
{
text: '# _This Is a Title_',
},
],
invalid: [
{
text: '# This is a title',
output: '# This Is a Title',
errors: [
{
message: 'Incorrect title casing: “This is a title”, use “This Is a Title” instead',
},
],
},
{
text: '# _This is a title_',
output: '# _This Is a Title_',
errors: [
{
message: 'Incorrect title casing: “This is a title”, use “This Is a Title” instead',
},
],
},
{
text: '# _**This is a title**_',
output: '# _**This Is a Title**_',
errors: [
{
message: 'Incorrect title casing: “This is a title”, use “This Is a Title” instead',
},
],
},
],
});
tester.run(
'textlint-rule-title-case',
{
rules: [
{
ruleId: 'title-case',
rule,
options: {
headingLevels: [1]
},
},
],
},
{
valid: [
{
// The rule should only be applied on document title (level 1)
// The document title (level 1) is using AP/APA title case but the section title (level 2) is *not*
text: '# This Is a Title\n\n## This is a subtitle',
},
],
invalid: [
{
text: '# This is a title\n\n## This Is a Subtitle',
output: '# This Is a Title\n\n## This Is a Subtitle',
errors: [
{
message:
'Incorrect title casing: “This is a title”, use “This Is a Title” instead',
},
],
},
],
}
);
tester.run(
'textlint-rule-title-case',
{
rules: [
{
ruleId: 'title-case',
rule,
options: {
exclude: [
'reveal.js'
]
},
},
],
},
{
valid: [
{
text: '# reveal.js Configuration Options',
},
],
invalid: [
{
text: '# node.js Configuration Options',
output: '# Node.js Configuration Options',
errors: [
{
message:
'Incorrect title casing: “node.js Configuration Options”, use “Node.js Configuration Options” instead',
},
],
},
],
}
);