Skip to content

Commit 7967152

Browse files
Add test for inherent impls anchors
1 parent 7d205af commit 7967152

8 files changed

+56
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div id="associatedconstant.YOLO" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/foo/anchors.rs.html#16">source</a></div><h4 class="code-header">const <a href="#associatedconstant.YOLO" class="constant">YOLO</a>: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<section id="associatedconstant.X" class="associatedconstant has-srclink"><span class="rightside"><a class="srclink" href="../src/foo/anchors.rs.html#42">source</a></span><h4 class="code-header">pub const <a href="#associatedconstant.X" class="constant">X</a>: <a class="primitive" href="{{channel}}/std/primitive.i32.html">i32</a> = 0i32</h4></section>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<section id="method.new" class="method has-srclink"><span class="rightside"><a class="srclink" href="../src/foo/anchors.rs.html#48">source</a></span><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a>() -&gt; Self</h4></section>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div id="method.bar" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/foo/anchors.rs.html#23">source</a></div><h4 class="code-header">fn <a href="#method.bar" class="fnname">bar</a>()</h4></div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div id="tymethod.foo" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/foo/anchors.rs.html#20">source</a></div><h4 class="code-header">fn <a href="#tymethod.foo" class="fnname">foo</a>()</h4></div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div id="associatedtype.T" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/foo/anchors.rs.html#13">source</a></div><h4 class="code-header">type <a href="#associatedtype.T" class="associatedtype">T</a></h4></div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<section id="associatedtype.Y" class="associatedtype has-srclink"><h4 class="code-header">type <a href="#associatedtype.Y" class="associatedtype">Y</a> = <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>

src/test/rustdoc/anchors.rs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This test ensures that anchors are generated in the right places.
2+
3+
#![feature(inherent_associated_types)]
4+
#![allow(incomplete_features)]
5+
#![crate_name = "foo"]
6+
7+
pub struct Foo;
8+
9+
// @has 'foo/trait.Bar.html'
10+
pub trait Bar {
11+
// There should be no anchors here.
12+
// @snapshot no_type_anchor - '//*[@id="associatedtype.T"]'
13+
type T;
14+
// There should be no anchors here.
15+
// @snapshot no_const_anchor - '//*[@id="associatedconstant.YOLO"]'
16+
const YOLO: u32;
17+
18+
// There should be no anchors here.
19+
// @snapshot no_tymethod_anchor - '//*[@id="tymethod.foo"]'
20+
fn foo();
21+
// There should be no anchors here.
22+
// @snapshot no_trait_method_anchor - '//*[@id="method.bar"]'
23+
fn bar() {}
24+
}
25+
26+
// @has 'foo/struct.Foo.html'
27+
impl Bar for Foo {
28+
// @has - '//*[@id="associatedtype.T"]/a[@class="anchor"]' ''
29+
type T = u32;
30+
// @has - '//*[@id="associatedconstant.YOLO"]/a[@class="anchor"]' ''
31+
const YOLO: u32 = 0;
32+
33+
// @has - '//*[@id="method.foo"]/a[@class="anchor"]' ''
34+
fn foo() {}
35+
// Same check for provided "bar" method.
36+
// @has - '//*[@id="method.bar"]/a[@class="anchor"]' ''
37+
}
38+
39+
impl Foo {
40+
// @snapshot no_const_anchor2 - '//*[@id="associatedconstant.X"]'
41+
// There should be no anchors here.
42+
pub const X: i32 = 0;
43+
// @snapshot no_type_anchor2 - '//*[@id="associatedtype.Y"]'
44+
// There should be no anchors here.
45+
pub type Y = u32;
46+
// @snapshot no_method_anchor - '//*[@id="method.new"]'
47+
// There should be no anchors here.
48+
pub fn new() -> Self { Self }
49+
}

0 commit comments

Comments
 (0)