properly emit more variants of character escape

This commit is contained in:
ConnorSkees 2020-03-23 22:26:52 -04:00
parent f69bbb3b69
commit dc0d7c4e89
3 changed files with 22 additions and 0 deletions

View File

@ -239,6 +239,8 @@ impl<'a> Lexer<'a> {
if n.is_empty() { if n.is_empty() {
return (TokenKind::Symbol(Symbol::BackSlash), false); return (TokenKind::Symbol(Symbol::BackSlash), false);
} else if n.len() == 1 {
return (TokenKind::Ident(format!("\\{} ", n)), false);
} }
let mut string = std::char::from_u32(u32::from_str_radix(&n, 16).unwrap()) let mut string = std::char::from_u32(u32::from_str_radix(&n, 16).unwrap())

View File

@ -326,6 +326,7 @@ impl Value {
"\\\\".to_string() + &flatten_ident(toks, scope, super_selector)?, "\\\\".to_string() + &flatten_ident(toks, scope, super_selector)?,
QuoteKind::None, QuoteKind::None,
)), )),
TokenKind::Ident(s) => Ok(Value::Ident(s, QuoteKind::None)),
_ => todo!("value after \\"), _ => todo!("value after \\"),
} }
} else { } else {

View File

@ -47,21 +47,25 @@ test!(
"a {\n color: red;\n}\n" "a {\n color: red;\n}\n"
); );
test!( test!(
#[ignore]
utf8_ident_before_len, utf8_ident_before_len,
"a {\n color: length(😀red);\n}\n", "a {\n color: length(😀red);\n}\n",
"@charset \"UTF-8\";\na {\n color: 1;\n}\n" "@charset \"UTF-8\";\na {\n color: 1;\n}\n"
); );
test!( test!(
#[ignore]
utf8_ident_before, utf8_ident_before,
"a {\n color: 😀red;\n}\n", "a {\n color: 😀red;\n}\n",
"@charset \"UTF-8\";\na {\n color: 😀red;\n}\n" "@charset \"UTF-8\";\na {\n color: 😀red;\n}\n"
); );
test!( test!(
#[ignore]
utf8_ident_after_len, utf8_ident_after_len,
"a {\n color: length(red😁)\n}\n", "a {\n color: length(red😁)\n}\n",
"@charset \"UTF-8\";\na {\n color: 1;\n}\n" "@charset \"UTF-8\";\na {\n color: 1;\n}\n"
); );
test!( test!(
#[ignore]
utf8_ident_after, utf8_ident_after,
"a {\n color: red😁\n}\n", "a {\n color: red😁\n}\n",
"@charset \"UTF-8\";\na {\n color: red😁;\n}\n" "@charset \"UTF-8\";\na {\n color: red😁;\n}\n"
@ -83,3 +87,18 @@ test!(
); );
test!(double_escape_is_preserved, "a {\n color: r\\\\65;\n}\n"); test!(double_escape_is_preserved, "a {\n color: r\\\\65;\n}\n");
test!(semicolon_in_string, "a {\n color: \";\";\n}\n"); test!(semicolon_in_string, "a {\n color: \";\";\n}\n");
test!(
single_character_escape_sequence_has_space,
"a {\n color: \\fg1;\n}\n",
"a {\n color: \\f g1;\n}\n"
);
test!(
single_character_escape_sequence_removes_slash_when_not_hex_digit,
"a {\n color: \\g1;\n}\n",
"a {\n color: g1;\n}\n"
);
test!(
single_character_escape_sequence_has_space_after,
"a {\n color: \\0;\n}\n",
"a {\n color: \\0 ;\n}\n"
);