Skip to content

Commit

Permalink
Move test into the tests.rs file
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 20, 2024
1 parent 55653a5 commit bc03e40
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
23 changes: 0 additions & 23 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,29 +1036,6 @@ fn doctest_run_fn(
Ok(())
}

#[cfg(test)]
#[test]
fn check_split_args() {
fn compare(input: &str, expected: &[&str]) {
let output = split_args(input);
let expected = expected.iter().map(|s| s.to_string()).collect::<Vec<_>>();
assert_eq!(expected, output, "test failed for {input:?}");
}

compare("'a' \"b\"c", &["a", "bc"]);
compare("'a' \"b \"c d", &["a", "b c", "d"]);
compare("'a' \"b\\\"c\"", &["a", "b\"c"]);
compare("'a\"'", &["a\""]);
compare("\"a'\"", &["a'"]);
compare("\\ a", &[" a"]);
compare("\\\\", &["\\"]);
compare("a'", &["a"]);
compare("a ", &["a"]);
compare("a b", &["a", "b"]);
compare("a\n\t \rb", &["a", "b"]);
compare("a\n\t1 \rb", &["a", "1", "b"]);
}

#[cfg(test)] // used in tests
impl DocTestVisitor for Vec<usize> {
fn visit_test(&mut self, _test: String, _config: LangString, rel_line: MdRelLine) {
Expand Down
22 changes: 22 additions & 0 deletions src/librustdoc/doctest/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,25 @@ fn main() {
let (output, len) = make_test(input, None, false, &opts, None);
assert_eq!((output, len), (expected, 1));
}

#[test]
fn check_split_args() {
fn compare(input: &str, expected: &[&str]) {
let output = super::split_args(input);
let expected = expected.iter().map(|s| s.to_string()).collect::<Vec<_>>();
assert_eq!(expected, output, "test failed for {input:?}");
}

compare("'a' \"b\"c", &["a", "bc"]);
compare("'a' \"b \"c d", &["a", "b c", "d"]);
compare("'a' \"b\\\"c\"", &["a", "b\"c"]);
compare("'a\"'", &["a\""]);
compare("\"a'\"", &["a'"]);
compare("\\ a", &[" a"]);
compare("\\\\", &["\\"]);
compare("a'", &["a"]);
compare("a ", &["a"]);
compare("a b", &["a", "b"]);
compare("a\n\t \rb", &["a", "b"]);
compare("a\n\t1 \rb", &["a", "1", "b"]);
}

0 comments on commit bc03e40

Please sign in to comment.