summaryrefslogtreecommitdiffstats
path: root/src/librustdoc/html/url_parts_builder/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustdoc/html/url_parts_builder/tests.rs')
-rw-r--r--src/librustdoc/html/url_parts_builder/tests.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/librustdoc/html/url_parts_builder/tests.rs b/src/librustdoc/html/url_parts_builder/tests.rs
new file mode 100644
index 000000000..636e1ab55
--- /dev/null
+++ b/src/librustdoc/html/url_parts_builder/tests.rs
@@ -0,0 +1,64 @@
+use super::*;
+
+fn t(builder: UrlPartsBuilder, expect: &str) {
+ assert_eq!(builder.finish(), expect);
+}
+
+#[test]
+fn empty() {
+ t(UrlPartsBuilder::new(), "");
+}
+
+#[test]
+fn singleton() {
+ t(UrlPartsBuilder::singleton("index.html"), "index.html");
+}
+
+#[test]
+fn push_several() {
+ let mut builder = UrlPartsBuilder::new();
+ builder.push("core");
+ builder.push("str");
+ builder.push("struct.Bytes.html");
+ t(builder, "core/str/struct.Bytes.html");
+}
+
+#[test]
+fn push_front_empty() {
+ let mut builder = UrlPartsBuilder::new();
+ builder.push_front("page.html");
+ t(builder, "page.html");
+}
+
+#[test]
+fn push_front_non_empty() {
+ let mut builder = UrlPartsBuilder::new();
+ builder.push("core");
+ builder.push("str");
+ builder.push("struct.Bytes.html");
+ builder.push_front("nightly");
+ t(builder, "nightly/core/str/struct.Bytes.html");
+}
+
+#[test]
+fn push_fmt() {
+ let mut builder = UrlPartsBuilder::new();
+ builder.push_fmt(format_args!("{}", "core"));
+ builder.push("str");
+ builder.push_front("nightly");
+ builder.push_fmt(format_args!("{}.{}.html", "struct", "Bytes"));
+ t(builder, "nightly/core/str/struct.Bytes.html");
+}
+
+#[test]
+fn collect() {
+ t(["core", "str"].into_iter().collect(), "core/str");
+ t(["core", "str", "struct.Bytes.html"].into_iter().collect(), "core/str/struct.Bytes.html");
+}
+
+#[test]
+fn extend() {
+ let mut builder = UrlPartsBuilder::singleton("core");
+ builder.extend(["str", "struct.Bytes.html"]);
+ t(builder, "core/str/struct.Bytes.html");
+}