Minor, remove double nesting of a test module
This commit is contained in:
parent
32cb8d40eb
commit
35994db6d3
1 changed files with 120 additions and 135 deletions
|
@ -1,137 +1,122 @@
|
||||||
#[cfg(test)]
|
use super::*;
|
||||||
mod tests {
|
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
fn check_raw_str(s: &str, expected_hashes: u16, expected_err: Option<RawStrError>) {
|
fn check_raw_str(s: &str, expected_hashes: u16, expected_err: Option<RawStrError>) {
|
||||||
let s = &format!("r{}", s);
|
let s = &format!("r{}", s);
|
||||||
let mut cursor = Cursor::new(s);
|
let mut cursor = Cursor::new(s);
|
||||||
cursor.bump();
|
cursor.bump();
|
||||||
let (n_hashes, err) = cursor.raw_double_quoted_string(0);
|
let (n_hashes, err) = cursor.raw_double_quoted_string(0);
|
||||||
assert_eq!(n_hashes, expected_hashes);
|
assert_eq!(n_hashes, expected_hashes);
|
||||||
assert_eq!(err, expected_err);
|
assert_eq!(err, expected_err);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_naked_raw_str() {
|
fn test_naked_raw_str() {
|
||||||
check_raw_str(r#""abc""#, 0, None);
|
check_raw_str(r#""abc""#, 0, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_raw_no_start() {
|
fn test_raw_no_start() {
|
||||||
check_raw_str(r##""abc"#"##, 0, None);
|
check_raw_str(r##""abc"#"##, 0, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_too_many_terminators() {
|
fn test_too_many_terminators() {
|
||||||
// this error is handled in the parser later
|
// this error is handled in the parser later
|
||||||
check_raw_str(r###"#"abc"##"###, 1, None);
|
check_raw_str(r###"#"abc"##"###, 1, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unterminated() {
|
fn test_unterminated() {
|
||||||
check_raw_str(
|
check_raw_str(
|
||||||
r#"#"abc"#,
|
r#"#"abc"#,
|
||||||
1,
|
1,
|
||||||
Some(RawStrError::NoTerminator {
|
Some(RawStrError::NoTerminator { expected: 1, found: 0, possible_terminator_offset: None }),
|
||||||
expected: 1,
|
);
|
||||||
found: 0,
|
check_raw_str(
|
||||||
possible_terminator_offset: None,
|
r###"##"abc"#"###,
|
||||||
}),
|
2,
|
||||||
);
|
Some(RawStrError::NoTerminator {
|
||||||
check_raw_str(
|
expected: 2,
|
||||||
r###"##"abc"#"###,
|
found: 1,
|
||||||
2,
|
possible_terminator_offset: Some(7),
|
||||||
Some(RawStrError::NoTerminator {
|
}),
|
||||||
expected: 2,
|
);
|
||||||
found: 1,
|
// We're looking for "# not just any #
|
||||||
possible_terminator_offset: Some(7),
|
check_raw_str(
|
||||||
}),
|
r###"##"abc#"###,
|
||||||
);
|
2,
|
||||||
// We're looking for "# not just any #
|
Some(RawStrError::NoTerminator { expected: 2, found: 0, possible_terminator_offset: None }),
|
||||||
check_raw_str(
|
)
|
||||||
r###"##"abc#"###,
|
}
|
||||||
2,
|
|
||||||
Some(RawStrError::NoTerminator {
|
#[test]
|
||||||
expected: 2,
|
fn test_invalid_start() {
|
||||||
found: 0,
|
check_raw_str(r##"#~"abc"#"##, 1, Some(RawStrError::InvalidStarter { bad_char: '~' }));
|
||||||
possible_terminator_offset: None,
|
}
|
||||||
}),
|
|
||||||
)
|
#[test]
|
||||||
}
|
fn test_unterminated_no_pound() {
|
||||||
|
// https://github.com/rust-lang/rust/issues/70677
|
||||||
#[test]
|
check_raw_str(
|
||||||
fn test_invalid_start() {
|
r#"""#,
|
||||||
check_raw_str(r##"#~"abc"#"##, 1, Some(RawStrError::InvalidStarter { bad_char: '~' }));
|
0,
|
||||||
}
|
Some(RawStrError::NoTerminator { expected: 0, found: 0, possible_terminator_offset: None }),
|
||||||
|
);
|
||||||
#[test]
|
}
|
||||||
fn test_unterminated_no_pound() {
|
|
||||||
// https://github.com/rust-lang/rust/issues/70677
|
#[test]
|
||||||
check_raw_str(
|
fn test_valid_shebang() {
|
||||||
r#"""#,
|
// https://github.com/rust-lang/rust/issues/70528
|
||||||
0,
|
let input = "#!/usr/bin/rustrun\nlet x = 5;";
|
||||||
Some(RawStrError::NoTerminator {
|
assert_eq!(strip_shebang(input), Some(18));
|
||||||
expected: 0,
|
}
|
||||||
found: 0,
|
|
||||||
possible_terminator_offset: None,
|
#[test]
|
||||||
}),
|
fn test_invalid_shebang_valid_rust_syntax() {
|
||||||
);
|
// https://github.com/rust-lang/rust/issues/70528
|
||||||
}
|
let input = "#! [bad_attribute]";
|
||||||
|
assert_eq!(strip_shebang(input), None);
|
||||||
#[test]
|
}
|
||||||
fn test_valid_shebang() {
|
|
||||||
// https://github.com/rust-lang/rust/issues/70528
|
#[test]
|
||||||
let input = "#!/usr/bin/rustrun\nlet x = 5;";
|
fn test_shebang_second_line() {
|
||||||
assert_eq!(strip_shebang(input), Some(18));
|
// Because shebangs are interpreted by the kernel, they must be on the first line
|
||||||
}
|
let input = "\n#!/bin/bash";
|
||||||
|
assert_eq!(strip_shebang(input), None);
|
||||||
#[test]
|
}
|
||||||
fn test_invalid_shebang_valid_rust_syntax() {
|
|
||||||
// https://github.com/rust-lang/rust/issues/70528
|
#[test]
|
||||||
let input = "#! [bad_attribute]";
|
fn test_shebang_space() {
|
||||||
assert_eq!(strip_shebang(input), None);
|
let input = "#! /bin/bash";
|
||||||
}
|
assert_eq!(strip_shebang(input), Some(input.len()));
|
||||||
|
}
|
||||||
#[test]
|
|
||||||
fn test_shebang_second_line() {
|
#[test]
|
||||||
// Because shebangs are interpreted by the kernel, they must be on the first line
|
fn test_shebang_empty_shebang() {
|
||||||
let input = "\n#!/bin/bash";
|
let input = "#! \n[attribute(foo)]";
|
||||||
assert_eq!(strip_shebang(input), None);
|
assert_eq!(strip_shebang(input), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_shebang_space() {
|
fn test_invalid_shebang_comment() {
|
||||||
let input = "#! /bin/bash";
|
let input = "#!//bin/ami/a/comment\n[";
|
||||||
assert_eq!(strip_shebang(input), Some(input.len()));
|
assert_eq!(strip_shebang(input), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_shebang_empty_shebang() {
|
fn test_invalid_shebang_another_comment() {
|
||||||
let input = "#! \n[attribute(foo)]";
|
let input = "#!/*bin/ami/a/comment*/\n[attribute";
|
||||||
assert_eq!(strip_shebang(input), None);
|
assert_eq!(strip_shebang(input), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_shebang_comment() {
|
fn test_shebang_valid_rust_after() {
|
||||||
let input = "#!//bin/ami/a/comment\n[";
|
let input = "#!/*bin/ami/a/comment*/\npub fn main() {}";
|
||||||
assert_eq!(strip_shebang(input), None)
|
assert_eq!(strip_shebang(input), Some(23))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_shebang_another_comment() {
|
fn test_shebang_followed_by_attrib() {
|
||||||
let input = "#!/*bin/ami/a/comment*/\n[attribute";
|
let input = "#!/bin/rust-scripts\n#![allow_unused(true)]";
|
||||||
assert_eq!(strip_shebang(input), None)
|
assert_eq!(strip_shebang(input), Some(19));
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_shebang_valid_rust_after() {
|
|
||||||
let input = "#!/*bin/ami/a/comment*/\npub fn main() {}";
|
|
||||||
assert_eq!(strip_shebang(input), Some(23))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_shebang_followed_by_attrib() {
|
|
||||||
let input = "#!/bin/rust-scripts\n#![allow_unused(true)]";
|
|
||||||
assert_eq!(strip_shebang(input), Some(19));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue