@markuplint/rules 3.8.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/helpers.d.ts +2 -5
- package/lib/index.d.ts +240 -99
- package/lib/permitted-contents/utils.d.ts +90 -41
- package/lib/wai-aria/checkings/_.d.ts +12 -6
- package/lib/wai-aria/checkings/disallowed-prop.d.ts +8 -4
- package/lib/wai-aria/checkings/required-prop copy.d.ts +12 -6
- package/lib/wai-aria/checkings/unadopted-explicit-roles.d.ts +12 -6
- package/lib/xxx/index.d.ts +2 -0
- package/lib/xxx/index.js +32 -0
- package/package.json +11 -13
- package/test/attr-check.spec.js +77 -0
- package/test/attr-duplication/index.spec.js +159 -0
- package/test/attr-value-quotes/index.spec.js +133 -0
- package/test/case-sensitive-attr-name/index.spec.js +65 -0
- package/test/case-sensitive-tag-name/index.spec.js +80 -0
- package/test/character-reference/index.spec.js +57 -0
- package/test/class-naming/index.spec.js +470 -0
- package/test/create-message.spec.js +497 -0
- package/test/deprecated-attr/index.spec.js +48 -0
- package/test/deprecated-element/index.spec.js +48 -0
- package/test/disallowed-element/index.spec.js +90 -0
- package/test/doctype/index.spec.js +50 -0
- package/test/end-tag/index.spec.js +162 -0
- package/test/id-duplication/index.spec.js +47 -0
- package/test/ineffective-attr/index.spec.js +31 -0
- package/test/invalid-attr/index.spec.js +1632 -0
- package/test/label-has-control/index.spec.js +29 -0
- package/test/landmark-roles/index.spec.js +187 -0
- package/test/no-boolean-attr-value/index.spec.js +41 -0
- package/test/no-default-value/index.spec.js +74 -0
- package/test/no-empty-palpable-content/index.spec.js +115 -0
- package/test/no-hard-code-id/index.spec.js +100 -0
- package/test/no-refer-to-non-existent-id/index.spec.js +254 -0
- package/test/no-use-event-handler-attr/index.spec.js +57 -0
- package/test/permitted-contents/choice.spec.js +174 -0
- package/test/permitted-contents/count-pattern.spec.js +308 -0
- package/test/permitted-contents/index.spec.js +1371 -0
- package/test/permitted-contents/matches-selector.spec.js +59 -0
- package/test/permitted-contents/order.spec.js +351 -0
- package/test/permitted-contents/recursive-branch.spec.js +41 -0
- package/test/permitted-contents/represent-transparent-nodes.spec.js +24 -0
- package/test/permitted-contents/start.spec.js +67 -0
- package/test/placeholder-label-option/index.spec.js +113 -0
- package/test/require-accessible-name/index.spec.js +446 -0
- package/test/require-datetime/index.spec.js +54 -0
- package/test/require-datetime/utils.spec.js +52 -0
- package/test/required-attr/index.spec.js +414 -0
- package/test/required-element/index.spec.js +188 -0
- package/test/required-h1/index.spec.js +69 -0
- package/test/use-list/index.spec.js +109 -0
- package/test/wai-aria/checkings/value.spec.js +33 -0
- package/test/wai-aria/index.spec.js +1173 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
const specs = require('@markuplint/html-spec');
|
|
2
|
+
const { createTestElement } = require('@markuplint/ml-core');
|
|
3
|
+
|
|
4
|
+
const { countPattern } = require('../../lib/permitted-contents/count-pattern');
|
|
5
|
+
|
|
6
|
+
function c(models, innerHtml) {
|
|
7
|
+
const el = createTestElement(`<div>${innerHtml}</div>`);
|
|
8
|
+
return countPattern(models, Array.from(el.childNodes), specs, { ignoreHasMutableChildren: true }, 0);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
it('require: a', () => {
|
|
12
|
+
expect(c({ require: 'a' }, '<a></a>').type).toBe('MATCHED');
|
|
13
|
+
expect(c({ require: 'a' }, '<b></b>').type).toBe('MISSING_NODE_REQUIRED');
|
|
14
|
+
expect(c({ require: 'a' }, '<c></c>').type).toBe('MISSING_NODE_REQUIRED');
|
|
15
|
+
expect(c({ require: 'a' }, 'text').type).toBe('MISSING_NODE_REQUIRED');
|
|
16
|
+
expect(c({ require: 'a' }, '').type).toBe('MISSING_NODE_REQUIRED');
|
|
17
|
+
|
|
18
|
+
expect(c({ require: 'a' }, '<a></a>').matched.length).toBe(1);
|
|
19
|
+
expect(c({ require: 'a' }, '<b></b>').matched.length).toBe(0);
|
|
20
|
+
expect(c({ require: 'a' }, '<c></c>').matched.length).toBe(0);
|
|
21
|
+
expect(c({ require: 'a' }, 'text').matched.length).toBe(0);
|
|
22
|
+
expect(c({ require: 'a' }, '').matched.length).toBe(0);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('optional: a', () => {
|
|
26
|
+
expect(c({ optional: 'a' }, '<a></a>').type).toBe('MATCHED');
|
|
27
|
+
expect(c({ optional: 'a' }, '<a></a><a></a>').type).toBe('UNEXPECTED_EXTRA_NODE');
|
|
28
|
+
expect(c({ optional: 'a' }, '<b></b>').type).toBe('MATCHED_ZERO');
|
|
29
|
+
expect(c({ optional: 'a' }, '<c></c>').type).toBe('MATCHED_ZERO');
|
|
30
|
+
expect(c({ optional: 'a' }, 'text').type).toBe('MATCHED_ZERO');
|
|
31
|
+
expect(c({ optional: 'a' }, '').type).toBe('MATCHED_ZERO');
|
|
32
|
+
|
|
33
|
+
expect(c({ optional: 'a' }, '<a></a>').matched.length).toBe(1);
|
|
34
|
+
expect(c({ optional: 'a' }, '<a></a><a></a>').matched.length).toBe(1);
|
|
35
|
+
expect(c({ optional: 'a' }, '<b></b>').matched.length).toBe(0);
|
|
36
|
+
expect(c({ optional: 'a' }, '<c></c>').matched.length).toBe(0);
|
|
37
|
+
expect(c({ optional: 'a' }, 'text').matched.length).toBe(0);
|
|
38
|
+
expect(c({ optional: 'a' }, '').matched.length).toBe(0);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('oneOrMore: a', () => {
|
|
42
|
+
expect(c({ oneOrMore: 'a' }, '<a></a>').type).toBe('MATCHED');
|
|
43
|
+
expect(c({ oneOrMore: 'a' }, '<b></b>').type).toBe('MISSING_NODE_ONE_OR_MORE');
|
|
44
|
+
expect(c({ oneOrMore: 'a' }, '<c></c>').type).toBe('MISSING_NODE_ONE_OR_MORE');
|
|
45
|
+
expect(c({ oneOrMore: 'a' }, 'text').type).toBe('MISSING_NODE_ONE_OR_MORE');
|
|
46
|
+
expect(c({ oneOrMore: 'a' }, '').type).toBe('MISSING_NODE_ONE_OR_MORE');
|
|
47
|
+
|
|
48
|
+
expect(c({ oneOrMore: 'a' }, '<a></a>').matched.length).toBe(1);
|
|
49
|
+
expect(c({ oneOrMore: 'a' }, '<b></b>').matched.length).toBe(0);
|
|
50
|
+
expect(c({ oneOrMore: 'a' }, '<c></c>').matched.length).toBe(0);
|
|
51
|
+
expect(c({ oneOrMore: 'a' }, 'text').matched.length).toBe(0);
|
|
52
|
+
expect(c({ oneOrMore: 'a' }, '').matched.length).toBe(0);
|
|
53
|
+
|
|
54
|
+
expect(c({ oneOrMore: 'a' }, '<a></a><a></a><a></a>').matched.length).toBe(3);
|
|
55
|
+
expect(c({ oneOrMore: 'a' }, '<a></a><a></a><b></b>').matched.length).toBe(2);
|
|
56
|
+
expect(c({ oneOrMore: 'a' }, '<a></a><c></c><c></c>').matched.length).toBe(1);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('zeroOrMore: a', () => {
|
|
60
|
+
expect(c({ zeroOrMore: 'a' }, '<a></a>').type).toBe('MATCHED');
|
|
61
|
+
expect(c({ zeroOrMore: 'a' }, '<b></b>').type).toBe('MATCHED_ZERO');
|
|
62
|
+
expect(c({ zeroOrMore: 'a' }, '<c></c>').type).toBe('MATCHED_ZERO');
|
|
63
|
+
expect(c({ zeroOrMore: 'a' }, 'text').type).toBe('MATCHED_ZERO');
|
|
64
|
+
expect(c({ zeroOrMore: 'a' }, '').type).toBe('MATCHED_ZERO');
|
|
65
|
+
|
|
66
|
+
expect(c({ zeroOrMore: 'a' }, '<a></a>').matched.length).toBe(1);
|
|
67
|
+
expect(c({ zeroOrMore: 'a' }, '<b></b>').matched.length).toBe(0);
|
|
68
|
+
expect(c({ zeroOrMore: 'a' }, '<c></c>').matched.length).toBe(0);
|
|
69
|
+
expect(c({ zeroOrMore: 'a' }, 'text').matched.length).toBe(0);
|
|
70
|
+
expect(c({ zeroOrMore: 'a' }, '').matched.length).toBe(0);
|
|
71
|
+
|
|
72
|
+
expect(c({ zeroOrMore: 'a' }, '<a></a><a></a><a></a>').matched.length).toBe(3);
|
|
73
|
+
expect(c({ zeroOrMore: 'a' }, '<a></a><a></a><b></b>').matched.length).toBe(2);
|
|
74
|
+
expect(c({ zeroOrMore: 'a' }, '<a></a><c></c><c></c>').matched.length).toBe(1);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('require: #flow', () => {
|
|
78
|
+
expect(c({ require: '#flow' }, '<a></a>').type).toBe('MATCHED');
|
|
79
|
+
expect(c({ require: '#flow' }, '<b></b>').type).toBe('MATCHED');
|
|
80
|
+
expect(c({ require: '#flow' }, '<c></c>').type).toBe('MATCHED_ZERO');
|
|
81
|
+
expect(c({ require: '#flow' }, 'text').type).toBe('MATCHED');
|
|
82
|
+
expect(c({ require: '#flow' }, '').type).toBe('MATCHED_ZERO');
|
|
83
|
+
|
|
84
|
+
expect(c({ require: '#flow' }, '<a></a>').matched.length).toBe(1);
|
|
85
|
+
expect(c({ require: '#flow' }, '<b></b>').matched.length).toBe(1);
|
|
86
|
+
expect(c({ require: '#flow' }, '<c></c>').matched.length).toBe(0);
|
|
87
|
+
expect(c({ require: '#flow' }, 'text').matched.length).toBe(1);
|
|
88
|
+
expect(c({ require: '#flow' }, '').matched.length).toBe(0);
|
|
89
|
+
|
|
90
|
+
expect(c({ require: '#flow' }, '<a></a><a></a><a></a>').matched.length).toBe(1);
|
|
91
|
+
expect(c({ require: '#flow' }, '<b></b><a></a>').matched.length).toBe(1);
|
|
92
|
+
expect(c({ require: '#flow' }, '<c></c><a></a>').matched.length).toBe(0);
|
|
93
|
+
expect(c({ require: '#flow' }, 'text<a></a>').matched.length).toBe(1);
|
|
94
|
+
expect(c({ require: '#flow' }, '<a></a>').matched.length).toBe(1);
|
|
95
|
+
|
|
96
|
+
expect(c({ require: '#flow' }, '<a></a><a></a>').matched[0].nodeName).toBe('A');
|
|
97
|
+
expect(c({ require: '#flow' }, '<b></b><a></a>').matched[0].nodeName).toBe('B');
|
|
98
|
+
expect(c({ require: '#flow' }, 'text<a></a>').matched[0].nodeName).toBe('#text');
|
|
99
|
+
expect(c({ require: '#flow' }, '<a></a>').matched[0].nodeName).toBe('A');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('optional: #flow', () => {
|
|
103
|
+
expect(c({ optional: '#flow' }, '<a></a>').type).toBe('MATCHED');
|
|
104
|
+
expect(c({ optional: '#flow' }, '<b></b>').type).toBe('MATCHED');
|
|
105
|
+
expect(c({ optional: '#flow' }, '<c></c>').type).toBe('MATCHED_ZERO');
|
|
106
|
+
expect(c({ optional: '#flow' }, 'text').type).toBe('MATCHED');
|
|
107
|
+
expect(c({ optional: '#flow' }, '').type).toBe('MATCHED_ZERO');
|
|
108
|
+
|
|
109
|
+
expect(c({ optional: '#flow' }, '<a></a>').matched.length).toBe(1);
|
|
110
|
+
expect(c({ optional: '#flow' }, '<b></b>').matched.length).toBe(1);
|
|
111
|
+
expect(c({ optional: '#flow' }, '<c></c>').matched.length).toBe(0);
|
|
112
|
+
expect(c({ optional: '#flow' }, 'text').matched.length).toBe(1);
|
|
113
|
+
expect(c({ optional: '#flow' }, '').matched.length).toBe(0);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('oneOrMore: #flow', () => {
|
|
117
|
+
expect(c({ oneOrMore: '#flow' }, '<a></a>').type).toBe('MATCHED');
|
|
118
|
+
expect(c({ oneOrMore: '#flow' }, '<b></b>').type).toBe('MATCHED');
|
|
119
|
+
expect(c({ oneOrMore: '#flow' }, '<c></c>').type).toBe('MATCHED_ZERO');
|
|
120
|
+
expect(c({ oneOrMore: '#flow' }, 'text').type).toBe('MATCHED');
|
|
121
|
+
expect(c({ oneOrMore: '#flow' }, '').type).toBe('MATCHED_ZERO');
|
|
122
|
+
|
|
123
|
+
expect(c({ oneOrMore: '#flow' }, '<a></a>').matched.length).toBe(1);
|
|
124
|
+
expect(c({ oneOrMore: '#flow' }, '<b></b>').matched.length).toBe(1);
|
|
125
|
+
expect(c({ oneOrMore: '#flow' }, '<c></c>').matched.length).toBe(0);
|
|
126
|
+
expect(c({ oneOrMore: '#flow' }, 'text').matched.length).toBe(1);
|
|
127
|
+
expect(c({ oneOrMore: '#flow' }, '').matched.length).toBe(0);
|
|
128
|
+
|
|
129
|
+
expect(c({ oneOrMore: '#flow' }, '<a></a><a></a><a></a>').matched.length).toBe(3);
|
|
130
|
+
expect(c({ oneOrMore: '#flow' }, '<a></a><a></a><b></b>').matched.length).toBe(3);
|
|
131
|
+
expect(c({ oneOrMore: '#flow' }, '<a></a><c></c><c></c>').matched.length).toBe(1);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('zeroOrMore: #flow', () => {
|
|
135
|
+
expect(c({ zeroOrMore: '#flow' }, '<a></a>').type).toBe('MATCHED');
|
|
136
|
+
expect(c({ zeroOrMore: '#flow' }, '<b></b>').type).toBe('MATCHED');
|
|
137
|
+
expect(c({ zeroOrMore: '#flow' }, '<c></c>').type).toBe('MATCHED_ZERO');
|
|
138
|
+
expect(c({ zeroOrMore: '#flow' }, 'text').type).toBe('MATCHED');
|
|
139
|
+
expect(c({ zeroOrMore: '#flow' }, '').type).toBe('MATCHED_ZERO');
|
|
140
|
+
|
|
141
|
+
expect(c({ zeroOrMore: '#flow' }, '<a></a>').matched.length).toBe(1);
|
|
142
|
+
expect(c({ zeroOrMore: '#flow' }, '<b></b>').matched.length).toBe(1);
|
|
143
|
+
expect(c({ zeroOrMore: '#flow' }, '<c></c>').matched.length).toBe(0);
|
|
144
|
+
expect(c({ zeroOrMore: '#flow' }, 'text').matched.length).toBe(1);
|
|
145
|
+
expect(c({ zeroOrMore: '#flow' }, '').matched.length).toBe(0);
|
|
146
|
+
|
|
147
|
+
expect(c({ zeroOrMore: '#flow' }, '<a></a><a></a><a></a>').matched.length).toBe(3);
|
|
148
|
+
expect(c({ zeroOrMore: '#flow' }, '<a></a><a></a><b></b>').matched.length).toBe(3);
|
|
149
|
+
expect(c({ zeroOrMore: '#flow' }, '<a></a><c></c><c></c>').matched.length).toBe(1);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('zeroOrMore: :model(script-supporting)', () => {
|
|
153
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, '<a></a>').type).toBe('MATCHED_ZERO');
|
|
154
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, '<b></b>').type).toBe('MATCHED_ZERO');
|
|
155
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, '<c></c>').type).toBe('MATCHED_ZERO');
|
|
156
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, 'text').type).toBe('MATCHED_ZERO');
|
|
157
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, '').type).toBe('MATCHED_ZERO');
|
|
158
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, '<script></script>').type).toBe('MATCHED');
|
|
159
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, '<template></template>').type).toBe('MATCHED');
|
|
160
|
+
|
|
161
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, '<a></a>').matched.length).toBe(0);
|
|
162
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, '<b></b>').matched.length).toBe(0);
|
|
163
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, '<c></c>').matched.length).toBe(0);
|
|
164
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, 'text').matched.length).toBe(0);
|
|
165
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, '').matched.length).toBe(0);
|
|
166
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, '<script></script>').matched.length).toBe(1);
|
|
167
|
+
expect(c({ zeroOrMore: ':model(script-supporting)' }, '<template></template>').matched.length).toBe(1);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('min/max', () => {
|
|
171
|
+
expect(c({ require: 'c', min: 2 }, '').type).toBe('MISSING_NODE_REQUIRED');
|
|
172
|
+
expect(c({ require: 'c', min: 2 }, '<c></c>').type).toBe('MISSING_NODE_REQUIRED');
|
|
173
|
+
expect(c({ require: 'c', min: 2 }, '<c></c><c></c>').type).toBe('MATCHED');
|
|
174
|
+
expect(c({ require: 'c', max: 1 }, '<c></c><c></c>').type).toBe('UNEXPECTED_EXTRA_NODE');
|
|
175
|
+
expect(c({ require: 'c', max: 1 }, '<c></c><c></c>').hint?.max).toBe(1);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('the dl element', () => {
|
|
179
|
+
const models = {
|
|
180
|
+
oneOrMore: [
|
|
181
|
+
{
|
|
182
|
+
zeroOrMore: ':model(script-supporting)',
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
oneOrMore: 'dt',
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
zeroOrMore: ':model(script-supporting)',
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
oneOrMore: 'dd',
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
zeroOrMore: ':model(script-supporting)',
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
expect(c(models, '<dt></dt>').type).toBe('MISSING_NODE_ONE_OR_MORE');
|
|
200
|
+
expect(c(models, '<dd></dd>').type).toBe('MISSING_NODE_ONE_OR_MORE');
|
|
201
|
+
expect(c(models, '<dt></dt><dd></dd>').type).toBe('MATCHED');
|
|
202
|
+
expect(c(models, '<dt></dt><dt></dt><dd></dd>').type).toBe('MATCHED');
|
|
203
|
+
expect(c(models, '<dt></dt><dd></dd><dd></dd>').type).toBe('MATCHED');
|
|
204
|
+
expect(c(models, '<dt></dt><dd></dd><dd></dd><dt></dt>').type).toBe('MISSING_NODE_ONE_OR_MORE');
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('part of the ruby element', () => {
|
|
208
|
+
const models = {
|
|
209
|
+
// 1. One or the other of the following:
|
|
210
|
+
oneOrMore: [
|
|
211
|
+
// - Phrasing content, but with no ruby elements and with no ruby element descendants
|
|
212
|
+
':model(phrasing):not(ruby, :has(ruby))',
|
|
213
|
+
// - A single ruby element that itself has no ruby element descendants
|
|
214
|
+
'ruby:not(:has(ruby))',
|
|
215
|
+
],
|
|
216
|
+
};
|
|
217
|
+
expect(c(models, '<span></span>').type).toBe('MATCHED');
|
|
218
|
+
expect(c(models, 'text').type).toBe('MATCHED');
|
|
219
|
+
expect(c(models, 'text<span></span>').type).toBe('MATCHED');
|
|
220
|
+
expect(c(models, 'text<span>text in span</span>').type).toBe('MATCHED');
|
|
221
|
+
expect(c(models, '<ruby></ruby>').type).toBe('MATCHED');
|
|
222
|
+
expect(c(models, '<ruby></ruby><span></span>').type).toBe('MATCHED');
|
|
223
|
+
expect(c(models, '<span><ruby></ruby></span>').type).toBe('MISSING_NODE_ONE_OR_MORE');
|
|
224
|
+
expect(c(models, '<span><ruby></ruby></span>').query).toBe('ruby:not(:has(ruby))');
|
|
225
|
+
expect(c(models, '<ruby><ruby></ruby></ruby>').type).toBe('MISSING_NODE_ONE_OR_MORE');
|
|
226
|
+
expect(c(models, '<ruby><ruby></ruby></ruby>').query).toBe('ruby:not(:has(ruby))');
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('part of the ruby element', () => {
|
|
230
|
+
const models = {
|
|
231
|
+
// The content model of ruby elements consists of one or more of the following sequences:
|
|
232
|
+
oneOrMore: [
|
|
233
|
+
{
|
|
234
|
+
// 1. One or the other of the following:
|
|
235
|
+
oneOrMore: [
|
|
236
|
+
// - Phrasing content, but with no ruby elements and with no ruby element descendants
|
|
237
|
+
':model(phrasing):not(ruby, :has(ruby))',
|
|
238
|
+
// - A single ruby element that itself has no ruby element descendants
|
|
239
|
+
'ruby:not(:has(rt, rp))',
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
// 2. One or the other of the following:
|
|
244
|
+
choice: [
|
|
245
|
+
[
|
|
246
|
+
{
|
|
247
|
+
// - One or more rt elements
|
|
248
|
+
oneOrMore: 'rt',
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
[
|
|
252
|
+
{
|
|
253
|
+
// - An rp element
|
|
254
|
+
require: 'rp',
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
// followed by one or more rt elements, each of which is itself followed by an rp element
|
|
258
|
+
oneOrMore: [
|
|
259
|
+
{
|
|
260
|
+
require: 'rt',
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
require: 'rp',
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
],
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
expect(c(models, '<span></span>').type).toBe('MISSING_NODE_ONE_OR_MORE');
|
|
274
|
+
expect(c(models, '<span></span>').query).toBe('rt');
|
|
275
|
+
expect(c(models, '<span></span><rp></rp><rt></rt><rp></rp>').type).toBe('MATCHED');
|
|
276
|
+
expect(c(models, '<span></span><rp></rp><rt></rt>').type).toBe('MISSING_NODE_REQUIRED');
|
|
277
|
+
expect(c(models, '<span></span><rp></rp><rt></rt>').query).toBe('rp');
|
|
278
|
+
expect(c(models, '<span></span><rp></rp><rt></rt><rp></rp>').type).toBe('MATCHED');
|
|
279
|
+
expect(c(models, '<span></span><rp></rp><rt></rt><rp></rp><span></span><span></span>').type).toBe(
|
|
280
|
+
'UNEXPECTED_EXTRA_NODE',
|
|
281
|
+
);
|
|
282
|
+
expect(c(models, '<span></span><rp></rp><rt></rt><rp></rp><span></span><span></span>').query).toBe('rp');
|
|
283
|
+
expect(c(models, '<span></span><rt></rt><span></span><rt></rt>').type).toBe('MATCHED');
|
|
284
|
+
expect(c(models, 'text<rt></rt>text2<rt></rt>').type).toBe('MATCHED');
|
|
285
|
+
expect(c(models, 'text<rt></rt><rt></rt>text2<rt></rt><rt></rt>').type).toBe('MATCHED');
|
|
286
|
+
expect(c(models, 'text<rp></rp><rt></rt><rp></rp>text2<rt></rt>').type).toBe('MATCHED');
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('part of the ruby element', () => {
|
|
290
|
+
const models = {
|
|
291
|
+
// followed by one or more rt elements, each of which is itself followed by an rp element
|
|
292
|
+
oneOrMore: [
|
|
293
|
+
{
|
|
294
|
+
require: 'rt',
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
require: 'rp',
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
expect(c(models, '<rt></rt>').type).toBe('MISSING_NODE_REQUIRED');
|
|
303
|
+
expect(c(models, '<rt></rt>').query).toBe('rp');
|
|
304
|
+
expect(c(models, '<rt></rt><rp></rp>').type).toBe('MATCHED');
|
|
305
|
+
expect(c(models, '<rt></rt><rp></rp><rt></rt>').type).toBe('MISSING_NODE_REQUIRED');
|
|
306
|
+
expect(c(models, '<rt></rt><rp></rp><rt></rt>').query).toBe('rp');
|
|
307
|
+
expect(c(models, '<rt></rt><rp></rp><rt></rt><rp></rp>').type).toBe('MATCHED');
|
|
308
|
+
});
|