File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -166,6 +166,42 @@ fn literal_byte_string() {
166
166
"br\" \u{a0} \" " . parse :: < TokenStream > ( ) . unwrap_err ( ) ;
167
167
}
168
168
169
+ #[ test]
170
+ fn literal_c_string ( ) {
171
+ let strings = r###"
172
+ c"hello\x80我叫\u{1F980}" // from the RFC
173
+ cr"\"
174
+ cr##"Hello "world"!"##
175
+ c"\t\n\r\"\\"
176
+ "### ;
177
+
178
+ let mut tokens = strings. parse :: < TokenStream > ( ) . unwrap ( ) . into_iter ( ) ;
179
+
180
+ for expected in & [
181
+ r#"c"hello\x80我叫\u{1F980}""# ,
182
+ r#"cr"\""# ,
183
+ r###"cr##"Hello "world"!"##"### ,
184
+ r#"c"\t\n\r\"\\""# ,
185
+ ] {
186
+ match tokens. next ( ) . unwrap ( ) {
187
+ TokenTree :: Literal ( literal) => {
188
+ assert_eq ! ( literal. to_string( ) , * expected) ;
189
+ }
190
+ unexpected => panic ! ( "unexpected token: {:?}" , unexpected) ,
191
+ }
192
+ }
193
+
194
+ if let Some ( unexpected) = tokens. next ( ) {
195
+ panic ! ( "unexpected token: {:?}" , unexpected) ;
196
+ }
197
+
198
+ for invalid in & [ r#"c"\0""# , r#"c"\x00""# , r#"c"\u{0}""# , "c\" \0 \" " ] {
199
+ if let Ok ( unexpected) = invalid. parse :: < TokenStream > ( ) {
200
+ panic ! ( "unexpected token: {:?}" , unexpected) ;
201
+ }
202
+ }
203
+ }
204
+
169
205
#[ test]
170
206
fn literal_character ( ) {
171
207
assert_eq ! ( Literal :: character( 'x' ) . to_string( ) , "'x'" ) ;
You can’t perform that action at this time.
0 commit comments