diff options
| author | bors <bors@rust-lang.org> | 2021-02-26 00:17:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-02-26 00:17:22 +0000 |
| commit | d95d30486180387a875b14633aea4e4dd8f960da (patch) | |
| tree | 00fe29d185cb558b445fe81eec66bbbf9f8820f6 /src/librustdoc/html/markdown | |
| parent | c0a54cc4eb6111cac9ad75cc439f75b79698b4a7 (diff) | |
| parent | 66f4883308d999c8b405fdfd442562b8600a462d (diff) | |
| download | rust-d95d30486180387a875b14633aea4e4dd8f960da.tar.gz rust-d95d30486180387a875b14633aea4e4dd8f960da.zip | |
Auto merge of #78429 - casey:doctest-attribute-splitting, r=jyn514
[librustdoc] Only split lang string on `,`, ` `, and `\t`
Split markdown lang strings into tokens on `,`.
The previous behavior was to split lang strings into tokens on any
character that wasn't a `_`, `_`, or alphanumeric.
This is a potentially breaking change, so please scrutinize! See discussion in #78344.
I noticed some test cases that made me wonder if there might have been some reason for the original behavior:
```
t("{.no_run .example}", false, true, Ignore::None, true, false, false, false, v(), None);
t("{.sh .should_panic}", true, false, Ignore::None, false, false, false, false, v(), None);
t("{.example .rust}", false, false, Ignore::None, true, false, false, false, v(), None);
t("{.test_harness .rust}", false, false, Ignore::None, true, true, false, false, v(), None);
```
It seemed pretty peculiar to specifically test lang strings in braces, with all the tokens prefixed by `.`.
I did some digging, and it looks like the test cases were added way back in [this commit from 2014](https://github.com/rust-lang/rust/commit/3fef7a74ca9a) by `@skade.`
It looks like they were added just to make sure that the splitting was permissive, and aren't testing that those strings in particular are accepted.
Closes https://github.com/rust-lang/rust/issues/78344.
Diffstat (limited to 'src/librustdoc/html/markdown')
| -rw-r--r-- | src/librustdoc/html/markdown/tests.rs | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index 6b2cfe68575..59ca841715c 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -58,6 +58,9 @@ fn test_lang_string_parse() { t(Default::default()); t(LangString { original: "rust".into(), ..Default::default() }); + t(LangString { original: ".rust".into(), ..Default::default() }); + t(LangString { original: "{rust}".into(), ..Default::default() }); + t(LangString { original: "{.rust}".into(), ..Default::default() }); t(LangString { original: "sh".into(), rust: false, ..Default::default() }); t(LangString { original: "ignore".into(), ignore: Ignore::All, ..Default::default() }); t(LangString { @@ -75,16 +78,16 @@ fn test_lang_string_parse() { ..Default::default() }); t(LangString { original: "allow_fail".into(), allow_fail: true, ..Default::default() }); - t(LangString { original: "{.no_run .example}".into(), no_run: true, ..Default::default() }); + t(LangString { original: "no_run,example".into(), no_run: true, ..Default::default() }); t(LangString { - original: "{.sh .should_panic}".into(), + original: "sh,should_panic".into(), should_panic: true, rust: false, ..Default::default() }); - t(LangString { original: "{.example .rust}".into(), ..Default::default() }); + t(LangString { original: "example,rust".into(), ..Default::default() }); t(LangString { - original: "{.test_harness .rust}".into(), + original: "test_harness,.rust".into(), test_harness: true, ..Default::default() }); @@ -101,6 +104,18 @@ fn test_lang_string_parse() { ..Default::default() }); t(LangString { + original: "text,no_run, ".into(), + no_run: true, + rust: false, + ..Default::default() + }); + t(LangString { + original: "text,no_run,".into(), + no_run: true, + rust: false, + ..Default::default() + }); + t(LangString { original: "edition2015".into(), edition: Some(Edition::Edition2015), ..Default::default() @@ -113,6 +128,29 @@ fn test_lang_string_parse() { } #[test] +fn test_lang_string_tokenizer() { + fn case(lang_string: &str, want: &[&str]) { + let have = LangString::tokens(lang_string).collect::<Vec<&str>>(); + assert_eq!(have, want, "Unexpected lang string split for `{}`", lang_string); + } + + case("", &[]); + case("foo", &["foo"]); + case("foo,bar", &["foo", "bar"]); + case(".foo,.bar", &["foo", "bar"]); + case("{.foo,.bar}", &["foo", "bar"]); + case(" {.foo,.bar} ", &["foo", "bar"]); + case("foo bar", &["foo", "bar"]); + case("foo\tbar", &["foo", "bar"]); + case("foo\t, bar", &["foo", "bar"]); + case(" foo , bar ", &["foo", "bar"]); + case(",,foo,,bar,,", &["foo", "bar"]); + case("foo=bar", &["foo=bar"]); + case("a-b-c", &["a-b-c"]); + case("a_b_c", &["a_b_c"]); +} + +#[test] fn test_header() { fn t(input: &str, expect: &str) { let mut map = IdMap::new(); |
