rustdoc: merge doctest tooltip with notable traits tooltip

Fixes https://discord.com/channels/442252698964721669/443150878111694848/1066420140167680000

Fixes #91100
This commit is contained in:
Michael Howell 2023-01-26 13:32:33 -07:00
parent c62665e09c
commit 7aa4a205a8
12 changed files with 184 additions and 234 deletions

View File

@ -96,13 +96,19 @@ fn write_header(out: &mut Buffer, class: &str, extra_content: Option<Buffer>, to
); );
if tooltip != Tooltip::None { if tooltip != Tooltip::None {
let edition_code;
write!( write!(
out, out,
"<div class='tooltip'{}>ⓘ</div>", "<a href=\"#\" class=\"tooltip\" title=\"{}\">ⓘ</a>",
if let Tooltip::Edition(edition_info) = tooltip { match tooltip {
format!(" data-edition=\"{}\"", edition_info) Tooltip::Ignore => "This example is not tested",
} else { Tooltip::CompileFail => "This example deliberately fails to compile",
String::new() Tooltip::ShouldPanic => "This example panics",
Tooltip::Edition(edition) => {
edition_code = format!("This example runs with edition {edition}");
&edition_code
}
Tooltip::None => unreachable!(),
}, },
); );
} }

View File

@ -1313,7 +1313,7 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> O
if has_notable_trait { if has_notable_trait {
cx.types_with_notable_traits.insert(ty.clone()); cx.types_with_notable_traits.insert(ty.clone());
Some(format!( Some(format!(
" <a href=\"#\" class=\"notable-traits\" data-ty=\"{ty}\">ⓘ</a>", " <a href=\"#\" class=\"tooltip\" data-notable-ty=\"{ty}\">ⓘ</a>",
ty = Escape(&format!("{:#}", ty.print(cx))), ty = Escape(&format!("{:#}", ty.print(cx))),
)) ))
} else { } else {

View File

@ -697,8 +697,8 @@ h2.small-section-header > .anchor {
.main-heading a:hover, .main-heading a:hover,
.example-wrap > pre.rust a:hover, .example-wrap > pre.rust a:hover,
.all-items a:hover, .all-items a:hover,
.docblock a:not(.test-arrow):not(.scrape-help):hover, .docblock a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover,
.docblock-short a:not(.test-arrow):not(.scrape-help):hover, .docblock-short a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover,
.item-info a { .item-info a {
text-decoration: underline; text-decoration: underline;
} }
@ -1093,44 +1093,8 @@ pre.rust .doccomment {
display: block; display: block;
left: -25px; left: -25px;
top: 5px; top: 5px;
} margin: 0;
line-height: 1;
.example-wrap .tooltip:hover::after {
padding: 5px 3px 3px 3px;
border-radius: 6px;
margin-left: 5px;
font-size: 1rem;
border: 1px solid var(--border-color);
position: absolute;
width: max-content;
top: -2px;
z-index: 1;
background-color: var(--tooltip-background-color);
color: var(--tooltip-color);
}
.example-wrap .tooltip:hover::before {
content: " ";
position: absolute;
top: 50%;
left: 16px;
margin-top: -5px;
z-index: 1;
border: 5px solid transparent;
border-right-color: var(--tooltip-background-color);
}
.example-wrap.ignore .tooltip:hover::after {
content: "This example is not tested";
}
.example-wrap.compile_fail .tooltip:hover::after {
content: "This example deliberately fails to compile";
}
.example-wrap.should_panic .tooltip:hover::after {
content: "This example panics";
}
.example-wrap.edition .tooltip:hover::after {
content: "This code runs with edition " attr(data-edition);
} }
.example-wrap.compile_fail .tooltip, .example-wrap.compile_fail .tooltip,
@ -1196,7 +1160,7 @@ a.test-arrow:hover {
border-right: 3px solid var(--target-border-color); border-right: 3px solid var(--target-border-color);
} }
.notable-traits { .code-header a.tooltip {
color: inherit; color: inherit;
margin-right: 15px; margin-right: 15px;
position: relative; position: relative;
@ -1205,7 +1169,7 @@ a.test-arrow:hover {
/* placeholder thunk so that the mouse can easily travel from "(i)" to popover /* placeholder thunk so that the mouse can easily travel from "(i)" to popover
the resulting "hover tunnel" is a stepped triangle, approximating the resulting "hover tunnel" is a stepped triangle, approximating
https://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown */ https://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown */
.notable-traits:hover::after { a.tooltip:hover::after {
position: absolute; position: absolute;
top: calc(100% - 10px); top: calc(100% - 10px);
left: -15px; left: -15px;
@ -1214,11 +1178,11 @@ a.test-arrow:hover {
content: "\00a0"; content: "\00a0";
} }
.notable .content { .popover.tooltip .content {
margin: 0.25em 0.5em; margin: 0.25em 0.5em;
} }
.notable .content pre, .notable .content code { .popover.tooltip .content pre, .popover.tooltip .content code {
background: transparent; background: transparent;
margin: 0; margin: 0;
padding: 0; padding: 0;
@ -1226,7 +1190,7 @@ a.test-arrow:hover {
white-space: pre-wrap; white-space: pre-wrap;
} }
.notable .content > h3:first-child { .popover.tooltip .content > h3:first-child {
margin: 0 0 5px 0; margin: 0 0 5px 0;
} }

View File

@ -70,8 +70,6 @@ Original by Dempfi (https://github.com/dempfi/ayu)
--test-arrow-hover-background-color: rgba(57, 175, 215, 0.368); --test-arrow-hover-background-color: rgba(57, 175, 215, 0.368);
--target-background-color: rgba(255, 236, 164, 0.06); --target-background-color: rgba(255, 236, 164, 0.06);
--target-border-color: rgba(255, 180, 76, 0.85); --target-border-color: rgba(255, 180, 76, 0.85);
--tooltip-background-color: #314559;
--tooltip-color: #c5c5c5;
--kbd-color: #c5c5c5; --kbd-color: #c5c5c5;
--kbd-background: #314559; --kbd-background: #314559;
--kbd-box-shadow-color: #5c6773; --kbd-box-shadow-color: #5c6773;

View File

@ -65,8 +65,6 @@
--test-arrow-hover-background-color: #4e8bca; --test-arrow-hover-background-color: #4e8bca;
--target-background-color: #494a3d; --target-background-color: #494a3d;
--target-border-color: #bb7410; --target-border-color: #bb7410;
--tooltip-background-color: #000;
--tooltip-color: #fff;
--kbd-color: #000; --kbd-color: #000;
--kbd-background: #fafbfc; --kbd-background: #fafbfc;
--kbd-box-shadow-color: #c6cbd1; --kbd-box-shadow-color: #c6cbd1;

View File

@ -65,8 +65,6 @@
--test-arrow-hover-background-color: #4e8bca; --test-arrow-hover-background-color: #4e8bca;
--target-background-color: #fdffd3; --target-background-color: #fdffd3;
--target-border-color: #ad7c37; --target-border-color: #ad7c37;
--tooltip-background-color: #000;
--tooltip-color: #fff;
--kbd-color: #000; --kbd-color: #000;
--kbd-background: #fafbfc; --kbd-background: #fafbfc;
--kbd-box-shadow-color: #c6cbd1; --kbd-box-shadow-color: #c6cbd1;

View File

@ -379,7 +379,7 @@ function loadCss(cssUrl) {
} }
ev.preventDefault(); ev.preventDefault();
searchState.defocus(); searchState.defocus();
window.hideAllModals(true); // true = reset focus for notable traits window.hideAllModals(true); // true = reset focus for tooltips
} }
function handleShortcut(ev) { function handleShortcut(ev) {
@ -789,17 +789,17 @@ function loadCss(cssUrl) {
// we need to switch away from mobile mode and make the main content area scrollable. // we need to switch away from mobile mode and make the main content area scrollable.
hideSidebar(); hideSidebar();
} }
if (window.CURRENT_NOTABLE_ELEMENT) { if (window.CURRENT_TOOLTIP_ELEMENT) {
// As a workaround to the behavior of `contains: layout` used in doc togglers, the // As a workaround to the behavior of `contains: layout` used in doc togglers,
// notable traits popup is positioned using javascript. // tooltip popovers are positioned using javascript.
// //
// This means when the window is resized, we need to redo the layout. // This means when the window is resized, we need to redo the layout.
const base = window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE; const base = window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE;
const force_visible = base.NOTABLE_FORCE_VISIBLE; const force_visible = base.TOOLTIP_FORCE_VISIBLE;
hideNotable(false); hideTooltip(false);
if (force_visible) { if (force_visible) {
showNotable(base); showTooltip(base);
base.NOTABLE_FORCE_VISIBLE = true; base.TOOLTIP_FORCE_VISIBLE = true;
} }
} }
}); });
@ -827,27 +827,35 @@ function loadCss(cssUrl) {
}); });
}); });
function showNotable(e) { function showTooltip(e) {
if (!window.NOTABLE_TRAITS) { const notable_ty = e.getAttribute("data-notable-ty");
if (!window.NOTABLE_TRAITS && notable_ty) {
const data = document.getElementById("notable-traits-data"); const data = document.getElementById("notable-traits-data");
if (data) { if (data) {
window.NOTABLE_TRAITS = JSON.parse(data.innerText); window.NOTABLE_TRAITS = JSON.parse(data.innerText);
} else { } else {
throw new Error("showNotable() called on page without any notable traits!"); throw new Error("showTooltip() called with notable without any notable traits!");
} }
} }
if (window.CURRENT_NOTABLE_ELEMENT && window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE === e) { if (window.CURRENT_TOOLTIP_ELEMENT && window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE === e) {
// Make this function idempotent. // Make this function idempotent.
return; return;
} }
window.hideAllModals(false); window.hideAllModals(false);
const ty = e.getAttribute("data-ty");
const wrapper = document.createElement("div"); const wrapper = document.createElement("div");
wrapper.innerHTML = "<div class=\"content\">" + window.NOTABLE_TRAITS[ty] + "</div>"; if (notable_ty) {
wrapper.className = "notable popover"; wrapper.innerHTML = "<div class=\"content\">" +
window.NOTABLE_TRAITS[notable_ty] + "</div>";
} else if (e.getAttribute("title") !== undefined) {
const titleContent = document.createElement("div");
titleContent.className = "content";
titleContent.appendChild(document.createTextNode(e.getAttribute("title")));
wrapper.appendChild(titleContent);
}
wrapper.className = "tooltip popover";
const focusCatcher = document.createElement("div"); const focusCatcher = document.createElement("div");
focusCatcher.setAttribute("tabindex", "0"); focusCatcher.setAttribute("tabindex", "0");
focusCatcher.onfocus = hideNotable; focusCatcher.onfocus = hideTooltip;
wrapper.appendChild(focusCatcher); wrapper.appendChild(focusCatcher);
const pos = e.getBoundingClientRect(); const pos = e.getBoundingClientRect();
// 5px overlap so that the mouse can easily travel from place to place // 5px overlap so that the mouse can easily travel from place to place
@ -869,62 +877,62 @@ function loadCss(cssUrl) {
); );
} }
wrapper.style.visibility = ""; wrapper.style.visibility = "";
window.CURRENT_NOTABLE_ELEMENT = wrapper; window.CURRENT_TOOLTIP_ELEMENT = wrapper;
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE = e; window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE = e;
wrapper.onpointerleave = function(ev) { wrapper.onpointerleave = function(ev) {
// If this is a synthetic touch event, ignore it. A click event will be along shortly. // If this is a synthetic touch event, ignore it. A click event will be along shortly.
if (ev.pointerType !== "mouse") { if (ev.pointerType !== "mouse") {
return; return;
} }
if (!e.NOTABLE_FORCE_VISIBLE && !elemIsInParent(event.relatedTarget, e)) { if (!e.TOOLTIP_FORCE_VISIBLE && !elemIsInParent(event.relatedTarget, e)) {
hideNotable(true); hideTooltip(true);
} }
}; };
} }
function notableBlurHandler(event) { function tooltipBlurHandler(event) {
if (window.CURRENT_NOTABLE_ELEMENT && if (window.CURRENT_TOOLTIP_ELEMENT &&
!elemIsInParent(document.activeElement, window.CURRENT_NOTABLE_ELEMENT) && !elemIsInParent(document.activeElement, window.CURRENT_TOOLTIP_ELEMENT) &&
!elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT) && !elemIsInParent(event.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT) &&
!elemIsInParent(document.activeElement, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE) && !elemIsInParent(document.activeElement, window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE) &&
!elemIsInParent(event.relatedTarget, window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE) !elemIsInParent(event.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE)
) { ) {
// Work around a difference in the focus behaviour between Firefox, Chrome, and Safari. // Work around a difference in the focus behaviour between Firefox, Chrome, and Safari.
// When I click the button on an already-opened notable trait popover, Safari // When I click the button on an already-opened tooltip popover, Safari
// hides the popover and then immediately shows it again, while everyone else hides it // hides the popover and then immediately shows it again, while everyone else hides it
// and it stays hidden. // and it stays hidden.
// //
// To work around this, make sure the click finishes being dispatched before // To work around this, make sure the click finishes being dispatched before
// hiding the popover. Since `hideNotable()` is idempotent, this makes Safari behave // hiding the popover. Since `hideTooltip()` is idempotent, this makes Safari behave
// consistently with the other two. // consistently with the other two.
setTimeout(() => hideNotable(false), 0); setTimeout(() => hideTooltip(false), 0);
} }
} }
function hideNotable(focus) { function hideTooltip(focus) {
if (window.CURRENT_NOTABLE_ELEMENT) { if (window.CURRENT_TOOLTIP_ELEMENT) {
if (window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE) { if (window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.TOOLTIP_FORCE_VISIBLE) {
if (focus) { if (focus) {
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.focus(); window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.focus();
} }
window.CURRENT_NOTABLE_ELEMENT.NOTABLE_BASE.NOTABLE_FORCE_VISIBLE = false; window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.TOOLTIP_FORCE_VISIBLE = false;
} }
const body = document.getElementsByTagName("body")[0]; const body = document.getElementsByTagName("body")[0];
body.removeChild(window.CURRENT_NOTABLE_ELEMENT); body.removeChild(window.CURRENT_TOOLTIP_ELEMENT);
window.CURRENT_NOTABLE_ELEMENT = null; window.CURRENT_TOOLTIP_ELEMENT = null;
} }
} }
onEachLazy(document.getElementsByClassName("notable-traits"), e => { onEachLazy(document.getElementsByClassName("tooltip"), e => {
e.onclick = function() { e.onclick = function() {
this.NOTABLE_FORCE_VISIBLE = this.NOTABLE_FORCE_VISIBLE ? false : true; this.TOOLTIP_FORCE_VISIBLE = this.TOOLTIP_FORCE_VISIBLE ? false : true;
if (window.CURRENT_NOTABLE_ELEMENT && !this.NOTABLE_FORCE_VISIBLE) { if (window.CURRENT_TOOLTIP_ELEMENT && !this.TOOLTIP_FORCE_VISIBLE) {
hideNotable(true); hideTooltip(true);
} else { } else {
showNotable(this); showTooltip(this);
window.CURRENT_NOTABLE_ELEMENT.setAttribute("tabindex", "0"); window.CURRENT_TOOLTIP_ELEMENT.setAttribute("tabindex", "0");
window.CURRENT_NOTABLE_ELEMENT.focus(); window.CURRENT_TOOLTIP_ELEMENT.focus();
window.CURRENT_NOTABLE_ELEMENT.onblur = notableBlurHandler; window.CURRENT_TOOLTIP_ELEMENT.onblur = tooltipBlurHandler;
} }
return false; return false;
}; };
@ -933,16 +941,16 @@ function loadCss(cssUrl) {
if (ev.pointerType !== "mouse") { if (ev.pointerType !== "mouse") {
return; return;
} }
showNotable(this); showTooltip(this);
}; };
e.onpointerleave = function(ev) { e.onpointerleave = function(ev) {
// If this is a synthetic touch event, ignore it. A click event will be along shortly. // If this is a synthetic touch event, ignore it. A click event will be along shortly.
if (ev.pointerType !== "mouse") { if (ev.pointerType !== "mouse") {
return; return;
} }
if (!this.NOTABLE_FORCE_VISIBLE && if (!this.TOOLTIP_FORCE_VISIBLE &&
!elemIsInParent(ev.relatedTarget, window.CURRENT_NOTABLE_ELEMENT)) { !elemIsInParent(ev.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT)) {
hideNotable(true); hideTooltip(true);
} }
}; };
}); });
@ -1044,14 +1052,14 @@ function loadCss(cssUrl) {
} }
/** /**
* Hide popover menus, notable trait tooltips, and the sidebar (if applicable). * Hide popover menus, clickable tooltips, and the sidebar (if applicable).
* *
* Pass "true" to reset focus for notable traits. * Pass "true" to reset focus for tooltip popovers.
*/ */
window.hideAllModals = function(switchFocus) { window.hideAllModals = function(switchFocus) {
hideSidebar(); hideSidebar();
window.hidePopoverMenus(); window.hidePopoverMenus();
hideNotable(switchFocus); hideTooltip(switchFocus);
}; };
/** /**

View File

@ -30,24 +30,16 @@ define-function: (
".docblock .example-wrap.compile_fail", ".docblock .example-wrap.compile_fail",
{"border-left": "2px solid rgb(255, 0, 0)"}, {"border-left": "2px solid rgb(255, 0, 0)"},
) )
assert-css: ( click: ".docblock .example-wrap.compile_fail .tooltip"
".docblock .example-wrap.compile_fail .tooltip::after", assert-text: (
{ ".popover.tooltip",
"content": '"This example deliberately fails to compile"', "This example deliberately fails to compile"
"padding": "5px 3px 3px",
"background-color": |background|,
"color": |color|,
"border": "1px solid " + |border|,
},
)
assert-css: (
".docblock .example-wrap.compile_fail .tooltip::before",
{
"border-width": "5px",
"border-style": "solid",
"border-color": "rgba(0, 0, 0, 0) " + |background| + " rgba(0, 0, 0, 0) rgba(0, 0, 0, 0)",
},
) )
assert-css: (".popover.tooltip", {
"color": |color|,
"background-color": |background|,
"border-color": |border|,
})
// should_panic block // should_panic block
assert-css: ( assert-css: (
@ -69,24 +61,16 @@ define-function: (
".docblock .example-wrap.should_panic", ".docblock .example-wrap.should_panic",
{"border-left": "2px solid rgb(255, 0, 0)"}, {"border-left": "2px solid rgb(255, 0, 0)"},
) )
assert-css: ( click: ".docblock .example-wrap.should_panic .tooltip"
".docblock .example-wrap.should_panic .tooltip::after", assert-text: (
{ ".popover.tooltip",
"content": '"This example panics"', "This example panics"
"padding": "5px 3px 3px",
"background-color": |background|,
"color": |color|,
"border": "1px solid " + |border|,
},
)
assert-css: (
".docblock .example-wrap.should_panic .tooltip::before",
{
"border-width": "5px",
"border-style": "solid",
"border-color": "rgba(0, 0, 0, 0) " + |background| + " rgba(0, 0, 0, 0) rgba(0, 0, 0, 0)",
},
) )
assert-css: (".popover.tooltip", {
"color": |color|,
"background-color": |background|,
"border-color": |border|,
})
// ignore block // ignore block
assert-css: ( assert-css: (
@ -108,42 +92,36 @@ define-function: (
".docblock .example-wrap.ignore", ".docblock .example-wrap.ignore",
{"border-left": "2px solid rgb(255, 142, 0)"}, {"border-left": "2px solid rgb(255, 142, 0)"},
) )
assert-css: ( click: ".docblock .example-wrap.ignore .tooltip"
".docblock .example-wrap.ignore .tooltip::after", assert-text: (
{ ".popover.tooltip",
"content": '"This example is not tested"', "This example is not tested"
"padding": "5px 3px 3px",
"background-color": |background|,
"color": |color|,
"border": "1px solid " + |border|,
},
)
assert-css: (
".docblock .example-wrap.ignore .tooltip::before",
{
"border-width": "5px",
"border-style": "solid",
"border-color": "rgba(0, 0, 0, 0) " + |background| + " rgba(0, 0, 0, 0) rgba(0, 0, 0, 0)",
},
) )
assert-css: (".popover.tooltip", {
"color": |color|,
"background-color": |background|,
"border-color": |border|,
})
click: ".docblock .example-wrap.ignore .tooltip"
assert-false: ".popover.tooltip"
}, },
) )
call-function: ("check-colors", { call-function: ("check-colors", {
"theme": "ayu", "theme": "ayu",
"background": "rgb(49, 69, 89)", "background": "rgb(15, 20, 25)",
"color": "rgb(197, 197, 197)", "color": "rgb(197, 197, 197)",
"border": "rgb(92, 103, 115)", "border": "rgb(92, 103, 115)",
}) })
call-function: ("check-colors", { call-function: ("check-colors", {
"theme": "dark", "theme": "dark",
"background": "rgb(0, 0, 0)", "background": "rgb(53, 53, 53)",
"color": "rgb(255, 255, 255)", "color": "rgb(221, 221, 221)",
"border": "rgb(224, 224, 224)", "border": "rgb(224, 224, 224)",
}) })
call-function: ("check-colors", { call-function: ("check-colors", {
"theme": "light", "theme": "light",
"background": "rgb(0, 0, 0)", "background": "rgb(255, 255, 255)",
"color": "rgb(255, 255, 255)", "color": "rgb(0, 0, 0)",
"border": "rgb(224, 224, 224)", "border": "rgb(224, 224, 224)",
}) })

View File

@ -6,13 +6,13 @@ size: (1100, 600)
// Checking they have the same y position. // Checking they have the same y position.
compare-elements-position: ( compare-elements-position: (
"//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']", "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
("y"), ("y"),
) )
// Checking they don't have the same x position. // Checking they don't have the same x position.
compare-elements-position-false: ( compare-elements-position-false: (
"//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']", "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
("x"), ("x"),
) )
// The `i` should be *after* the type. // The `i` should be *after* the type.
@ -21,33 +21,33 @@ assert-position: (
{"x": 677}, {"x": 677},
) )
assert-position: ( assert-position: (
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
{"x": 955}, {"x": 955},
) )
// The tooltip should be below the `i` // The tooltip should be below the `i`
// Also, clicking the tooltip should bring its text into the DOM // Also, clicking the tooltip should bring its text into the DOM
assert-count: ("//*[@class='notable popover']", 0) assert-count: ("//*[@class='tooltip popover']", 0)
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
assert-count: ("//*[@class='notable popover']", 1) assert-count: ("//*[@class='tooltip popover']", 1)
compare-elements-position-near: ( compare-elements-position-near: (
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
"//*[@class='notable popover']", "//*[@class='tooltip popover']",
{"y": 30} {"y": 30}
) )
compare-elements-position-false: ( compare-elements-position-false: (
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
"//*[@class='notable popover']", "//*[@class='tooltip popover']",
("x") ("x")
) )
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
move-cursor-to: "//h1" move-cursor-to: "//h1"
assert-count: ("//*[@class='notable popover']", 0) assert-count: ("//*[@class='tooltip popover']", 0)
// Now only the `i` should be on the next line. // Now only the `i` should be on the next line.
size: (1055, 600) size: (1055, 600)
compare-elements-position-false: ( compare-elements-position-false: (
"//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']", "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
("y", "x"), ("y", "x"),
) )
@ -56,13 +56,13 @@ size: (980, 600)
// Checking they have the same y position. // Checking they have the same y position.
compare-elements-position: ( compare-elements-position: (
"//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']", "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
("y"), ("y"),
) )
// Checking they don't have the same x position. // Checking they don't have the same x position.
compare-elements-position-false: ( compare-elements-position-false: (
"//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']", "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
("x"), ("x"),
) )
// The `i` should be *after* the type. // The `i` should be *after* the type.
@ -71,7 +71,7 @@ assert-position: (
{"x": 245}, {"x": 245},
) )
assert-position: ( assert-position: (
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
{"x": 523}, {"x": 523},
) )
@ -80,13 +80,13 @@ size: (650, 600)
// Checking they have the same y position. // Checking they have the same y position.
compare-elements-position: ( compare-elements-position: (
"//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']", "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
("y"), ("y"),
) )
// Checking they don't have the same x position. // Checking they don't have the same x position.
compare-elements-position-false: ( compare-elements-position-false: (
"//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']", "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
("x"), ("x"),
) )
// The `i` should be *after* the type. // The `i` should be *after* the type.
@ -95,29 +95,29 @@ assert-position: (
{"x": 15}, {"x": 15},
) )
assert-position: ( assert-position: (
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
{"x": 293}, {"x": 293},
) )
// The tooltip should STILL be below `i` // The tooltip should STILL be below `i`
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
assert-count: ("//*[@class='notable popover']", 1) assert-count: ("//*[@class='tooltip popover']", 1)
compare-elements-position-near: ( compare-elements-position-near: (
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
"//*[@class='notable popover']", "//*[@class='tooltip popover']",
{"y": 30} {"y": 30}
) )
compare-elements-position-false: ( compare-elements-position-false: (
"//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']", "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']",
"//*[@class='notable popover']", "//*[@class='tooltip popover']",
("x") ("x")
) )
assert-position: ( assert-position: (
"//*[@class='notable popover']", "//*[@class='tooltip popover']",
{"x": 0} {"x": 0}
) )
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
move-cursor-to: "//h1" move-cursor-to: "//h1"
assert-count: ("//*[@class='notable popover']", 0) assert-count: ("//*[@class='tooltip popover']", 0)
// Now check the colors. // Now check the colors.
define-function: ( define-function: (
@ -133,26 +133,26 @@ define-function: (
// We reload the page so the local storage settings are being used. // We reload the page so the local storage settings are being used.
reload: reload:
move-cursor-to: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" move-cursor-to: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
assert-count: (".notable.popover", 1) assert-count: (".tooltip.popover", 1)
assert-css: ( assert-css: (
".notable.popover h3", ".tooltip.popover h3",
{"color": |header_color|}, {"color": |header_color|},
ALL, ALL,
) )
assert-css: ( assert-css: (
".notable.popover pre", ".tooltip.popover pre",
{"color": |content_color|}, {"color": |content_color|},
ALL, ALL,
) )
assert-css: ( assert-css: (
".notable.popover pre a.struct", ".tooltip.popover pre a.struct",
{"color": |type_color|}, {"color": |type_color|},
ALL, ALL,
) )
assert-css: ( assert-css: (
".notable.popover pre a.trait", ".tooltip.popover pre a.trait",
{"color": |trait_color|}, {"color": |trait_color|},
ALL, ALL,
) )
@ -195,24 +195,24 @@ call-function: (
reload: reload:
// Check that pressing escape works // Check that pressing escape works
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
move-cursor-to: "//*[@class='notable popover']" move-cursor-to: "//*[@class='tooltip popover']"
assert-count: ("//*[@class='notable popover']", 1) assert-count: ("//*[@class='tooltip popover']", 1)
press-key: "Escape" press-key: "Escape"
assert-count: ("//*[@class='notable popover']", 0) assert-count: ("//*[@class='tooltip popover']", 0)
assert: "#method\.create_an_iterator_from_read .notable-traits:focus" assert: "#method\.create_an_iterator_from_read .tooltip:focus"
// Check that clicking outside works. // Check that clicking outside works.
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
assert-count: ("//*[@class='notable popover']", 1) assert-count: ("//*[@class='tooltip popover']", 1)
click: ".search-input" click: ".search-input"
assert-count: ("//*[@class='notable popover']", 0) assert-count: ("//*[@class='tooltip popover']", 0)
assert-false: "#method\.create_an_iterator_from_read .notable-traits:focus" assert-false: "#method\.create_an_iterator_from_read .tooltip:focus"
// Check that pressing tab over and over works. // Check that pressing tab over and over works.
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
move-cursor-to: "//*[@class='notable popover']" move-cursor-to: "//*[@class='tooltip popover']"
assert-count: ("//*[@class='notable popover']", 1) assert-count: ("//*[@class='tooltip popover']", 1)
press-key: "Tab" press-key: "Tab"
press-key: "Tab" press-key: "Tab"
press-key: "Tab" press-key: "Tab"
@ -220,8 +220,8 @@ press-key: "Tab"
press-key: "Tab" press-key: "Tab"
press-key: "Tab" press-key: "Tab"
press-key: "Tab" press-key: "Tab"
assert-count: ("//*[@class='notable popover']", 0) assert-count: ("//*[@class='tooltip popover']", 0)
assert: "#method\.create_an_iterator_from_read .notable-traits:focus" assert: "#method\.create_an_iterator_from_read .tooltip:focus"
// Now we check that the focus isn't given back to the wrong item when opening // Now we check that the focus isn't given back to the wrong item when opening
// another popover. // another popover.
@ -231,8 +231,8 @@ click: "#method\.create_an_iterator_from_read .fn"
assert-window-property-false: {"scrollY": |scroll|} assert-window-property-false: {"scrollY": |scroll|}
// Store the new position. // Store the new position.
store-window-property: (scroll, "scrollY") store-window-property: (scroll, "scrollY")
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
wait-for: "//*[@class='notable popover']" wait-for: "//*[@class='tooltip popover']"
click: "#settings-menu a" click: "#settings-menu a"
click: ".search-input" click: ".search-input"
// We ensure we didn't come back to the previous focused item. // We ensure we didn't come back to the previous focused item.
@ -245,8 +245,8 @@ click: "#method\.create_an_iterator_from_read .fn"
assert-window-property-false: {"scrollY": |scroll|} assert-window-property-false: {"scrollY": |scroll|}
// Store the new position. // Store the new position.
store-window-property: (scroll, "scrollY") store-window-property: (scroll, "scrollY")
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
wait-for: "//*[@class='notable popover']" wait-for: "//*[@class='tooltip popover']"
click: "#settings-menu a" click: "#settings-menu a"
press-key: "Escape" press-key: "Escape"
// We ensure we didn't come back to the previous focused item. // We ensure we didn't come back to the previous focused item.
@ -254,23 +254,23 @@ assert-window-property-false: {"scrollY": |scroll|}
// Opening the mobile sidebar should close the popover. // Opening the mobile sidebar should close the popover.
size: (650, 600) size: (650, 600)
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
assert-count: ("//*[@class='notable popover']", 1) assert-count: ("//*[@class='tooltip popover']", 1)
click: ".sidebar-menu-toggle" click: ".sidebar-menu-toggle"
assert: "//*[@class='sidebar shown']" assert: "//*[@class='sidebar shown']"
assert-count: ("//*[@class='notable popover']", 0) assert-count: ("//*[@class='tooltip popover']", 0)
assert-false: "#method\.create_an_iterator_from_read .notable-traits:focus" assert-false: "#method\.create_an_iterator_from_read .tooltip:focus"
// Clicking a notable popover should close the sidebar. // Clicking a notable trait tooltip popover should close the sidebar.
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
assert-count: ("//*[@class='notable popover']", 1) assert-count: ("//*[@class='tooltip popover']", 1)
assert-false: "//*[@class='sidebar shown']" assert-false: "//*[@class='sidebar shown']"
// Also check the focus handling for the help button. // Also check the focus handling for the help button.
size: (1100, 600) size: (1100, 600)
reload: reload:
assert-count: ("//*[@class='notable popover']", 0) assert-count: ("//*[@class='tooltip popover']", 0)
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']" click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
assert-count: ("//*[@class='notable popover']", 1) assert-count: ("//*[@class='tooltip popover']", 1)
click: "#help-button a" click: "#help-button a"
assert-count: ("//*[@class='notable popover']", 0) assert-count: ("//*[@class='tooltip popover']", 0)
assert-false: "#method\.create_an_iterator_from_read .notable-traits:focus" assert-false: "#method\.create_an_iterator_from_read .tooltip:focus"

View File

@ -3,7 +3,7 @@
// @has foo/fn.bar.html '//*[@class="example-wrap compile_fail"]/*[@class="tooltip"]' "ⓘ" // @has foo/fn.bar.html '//*[@class="example-wrap compile_fail"]/*[@class="tooltip"]' "ⓘ"
// @has foo/fn.bar.html '//*[@class="example-wrap ignore"]/*[@class="tooltip"]' "ⓘ" // @has foo/fn.bar.html '//*[@class="example-wrap ignore"]/*[@class="tooltip"]' "ⓘ"
// @has foo/fn.bar.html '//*[@class="example-wrap should_panic"]/*[@class="tooltip"]' "ⓘ" // @has foo/fn.bar.html '//*[@class="example-wrap should_panic"]/*[@class="tooltip"]' "ⓘ"
// @has foo/fn.bar.html '//*[@data-edition="2018"]' "ⓘ" // @has foo/fn.bar.html '//*[@title="This example runs with edition 2018"]' "ⓘ"
/// foo /// foo
/// ///

View File

@ -9,7 +9,7 @@ impl<T: SomeTrait> SomeTrait for Wrapper<T> {}
#[doc(notable_trait)] #[doc(notable_trait)]
pub trait SomeTrait { pub trait SomeTrait {
// @has doc_notable_trait/trait.SomeTrait.html // @has doc_notable_trait/trait.SomeTrait.html
// @has - '//a[@class="notable-traits"]/@data-ty' 'Wrapper<Self>' // @has - '//a[@class="tooltip"]/@data-notable-ty' 'Wrapper<Self>'
// @snapshot wrap-me - '//script[@id="notable-traits-data"]' // @snapshot wrap-me - '//script[@id="notable-traits-data"]'
fn wrap_me(self) -> Wrapper<Self> where Self: Sized { fn wrap_me(self) -> Wrapper<Self> where Self: Sized {
Wrapper { Wrapper {
@ -23,7 +23,7 @@ impl SomeTrait for SomeStruct {}
impl SomeStruct { impl SomeStruct {
// @has doc_notable_trait/struct.SomeStruct.html // @has doc_notable_trait/struct.SomeStruct.html
// @has - '//a[@class="notable-traits"]/@data-ty' 'SomeStruct' // @has - '//a[@class="tooltip"]/@data-notable-ty' 'SomeStruct'
// @snapshot some-struct-new - '//script[@id="notable-traits-data"]' // @snapshot some-struct-new - '//script[@id="notable-traits-data"]'
pub fn new() -> SomeStruct { pub fn new() -> SomeStruct {
SomeStruct SomeStruct
@ -31,7 +31,7 @@ impl SomeStruct {
} }
// @has doc_notable_trait/fn.bare_fn.html // @has doc_notable_trait/fn.bare_fn.html
// @has - '//a[@class="notable-traits"]/@data-ty' 'SomeStruct' // @has - '//a[@class="tooltip"]/@data-notable-ty' 'SomeStruct'
// @snapshot bare-fn - '//script[@id="notable-traits-data"]' // @snapshot bare-fn - '//script[@id="notable-traits-data"]'
pub fn bare_fn() -> SomeStruct { pub fn bare_fn() -> SomeStruct {
SomeStruct SomeStruct

View File

@ -3,7 +3,7 @@
use std::iter::Iterator; use std::iter::Iterator;
// @has foo/struct.Odd.html // @has foo/struct.Odd.html
// @has - '//*[@id="method.new"]//a[@class="notable-traits"]/@data-ty' 'Odd' // @has - '//*[@id="method.new"]//a[@class="tooltip"]/@data-notable-ty' 'Odd'
// @snapshot odd - '//script[@id="notable-traits-data"]' // @snapshot odd - '//script[@id="notable-traits-data"]'
pub struct Odd { pub struct Odd {
current: usize, current: usize,