Skip to content

Commit

Permalink
test: add tests for CustomFunction parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix-ru committed May 7, 2023
1 parent b7281b8 commit c2bde99
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions selectors/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,14 @@ impl<'i, Impl: SelectorImpl<'i>> Selector<'i, Impl> {
let old_len = self.1.len();
let mut old = std::mem::replace(&mut self.1, Vec::with_capacity(old_len + components.len()));

// Fast track: insert at index 0 is same as Vec::append
// Fast track: insert at index 0 is the same as Vec::append
if index == 0 {
self.1.append(&mut components);
self.1.append(&mut old);
return;
}

// Manually move first `index` elements
// Manually move the first `index` elements
let mut old_iter = old.into_iter();
let i = 0;
while let (Some(old_component), true) = (old_iter.next(), i < index) {
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6008,8 +6008,14 @@ mod tests {
"::cue(v[voice=active]){color:#ff0}",
);
minify_test(":foo(bar) { color: yellow }", ":foo(bar){color:#ff0}");
minify_test(":foo(bar baz qux) { color: yellow }", ":foo(bar baz qux){color:#ff0}");
minify_test(":foo(.bar .baz .qux) { color: yellow }", ":foo(.bar .baz .qux){color:#ff0}");
minify_test(":foo( .bar .baz .qux ) { color: yellow }", ":foo( .bar .baz .qux ){color:#ff0}");
minify_test("::foo(bar) { color: yellow }", "::foo(bar){color:#ff0}");
minify_test("::foo(*) { color: yellow }", "::foo(*){color:#ff0}");
minify_test("::foo(bar baz qux) { color: yellow }", "::foo(bar baz qux){color:#ff0}");
minify_test("::foo(.bar .baz .qux) { color: yellow }", "::foo(.bar .baz .qux){color:#ff0}");
minify_test("::foo( .bar .baz .qux ) { color: yellow }", "::foo( .bar .baz .qux ){color:#ff0}");

minify_test(":is(.foo) { color: yellow }", ".foo{color:#ff0}");
minify_test(":is(#foo) { color: yellow }", "#foo{color:#ff0}");
Expand Down
4 changes: 2 additions & 2 deletions src/properties/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl<'i> TokenList<'i> {
pub(crate) fn parse<'t>(
input: &mut Parser<'i, 't>,
options: &ParserOptions<'_, 'i>,
depth: usize
depth: usize,
) -> Result<Self, ParseError<'i, ParserError<'i>>> {
let mut tokens = vec![];
TokenList::parse_into(input, &mut tokens, options, depth, false)?;
Expand All @@ -315,7 +315,7 @@ impl<'i> TokenList<'i> {
pub(crate) fn parse_preserve_whitespace<'t>(
input: &mut Parser<'i, 't>,
options: &ParserOptions<'_, 'i>,
depth: usize
depth: usize,
) -> Result<Self, ParseError<'i, ParserError<'i>>> {
let mut tokens = vec![];
TokenList::parse_into(input, &mut tokens, options, depth, true)?;
Expand Down

0 comments on commit c2bde99

Please sign in to comment.