~~~
Rustdoc also supplies some extra sugar for helping with some tedious
-documentation examples. If a line is prefixed with a `#` character, then the
-line will not show up in the HTML documentation, but it will be used when
-testing the code block.
+documentation examples. If a line is prefixed with `# `, then the line
+will not show up in the HTML documentation, but it will be used when
+testing the code block (NB. the space after the `#` is required, so
+that one can still write things like `#[deriving(Eq)]`).
~~~
```rust
vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
let text = str::from_utf8(text);
let mut lines = text.lines().filter(|l| {
- !l.trim().starts_with("#")
+ !l.trim().starts_with("# ")
});
let text = lines.to_owned_vec().connect("\n");
vec::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
let tests: &mut ::test::Collector = intrinsics::transmute(opaque);
let text = str::from_utf8(text);
- let mut lines = text.lines().map(|l| l.trim_chars(&'#'));
+ let mut lines = text.lines().map(|l| {
+ if l.starts_with("# ") {l.slice_from(2)} else {l}
+ });
let text = lines.to_owned_vec().connect("\n");
tests.add_test(text, ignore, shouldfail);
})
self.cnt += 1;
let libs = (*self.libs).clone();
let cratename = self.cratename.to_owned();
+ debug!("Creating test {}: {}", name, test);
self.tests.push(test::TestDescAndFn {
desc: test::TestDesc {
name: test::DynTestName(name),
--- /dev/null
+-include ../tools.mk
+
+all:
+ $(RUSTDOC) --test foo.rs
+ $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
+ cp verify.sh $(TMPDIR)
+ $(call RUN,verify.sh) $(TMPDIR)
--- /dev/null
+#[crate_id="foo#0.1"];
+
+/// The '# ' lines should be removed from the output, but the #[deriving] should be
+/// retained.
+///
+/// ```rust
+/// mod to_make_deriving_work { // FIXME #4913
+///
+/// # #[deriving(Eq)] // invisible
+/// # struct Foo; // invisible
+///
+/// #[deriving(Eq)] // Bar
+/// struct Bar(Foo);
+///
+/// fn test() {
+/// let x = Bar(Foo);
+/// assert!(x == x); // check that the derivings worked
+/// }
+///
+/// }
+/// ```
+pub fn foo() {}
--- /dev/null
+#!/bin/sh
+
+file="$1/doc/foo/fn.foo.html"
+
+grep -v 'invisible' $file &&
+grep '#\[deriving(Eq)\] // Bar' $file
+
+exit $?