Created
June 26, 2012 21:10
-
-
Save brson/2999062 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn test_buf_len() { | |
let s0 = "hello"; | |
let s1 = "there"; | |
let s2 = "thing"; | |
do str::as_c_str(s0) {|p0| | |
do str::as_c_str(s1) {|p1| | |
do str::as_c_str(s2) {|p2| | |
let v = [p0, p1, p2, null()]/~; | |
do vec::as_buf(v) {|vp| | |
assert unsafe { buf_len(vp) } == 3u; | |
} | |
} | |
} | |
} | |
} | |
pure fn each<T>(v: [const T]/&, f: fn(T) -> bool) { | |
do vec::unpack_slice(v) {|p, n| | |
let mut n = n; | |
let mut p = p; | |
while n > 0u { | |
unsafe { | |
if !f(*p) { break; } | |
p = ptr::offset(p, 1u); | |
} | |
n -= 1u; | |
} | |
} | |
} | |
do iter::repeat(10u) {|| | |
do task::spawn {|| | |
iter::repeat(10u, {|| task::yield() }); | |
send(ch_a, "a"); | |
}; | |
assert select2(po_a, po_b) == either::left("a"); | |
do task::spawn {|| | |
iter::repeat(10u, {|| task::yield() }); | |
send(ch_b, "b"); | |
}; | |
assert select2(po_a, po_b) == either::right("b"); | |
} | |
do [ | |
"Sunday", | |
"Monday", | |
"Tuesday", | |
"Wednesday", | |
"Thursday", | |
"Friday", | |
"Saturday" | |
]/~.iter { |day| assert test(day, "%A"); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment