Skip to content

Commit 77ec044

Browse files
committed
mk: Start testing the cheatsheet
1 parent c2ef4e5 commit 77ec044

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ do
806806
make_dir $h/test/doc-guide-container
807807
make_dir $h/test/doc-guide-tasks
808808
make_dir $h/test/doc-guide-conditions
809+
make_dir $h/test/doc-complement-cheatsheet
809810
make_dir $h/test/doc-rust
810811
done
811812

doc/complement-cheatsheet.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let y: int = x.unwrap();
4848

4949
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.
5050

51-
~~~
51+
~~~ {.xfail-test}
5252
use std::path::Path;
5353
use std::io::fs::File;
5454
@@ -63,6 +63,9 @@ Use the [`lines`](http://static.rust-lang.org/doc/master/std/io/trait.Buffer.htm
6363

6464
~~~
6565
use std::io::buffered::BufferedReader;
66+
# use std::io::mem::MemReader;
67+
68+
# let reader = MemReader::new(~[]);
6669
6770
let mut reader = BufferedReader::new(reader);
6871
for line in reader.lines() {
@@ -149,6 +152,9 @@ Phantom types are useful for enforcing state at compile time. For example:
149152
~~~
150153
struct Door<State>(~str);
151154
155+
struct Open;
156+
struct Closed;
157+
152158
fn close(Door(name): Door<Open>) -> Door<Closed> {
153159
Door::<Closed>(name)
154160
}
@@ -157,7 +163,12 @@ fn open(Door(name): Door<Closed>) -> Door<Open> {
157163
Door::<Open>(name)
158164
}
159165
160-
let _ = close(Door::<Open>(~"front")); // ok
166+
let _ = close(Door::<Open>(~"front"));
167+
~~~
168+
169+
Attempting to close a closed door is prevented statically:
170+
171+
~~~ {.xfail-test}
161172
let _ = close(Door::<Closed>(~"front")); // error: mismatched types: expected `main::Door<main::Open>` but found `main::Door<main::Closed>`
162173
~~~
163174

@@ -185,7 +196,7 @@ Window* createWindow(int width, int height);
185196

186197
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:
187198

188-
~~~
199+
~~~ {.xfail-test}
189200
enum Window {}
190201
extern "C" {
191202
fn createWindow(width: c_int, height: c_int) -> *Window;

mk/tests.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
2222
# Markdown files under doc/ that should have their code extracted and run
2323
DOC_TEST_NAMES = tutorial guide-ffi guide-macros guide-lifetimes \
2424
guide-tasks guide-conditions guide-container guide-pointers \
25+
complement-cheatsheet \
2526
rust
2627

2728
######################################################################

0 commit comments

Comments
 (0)