Add raw string literal test cases

This commit is contained in:
David Tolnay 2023-02-04 15:21:02 -08:00
parent 3b90e7d1ed
commit f0a3490e97
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -5,6 +5,7 @@
)]
use proc_macro2::{Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
use std::iter;
use std::panic;
use std::str::{self, FromStr};
@ -118,6 +119,25 @@ fn literal_string() {
#[test]
fn literal_raw_string() {
"r\"\r\n\"".parse::<TokenStream>().unwrap();
fn raw_string_literal_with_hashes(n: usize) -> String {
let mut literal = String::new();
literal.push('r');
literal.extend(iter::repeat('#').take(n));
literal.push('"');
literal.push('"');
literal.extend(iter::repeat('#').take(n));
literal
}
raw_string_literal_with_hashes(255)
.parse::<TokenStream>()
.unwrap();
// https://github.com/rust-lang/rust/pull/95251
raw_string_literal_with_hashes(256)
.parse::<TokenStream>()
.unwrap();
}
#[test]