Skip to content

Commit 52a8b83

Browse files
committed
---
yaml --- r: 21048 b: refs/heads/snap-stage3 c: ac4132b h: refs/heads/master v: v3
1 parent f70b021 commit 52a8b83

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 78d19d8f1bdb64317ebdb072c25ee1240a562095
4+
refs/heads/snap-stage3: ac4132b7fda1e2bd356a5af8d89badf3e05f7a1a
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/cell.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ fn empty_cell<T>() -> Cell<T> {
1818
impl<T> Cell<T> {
1919
/// Yields the value, failing if the cell is empty.
2020
fn take() -> T {
21-
let mut value = none;
22-
value <-> self.value;
23-
if value.is_none() {
21+
if self.is_empty() {
2422
fail ~"attempt to take an empty cell";
2523
}
24+
25+
let mut value = none;
26+
value <-> self.value;
2627
return option::unwrap(value);
2728
}
2829

2930
/// Returns the value, failing if the cell is full.
3031
fn put_back(+value: T) {
31-
if self.value.is_none() {
32+
if !self.is_empty() {
3233
fail ~"attempt to put a value back into a full cell";
3334
}
3435
self.value = some(move value);
@@ -39,3 +40,30 @@ impl<T> Cell<T> {
3940
self.value.is_none()
4041
}
4142
}
43+
44+
#[test]
45+
fn test_basic() {
46+
let value_cell = Cell(~10);
47+
assert !value_cell.is_empty();
48+
let value = value_cell.take();
49+
assert value == ~10;
50+
assert value_cell.is_empty();
51+
value_cell.put_back(value);
52+
assert !value_cell.is_empty();
53+
}
54+
55+
#[test]
56+
#[should_fail]
57+
#[ignore(cfg(windows))]
58+
fn test_take_empty() {
59+
let value_cell = empty_cell::<~int>();
60+
value_cell.take();
61+
}
62+
63+
#[test]
64+
#[should_fail]
65+
#[ignore(cfg(windows))]
66+
fn test_put_back_non_empty() {
67+
let value_cell = Cell(~10);
68+
value_cell.put_back(~20);
69+
}

0 commit comments

Comments
 (0)