about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-03-18 21:50:48 +0100
committerGitHub <noreply@github.com>2022-03-18 21:50:48 +0100
commitc27192041ae1a34c63eda1102ed1b6c6bfe7eb13 (patch)
tree5893259424947966da735d7524d28fcb1ebae898
parent0f002eb4c6e5c63a17ad2b1893645043ec7e5674 (diff)
parent4e3dbb3c19bb4059e30030e7c4be62e1d8919649 (diff)
downloadrust-c27192041ae1a34c63eda1102ed1b6c6bfe7eb13.tar.gz
rust-c27192041ae1a34c63eda1102ed1b6c6bfe7eb13.zip
Rollup merge of #94993 - GrishaVar:too-many-hashes-test, r=Dylan-DPC
Add test for >65535 hashes in lexing raw string
-rw-r--r--compiler/rustc_lexer/src/tests.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/compiler/rustc_lexer/src/tests.rs b/compiler/rustc_lexer/src/tests.rs
index 94017b7b286..548de67449a 100644
--- a/compiler/rustc_lexer/src/tests.rs
+++ b/compiler/rustc_lexer/src/tests.rs
@@ -67,6 +67,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
     let input = "#!/usr/bin/rustrun\nlet x = 5;";