3 fn check_raw_str(s: &str, expected_hashes: u16, expected_err: Option<RawStrError>) {
4 let s = &format!("r{}", s);
5 let mut cursor = Cursor::new(s);
7 let (n_hashes, err) = cursor.raw_double_quoted_string(0);
8 assert_eq!(n_hashes, expected_hashes);
9 assert_eq!(err, expected_err);
13 fn test_naked_raw_str() {
14 check_raw_str(r#""abc""#, 0, None);
18 fn test_raw_no_start() {
19 check_raw_str(r##""abc"#"##, 0, None);
23 fn test_too_many_terminators() {
24 // this error is handled in the parser later
25 check_raw_str(r###"#"abc"##"###, 1, None);
29 fn test_unterminated() {
33 Some(RawStrError::NoTerminator { expected: 1, found: 0, possible_terminator_offset: None }),
38 Some(RawStrError::NoTerminator {
41 possible_terminator_offset: Some(7),
44 // We're looking for "# not just any #
48 Some(RawStrError::NoTerminator { expected: 2, found: 0, possible_terminator_offset: None }),
53 fn test_invalid_start() {
54 check_raw_str(r##"#~"abc"#"##, 1, Some(RawStrError::InvalidStarter { bad_char: '~' }));
58 fn test_unterminated_no_pound() {
59 // https://github.com/rust-lang/rust/issues/70677
63 Some(RawStrError::NoTerminator { expected: 0, found: 0, possible_terminator_offset: None }),
68 fn test_valid_shebang() {
69 // https://github.com/rust-lang/rust/issues/70528
70 let input = "#!/usr/bin/rustrun\nlet x = 5;";
71 assert_eq!(strip_shebang(input), Some(18));
75 fn test_invalid_shebang_valid_rust_syntax() {
76 // https://github.com/rust-lang/rust/issues/70528
77 let input = "#! [bad_attribute]";
78 assert_eq!(strip_shebang(input), None);
82 fn test_shebang_second_line() {
83 // Because shebangs are interpreted by the kernel, they must be on the first line
84 let input = "\n#!/bin/bash";
85 assert_eq!(strip_shebang(input), None);
89 fn test_shebang_space() {
90 let input = "#! /bin/bash";
91 assert_eq!(strip_shebang(input), Some(input.len()));
95 fn test_shebang_empty_shebang() {
96 let input = "#! \n[attribute(foo)]";
97 assert_eq!(strip_shebang(input), None);
101 fn test_invalid_shebang_comment() {
102 let input = "#!//bin/ami/a/comment\n[";
103 assert_eq!(strip_shebang(input), None)
107 fn test_invalid_shebang_another_comment() {
108 let input = "#!/*bin/ami/a/comment*/\n[attribute";
109 assert_eq!(strip_shebang(input), None)
113 fn test_shebang_valid_rust_after() {
114 let input = "#!/*bin/ami/a/comment*/\npub fn main() {}";
115 assert_eq!(strip_shebang(input), Some(23))
119 fn test_shebang_followed_by_attrib() {
120 let input = "#!/bin/rust-scripts\n#![allow_unused(true)]";
121 assert_eq!(strip_shebang(input), Some(19));