Skip to content

Commit 5477bd2

Browse files
committed
Add c-str literal test
1 parent 3c20a59 commit 5477bd2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/test.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,42 @@ fn literal_byte_string() {
166166
"br\"\u{a0}\"".parse::<TokenStream>().unwrap_err();
167167
}
168168

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+
169205
#[test]
170206
fn literal_character() {
171207
assert_eq!(Literal::character('x').to_string(), "'x'");

0 commit comments

Comments
 (0)