Skip to content

Commit e87082e

Browse files
committed
add failing tests
1 parent 4455048 commit e87082e

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

crates/oxide/src/extractor/arbitrary_property_machine.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,4 +411,26 @@ mod tests {
411411
}
412412
}
413413
}
414+
415+
#[test]
416+
fn test_exceptions() {
417+
for (input, expected) in [
418+
// JS string interpolation
419+
// In key
420+
("[${x}:value]", vec![]),
421+
// As part of the key
422+
("[background-${property}:value]", vec![]),
423+
// In value
424+
("[key:${x}]", vec![]),
425+
// As part of the value
426+
("[key:value-${x}]", vec![]),
427+
// Allowed in strings
428+
("[--img:url('${x}')]", vec!["[--img:url('${x}')]"]),
429+
] {
430+
assert_eq!(
431+
ArbitraryPropertyMachine::<IdleState>::test_extract_all(input),
432+
expected
433+
);
434+
}
435+
}
414436
}

crates/oxide/src/extractor/arbitrary_value_machine.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,17 @@ mod tests {
188188
assert_eq!(ArbitraryValueMachine::test_extract_all(input), expected);
189189
}
190190
}
191+
192+
#[test]
193+
fn test_exceptions() {
194+
for (input, expected) in [
195+
// JS string interpolation
196+
("[${x}]", vec![]),
197+
("[url(${x})]", vec![]),
198+
// Allowed in strings
199+
("[url('${x}')]", vec!["[url('${x}')]"]),
200+
] {
201+
assert_eq!(ArbitraryValueMachine::test_extract_all(input), expected);
202+
}
203+
}
191204
}

crates/oxide/src/extractor/candidate_machine.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,32 @@ mod tests {
327327
);
328328
}
329329
}
330+
331+
#[test]
332+
fn test_js_interpolation() {
333+
for (input, expected) in [
334+
// Utilities
335+
// Arbitrary value
336+
("bg-[${color}]", vec![]),
337+
// Arbitrary property
338+
("[color:${value}]", vec![]),
339+
("[${key}:value]", vec![]),
340+
("[${key}:${value}]", vec![]),
341+
// Arbitrary property for CSS variables
342+
("[--color:${value}]", vec![]),
343+
("[--color-${name}:value]", vec![]),
344+
// Arbitrary variable
345+
("bg-(--my-${name})", vec![]),
346+
(
347+
"bg-(--my-image,url('https://example.com?q=${value}'))",
348+
vec!["bg-(--my-image,url('https://example.com?q=${value}'))"],
349+
),
350+
// Variants
351+
("data-[state=${state}]:flex", vec![]),
352+
("support-(--my-${value}):flex", vec![]),
353+
("[@media(width>=${value})]:flex", vec![]),
354+
] {
355+
assert_eq!(CandidateMachine::test_extract_all(input), expected);
356+
}
357+
}
330358
}

0 commit comments

Comments
 (0)