diff --git a/configure b/configure index 3a3dbd55508..54473d82285 100755 --- a/configure +++ b/configure @@ -806,6 +806,7 @@ do make_dir $h/test/doc-guide-container make_dir $h/test/doc-guide-tasks make_dir $h/test/doc-guide-conditions + make_dir $h/test/doc-complement-cheatsheet make_dir $h/test/doc-rust done diff --git a/doc/complement-cheatsheet.md b/doc/complement-cheatsheet.md index 19d88f9a05e..d9dc527caee 100644 --- a/doc/complement-cheatsheet.md +++ b/doc/complement-cheatsheet.md @@ -48,7 +48,7 @@ let y: int = x.unwrap(); Use [`File::open`](http://static.rust-lang.org/doc/master/std/io/fs/struct.File.html#method.open) to create a [`File`](http://static.rust-lang.org/doc/master/std/io/fs/struct.File.html) struct, which implements the [`Reader`](http://static.rust-lang.org/doc/master/std/io/trait.Reader.html) trait. -~~~ +~~~ {.xfail-test} use std::path::Path; use std::io::fs::File; @@ -63,6 +63,9 @@ Use the [`lines`](http://static.rust-lang.org/doc/master/std/io/trait.Buffer.htm ~~~ use std::io::buffered::BufferedReader; +# use std::io::mem::MemReader; + +# let reader = MemReader::new(~[]); let mut reader = BufferedReader::new(reader); for line in reader.lines() { @@ -149,6 +152,9 @@ Phantom types are useful for enforcing state at compile time. For example: ~~~ struct Door(~str); +struct Open; +struct Closed; + fn close(Door(name): Door) -> Door { Door::(name) } @@ -157,7 +163,12 @@ fn open(Door(name): Door) -> Door { Door::(name) } -let _ = close(Door::(~"front")); // ok +let _ = close(Door::(~"front")); +~~~ + +Attempting to close a closed door is prevented statically: + +~~~ {.xfail-test} let _ = close(Door::(~"front")); // error: mismatched types: expected `main::Door` but found `main::Door` ~~~ @@ -185,7 +196,7 @@ Window* createWindow(int width, int height); You can use a zero-element `enum` ([phantom type](#how-do-i-express-phantom-types)) to represent the opaque object handle. The FFI would look like this: -~~~ +~~~ {.xfail-test} enum Window {} extern "C" { fn createWindow(width: c_int, height: c_int) -> *Window; diff --git a/mk/tests.mk b/mk/tests.mk index becfb5e9871..d50f9878bd1 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -22,6 +22,7 @@ TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES) # Markdown files under doc/ that should have their code extracted and run DOC_TEST_NAMES = tutorial guide-ffi guide-macros guide-lifetimes \ guide-tasks guide-conditions guide-container guide-pointers \ + complement-cheatsheet \ rust ######################################################################