Skip to content

Commit

Permalink
test(css/parser): Add malformed hex color tests (#3762)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Feb 27, 2022
1 parent 752edf8 commit 9f90882
Show file tree
Hide file tree
Showing 3 changed files with 307 additions and 11 deletions.
4 changes: 4 additions & 0 deletions crates/swc_css_parser/tests/fixture/hex-colors/input.css
Expand Up @@ -10,4 +10,8 @@ a {
color: #0000;
color: #ffff;
color: #FFFF;
color: #1;
color: #FF;
color: #123456789;
color: #xyz;
}
130 changes: 127 additions & 3 deletions crates/swc_css_parser/tests/fixture/hex-colors/output.json
Expand Up @@ -2,15 +2,15 @@
"type": "Stylesheet",
"span": {
"start": 0,
"end": 193,
"end": 256,
"ctxt": 0
},
"rules": [
{
"type": "QualifiedRule",
"span": {
"start": 0,
"end": 192,
"end": 255,
"ctxt": 0
},
"prelude": {
Expand Down Expand Up @@ -74,7 +74,7 @@
"type": "SimpleBlock",
"span": {
"start": 2,
"end": 192,
"end": 255,
"ctxt": 0
},
"name": "{",
Expand Down Expand Up @@ -419,6 +419,130 @@
}
],
"important": null
},
{
"type": "Declaration",
"span": {
"start": 193,
"end": 202,
"ctxt": 0
},
"name": {
"type": "Ident",
"span": {
"start": 193,
"end": 198,
"ctxt": 0
},
"value": "color",
"raw": "color"
},
"value": [
{
"type": "HexColor",
"span": {
"start": 200,
"end": 202,
"ctxt": 0
},
"value": "1",
"raw": "1"
}
],
"important": null
},
{
"type": "Declaration",
"span": {
"start": 206,
"end": 216,
"ctxt": 0
},
"name": {
"type": "Ident",
"span": {
"start": 206,
"end": 211,
"ctxt": 0
},
"value": "color",
"raw": "color"
},
"value": [
{
"type": "HexColor",
"span": {
"start": 213,
"end": 216,
"ctxt": 0
},
"value": "FF",
"raw": "FF"
}
],
"important": null
},
{
"type": "Declaration",
"span": {
"start": 220,
"end": 237,
"ctxt": 0
},
"name": {
"type": "Ident",
"span": {
"start": 220,
"end": 225,
"ctxt": 0
},
"value": "color",
"raw": "color"
},
"value": [
{
"type": "HexColor",
"span": {
"start": 227,
"end": 237,
"ctxt": 0
},
"value": "123456789",
"raw": "123456789"
}
],
"important": null
},
{
"type": "Declaration",
"span": {
"start": 241,
"end": 252,
"ctxt": 0
},
"name": {
"type": "Ident",
"span": {
"start": 241,
"end": 246,
"ctxt": 0
},
"value": "color",
"raw": "color"
},
"value": [
{
"type": "HexColor",
"span": {
"start": 248,
"end": 252,
"ctxt": 0
},
"value": "xyz",
"raw": "xyz"
}
],
"important": null
}
]
}
Expand Down
184 changes: 176 additions & 8 deletions crates/swc_css_parser/tests/fixture/hex-colors/span.rust-debug
Expand Up @@ -6,8 +6,8 @@ error: Stylesheet
3 | | color: #ffffff;
4 | | color: #FFFFFF;
... |
12 | | color: #FFFF;
13 | | }
16 | | color: #xyz;
17 | | }
| |__^

error: Rule
Expand All @@ -18,8 +18,8 @@ error: Rule
3 | | color: #ffffff;
4 | | color: #FFFFFF;
... |
12 | | color: #FFFF;
13 | | }
16 | | color: #xyz;
17 | | }
| |_^

error: QualifiedRule
Expand All @@ -30,8 +30,8 @@ error: QualifiedRule
3 | | color: #ffffff;
4 | | color: #FFFFFF;
... |
12 | | color: #FFFF;
13 | | }
16 | | color: #xyz;
17 | | }
| |_^

error: SelectorList
Expand Down Expand Up @@ -85,8 +85,8 @@ error: SimpleBlock
3 | | color: #ffffff;
4 | | color: #FFFFFF;
... |
12 | | color: #FFFF;
13 | | }
16 | | color: #xyz;
17 | | }
| |_^

error: StyleBlock
Expand Down Expand Up @@ -551,3 +551,171 @@ error: HexColor
12 | color: #FFFF;
| ^^^^^

error: StyleBlock
--> $DIR/tests/fixture/hex-colors/input.css:13:3
|
13 | color: #1;
| ^^^^^^^^^

error: Declaration
--> $DIR/tests/fixture/hex-colors/input.css:13:3
|
13 | color: #1;
| ^^^^^^^^^

