Skip to content

Commit 140640a

Browse files
Add regression test for patterns support in "jump to def" feature
1 parent f6525a6 commit 140640a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/rustdoc/jump-to-def-pats.rs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// This test ensures that patterns also get a link generated.
2+
3+
//@ compile-flags: -Zunstable-options --generate-link-to-definition
4+
5+
#![crate_name = "foo"]
6+
7+
//@ has 'src/foo/jump-to-def-pats.rs.html'
8+
9+
use std::fmt;
10+
11+
pub enum MyEnum<T, E> {
12+
Ok(T),
13+
Err(E),
14+
Some(T),
15+
None,
16+
}
17+
18+
pub enum X {
19+
A,
20+
}
21+
22+
pub fn foo() -> Result<(), ()> {
23+
// FIXME: would be nice to be able to check both the class and the href at the same time so
24+
// we could check the text as well...
25+
//@ has - '//a[@class="prelude-val"]/@href' '{{channel}}/core/result/enum.Result.html#variant.Ok'
26+
//@ has - '//a[@href="{{channel}}/core/result/enum.Result.html#variant.Ok"]' 'Ok'
27+
Ok(())
28+
}
29+
30+
impl<T, E> fmt::Display for MyEnum<T, E> {
31+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32+
match self {
33+
//@ has - '//a[@href="#12"]' 'Self::Ok'
34+
Self::Ok(_) => f.write_str("MyEnum::Ok"),
35+
//@ has - '//a[@href="#13"]' 'MyEnum::Err'
36+
MyEnum::Err(_) => f.write_str("MyEnum::Err"),
37+
//@ has - '//a[@href="#14"]' 'Self::Some'
38+
Self::Some(_) => f.write_str("MyEnum::Some"),
39+
//@ has - '//a[@href="#15"]' 'Self::None'
40+
Self::None => f.write_str("MyEnum::None"),
41+
}
42+
}
43+
}
44+
45+
impl X {
46+
fn p(&self) -> &str {
47+
match self {
48+
//@ has - '//a[@href="#19"]' 'Self::A'
49+
Self::A => "X::A",
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)