From fb7008c0a08264f42d44f010786edf15492c9bce Mon Sep 17 00:00:00 2001 From: mitaa Date: Sat, 5 Dec 2015 23:09:20 +0100 Subject: [PATCH] Add tests --- src/librustdoc/html/markdown.rs | 27 +++++++++++++++++ src/librustdoc/html/render.rs | 19 ++++++++++++ src/test/rustdoc/issue-25001.rs | 53 +++++++++++++++++++++++++++++++++ src/test/rustdoc/issue-29449.rs | 30 +++++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 src/test/rustdoc/issue-25001.rs create mode 100644 src/test/rustdoc/issue-29449.rs diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index a6d6802c0e1..a5436886a7e 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -585,6 +585,7 @@ mod tests { fn issue_17736() { let markdown = "# title"; format!("{}", Markdown(markdown)); + reset_ids(); } #[test] @@ -609,6 +610,32 @@ mod tests { baz ❤ #qux"); } + #[test] + fn test_header_ids_multiple_blocks() { + fn t(input: &str, expect: &str) { + let output = format!("{}", Markdown(input)); + assert_eq!(output, expect); + } + + let test = || { + t("# Example", "\n

\ + Example

"); + t("# Panics", "\n

\ + Panics

"); + t("# Example", "\n

\ + Example

"); + t("# Main", "\n

\ + Main

"); + t("# Example", "\n

\ + Example

"); + t("# Panics", "\n

\ + Panics

"); + }; + test(); + reset_ids(); + test(); + } + #[test] fn test_plain_summary_line() { fn t(input: &str, expect: &str) { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index aac2a52984a..58d7a36aac8 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2708,3 +2708,22 @@ fn get_index_type_name(clean_type: &clean::Type) -> Option { pub fn cache() -> Arc { CACHE_KEY.with(|c| c.borrow().clone()) } + +#[cfg(test)] +#[test] +fn test_unique_id() { + let input = ["foo", "examples", "examples", "method.into_iter","examples", + "method.into_iter", "foo", "main", "search", "methods", + "examples", "method.into_iter", "assoc_type.Item", "assoc_type.Item"]; + let expected = ["foo", "examples", "examples-1", "method.into_iter", "examples-2", + "method.into_iter-1", "foo-1", "main-1", "search-1", "methods-1", + "examples-3", "method.into_iter-2", "assoc_type.Item", "assoc_type.Item-1"]; + + let test = || { + let actual: Vec = input.iter().map(|s| derive_id(s.to_string())).collect(); + assert_eq!(&actual[..], expected); + }; + test(); + reset_ids(); + test(); +} diff --git a/src/test/rustdoc/issue-25001.rs b/src/test/rustdoc/issue-25001.rs new file mode 100644 index 00000000000..e4d97828d50 --- /dev/null +++ b/src/test/rustdoc/issue-25001.rs @@ -0,0 +1,53 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// @has issue_25001/struct.Foo.html +pub struct Foo(T); + +pub trait Bar { + type Item; + + fn quux(self); +} + +impl Foo { + // @has - '//*[@id="method.pass"]//code' 'fn pass()' + pub fn pass() {} +} +impl Foo { + // @has - '//*[@id="method.pass-1"]//code' 'fn pass() -> usize' + pub fn pass() -> usize { 42 } +} +impl Foo { + // @has - '//*[@id="method.pass-2"]//code' 'fn pass() -> isize' + pub fn pass() -> isize { 42 } +} + +impl Bar for Foo { + // @has - '//*[@id="assoc_type.Item"]//code' 'type Item = T' + type Item=T; + + // @has - '//*[@id="method.quux"]//code' 'fn quux(self)' + fn quux(self) {} +} +impl<'a, T> Bar for &'a Foo { + // @has - '//*[@id="assoc_type.Item-1"]//code' "type Item = &'a T" + type Item=&'a T; + + // @has - '//*[@id="method.quux-1"]//code' 'fn quux(self)' + fn quux(self) {} +} +impl<'a, T> Bar for &'a mut Foo { + // @has - '//*[@id="assoc_type.Item-2"]//code' "type Item = &'a mut T" + type Item=&'a mut T; + + // @has - '//*[@id="method.quux-2"]//code' 'fn quux(self)' + fn quux(self) {} +} diff --git a/src/test/rustdoc/issue-29449.rs b/src/test/rustdoc/issue-29449.rs new file mode 100644 index 00000000000..f296048e30b --- /dev/null +++ b/src/test/rustdoc/issue-29449.rs @@ -0,0 +1,30 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// @has issue_29449/struct.Foo.html +pub struct Foo; + +impl Foo { + // @has - '//*[@id="examples"]//a' 'Examples' + // @has - '//*[@id="panics"]//a' 'Panics' + /// # Examples + /// # Panics + pub fn bar() {} + + // @has - '//*[@id="examples-1"]//a' 'Examples' + /// # Examples + pub fn bar_1() {} + + // @has - '//*[@id="examples-2"]//a' 'Examples' + // @has - '//*[@id="panics-1"]//a' 'Panics' + /// # Examples + /// # Panics + pub fn bar_2() {} +}