Handle arbitrary attribute modifiers (kinda)

This commit is contained in:
ConnorSkees 2020-01-26 12:23:21 -05:00
parent c183ea8c1e
commit 63dd66f0f7
3 changed files with 18 additions and 7 deletions

View File

@ -272,7 +272,7 @@ impl<'a> Lexer<'a> {
'^' => AttributeKind::StartsWith, '^' => AttributeKind::StartsWith,
'$' => AttributeKind::EndsWith, '$' => AttributeKind::EndsWith,
'*' => AttributeKind::Contains, '*' => AttributeKind::Contains,
_ => todo!("expected kind (should be error)"), _ => todo!("Expected ']'")
}; };
if kind != AttributeKind::Equals { if kind != AttributeKind::Equals {
@ -285,7 +285,7 @@ impl<'a> Lexer<'a> {
let mut case_sensitive = CaseKind::Sensitive; let mut case_sensitive = CaseKind::Sensitive;
while let Some(c) = self.buf.peek() { while let Some(c) = self.buf.peek() {
if !c.is_alphabetic() && c != &'-' && c != &'_' && c != &'"' && c != &'\'' { if c == &']' && !c.is_whitespace() {
break; break;
} }
@ -326,7 +326,6 @@ impl<'a> Lexer<'a> {
.expect("this is impossible because we have already peeked"); .expect("this is impossible because we have already peeked");
self.pos.next_char(); self.pos.next_char();
value.push(tok); value.push(tok);
self.devour_whitespace();
} }
self.devour_whitespace(); self.devour_whitespace();

View File

@ -346,8 +346,8 @@ pub(crate) enum CaseKind {
impl Display for CaseKind { impl Display for CaseKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::InsensitiveCapital => write!(f, " I"), Self::InsensitiveCapital => write!(f, "I"),
Self::InsensitiveLowercase => write!(f, " i"), Self::InsensitiveLowercase => write!(f, "i"),
Self::Sensitive => write!(f, ""), Self::Sensitive => write!(f, ""),
} }
} }

View File

@ -129,12 +129,24 @@ mod test_selectors {
test!(selector_attribute_any, "[attr] {\n color: red;\n}\n"); test!(selector_attribute_any, "[attr] {\n color: red;\n}\n");
test!( test!(
selector_attribute_any_lower_case_insensitive, selector_attribute_any_lower_case_insensitive,
"[attr i] {\n color: red;\n}\n" "[attr=val i] {\n color: red;\n}\n"
); );
test!( test!(
selector_attribute_any_upper_case_insensitive, selector_attribute_any_upper_case_insensitive,
"[attr I] {\n color: red;\n}\n" "[attr=val I] {\n color: red;\n}\n"
); );
test!(
selector_attribute_arbitrary_modifier,
"[attr=val c] {\n color: red;\n}\n"
);
test!(
selector_attribute_i_in_attr,
"[atitr=val] {\n color: red;\n}\n"
);
// test!(
// selector_attribute_i_in_val,
// "[attr=vail] {\n color: red;\n}\n"
// );
test!( test!(
selector_attribute_equals, selector_attribute_equals,
"[attr=val] {\n color: red;\n}\n" "[attr=val] {\n color: red;\n}\n"