Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add unicode-range tests.
  • Loading branch information
SimonSapin committed Feb 14, 2017
commit 8e867217d5023a1ad1a81ac96ea0ed4efcb60bd0
7 changes: 7 additions & 0 deletions src/css-parsing-tests/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ associated with the expected result.
the output as null for invalid syntax,
or an array of two integers ``[A, B]``.

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


Result representation
=====================
Expand Down
81 changes: 81 additions & 0 deletions src/css-parsing-tests/urange.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[

"u+1, U+10, U+100, U+1000, U+10000, U+100000, U+1000000", [
[1, 1],
[16, 16],
[256, 256],
[4096, 4096],
[65536, 65536],
[1048576, 1048576],
null
],

"u+?, u+1?, U+10?, U+100?, U+1000?, U+10000?, U+100000?", [
[0, 15],
[16, 31],
[256, 271],
[4096, 4111],
[65536, 65551],
[1048576, 1048591],
null
],

"u+??, U+1??, U+10??, U+100??, U+1000??, U+10000??", [
[0, 255],
[256, 511],
[4096, 4351],
[65536, 65791],
[1048576, 1048831],
null
],

"u+???, U+1???, U+10???, U+100???, U+1000???", [
[0, 4095],
[4096, 8191],
[65536, 69631],
[1048576, 1052671],
null
],

"u+????, U+1????, U+10????, U+100????", [
[0, 65535],
[65536, 131071],
[1048576, 1114111],
null
],

"u+?????, U+1?????, U+10?????", [
[0, 1048575],
null,
null
],

"u+??????, U+1??????", [
null,
null
],


"u+20-3F, u+3F-3F, u+3F-3E, U+0-110000, U+0-10FFFF, U+100000-2, U+1000000-2, U+10-200000", [
[32, 63],
[63, 63],
null,
null,
[0, 1114111],
null,
null,
null
],

"ù+12, Ü+12, u +12, U+ 12, U+12 - 20, U+1?2, U+1?-50, U+1- 2", [
null,
null,
null,
null,
null,
null,
null,
null
]

]
17 changes: 16 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use super::{Parser, Delimiter, Token, NumericValue, PercentageValue, SourceLocat
parse_one_declaration, parse_one_rule, parse_important,
stylesheet_encoding, EncodingSupport,
TokenSerializationType,
Color, RGBA, parse_nth, ToCss};
Color, RGBA, parse_nth, UnicodeRange, ToCss};

macro_rules! JArray {
($($e: expr,)*) => { JArray![ $( $e ),* ] };
Expand Down Expand Up @@ -350,6 +350,21 @@ fn nth() {
});
}

#[test]
fn unicode_range() {
run_json_tests(include_str!("css-parsing-tests/urange.json"), |input| {
input.parse_comma_separated(|input| {
let result = UnicodeRange::parse(input).ok().map(|r| (r.start, r.end));
if input.is_exhausted() {
Ok(result)
} else {
while let Ok(_) = input.next() {}
Ok(None)
}
}).unwrap().to_json()
});
}


#[test]
fn serializer_not_preserving_comments() {
Expand Down