From 63dd66f0f7ca4c3f3321c0e50286cbda8a16d816 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 26 Jan 2020 12:23:21 -0500 Subject: [PATCH] Handle arbitrary attribute modifiers (kinda) --- src/lexer.rs | 5 ++--- src/selector.rs | 4 ++-- tests/main.rs | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/lexer.rs b/src/lexer.rs index 2367d16..8c3bf83 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -272,7 +272,7 @@ impl<'a> Lexer<'a> { '^' => AttributeKind::StartsWith, '$' => AttributeKind::EndsWith, '*' => AttributeKind::Contains, - _ => todo!("expected kind (should be error)"), + _ => todo!("Expected ']'") }; if kind != AttributeKind::Equals { @@ -285,7 +285,7 @@ impl<'a> Lexer<'a> { let mut case_sensitive = CaseKind::Sensitive; while let Some(c) = self.buf.peek() { - if !c.is_alphabetic() && c != &'-' && c != &'_' && c != &'"' && c != &'\'' { + if c == &']' && !c.is_whitespace() { break; } @@ -326,7 +326,6 @@ impl<'a> Lexer<'a> { .expect("this is impossible because we have already peeked"); self.pos.next_char(); value.push(tok); - self.devour_whitespace(); } self.devour_whitespace(); diff --git a/src/selector.rs b/src/selector.rs index 778582b..c40ae5e 100644 --- a/src/selector.rs +++ b/src/selector.rs @@ -346,8 +346,8 @@ pub(crate) enum CaseKind { impl Display for CaseKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::InsensitiveCapital => write!(f, " I"), - Self::InsensitiveLowercase => write!(f, " i"), + Self::InsensitiveCapital => write!(f, "I"), + Self::InsensitiveLowercase => write!(f, "i"), Self::Sensitive => write!(f, ""), } } diff --git a/tests/main.rs b/tests/main.rs index b3dbf1d..c3cfbc1 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -129,12 +129,24 @@ mod test_selectors { test!(selector_attribute_any, "[attr] {\n color: red;\n}\n"); test!( selector_attribute_any_lower_case_insensitive, - "[attr i] {\n color: red;\n}\n" + "[attr=val i] {\n color: red;\n}\n" ); test!( 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!( selector_attribute_equals, "[attr=val] {\n color: red;\n}\n"