about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2019-11-23 18:45:55 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2019-11-23 18:46:07 +0100
commit433f2b030b1c672bd19f38f6247d8aadce438189 (patch)
treed1725470bcdab2a3a3d2281043315f66547ed700
parent454d13badf6a5d423ba1cc56d106137752db719c (diff)
downloadrust-433f2b030b1c672bd19f38f6247d8aadce438189.tar.gz
rust-433f2b030b1c672bd19f38f6247d8aadce438189.zip
Add test for anchors
-rw-r--r--src/test/rustdoc-ui/intra-links-anchors.rs45
-rw-r--r--src/test/rustdoc-ui/intra-links-anchors.stderr32
-rw-r--r--src/test/rustdoc/intra-links-anchors.rs12
3 files changed, 89 insertions, 0 deletions
diff --git a/src/test/rustdoc-ui/intra-links-anchors.rs b/src/test/rustdoc-ui/intra-links-anchors.rs
new file mode 100644
index 00000000000..8603f65dde1
--- /dev/null
+++ b/src/test/rustdoc-ui/intra-links-anchors.rs
@@ -0,0 +1,45 @@
+#![deny(intra_doc_link_resolution_failure)]
+
+// A few tests on anchors.
+
+/// Hello people.
+///
+/// You can anchors? Here's one!
+///
+/// # hola
+///
+/// Isn't it amazing?
+pub struct Foo {
+    pub f: u8,
+}
+
+pub enum Enum {
+    A,
+    B,
+}
+
+/// Have you heard about stuff?
+///
+/// Like [Foo#hola].
+///
+/// Or maybe [Foo::f#hola].
+//~^ ERROR `[Foo::f#hola]` has an anchor issue...
+pub fn foo() {}
+
+/// Empty.
+///
+/// Another anchor error: [hello#people#!].
+//~^ ERROR `[hello#people#!]` has an anchor issue...
+pub fn bar() {}
+
+/// Empty?
+///
+/// Damn enum's variants: [Enum::A#whatever].
+//~^ ERROR `[Enum::A#whatever]` has an anchor issue...
+pub fn enum_link() {}
+
+/// Primitives?
+///
+/// [u32#hello]
+//~^ ERROR `[u32#hello]` has an anchor issue...
+pub fn x() {}
diff --git a/src/test/rustdoc-ui/intra-links-anchors.stderr b/src/test/rustdoc-ui/intra-links-anchors.stderr
new file mode 100644
index 00000000000..39e83b5659b
--- /dev/null
+++ b/src/test/rustdoc-ui/intra-links-anchors.stderr
@@ -0,0 +1,32 @@
+error: `[Foo::f#hola]` has an anchor issue...
+  --> $DIR/intra-links-anchors.rs:25:15
+   |
+LL | /// Or maybe [Foo::f#hola].
+   |               ^^^^^^^^^^^ struct fields cannot be followed by anchors
+   |
+note: lint level defined here
+  --> $DIR/intra-links-anchors.rs:1:9
+   |
+LL | #![deny(intra_doc_link_resolution_failure)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: `[hello#people#!]` has an anchor issue...
+  --> $DIR/intra-links-anchors.rs:31:28
+   |
+LL | /// Another anchor error: [hello#people#!].
+   |                            ^^^^^^^^^^^^^^ only one `#` is allowed in a link
+
+error: `[Enum::A#whatever]` has an anchor issue...
+  --> $DIR/intra-links-anchors.rs:37:28
+   |
+LL | /// Damn enum's variants: [Enum::A#whatever].
+   |                            ^^^^^^^^^^^^^^^^ variants cannot be followed by anchors
+
+error: `[u32#hello]` has an anchor issue...
+  --> $DIR/intra-links-anchors.rs:43:6
+   |
+LL | /// [u32#hello]
+   |      ^^^^^^^^^ primitive types cannot be followed by anchors
+
+error: aborting due to 4 previous errors
+
diff --git a/src/test/rustdoc/intra-links-anchors.rs b/src/test/rustdoc/intra-links-anchors.rs
new file mode 100644
index 00000000000..f554e16b4f4
--- /dev/null
+++ b/src/test/rustdoc/intra-links-anchors.rs
@@ -0,0 +1,12 @@
+/// I want...
+///
+/// # Anchor!
+pub struct Something;
+
+// @has intra_links_anchors/struct.SomeOtherType.html
+// @has - '//a/@href' '../intra_links_anchors/struct.Something.html#Anchor!'
+
+/// I want...
+///
+/// To link to [Something#Anchor!]
+pub struct SomeOtherType;