Skip to content

Commit 2340d70

Browse files
committed
Add test code for unescaping byte strings
1 parent bdf8547 commit 2340d70

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

crates/syntax/src/ast/token_ext.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,31 @@ bcde", "abcde",
456456
);
457457
}
458458

459+
fn check_byte_string_value<'a, const N: usize>(
460+
lit: &str,
461+
expected: impl Into<Option<&'a [u8; N]>>,
462+
) {
463+
assert_eq!(
464+
ast::ByteString { syntax: make::tokens::literal(&format!("b\"{}\"", lit)) }
465+
.value()
466+
.as_deref(),
467+
expected.into().map(|value| &value[..])
468+
);
469+
}
470+
471+
#[test]
472+
fn test_byte_string_escape() {
473+
check_byte_string_value(r"foobar", b"foobar");
474+
check_byte_string_value(r"\foobar", None::<&[u8; 0]>);
475+
check_byte_string_value(r"\nfoobar", b"\nfoobar");
476+
check_byte_string_value(r"C:\\Windows\\System32\\", b"C:\\Windows\\System32\\");
477+
check_byte_string_value(r"\x61bcde", b"abcde");
478+
check_byte_string_value(
479+
r"a\
480+
bcde", b"abcde",
481+
);
482+
}
483+
459484
#[test]
460485
fn test_value_underscores() {
461486
check_float_value("3.141592653589793_f64", 3.141592653589793_f64);

0 commit comments

Comments
 (0)