Skip to content

Commit 96da64e

Browse files
committed
rustdoc: add test cases, and fix, search tabs
1 parent 3b9e0fe commit 96da64e

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/librustdoc/html/static/js/search.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -2334,11 +2334,16 @@ ${item.displayPath}<span class="${type}">${name}</span>\
23342334
}
23352335

23362336
function makeTabHeader(tabNb, text, nbElems) {
2337+
// https://blog.horizon-eda.org/misc/2020/02/19/ui.html
2338+
let fmtNbElems =
2339+
nbElems < 10 ? `\u{2007}\u{2007}(${nbElems})` :
2340+
nbElems < 100 ? `\u{2007}(${nbElems})` :
2341+
`(${nbElems})`;
23372342
if (searchState.currentTab === tabNb) {
23382343
return "<button class=\"selected\">" + text +
2339-
" <span class=\"count\">(" + nbElems + ")</span></button>";
2344+
"<span class=\"count\">" + fmtNbElems + "</span></button>";
23402345
}
2341-
return "<button>" + text + " <span class=\"count\">(" + nbElems + ")</span></button>";
2346+
return "<button>" + text + "<span class=\"count\">" + fmtNbElems + "</span></button>";
23422347
}
23432348

23442349
/**

tests/rustdoc-gui/search-tab.goml

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Checking the colors of the search tab headers.
2-
go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html?search=something"
2+
go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html?search=foo"
33
show-text: true
44

55
define-function: (
@@ -74,3 +74,14 @@ call-function: ("check-colors", {
7474
"border_top_selected": "2px solid #0089ff",
7575
"border_top_hover": "2px solid #0089ff",
7676
})
77+
78+
// Check the size and count in tabs
79+
assert-text: ("#search-tabs > button:nth-child(1) > .count", " (23)")
80+
assert-text: ("#search-tabs > button:nth-child(2) > .count", "  (4)")
81+
assert-text: ("#search-tabs > button:nth-child(3) > .count", "  (0)")
82+
store-property: ("#search-tabs > button:nth-child(1)", {"offsetWidth": buttonWidth})
83+
assert-property: ("#search-tabs > button:nth-child(2)", {"offsetWidth": |buttonWidth|})
84+
assert-property: ("#search-tabs > button:nth-child(3)", {"offsetWidth": |buttonWidth|})
85+
store-property: ("#search-tabs > button:nth-child(1) > .count", {"offsetWidth": countWidth})
86+
assert-property: ("#search-tabs > button:nth-child(2) > .count", {"offsetWidth": |countWidth|})
87+
assert-property: ("#search-tabs > button:nth-child(3) > .count", {"offsetWidth": |countWidth|})

0 commit comments

Comments
 (0)