about summary refs log tree commit diff
path: root/src/rustdoc
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-01-31 20:54:46 -0800
committerBrian Anderson <banderson@mozilla.com>2012-01-31 20:54:46 -0800
commit77824cf2edd63ec1bfbb6e709b29b3c671b3d2e7 (patch)
tree840815c0b24dc0319eb7158e718cb210980c2f6a /src/rustdoc
parentf9f938887470cbc2490d1b991ffec8713470d565 (diff)
downloadrust-77824cf2edd63ec1bfbb6e709b29b3c671b3d2e7.tar.gz
rust-77824cf2edd63ec1bfbb6e709b29b3c671b3d2e7.zip
rustdoc: Write markdown for impls
Diffstat (limited to 'src/rustdoc')
-rw-r--r--src/rustdoc/markdown_pass.rs97
1 files changed, 96 insertions, 1 deletions
diff --git a/src/rustdoc/markdown_pass.rs b/src/rustdoc/markdown_pass.rs
index a231e6eed80..4aab41e38cc 100644
--- a/src/rustdoc/markdown_pass.rs
+++ b/src/rustdoc/markdown_pass.rs
@@ -138,7 +138,7 @@ fn write_mod_contents(
           doc::enumtag(enumdoc) { write_enum(ctxt, enumdoc) }
           doc::restag(resdoc) { write_res(ctxt, resdoc) }
           doc::ifacetag(ifacedoc) { write_iface(ctxt, ifacedoc) }
-          doc::impltag(impldoc) { fail }
+          doc::impltag(impldoc) { write_impl(ctxt, impldoc) }
         }
     }
 }
@@ -648,6 +648,101 @@ fn should_write_iface_method_failure_conditions() {
     assert str::contains(markdown, "Failure conditions: nuked");
 }
 
+fn write_impl(ctxt: ctxt, doc: doc::impldoc) {
+    assert option::is_some(doc.self_ty);
+    let self_ty = option::get(doc.self_ty);
+    alt doc.iface_ty {
+      some(iface_ty) {
+        write_header(ctxt, h2,
+                     #fmt("Implementation `%s` of `%s` for `%s`",
+                          doc.name, iface_ty, self_ty));
+      }
+      none {
+        write_header(ctxt, h2,
+                     #fmt("Implementation `%s` for `%s`",
+                          doc.name, self_ty));
+      }
+    }
+    write_brief(ctxt, doc.brief);
+    write_desc(ctxt, doc.desc);
+    write_methods(ctxt, doc.methods);
+}
+
+#[test]
+fn should_write_impl_header() {
+    let markdown = test::render("impl i for int { fn a() { } }");
+    assert str::contains(markdown, "## Implementation `i` for `int`");
+}
+
+#[test]
+fn should_write_impl_header_with_iface() {
+    let markdown = test::render("impl i of j for int { fn a() { } }");
+    assert str::contains(markdown, "## Implementation `i` of `j` for `int`");
+}
+
+#[test]
+fn should_write_impl_brief() {
+    let markdown = test::render(
+        "#[doc(brief = \"brief\")] impl i for int { fn a() { } }");
+    assert str::contains(markdown, "brief");
+}
+
+#[test]
+fn should_write_impl_desc() {
+    let markdown = test::render(
+        "#[doc(desc = \"desc\")] impl i for int { fn a() { } }");
+    assert str::contains(markdown, "desc");
+}
+
+#[test]
+fn should_write_impl_method_header() {
+    let markdown = test::render(
+        "impl i for int { fn a() { } }");
+    assert str::contains(markdown, "### Method `a`");
+}
+
+#[test]
+fn should_write_impl_method_signature() {
+    let markdown = test::render(
+        "impl i for int { fn a() { } }");
+    assert str::contains(markdown, "\n    fn a()");
+}
+
+#[test]
+fn should_write_impl_method_argument_header() {
+    let markdown = test::render(
+        "impl a for int { fn a(b: int) { } }");
+    assert str::contains(markdown, "\n\nArguments:\n\n");
+}
+
+#[test]
+fn should_write_impl_method_arguments() {
+    let markdown = test::render(
+        "impl a for int { fn a(b: int) { } }");
+    assert str::contains(markdown, "* `b`: `int`\n");
+}
+
+#[test]
+fn should_not_write_impl_method_arguments_if_none() {
+    let markdown = test::render(
+        "impl a for int { fn a() { } }");
+    assert !str::contains(markdown, "Arguments");
+}
+
+#[test]
+fn should_write_impl_method_return_info() {
+    let markdown = test::render(
+        "impl a for int { fn a() -> int { } }");
+    assert str::contains(markdown, "Returns `int`");
+}
+
+#[test]
+fn should_write_impl_method_failure_conditions() {
+    let markdown = test::render(
+        "impl a for int { #[doc(failure = \"nuked\")] fn a() { } }");
+    assert str::contains(markdown, "Failure conditions: nuked");
+}
+
 #[cfg(test)]
 mod test {
     fn render(source: str) -> str {