5 fn check_raw_str(s: &str, expected_hashes: u16, expected_err: Option<RawStrError>) {
6 let s = &format!("r{}", s);
7 let mut cursor = Cursor::new(s);
9 let (n_hashes, err) = cursor.raw_double_quoted_string(0);
10 assert_eq!(n_hashes, expected_hashes);
11 assert_eq!(err, expected_err);
15 fn test_naked_raw_str() {
16 check_raw_str(r#""abc""#, 0, None);
20 fn test_raw_no_start() {
21 check_raw_str(r##""abc"#"##, 0, None);
25 fn test_too_many_terminators() {
26 // this error is handled in the parser later
27 check_raw_str(r###"#"abc"##"###, 1, None);
31 fn test_unterminated() {
35 Some(RawStrError::NoTerminator {
38 possible_terminator_offset: None,
44 Some(RawStrError::NoTerminator {
47 possible_terminator_offset: Some(7),
50 // We're looking for "# not just any #
54 Some(RawStrError::NoTerminator {
57 possible_terminator_offset: None,
63 fn test_invalid_start() {
64 check_raw_str(r##"#~"abc"#"##, 1, Some(RawStrError::InvalidStarter { bad_char: '~' }));
68 fn test_unterminated_no_pound() {
69 // https://github.com/rust-lang/rust/issues/70677
73 Some(RawStrError::NoTerminator {
76 possible_terminator_offset: None,
82 fn test_valid_shebang() {
83 // https://github.com/rust-lang/rust/issues/70528
84 let input = "#!/usr/bin/rustrun\nlet x = 5;";
85 assert_eq!(strip_shebang(input), Some(18));
89 fn test_invalid_shebang_valid_rust_syntax() {
90 // https://github.com/rust-lang/rust/issues/70528
91 let input = "#! [bad_attribute]";
92 assert_eq!(strip_shebang(input), None);
96 fn test_shebang_second_line() {
97 // Because shebangs are interpreted by the kernel, they must be on the first line
98 let input = "\n#!/bin/bash";
99 assert_eq!(strip_shebang(input), None);
103 fn test_shebang_space() {
104 let input = "#! /bin/bash";
105 assert_eq!(strip_shebang(input), Some(input.len()));
109 fn test_shebang_empty_shebang() {
110 let input = "#! \n[attribute(foo)]";
111 assert_eq!(strip_shebang(input), None);
115 fn test_invalid_shebang_comment() {
116 let input = "#!//bin/ami/a/comment\n[";
117 assert_eq!(strip_shebang(input), None)
121 fn test_invalid_shebang_another_comment() {
122 let input = "#!/*bin/ami/a/comment*/\n[attribute";
123 assert_eq!(strip_shebang(input), None)
127 fn test_shebang_valid_rust_after() {
128 let input = "#!/*bin/ami/a/comment*/\npub fn main() {}";
129 assert_eq!(strip_shebang(input), Some(23))
133 fn test_shebang_followed_by_attrib() {
134 let input = "#!/bin/rust-scripts\n#![allow_unused(true)]";
135 assert_eq!(strip_shebang(input), Some(19));