error: DeclarationName
--> $DIR/tests/fixture/hex-colors/input.css:13:3
|
13 | color: #1;
| ^^^^^

error: Ident
--> $DIR/tests/fixture/hex-colors/input.css:13:3
|
13 | color: #1;
| ^^^^^

error: Value
--> $DIR/tests/fixture/hex-colors/input.css:13:10
|
13 | color: #1;
| ^^

error: Color
--> $DIR/tests/fixture/hex-colors/input.css:13:10
|
13 | color: #1;
| ^^

error: HexColor
--> $DIR/tests/fixture/hex-colors/input.css:13:10
|
13 | color: #1;
| ^^

error: StyleBlock
--> $DIR/tests/fixture/hex-colors/input.css:14:3
|
14 | color: #FF;
| ^^^^^^^^^^

error: Declaration
--> $DIR/tests/fixture/hex-colors/input.css:14:3
|
14 | color: #FF;
| ^^^^^^^^^^

error: DeclarationName
--> $DIR/tests/fixture/hex-colors/input.css:14:3
|
14 | color: #FF;
| ^^^^^

error: Ident
--> $DIR/tests/fixture/hex-colors/input.css:14:3
|
14 | color: #FF;
| ^^^^^

error: Value
--> $DIR/tests/fixture/hex-colors/input.css:14:10
|
14 | color: #FF;
| ^^^

error: Color
--> $DIR/tests/fixture/hex-colors/input.css:14:10
|
14 | color: #FF;
| ^^^

error: HexColor
--> $DIR/tests/fixture/hex-colors/input.css:14:10
|
14 | color: #FF;
| ^^^

error: StyleBlock
--> $DIR/tests/fixture/hex-colors/input.css:15:3
|
15 | color: #123456789;
| ^^^^^^^^^^^^^^^^^

error: Declaration
--> $DIR/tests/fixture/hex-colors/input.css:15:3
|
15 | color: #123456789;
| ^^^^^^^^^^^^^^^^^

error: DeclarationName
--> $DIR/tests/fixture/hex-colors/input.css:15:3
|
15 | color: #123456789;
| ^^^^^

error: Ident
--> $DIR/tests/fixture/hex-colors/input.css:15:3
|
15 | color: #123456789;
| ^^^^^

error: Value
--> $DIR/tests/fixture/hex-colors/input.css:15:10
|
15 | color: #123456789;
| ^^^^^^^^^^

error: Color
--> $DIR/tests/fixture/hex-colors/input.css:15:10
|
15 | color: #123456789;
| ^^^^^^^^^^

error: HexColor
--> $DIR/tests/fixture/hex-colors/input.css:15:10
|
15 | color: #123456789;
| ^^^^^^^^^^

error: StyleBlock
--> $DIR/tests/fixture/hex-colors/input.css:16:3
|
16 | color: #xyz;
| ^^^^^^^^^^^

error: Declaration
--> $DIR/tests/fixture/hex-colors/input.css:16:3
|
16 | color: #xyz;
| ^^^^^^^^^^^

error: DeclarationName
--> $DIR/tests/fixture/hex-colors/input.css:16:3
|
16 | color: #xyz;
| ^^^^^

error: Ident
--> $DIR/tests/fixture/hex-colors/input.css:16:3
|
16 | color: #xyz;
| ^^^^^

error: Value
--> $DIR/tests/fixture/hex-colors/input.css:16:10
|
16 | color: #xyz;
| ^^^^

error: Color
--> $DIR/tests/fixture/hex-colors/input.css:16:10
|
16 | color: #xyz;
| ^^^^

error: HexColor
--> $DIR/tests/fixture/hex-colors/input.css:16:10
|
16 | color: #xyz;
| ^^^^

1 comment on commit 9f90882

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 9f90882 Previous: f5a3647 Ratio
full_es2015 201500908 ns/iter (± 9810740) 150364826 ns/iter (± 29462706) 1.34
full_es2016 208230803 ns/iter (± 12107043) 174154302 ns/iter (± 5485499) 1.20
full_es2017 208679373 ns/iter (± 14317623) 145885454 ns/iter (± 30952438) 1.43
full_es2018 207429976 ns/iter (± 14903252) 145763201 ns/iter (± 21453669) 1.42
full_es2019 206483403 ns/iter (± 10573973) 169037739 ns/iter (± 8617866) 1.22
full_es2020 181125099 ns/iter (± 8895443) 155039203 ns/iter (± 4894201) 1.17
full_es3 256901121 ns/iter (± 11848952) 215178627 ns/iter (± 4901960) 1.19
full_es5 257525370 ns/iter (± 15740549) 212913247 ns/iter (± 17828888) 1.21
parser 834086 ns/iter (± 86283) 589626 ns/iter (± 26787) 1.41

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.