From 4e3dbb3c19bb4059e30030e7c4be62e1d8919649 Mon Sep 17 00:00:00 2001 From: Grisha <33952698+GrishaVar@users.noreply.github.com> Date: Wed, 16 Mar 2022 06:37:41 +0100 Subject: [PATCH] Add test for >65535 hashes in lexing raw string --- compiler/rustc_lexer/src/tests.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/compiler/rustc_lexer/src/tests.rs b/compiler/rustc_lexer/src/tests.rs index 94017b7b286e2..548de67449abf 100644 --- a/compiler/rustc_lexer/src/tests.rs +++ b/compiler/rustc_lexer/src/tests.rs @@ -66,6 +66,23 @@ fn test_unterminated_no_pound() { ); } +#[test] +fn test_too_many_hashes() { + let max_count = u16::MAX; + let mut hashes: String = "#".repeat(max_count.into()); + + // Valid number of hashes (65535 = 2^16 - 1), but invalid string. + check_raw_str(&hashes, max_count, Some(RawStrError::InvalidStarter { bad_char: '\u{0}' })); + + // One more hash sign (65536 = 2^16) becomes too many. + hashes.push('#'); + check_raw_str( + &hashes, + 0, + Some(RawStrError::TooManyDelimiters { found: usize::from(max_count) + 1 }), + ); +} + #[test] fn test_valid_shebang() { // https://github.com/rust-lang/rust/issues/70528