@@ -54,8 +54,99 @@ public class TokenQueueTest {
54
54
assertEquals ("\\ &" , TokenQueue .unescape ("\\ \\ \\ &" ));
55
55
}
56
56
57
- @ Test public void escapeCssIdentifier () {
58
- assertEquals ("one\\ #two\\ .three\\ /four\\ \\ five" , TokenQueue .escapeCssIdentifier ("one#two.three/four\\ five" ));
57
+ @ ParameterizedTest
58
+ @ MethodSource ("escapeCssIdentifier_WebPlatformTestParameters" )
59
+ @ MethodSource ("escapeCssIdentifier_additionalParameters" )
60
+ public void escapeCssIdentifier (String expected , String input ) {
61
+ assertEquals (expected , TokenQueue .escapeCssIdentifier (input ));
62
+ }
63
+
64
+ // https://github.com/web-platform-tests/wpt/blob/328fa1c67bf5dfa6f24571d4c41dd10224b6d247/css/cssom/escape.html
65
+ private static Stream <Arguments > escapeCssIdentifier_WebPlatformTestParameters () {
66
+ return Stream .of (
67
+ Arguments .of ("" , "" ),
68
+
69
+ // Null bytes
70
+ Arguments .of ("\uFFFD " , "\0 " ),
71
+ Arguments .of ("a\uFFFD " , "a\0 " ),
72
+ Arguments .of ("\uFFFD b" , "\0 b" ),
73
+ Arguments .of ("a\uFFFD b" , "a\0 b" ),
74
+
75
+ // Replacement character
76
+ Arguments .of ("\uFFFD " , "\uFFFD " ),
77
+ Arguments .of ("a\uFFFD " , "a\uFFFD " ),
78
+ Arguments .of ("\uFFFD b" , "\uFFFD b" ),
79
+ Arguments .of ("a\uFFFD b" , "a\uFFFD b" ),
80
+
81
+ // Number prefix
82
+ Arguments .of ("\\ 30 a" , "0a" ),
83
+ Arguments .of ("\\ 31 a" , "1a" ),
84
+ Arguments .of ("\\ 32 a" , "2a" ),
85
+ Arguments .of ("\\ 33 a" , "3a" ),
86
+ Arguments .of ("\\ 34 a" , "4a" ),
87
+ Arguments .of ("\\ 35 a" , "5a" ),
88
+ Arguments .of ("\\ 36 a" , "6a" ),
89
+ Arguments .of ("\\ 37 a" , "7a" ),
90
+ Arguments .of ("\\ 38 a" , "8a" ),
91
+ Arguments .of ("\\ 39 a" , "9a" ),
92
+
93
+ // Letter number prefix
94
+ Arguments .of ("a0b" , "a0b" ),
95
+ Arguments .of ("a1b" , "a1b" ),
96
+ Arguments .of ("a2b" , "a2b" ),
97
+ Arguments .of ("a3b" , "a3b" ),
98
+ Arguments .of ("a4b" , "a4b" ),
99
+ Arguments .of ("a5b" , "a5b" ),
100
+ Arguments .of ("a6b" , "a6b" ),
101
+ Arguments .of ("a7b" , "a7b" ),
102
+ Arguments .of ("a8b" , "a8b" ),
103
+ Arguments .of ("a9b" , "a9b" ),
104
+
105
+ // Dash number prefix
106
+ Arguments .of ("-\\ 30 a" , "-0a" ),
107
+ Arguments .of ("-\\ 31 a" , "-1a" ),
108
+ Arguments .of ("-\\ 32 a" , "-2a" ),
109
+ Arguments .of ("-\\ 33 a" , "-3a" ),
110
+ Arguments .of ("-\\ 34 a" , "-4a" ),
111
+ Arguments .of ("-\\ 35 a" , "-5a" ),
112
+ Arguments .of ("-\\ 36 a" , "-6a" ),
113
+ Arguments .of ("-\\ 37 a" , "-7a" ),
114
+ Arguments .of ("-\\ 38 a" , "-8a" ),
115
+ Arguments .of ("-\\ 39 a" , "-9a" ),
116
+
117
+ // Double dash prefix
118
+ Arguments .of ("--a" , "--a" ),
119
+
120
+ // Various tests
121
+ Arguments .of ("\\ 1 \\ 2 \\ 1e \\ 1f " , "\u0001 \u0002 \u001E \u001F " ),
122
+ Arguments .of ("\u0080 \u002D \u005F \u00A9 " , "\u0080 \u002D \u005F \u00A9 " ),
123
+ Arguments .of ("\\ 7f \u0080 \u0081 \u0082 \u0083 \u0084 \u0085 \u0086 \u0087 \u0088 \u0089 \u008A \u008B \u008C \u008D \u008E \u008F \u0090 \u0091 \u0092 \u0093 \u0094 \u0095 \u0096 \u0097 \u0098 \u0099 \u009A \u009B \u009C \u009D \u009E \u009F " , "\u007F \u0080 \u0081 \u0082 \u0083 \u0084 \u0085 \u0086 \u0087 \u0088 \u0089 \u008A \u008B \u008C \u008D \u008E \u008F \u0090 \u0091 \u0092 \u0093 \u0094 \u0095 \u0096 \u0097 \u0098 \u0099 \u009A \u009B \u009C \u009D \u009E \u009F " ),
124
+ Arguments .of ("\u00A0 \u00A1 \u00A2 " , "\u00A0 \u00A1 \u00A2 " ),
125
+ Arguments .of ("a0123456789b" , "a0123456789b" ),
126
+ Arguments .of ("abcdefghijklmnopqrstuvwxyz" , "abcdefghijklmnopqrstuvwxyz" ),
127
+ Arguments .of ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" , "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ),
128
+
129
+ Arguments .of ("hello\\ \\ world" , "hello\\ world" ), // Backslashes get backslash-escaped
130
+ Arguments .of ("hello\u1234 world" , "hello\u1234 world" ), // Code points greater than U+0080 are preserved
131
+ Arguments .of ("\\ -" , "-" ), // CSS.escape: Single dash escaped
132
+
133
+ Arguments .of ("\\ \\ !xy" , "\u0020 \u0021 \u0078 \u0079 " ),
134
+
135
+ // astral symbol (U+1D306 TETRAGRAM FOR CENTRE)
136
+ Arguments .of ("\uD834 \uDF06 " , "\uD834 \uDF06 " ),
137
+
138
+ // lone surrogates
139
+ Arguments .of ("\uDF06 " , "\uDF06 " ),
140
+ Arguments .of ("\uD834 " , "\uD834 " )
141
+ );
142
+ }
143
+
144
+ private static Stream <Arguments > escapeCssIdentifier_additionalParameters () {
145
+ return Stream .of (
146
+ Arguments .of ("one\\ #two\\ .three\\ /four\\ \\ five" , "one#two.three/four\\ five" ),
147
+ Arguments .of ("-a" , "-a" ),
148
+ Arguments .of ("--" , "--" )
149
+ );
59
150
}
60
151
61
152
@ Test public void chompToIgnoreCase () {
0 commit comments