Skip to content

Commit

Permalink
Add GUI tests for comments highlighting in items declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 13, 2023
1 parent cb2d1ad commit a6e7262
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
73 changes: 73 additions & 0 deletions tests/rustdoc-gui/item-decl-comment-highlighting.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// This test checks that comments in item declarations are highlighted.
go-to: "file://" + |DOC_PATH| + "/test_docs/private/enum.Enum.html"
show-text: true

define-function: (
"check-item-decl-comment",
(theme, url, comment_color),
block {
go-to: |url|
set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}
reload:
assert-css: (".item-decl .comment", {"color": |comment_color|}, ALL)
}
)

define-function: (
"check-items-for-theme",
(theme, comment_color),
block {
call-function: ("check-item-decl-comment", {
"theme": |theme|,
"url": "file://" + |DOC_PATH| + "/test_docs/private/enum.Enum.html",
"comment_color": |comment_color|,
})
call-function: ("check-item-decl-comment", {
"theme": |theme|,
"url": "file://" + |DOC_PATH| + "/test_docs/private/struct.Struct.html",
"comment_color": |comment_color|,
})
call-function: ("check-item-decl-comment", {
"theme": |theme|,
"url": "file://" + |DOC_PATH| + "/test_docs/private/struct.Tuple.html",
"comment_color": |comment_color|,
})
call-function: ("check-item-decl-comment", {
"theme": |theme|,
"url": "file://" + |DOC_PATH| + "/test_docs/private/union.Union.html",
"comment_color": |comment_color|,
})
call-function: ("check-item-decl-comment", {
"theme": |theme|,
"url": "file://" + |DOC_PATH| + "/proc_macro_test/macro.make_answer.html",
"comment_color": |comment_color|,
})
call-function: ("check-item-decl-comment", {
"theme": |theme|,
"url": "file://" + |DOC_PATH| + "/proc_macro_test/derive.HelperAttr.html",
"comment_color": |comment_color|,
})
}
)

call-function: (
"check-items-for-theme",
{
"theme": "ayu",
"comment_color": "#788797",
}
)
call-function: (
"check-items-for-theme",
{
"theme": "dark",
"comment_color": "#8d8d8b",
}
)
call-function: (
"check-items-for-theme",
{
"theme": "light",
"comment_color": "#8e908c",
}
)
7 changes: 7 additions & 0 deletions tests/rustdoc-gui/src/proc_macro_test/Cargo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "proc_macro_test"
version = "0.1.0"
8 changes: 8 additions & 0 deletions tests/rustdoc-gui/src/proc_macro_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "proc_macro_test"
version = "0.1.0"
edition = "2021"

[lib]
path = "lib.rs"
proc-macro = true
11 changes: 11 additions & 0 deletions tests/rustdoc-gui/src/proc_macro_test/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use proc_macro::TokenStream;

#[proc_macro]
pub fn make_answer(_item: TokenStream) -> TokenStream {
"fn answer() -> u32 { 42 }".parse().unwrap()
}

#[proc_macro_derive(HelperAttr, attributes(helper))]
pub fn derive_helper_attr(_item: TokenStream) -> TokenStream {
TokenStream::new()
}
18 changes: 18 additions & 0 deletions tests/rustdoc-gui/src/test_docs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,21 @@ pub mod foreign_impl_order {
fn f(&mut self, fg: [u8; 3]) {}
}
}

pub mod private {
pub struct Tuple(u32, u8);
pub struct Struct {
a: u8,
}

pub union Union {
a: u8,
b: u16,
}

pub enum Enum {
A,
#[doc(hidden)]
B,
}
}

0 comments on commit a6e7262

Please sign in to comment.