Skip to content

Commit 78938c9

Browse files
committed
Add unicode-range tests.
1 parent 067eab1 commit 78938c9

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

src/css-parsing-tests/README.rst

+7
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ associated with the expected result.
142142
the output as null for invalid syntax,
143143
or an array of two integers ``[A, B]``.
144144

145+
``urange.json``
146+
Tests the `urange <https://drafts.csswg.org/css-syntax-3/#urange>`_
147+
syntax defined in CSS Syntax Level 3.
148+
The Unicode input is represented by a JSON string,
149+
the output as null for invalid syntax,
150+
or an array of two integers ``[start, end]``.
151+
145152

146153
Result representation
147154
=====================

src/css-parsing-tests/urange.json

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
[
2+
3+
"u+1, U+10, U+100, U+1000, U+10000, U+100000, U+1000000", [
4+
[1, 1],
5+
[16, 16],
6+
[256, 256],
7+
[4096, 4096],
8+
[65536, 65536],
9+
[1048576, 1048576],
10+
null
11+
],
12+
13+
"u+?, u+1?, U+10?, U+100?, U+1000?, U+10000?, U+100000?", [
14+
[0, 15],
15+
[16, 31],
16+
[256, 271],
17+
[4096, 4111],
18+
[65536, 65551],
19+
[1048576, 1048591],
20+
null
21+
],
22+
23+
"u+??, U+1??, U+10??, U+100??, U+1000??, U+10000??", [
24+
[0, 255],
25+
[256, 511],
26+
[4096, 4351],
27+
[65536, 65791],
28+
[1048576, 1048831],
29+
null
30+
],
31+
32+
"u+???, U+1???, U+10???, U+100???, U+1000???", [
33+
[0, 4095],
34+
[4096, 8191],
35+
[65536, 69631],
36+
[1048576, 1052671],
37+
null
38+
],
39+
40+
"u+????, U+1????, U+10????, U+100????", [
41+
[0, 65535],
42+
[65536, 131071],
43+
[1048576, 1114111],
44+
null
45+
],
46+
47+
"u+?????, U+1?????, U+10?????", [
48+
[0, 1048575],
49+
null,
50+
null
51+
],
52+
53+
"u+??????, U+1??????", [
54+
null,
55+
null
56+
],
57+
58+
59+
"u+20-3F, u+3F-3F, u+3F-3E, U+0-110000, U+0-10FFFF, U+100000-2, U+1000000-2, U+10-200000", [
60+
[32, 63],
61+
[63, 63],
62+
null,
63+
null,
64+
[0, 1114111],
65+
null,
66+
null,
67+
null
68+
],
69+
70+
"ù+12, Ü+12, u +12, U+ 12, U+12 - 20, U+1?2, U+1?-50, U+1- 2", [
71+
null,
72+
null,
73+
null,
74+
null,
75+
null,
76+
null,
77+
null,
78+
null
79+
]
80+
81+
]

src/tests.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use super::{Parser, Delimiter, Token, NumericValue, PercentageValue, SourceLocat
2323
parse_one_declaration, parse_one_rule, parse_important,
2424
stylesheet_encoding, EncodingSupport,
2525
TokenSerializationType,
26-
Color, RGBA, parse_nth, ToCss};
26+
Color, RGBA, parse_nth, UnicodeRange, ToCss};
2727

2828
macro_rules! JArray {
2929
($($e: expr,)*) => { JArray![ $( $e ),* ] };
@@ -358,6 +358,21 @@ fn nth() {
358358
});
359359
}
360360

361+
#[test]
362+
fn unicode_range() {
363+
run_json_tests(include_str!("css-parsing-tests/urange.json"), |input| {
364+
input.parse_comma_separated(|input| {
365+
let result = UnicodeRange::parse(input).ok().map(|r| (r.start, r.end));
366+
if input.is_exhausted() {
367+
Ok(result)
368+
} else {
369+
while let Ok(_) = input.next() {}
370+
Ok(None)
371+
}
372+
}).unwrap().to_json()
373+
});
374+
}
375+
361376

362377
#[test]
363378
fn serializer_not_preserving_comments() {

0 commit comments

Comments
 (0)