-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[functions] Add WPT for @function prelude parsing
Bug: 325504770 Change-Id: I91efca8c6441a86328205c761caa4f4cbbe4d097 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6158324 Reviewed-by: Steinar H Gunderson <[email protected]> Commit-Queue: Anders Hartvoll Ruud <[email protected]> Cr-Commit-Position: refs/heads/main@{#1408606}
- Loading branch information
1 parent
9f38b08
commit 9e75c82
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<!DOCTYPE html> | ||
<title>Custom Functions: Prelude Parsing</title> | ||
<link rel="help" href="https://drafts.csswg.org/css-mixins-1/#function-rule"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
function test_valid_prelude(rule_without_block) { | ||
test(() => { | ||
let s = new CSSStyleSheet(); | ||
s.replaceSync(`${rule_without_block} {}`); | ||
assert_equals(s.cssRules.length, 1); | ||
}, `${rule_without_block} is valid`); | ||
} | ||
|
||
function test_invalid_prelude(rule_without_block) { | ||
test(() => { | ||
let s = new CSSStyleSheet(); | ||
s.replaceSync(`${rule_without_block} {}`); | ||
assert_equals(s.cssRules.length, 0); | ||
}, `${rule_without_block} is invalid`); | ||
} | ||
|
||
test_valid_prelude('@function --foo()'); | ||
test_valid_prelude('@function --foo( )'); | ||
test_valid_prelude('@function --foo(--x)'); | ||
test_valid_prelude('@function --foo( --x )'); | ||
|
||
test_invalid_prelude('@function --foo ()'); | ||
test_invalid_prelude('@function --foo (--x)'); | ||
|
||
// All single <syntax-component> types. | ||
test_valid_prelude('@function --foo(--x auto)'); | ||
test_valid_prelude('@function --foo(--x <angle>)'); | ||
test_valid_prelude('@function --foo(--x <color>)'); | ||
test_valid_prelude('@function --foo(--x <custom-ident>)'); | ||
test_valid_prelude('@function --foo(--x <image>)'); | ||
test_valid_prelude('@function --foo(--x <integer>)'); | ||
test_valid_prelude('@function --foo(--x <length>)'); | ||
test_valid_prelude('@function --foo(--x <length-percentage>)'); | ||
test_valid_prelude('@function --foo(--x <number>)'); | ||
test_valid_prelude('@function --foo(--x <percentage>)'); | ||
test_valid_prelude('@function --foo(--x <resolution>)'); | ||
test_valid_prelude('@function --foo(--x <string>)'); | ||
test_valid_prelude('@function --foo(--x <time>)'); | ||
test_valid_prelude('@function --foo(--x <url>)'); | ||
test_valid_prelude('@function --foo(--x <transform-function>)'); | ||
test_valid_prelude('@function --foo(--x <transform-list>)'); | ||
|
||
test_valid_prelude('@function --foo(--x type(auto))'); | ||
test_valid_prelude('@function --foo(--x type(<length>))'); | ||
test_valid_prelude('@function --foo(--x type(<length> | auto))'); | ||
test_valid_prelude('@function --foo(--x type(none | auto))'); | ||
test_valid_prelude('@function --foo(--x type(*))'); | ||
|
||
// Multiple parameters. | ||
test_valid_prelude('@function --foo(--x, --y)'); | ||
test_valid_prelude('@function --foo(--x, --y, --z)'); | ||
test_valid_prelude('@function --foo(--x <length>, --y, --z)'); | ||
test_valid_prelude('@function --foo(--x, --y <number>, --z <angle>)'); | ||
|
||
// Defaults. | ||
test_valid_prelude('@function --foo(--x : 10px)'); | ||
test_valid_prelude('@function --foo(--x <length>: 10px)'); | ||
test_valid_prelude('@function --foo(--x <length>: 10px, --y)'); | ||
test_valid_prelude('@function --foo(--x, --y <length>: 10px)'); | ||
test_valid_prelude('@function --foo(--x type(<length> | auto): auto)'); | ||
// The value does not have to match the type during @function parsing: | ||
test_valid_prelude('@function --foo(--x <angle>: 10px)'); | ||
|
||
test_invalid_prelude('@function --foo(--x: 10px !important)'); | ||
|
||
// Lists. | ||
test_valid_prelude('@function --foo(--x <length>#)'); | ||
test_valid_prelude('@function --foo(--x <length>+)'); | ||
test_valid_prelude('@function --foo(--x type(<length>+))'); | ||
test_valid_prelude('@function --foo(--x <transform-function>#)'); | ||
test_valid_prelude('@function --foo(--x <transform-function>+)'); | ||
// <transform-list> is special: a multiplier cannot follow it. | ||
test_invalid_prelude('@function --foo(--x <transform-list>#)'); | ||
test_invalid_prelude('@function --foo(--x <transform-list>+)'); | ||
|
||
test_invalid_prelude('@function --foo(--x *)'); | ||
test_invalid_prelude('@function --foo(--x !)'); | ||
test_invalid_prelude('@function --foo(--x 50px)'); | ||
test_invalid_prelude('@function --foo(--x <length> | auto)'); | ||
test_invalid_prelude('@function --foo(--x none | auto)'); | ||
test_invalid_prelude('@function --foo(--x <dino>)'); | ||
|
||
// Return value types. | ||
test_valid_prelude('@function --foo(--x) returns type(*)'); | ||
test_valid_prelude('@function --foo(--x) returns <length>'); | ||
test_valid_prelude('@function --foo(--x) returns <length>+'); | ||
test_valid_prelude('@function --foo(--x) returns type(<length>)'); | ||
test_valid_prelude('@function --foo(--x) returns type(<length> | auto)'); | ||
test_valid_prelude('@function --foo(--x) returns type(foo | bar)'); | ||
|
||
test_invalid_prelude('@function --foo(--x) !'); | ||
test_invalid_prelude('@function --foo(--x) length'); | ||
test_invalid_prelude('@function --foo(--x) returns'); | ||
test_invalid_prelude('@function --foo(--x) returns '); | ||
test_invalid_prelude('@function --foo(--x) returns *'); | ||
test_invalid_prelude('@function --foo(--x) returns <transform-list>#'); | ||
test_invalid_prelude('@function --foo(--x) returns <transform-list>+'); | ||
test_invalid_prelude('@function --foo(--x) returns auto | none'); | ||
test_invalid_prelude('@function --foo(--x): <length>'); | ||
test_invalid_prelude('@function --foo(--x): length'); | ||
test_invalid_prelude('@function --foo(--x) returneth <length>'); | ||
</script> |