Skip to content

Commit c271920

Browse files
authoredMar 18, 2022
Rollup merge of #94993 - GrishaVar:too-many-hashes-test, r=Dylan-DPC
Add test for >65535 hashes in lexing raw string
2 parents 0f002eb + 4e3dbb3 commit c271920

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎compiler/rustc_lexer/src/tests.rs

+17
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ fn test_unterminated_no_pound() {
6666
);
6767
}
6868

69+
#[test]
70+
fn test_too_many_hashes() {
71+
let max_count = u16::MAX;
72+
let mut hashes: String = "#".repeat(max_count.into());
73+
74+
// Valid number of hashes (65535 = 2^16 - 1), but invalid string.
75+
check_raw_str(&hashes, max_count, Some(RawStrError::InvalidStarter { bad_char: '\u{0}' }));
76+
77+
// One more hash sign (65536 = 2^16) becomes too many.
78+
hashes.push('#');
79+
check_raw_str(
80+
&hashes,
81+
0,
82+
Some(RawStrError::TooManyDelimiters { found: usize::from(max_count) + 1 }),
83+
);
84+
}
85+
6986
#[test]
7087
fn test_valid_shebang() {
7188
// https://github.com/rust-lang/rust/issues/70528

0 commit comments

Comments
 (0)
Please sign in to comment.