librustc: Remove fail_unless!
This commit is contained in:
parent
a17a9d41f6
commit
1e91595520
862 changed files with 5898 additions and 5911 deletions
|
@ -1971,7 +1971,7 @@ let v = ~[1,2,3];
|
|||
|
||||
mutate(copy v); // Pass a copy
|
||||
|
||||
fail_unless!(v[0] == 1); // Original was not modified
|
||||
assert!(v[0] == 1); // Original was not modified
|
||||
~~~~
|
||||
|
||||
### Unary move expressions
|
||||
|
@ -2491,7 +2491,7 @@ An example of a tuple type and its use:
|
|||
type Pair<'self> = (int,&'self str);
|
||||
let p: Pair<'static> = (10,"hello");
|
||||
let (a, b) = p;
|
||||
fail_unless!(b != "world");
|
||||
assert!(b != "world");
|
||||
~~~~
|
||||
|
||||
|
||||
|
@ -2519,7 +2519,7 @@ An example of a vector type and its use:
|
|||
~~~~
|
||||
let v: &[int] = &[7, 5, 3];
|
||||
let i: int = v[2];
|
||||
fail_unless!(i == 3);
|
||||
assert!(i == 3);
|
||||
~~~~
|
||||
|
||||
All in-bounds elements of a vector are always initialized,
|
||||
|
@ -2925,7 +2925,7 @@ example of an _implicit dereference_ operation performed on box values:
|
|||
~~~~~~~~
|
||||
struct Foo { y: int }
|
||||
let x = @Foo{y: 10};
|
||||
fail_unless!(x.y == 10);
|
||||
assert!(x.y == 10);
|
||||
~~~~~~~~
|
||||
|
||||
Other operations act on box values as single-word-sized address values. For
|
||||
|
|
|
@ -239,7 +239,7 @@ fn unix_time_in_microseconds() -> u64 {
|
|||
}
|
||||
}
|
||||
|
||||
# fn main() { fail_unless!(fmt!("%?", unix_time_in_microseconds()) != ~""); }
|
||||
# fn main() { assert!(fmt!("%?", unix_time_in_microseconds()) != ~""); }
|
||||
~~~~
|
||||
|
||||
The `#[nolink]` attribute indicates that there's no foreign library to
|
||||
|
|
|
@ -297,7 +297,7 @@ let result = ports.foldl(0, |accum, port| *accum + port.recv() );
|
|||
|
||||
Rust has a built-in mechanism for raising exceptions. The `fail!()` macro
|
||||
(which can also be written with an error string as an argument: `fail!(
|
||||
~reason)`) and the `fail_unless!` construct (which effectively calls `fail!()`
|
||||
~reason)`) and the `assert!` construct (which effectively calls `fail!()`
|
||||
if a boolean expression is false) are both ways to raise exceptions. When a
|
||||
task raises an exception the task unwinds its stack---running destructors and
|
||||
freeing memory along the way---and then exits. Unlike exceptions in C++,
|
||||
|
@ -339,7 +339,7 @@ let result: Result<int, ()> = do task::try {
|
|||
fail!(~"oops!");
|
||||
}
|
||||
};
|
||||
fail_unless!(result.is_err());
|
||||
assert!(result.is_err());
|
||||
~~~
|
||||
|
||||
Unlike `spawn`, the function spawned using `try` may return a value,
|
||||
|
@ -401,7 +401,7 @@ do spawn { // Bidirectionally linked
|
|||
// Wait for the supervised child task to exist.
|
||||
let message = receiver.recv();
|
||||
// Kill both it and the parent task.
|
||||
fail_unless!(message != 42);
|
||||
assert!(message != 42);
|
||||
}
|
||||
do try { // Unidirectionally linked
|
||||
sender.send(42);
|
||||
|
@ -507,13 +507,13 @@ do spawn {
|
|||
};
|
||||
|
||||
from_child.send(22);
|
||||
fail_unless!(from_child.recv() == ~"22");
|
||||
assert!(from_child.recv() == ~"22");
|
||||
|
||||
from_child.send(23);
|
||||
from_child.send(0);
|
||||
|
||||
fail_unless!(from_child.recv() == ~"23");
|
||||
fail_unless!(from_child.recv() == ~"0");
|
||||
assert!(from_child.recv() == ~"23");
|
||||
assert!(from_child.recv() == ~"0");
|
||||
|
||||
# }
|
||||
~~~~
|
||||
|
|
|
@ -381,7 +381,7 @@ expression to the given type.
|
|||
~~~~
|
||||
let x: float = 4.0;
|
||||
let y: uint = x as uint;
|
||||
fail_unless!(y == 4u);
|
||||
assert!(y == 4u);
|
||||
~~~~
|
||||
|
||||
## Syntax extensions
|
||||
|
@ -850,8 +850,8 @@ Ending the function with a semicolon like so is equivalent to returning `()`.
|
|||
fn line(a: int, b: int, x: int) -> int { a * x + b }
|
||||
fn oops(a: int, b: int, x: int) -> () { a * x + b; }
|
||||
|
||||
fail_unless!(8 == line(5, 3, 1));
|
||||
fail_unless!(() == oops(5, 3, 1));
|
||||
assert!(8 == line(5, 3, 1));
|
||||
assert!(() == oops(5, 3, 1));
|
||||
~~~~
|
||||
|
||||
As with `match` expressions and `let` bindings, function arguments support
|
||||
|
@ -1417,8 +1417,8 @@ and [`core::str`]. Here are some examples.
|
|||
let crayons = [Almond, AntiqueBrass, Apricot];
|
||||
|
||||
// Check the length of the vector
|
||||
fail_unless!(crayons.len() == 3);
|
||||
fail_unless!(!crayons.is_empty());
|
||||
assert!(crayons.len() == 3);
|
||||
assert!(!crayons.is_empty());
|
||||
|
||||
// Iterate over a vector, obtaining a pointer to each element
|
||||
for crayons.each |crayon| {
|
||||
|
|
|
@ -65,7 +65,7 @@ pub fn parse_config(args: ~[~str]) -> config {
|
|||
getopts::optflag(~"jit"),
|
||||
getopts::optflag(~"newrt")];
|
||||
|
||||
fail_unless!(!args.is_empty());
|
||||
assert!(!args.is_empty());
|
||||
let args_ = vec::tail(args);
|
||||
let matches =
|
||||
&match getopts::getopts(args_, opts) {
|
||||
|
|
|
@ -25,7 +25,7 @@ fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] {
|
|||
let mut env = os::env();
|
||||
|
||||
// Make sure we include the aux directory in the path
|
||||
fail_unless!(prog.ends_with(~".exe"));
|
||||
assert!(prog.ends_with(~".exe"));
|
||||
let aux_path = prog.slice(0u, prog.len() - 4u) + ~".libaux";
|
||||
|
||||
env = do vec::map(env) |pair| {
|
||||
|
|
|
@ -292,30 +292,30 @@ pub fn test() {
|
|||
}
|
||||
|
||||
assert_eq!(seq_range(10, 15), @[10, 11, 12, 13, 14]);
|
||||
fail_unless!(from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]);
|
||||
fail_unless!(from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]);
|
||||
assert!(from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]);
|
||||
assert!(from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn append_test() {
|
||||
fail_unless!(@[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]);
|
||||
assert!(@[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_from_owned() {
|
||||
fail_unless!(from_owned::<int>(~[]) == @[]);
|
||||
fail_unless!(from_owned(~[true]) == @[true]);
|
||||
fail_unless!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
|
||||
fail_unless!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
|
||||
fail_unless!(from_owned(~[~[42]]) == @[~[42]]);
|
||||
assert!(from_owned::<int>(~[]) == @[]);
|
||||
assert!(from_owned(~[true]) == @[true]);
|
||||
assert!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
|
||||
assert!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
|
||||
assert!(from_owned(~[~[42]]) == @[~[42]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_from_slice() {
|
||||
fail_unless!(from_slice::<int>([]) == @[]);
|
||||
fail_unless!(from_slice([true]) == @[true]);
|
||||
fail_unless!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
|
||||
fail_unless!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
|
||||
fail_unless!(from_slice([@[42]]) == @[@[42]]);
|
||||
assert!(from_slice::<int>([]) == @[]);
|
||||
assert!(from_slice([true]) == @[true]);
|
||||
assert!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
|
||||
assert!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
|
||||
assert!(from_slice([@[42]]) == @[@[42]]);
|
||||
}
|
||||
|
||||
|
|
|
@ -86,20 +86,20 @@ pub fn test_bool_from_str() {
|
|||
use from_str::FromStr;
|
||||
|
||||
do all_values |v| {
|
||||
fail_unless!(Some(v) == FromStr::from_str(to_str(v)))
|
||||
assert!(Some(v) == FromStr::from_str(to_str(v)))
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_bool_to_str() {
|
||||
fail_unless!(to_str(false) == ~"false");
|
||||
fail_unless!(to_str(true) == ~"true");
|
||||
assert!(to_str(false) == ~"false");
|
||||
assert!(to_str(true) == ~"true");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_bool_to_bit() {
|
||||
do all_values |v| {
|
||||
fail_unless!(to_bit(v) == if is_true(v) { 1u8 } else { 0u8 });
|
||||
assert!(to_bit(v) == if is_true(v) { 1u8 } else { 0u8 });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
|
|||
*
|
||||
* # Example
|
||||
*
|
||||
* fail_unless!(transmute("L") == ~[76u8, 0u8]);
|
||||
* assert!(transmute("L") == ~[76u8, 0u8]);
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub unsafe fn transmute<L, G>(thing: L) -> G {
|
||||
|
@ -116,7 +116,7 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn test_reinterpret_cast() {
|
||||
fail_unless!(1u == unsafe { reinterpret_cast(&1) });
|
||||
assert!(1u == unsafe { reinterpret_cast(&1) });
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -127,8 +127,8 @@ pub mod tests {
|
|||
let ptr: *int = transmute(box); // refcount 2
|
||||
let _box1: @~str = reinterpret_cast(&ptr);
|
||||
let _box2: @~str = reinterpret_cast(&ptr);
|
||||
fail_unless!(*_box1 == ~"box box box");
|
||||
fail_unless!(*_box2 == ~"box box box");
|
||||
assert!(*_box1 == ~"box box box");
|
||||
assert!(*_box2 == ~"box box box");
|
||||
// Will destroy _box1 and _box2. Without the bump, this would
|
||||
// use-after-free. With too many bumps, it would leak.
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ pub mod tests {
|
|||
unsafe {
|
||||
let x = @100u8;
|
||||
let x: *BoxRepr = transmute(x);
|
||||
fail_unless!((*x).data == 100);
|
||||
assert!((*x).data == 100);
|
||||
let _x: @int = transmute(x);
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ pub mod tests {
|
|||
#[test]
|
||||
pub fn test_transmute2() {
|
||||
unsafe {
|
||||
fail_unless!(~[76u8, 0u8] == transmute(~"L"));
|
||||
assert!(~[76u8, 0u8] == transmute(~"L"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,12 +80,12 @@ pub impl<T> Cell<T> {
|
|||
#[test]
|
||||
fn test_basic() {
|
||||
let value_cell = Cell(~10);
|
||||
fail_unless!(!value_cell.is_empty());
|
||||
assert!(!value_cell.is_empty());
|
||||
let value = value_cell.take();
|
||||
fail_unless!(value == ~10);
|
||||
fail_unless!(value_cell.is_empty());
|
||||
assert!(value == ~10);
|
||||
assert!(value_cell.is_empty());
|
||||
value_cell.put_back(value);
|
||||
fail_unless!(!value_cell.is_empty());
|
||||
assert!(!value_cell.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -200,7 +200,7 @@ pub fn escape_unicode(c: char) -> ~str {
|
|||
let (c, pad) = (if c <= '\xff' { ('x', 2u) }
|
||||
else if c <= '\uffff' { ('u', 4u) }
|
||||
else { ('U', 8u) });
|
||||
fail_unless!(str::len(s) <= pad);
|
||||
assert!(str::len(s) <= pad);
|
||||
let mut out = ~"\\";
|
||||
unsafe {
|
||||
str::push_str(&mut out, str::from_char(c));
|
||||
|
@ -258,32 +258,32 @@ impl Eq for char {
|
|||
|
||||
#[test]
|
||||
fn test_is_lowercase() {
|
||||
fail_unless!(is_lowercase('a'));
|
||||
fail_unless!(is_lowercase('ö'));
|
||||
fail_unless!(is_lowercase('ß'));
|
||||
fail_unless!(!is_lowercase('Ü'));
|
||||
fail_unless!(!is_lowercase('P'));
|
||||
assert!(is_lowercase('a'));
|
||||
assert!(is_lowercase('ö'));
|
||||
assert!(is_lowercase('ß'));
|
||||
assert!(!is_lowercase('Ü'));
|
||||
assert!(!is_lowercase('P'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_uppercase() {
|
||||
fail_unless!(!is_uppercase('h'));
|
||||
fail_unless!(!is_uppercase('ä'));
|
||||
fail_unless!(!is_uppercase('ß'));
|
||||
fail_unless!(is_uppercase('Ö'));
|
||||
fail_unless!(is_uppercase('T'));
|
||||
assert!(!is_uppercase('h'));
|
||||
assert!(!is_uppercase('ä'));
|
||||
assert!(!is_uppercase('ß'));
|
||||
assert!(is_uppercase('Ö'));
|
||||
assert!(is_uppercase('T'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_whitespace() {
|
||||
fail_unless!(is_whitespace(' '));
|
||||
fail_unless!(is_whitespace('\u2007'));
|
||||
fail_unless!(is_whitespace('\t'));
|
||||
fail_unless!(is_whitespace('\n'));
|
||||
assert!(is_whitespace(' '));
|
||||
assert!(is_whitespace('\u2007'));
|
||||
assert!(is_whitespace('\t'));
|
||||
assert!(is_whitespace('\n'));
|
||||
|
||||
fail_unless!(!is_whitespace('a'));
|
||||
fail_unless!(!is_whitespace('_'));
|
||||
fail_unless!(!is_whitespace('\u0000'));
|
||||
assert!(!is_whitespace('a'));
|
||||
assert!(!is_whitespace('_'));
|
||||
assert!(!is_whitespace('\u0000'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -299,24 +299,24 @@ fn test_to_digit() {
|
|||
assert_eq!(to_digit('z', 36u), Some(35u));
|
||||
assert_eq!(to_digit('Z', 36u), Some(35u));
|
||||
|
||||
fail_unless!(to_digit(' ', 10u).is_none());
|
||||
fail_unless!(to_digit('$', 36u).is_none());
|
||||
assert!(to_digit(' ', 10u).is_none());
|
||||
assert!(to_digit('$', 36u).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_ascii() {
|
||||
fail_unless!(str::all(~"banana", is_ascii));
|
||||
fail_unless!(! str::all(~"ประเทศไทย中华Việt Nam", is_ascii));
|
||||
assert!(str::all(~"banana", is_ascii));
|
||||
assert!(! str::all(~"ประเทศไทย中华Việt Nam", is_ascii));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_digit() {
|
||||
fail_unless!(is_digit('2'));
|
||||
fail_unless!(is_digit('7'));
|
||||
fail_unless!(! is_digit('c'));
|
||||
fail_unless!(! is_digit('i'));
|
||||
fail_unless!(! is_digit('z'));
|
||||
fail_unless!(! is_digit('Q'));
|
||||
assert!(is_digit('2'));
|
||||
assert!(is_digit('7'));
|
||||
assert!(! is_digit('c'));
|
||||
assert!(! is_digit('i'));
|
||||
assert!(! is_digit('z'));
|
||||
assert!(! is_digit('Q'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -177,7 +177,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_int_totaleq() {
|
||||
fail_unless!(5.equals(&5));
|
||||
fail_unless!(!2.equals(&17));
|
||||
assert!(5.equals(&5));
|
||||
assert!(!2.equals(&17));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -465,6 +465,6 @@ pub mod test {
|
|||
let _chan = chan;
|
||||
}
|
||||
|
||||
fail_unless!(!port.peek());
|
||||
assert!(!port.peek());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ mod test {
|
|||
trouble(1);
|
||||
}
|
||||
|
||||
fail_unless!(inner_trapped);
|
||||
assert!(inner_trapped);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -143,7 +143,7 @@ mod test {
|
|||
trouble(1);
|
||||
}
|
||||
|
||||
fail_unless!(outer_trapped);
|
||||
assert!(outer_trapped);
|
||||
}
|
||||
|
||||
fn nested_reraise_trap_test_inner() {
|
||||
|
@ -160,7 +160,7 @@ mod test {
|
|||
trouble(1);
|
||||
}
|
||||
|
||||
fail_unless!(inner_trapped);
|
||||
assert!(inner_trapped);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -175,7 +175,7 @@ mod test {
|
|||
nested_reraise_trap_test_inner();
|
||||
}
|
||||
|
||||
fail_unless!(outer_trapped);
|
||||
assert!(outer_trapped);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -190,6 +190,6 @@ mod test {
|
|||
trouble(1);
|
||||
}
|
||||
|
||||
fail_unless!(trapped);
|
||||
assert!(trapped);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ priv impl<T> DList<T> {
|
|||
// Remove a node from the list.
|
||||
fn unlink(@mut self, nobe: @mut DListNode<T>) {
|
||||
self.assert_mine(nobe);
|
||||
fail_unless!(self.size > 0);
|
||||
assert!(self.size > 0);
|
||||
self.link(nobe.prev, nobe.next);
|
||||
nobe.prev = None; // Release extraneous references.
|
||||
nobe.next = None;
|
||||
|
@ -193,7 +193,7 @@ priv impl<T> DList<T> {
|
|||
nobe: DListLink<T>,
|
||||
neighbour: @mut DListNode<T>) {
|
||||
self.assert_mine(neighbour);
|
||||
fail_unless!(self.size > 0);
|
||||
assert!(self.size > 0);
|
||||
self.link(neighbour.prev, nobe);
|
||||
self.link(nobe, Some(neighbour));
|
||||
self.size += 1;
|
||||
|
@ -202,7 +202,7 @@ priv impl<T> DList<T> {
|
|||
neighbour: @mut DListNode<T>,
|
||||
nobe: DListLink<T>) {
|
||||
self.assert_mine(neighbour);
|
||||
fail_unless!(self.size > 0);
|
||||
assert!(self.size > 0);
|
||||
self.link(nobe, neighbour.next);
|
||||
self.link(Some(neighbour), nobe);
|
||||
self.size += 1;
|
||||
|
@ -410,7 +410,7 @@ pub impl<T> DList<T> {
|
|||
/// Check data structure integrity. O(n).
|
||||
fn assert_consistent(@mut self) {
|
||||
if self.hd.is_none() || self.tl.is_none() {
|
||||
fail_unless!(self.hd.is_none() && self.tl.is_none());
|
||||
assert!(self.hd.is_none() && self.tl.is_none());
|
||||
}
|
||||
// iterate forwards
|
||||
let mut count = 0;
|
||||
|
@ -418,7 +418,7 @@ pub impl<T> DList<T> {
|
|||
let mut rabbit = link;
|
||||
while link.is_some() {
|
||||
let nobe = link.get();
|
||||
fail_unless!(nobe.linked);
|
||||
assert!(nobe.linked);
|
||||
// check cycle
|
||||
if rabbit.is_some() {
|
||||
rabbit = rabbit.get().next;
|
||||
|
@ -427,19 +427,19 @@ pub impl<T> DList<T> {
|
|||
rabbit = rabbit.get().next;
|
||||
}
|
||||
if rabbit.is_some() {
|
||||
fail_unless!(!managed::mut_ptr_eq(rabbit.get(), nobe));
|
||||
assert!(!managed::mut_ptr_eq(rabbit.get(), nobe));
|
||||
}
|
||||
// advance
|
||||
link = nobe.next_link();
|
||||
count += 1;
|
||||
}
|
||||
fail_unless!(count == self.len());
|
||||
assert!(count == self.len());
|
||||
// iterate backwards - some of this is probably redundant.
|
||||
link = self.peek_tail_n();
|
||||
rabbit = link;
|
||||
while link.is_some() {
|
||||
let nobe = link.get();
|
||||
fail_unless!(nobe.linked);
|
||||
assert!(nobe.linked);
|
||||
// check cycle
|
||||
if rabbit.is_some() {
|
||||
rabbit = rabbit.get().prev;
|
||||
|
@ -448,13 +448,13 @@ pub impl<T> DList<T> {
|
|||
rabbit = rabbit.get().prev;
|
||||
}
|
||||
if rabbit.is_some() {
|
||||
fail_unless!(!managed::mut_ptr_eq(rabbit.get(), nobe));
|
||||
assert!(!managed::mut_ptr_eq(rabbit.get(), nobe));
|
||||
}
|
||||
// advance
|
||||
link = nobe.prev_link();
|
||||
count -= 1;
|
||||
}
|
||||
fail_unless!(count == 0);
|
||||
assert!(count == 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,7 +510,7 @@ impl<T> BaseIter<T> for @mut DList<T> {
|
|||
let mut link = self.peek_n();
|
||||
while link.is_some() {
|
||||
let nobe = link.get();
|
||||
fail_unless!(nobe.linked);
|
||||
assert!(nobe.linked);
|
||||
|
||||
{
|
||||
let frozen_nobe = &*nobe;
|
||||
|
@ -563,7 +563,7 @@ mod tests {
|
|||
abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 6);
|
||||
abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 7);
|
||||
abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 8);
|
||||
abcd.assert_consistent(); fail_unless!(abcd.is_empty());
|
||||
abcd.assert_consistent(); assert!(abcd.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_append() {
|
||||
|
@ -579,7 +579,7 @@ mod tests {
|
|||
a.assert_consistent(); assert_eq!(a.pop().get(), 4);
|
||||
a.assert_consistent(); assert_eq!(a.pop().get(), 5);
|
||||
a.assert_consistent(); assert_eq!(a.pop().get(), 6);
|
||||
a.assert_consistent(); fail_unless!(a.is_empty());
|
||||
a.assert_consistent(); assert!(a.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_append_empty() {
|
||||
|
@ -592,7 +592,7 @@ mod tests {
|
|||
a.assert_consistent(); assert_eq!(a.pop().get(), 1);
|
||||
a.assert_consistent(); assert_eq!(a.pop().get(), 2);
|
||||
a.assert_consistent(); assert_eq!(a.pop().get(), 3);
|
||||
a.assert_consistent(); fail_unless!(a.is_empty());
|
||||
a.assert_consistent(); assert!(a.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_append_to_empty() {
|
||||
|
@ -605,7 +605,7 @@ mod tests {
|
|||
a.assert_consistent(); assert_eq!(a.pop().get(), 4);
|
||||
a.assert_consistent(); assert_eq!(a.pop().get(), 5);
|
||||
a.assert_consistent(); assert_eq!(a.pop().get(), 6);
|
||||
a.assert_consistent(); fail_unless!(a.is_empty());
|
||||
a.assert_consistent(); assert!(a.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_append_two_empty() {
|
||||
|
@ -645,7 +645,7 @@ mod tests {
|
|||
b.assert_consistent(); assert_eq!(b.pop().get(), 4);
|
||||
b.assert_consistent(); assert_eq!(b.pop().get(), 5);
|
||||
b.assert_consistent(); assert_eq!(b.pop().get(), 6);
|
||||
b.assert_consistent(); fail_unless!(b.is_empty());
|
||||
b.assert_consistent(); assert!(b.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_reverse() {
|
||||
|
@ -657,7 +657,7 @@ mod tests {
|
|||
a.assert_consistent(); assert_eq!(a.pop().get(), 3);
|
||||
a.assert_consistent(); assert_eq!(a.pop().get(), 4);
|
||||
a.assert_consistent(); assert_eq!(a.pop().get(), 5);
|
||||
a.assert_consistent(); fail_unless!(a.is_empty());
|
||||
a.assert_consistent(); assert!(a.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_reverse_empty() {
|
||||
|
@ -681,7 +681,7 @@ mod tests {
|
|||
a.assert_consistent(); assert_eq!(a.pop().get(), 4);
|
||||
a.assert_consistent(); assert_eq!(a.pop().get(), 3);
|
||||
a.assert_consistent(); assert_eq!(a.pop().get(), 5);
|
||||
a.assert_consistent(); fail_unless!(a.is_empty());
|
||||
a.assert_consistent(); assert!(a.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_clear() {
|
||||
|
@ -694,8 +694,8 @@ mod tests {
|
|||
pub fn test_dlist_is_empty() {
|
||||
let empty = DList::<int>();
|
||||
let full1 = from_vec(~[1,2,3]);
|
||||
fail_unless!(empty.is_empty());
|
||||
fail_unless!(!full1.is_empty());
|
||||
assert!(empty.is_empty());
|
||||
assert!(!full1.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_head_tail() {
|
||||
|
@ -714,8 +714,8 @@ mod tests {
|
|||
assert_eq!(l.tail(), 3);
|
||||
assert_eq!(l.head(), 3);
|
||||
assert_eq!(l.pop().get(), 3);
|
||||
fail_unless!(l.is_empty());
|
||||
fail_unless!(l.pop().is_none());
|
||||
assert!(l.is_empty());
|
||||
assert!(l.pop().is_none());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_pop_tail() {
|
||||
|
@ -727,8 +727,8 @@ mod tests {
|
|||
assert_eq!(l.tail(), 1);
|
||||
assert_eq!(l.head(), 1);
|
||||
assert_eq!(l.pop_tail().get(), 1);
|
||||
fail_unless!(l.is_empty());
|
||||
fail_unless!(l.pop_tail().is_none());
|
||||
assert!(l.is_empty());
|
||||
assert!(l.pop_tail().is_none());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_push() {
|
||||
|
@ -786,7 +786,7 @@ mod tests {
|
|||
l.assert_consistent(); assert_eq!(l.tail(), 3);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 2);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 3);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
l.assert_consistent(); assert!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_mid() {
|
||||
|
@ -801,7 +801,7 @@ mod tests {
|
|||
l.assert_consistent(); assert_eq!(l.tail(), 3);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 1);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 3);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
l.assert_consistent(); assert!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_tail() {
|
||||
|
@ -816,7 +816,7 @@ mod tests {
|
|||
l.assert_consistent(); assert_eq!(l.tail(), 2);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 1);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 2);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
l.assert_consistent(); assert!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_one_two() {
|
||||
|
@ -832,7 +832,7 @@ mod tests {
|
|||
l.assert_consistent(); assert_eq!(l.head(), 3);
|
||||
l.assert_consistent(); assert_eq!(l.tail(), 3);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 3);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
l.assert_consistent(); assert!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_one_three() {
|
||||
|
@ -847,7 +847,7 @@ mod tests {
|
|||
l.assert_consistent(); assert_eq!(l.head(), 2);
|
||||
l.assert_consistent(); assert_eq!(l.tail(), 2);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 2);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
l.assert_consistent(); assert!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_two_three() {
|
||||
|
@ -862,7 +862,7 @@ mod tests {
|
|||
l.assert_consistent(); assert_eq!(l.head(), 1);
|
||||
l.assert_consistent(); assert_eq!(l.tail(), 1);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 1);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
l.assert_consistent(); assert!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_all() {
|
||||
|
@ -874,8 +874,8 @@ mod tests {
|
|||
l.assert_consistent(); l.remove(two);
|
||||
l.assert_consistent(); l.remove(three);
|
||||
l.assert_consistent(); l.remove(one); // Twenty-three is number one!
|
||||
l.assert_consistent(); fail_unless!(l.peek().is_none());
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
l.assert_consistent(); assert!(l.peek().is_none());
|
||||
l.assert_consistent(); assert!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_insert_n_before() {
|
||||
|
@ -891,7 +891,7 @@ mod tests {
|
|||
l.assert_consistent(); assert_eq!(l.pop().get(), 1);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 3);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 2);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
l.assert_consistent(); assert!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_insert_n_after() {
|
||||
|
@ -907,7 +907,7 @@ mod tests {
|
|||
l.assert_consistent(); assert_eq!(l.pop().get(), 1);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 3);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 2);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
l.assert_consistent(); assert!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_insert_before_head() {
|
||||
|
@ -922,7 +922,7 @@ mod tests {
|
|||
l.assert_consistent(); assert_eq!(l.pop().get(), 3);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 1);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 2);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
l.assert_consistent(); assert!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_insert_after_tail() {
|
||||
|
@ -937,7 +937,7 @@ mod tests {
|
|||
l.assert_consistent(); assert_eq!(l.pop().get(), 1);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 2);
|
||||
l.assert_consistent(); assert_eq!(l.pop().get(), 3);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
l.assert_consistent(); assert!(l.is_empty());
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
pub fn test_dlist_asymmetric_link() {
|
||||
|
|
|
@ -176,7 +176,7 @@ fn test_either_left() {
|
|||
let val = Left(10);
|
||||
fn f_left(x: &int) -> bool { *x == 10 }
|
||||
fn f_right(_x: &uint) -> bool { false }
|
||||
fail_unless!((either(f_left, f_right, &val)));
|
||||
assert!((either(f_left, f_right, &val)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -184,7 +184,7 @@ fn test_either_right() {
|
|||
let val = Right(10u);
|
||||
fn f_left(_x: &int) -> bool { false }
|
||||
fn f_right(x: &uint) -> bool { *x == 10u }
|
||||
fail_unless!((either(f_left, f_right, &val)));
|
||||
assert!((either(f_left, f_right, &val)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -55,7 +55,7 @@ pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] {
|
|||
len as size_t,
|
||||
ptr::addr_of(&outsz),
|
||||
lz_norm);
|
||||
fail_unless!(res as int != 0);
|
||||
assert!(res as int != 0);
|
||||
let out = vec::raw::from_buf_raw(res as *u8,
|
||||
outsz as uint);
|
||||
libc::free(res);
|
||||
|
@ -73,7 +73,7 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
|
|||
len as size_t,
|
||||
ptr::addr_of(&outsz),
|
||||
0);
|
||||
fail_unless!(res as int != 0);
|
||||
assert!(res as int != 0);
|
||||
let out = vec::raw::from_buf_raw(res as *u8,
|
||||
outsz as uint);
|
||||
libc::free(res);
|
||||
|
@ -102,6 +102,6 @@ fn test_flate_round_trip() {
|
|||
debug!("%u bytes deflated to %u (%.1f%% size)",
|
||||
in.len(), cmp.len(),
|
||||
100.0 * ((cmp.len() as float) / (in.len() as float)));
|
||||
fail_unless!((in == out));
|
||||
assert!((in == out));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -456,7 +456,7 @@ pub fn test_siphash() {
|
|||
let vec = u8to64_le!(vecs[t], 0);
|
||||
let out = buf.hash_keyed(k0, k1);
|
||||
debug!("got %?, expected %?", out, vec);
|
||||
fail_unless!(vec == out);
|
||||
assert!(vec == out);
|
||||
|
||||
stream_full.reset();
|
||||
stream_full.input(buf);
|
||||
|
@ -465,7 +465,7 @@ pub fn test_siphash() {
|
|||
let v = to_hex_str(&vecs[t]);
|
||||
debug!("%d: (%s) => inc=%s full=%s", t, v, i, f);
|
||||
|
||||
fail_unless!(f == i && f == v);
|
||||
assert!(f == i && f == v);
|
||||
|
||||
buf += ~[t as u8];
|
||||
stream_inc.input(~[t as u8]);
|
||||
|
@ -477,20 +477,20 @@ pub fn test_siphash() {
|
|||
#[test] #[cfg(target_arch = "arm")]
|
||||
pub fn test_hash_uint() {
|
||||
let val = 0xdeadbeef_deadbeef_u64;
|
||||
fail_unless!((val as u64).hash() != (val as uint).hash());
|
||||
fail_unless!((val as u32).hash() == (val as uint).hash());
|
||||
assert!((val as u64).hash() != (val as uint).hash());
|
||||
assert!((val as u32).hash() == (val as uint).hash());
|
||||
}
|
||||
#[test] #[cfg(target_arch = "x86_64")]
|
||||
pub fn test_hash_uint() {
|
||||
let val = 0xdeadbeef_deadbeef_u64;
|
||||
fail_unless!((val as u64).hash() == (val as uint).hash());
|
||||
fail_unless!((val as u32).hash() != (val as uint).hash());
|
||||
assert!((val as u64).hash() == (val as uint).hash());
|
||||
assert!((val as u32).hash() != (val as uint).hash());
|
||||
}
|
||||
#[test] #[cfg(target_arch = "x86")]
|
||||
pub fn test_hash_uint() {
|
||||
let val = 0xdeadbeef_deadbeef_u64;
|
||||
fail_unless!((val as u64).hash() != (val as uint).hash());
|
||||
fail_unless!((val as u32).hash() == (val as uint).hash());
|
||||
assert!((val as u64).hash() != (val as uint).hash());
|
||||
assert!((val as u32).hash() == (val as uint).hash());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -505,17 +505,17 @@ pub fn test_hash_idempotent() {
|
|||
pub fn test_hash_no_bytes_dropped_64() {
|
||||
let val = 0xdeadbeef_deadbeef_u64;
|
||||
|
||||
fail_unless!(val.hash() != zero_byte(val, 0).hash());
|
||||
fail_unless!(val.hash() != zero_byte(val, 1).hash());
|
||||
fail_unless!(val.hash() != zero_byte(val, 2).hash());
|
||||
fail_unless!(val.hash() != zero_byte(val, 3).hash());
|
||||
fail_unless!(val.hash() != zero_byte(val, 4).hash());
|
||||
fail_unless!(val.hash() != zero_byte(val, 5).hash());
|
||||
fail_unless!(val.hash() != zero_byte(val, 6).hash());
|
||||
fail_unless!(val.hash() != zero_byte(val, 7).hash());
|
||||
assert!(val.hash() != zero_byte(val, 0).hash());
|
||||
assert!(val.hash() != zero_byte(val, 1).hash());
|
||||
assert!(val.hash() != zero_byte(val, 2).hash());
|
||||
assert!(val.hash() != zero_byte(val, 3).hash());
|
||||
assert!(val.hash() != zero_byte(val, 4).hash());
|
||||
assert!(val.hash() != zero_byte(val, 5).hash());
|
||||
assert!(val.hash() != zero_byte(val, 6).hash());
|
||||
assert!(val.hash() != zero_byte(val, 7).hash());
|
||||
|
||||
fn zero_byte(val: u64, byte: uint) -> u64 {
|
||||
fail_unless!(byte < 8);
|
||||
assert!(byte < 8);
|
||||
val & !(0xff << (byte * 8))
|
||||
}
|
||||
}
|
||||
|
@ -524,13 +524,13 @@ pub fn test_hash_no_bytes_dropped_64() {
|
|||
pub fn test_hash_no_bytes_dropped_32() {
|
||||
let val = 0xdeadbeef_u32;
|
||||
|
||||
fail_unless!(val.hash() != zero_byte(val, 0).hash());
|
||||
fail_unless!(val.hash() != zero_byte(val, 1).hash());
|
||||
fail_unless!(val.hash() != zero_byte(val, 2).hash());
|
||||
fail_unless!(val.hash() != zero_byte(val, 3).hash());
|
||||
assert!(val.hash() != zero_byte(val, 0).hash());
|
||||
assert!(val.hash() != zero_byte(val, 1).hash());
|
||||
assert!(val.hash() != zero_byte(val, 2).hash());
|
||||
assert!(val.hash() != zero_byte(val, 3).hash());
|
||||
|
||||
fn zero_byte(val: u32, byte: uint) -> u32 {
|
||||
fail_unless!(byte < 4);
|
||||
assert!(byte < 4);
|
||||
val & !(0xff << (byte * 8))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -676,18 +676,18 @@ pub mod linear {
|
|||
#[test]
|
||||
pub fn test_insert() {
|
||||
let mut m = LinearMap::new();
|
||||
fail_unless!(m.insert(1, 2));
|
||||
fail_unless!(m.insert(2, 4));
|
||||
fail_unless!(*m.get(&1) == 2);
|
||||
fail_unless!(*m.get(&2) == 4);
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(2, 4));
|
||||
assert!(*m.get(&1) == 2);
|
||||
assert!(*m.get(&2) == 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_mut() {
|
||||
let mut m = LinearMap::new();
|
||||
fail_unless!(m.insert(1, 12));
|
||||
fail_unless!(m.insert(2, 8));
|
||||
fail_unless!(m.insert(5, 14));
|
||||
assert!(m.insert(1, 12));
|
||||
assert!(m.insert(2, 8));
|
||||
assert!(m.insert(5, 14));
|
||||
let new = 100;
|
||||
match m.find_mut(&5) {
|
||||
None => fail!(), Some(x) => *x = new
|
||||
|
@ -698,110 +698,110 @@ pub mod linear {
|
|||
#[test]
|
||||
pub fn test_insert_overwrite() {
|
||||
let mut m = LinearMap::new();
|
||||
fail_unless!(m.insert(1, 2));
|
||||
fail_unless!(*m.get(&1) == 2);
|
||||
fail_unless!(!m.insert(1, 3));
|
||||
fail_unless!(*m.get(&1) == 3);
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(*m.get(&1) == 2);
|
||||
assert!(!m.insert(1, 3));
|
||||
assert!(*m.get(&1) == 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_insert_conflicts() {
|
||||
let mut m = linear::linear_map_with_capacity(4);
|
||||
fail_unless!(m.insert(1, 2));
|
||||
fail_unless!(m.insert(5, 3));
|
||||
fail_unless!(m.insert(9, 4));
|
||||
fail_unless!(*m.get(&9) == 4);
|
||||
fail_unless!(*m.get(&5) == 3);
|
||||
fail_unless!(*m.get(&1) == 2);
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(5, 3));
|
||||
assert!(m.insert(9, 4));
|
||||
assert!(*m.get(&9) == 4);
|
||||
assert!(*m.get(&5) == 3);
|
||||
assert!(*m.get(&1) == 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_conflict_remove() {
|
||||
let mut m = linear::linear_map_with_capacity(4);
|
||||
fail_unless!(m.insert(1, 2));
|
||||
fail_unless!(m.insert(5, 3));
|
||||
fail_unless!(m.insert(9, 4));
|
||||
fail_unless!(m.remove(&1));
|
||||
fail_unless!(*m.get(&9) == 4);
|
||||
fail_unless!(*m.get(&5) == 3);
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(5, 3));
|
||||
assert!(m.insert(9, 4));
|
||||
assert!(m.remove(&1));
|
||||
assert!(*m.get(&9) == 4);
|
||||
assert!(*m.get(&5) == 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_is_empty() {
|
||||
let mut m = linear::linear_map_with_capacity(4);
|
||||
fail_unless!(m.insert(1, 2));
|
||||
fail_unless!(!m.is_empty());
|
||||
fail_unless!(m.remove(&1));
|
||||
fail_unless!(m.is_empty());
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(!m.is_empty());
|
||||
assert!(m.remove(&1));
|
||||
assert!(m.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_pop() {
|
||||
let mut m = LinearMap::new();
|
||||
m.insert(1, 2);
|
||||
fail_unless!(m.pop(&1) == Some(2));
|
||||
fail_unless!(m.pop(&1) == None);
|
||||
assert!(m.pop(&1) == Some(2));
|
||||
assert!(m.pop(&1) == None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_swap() {
|
||||
let mut m = LinearMap::new();
|
||||
fail_unless!(m.swap(1, 2) == None);
|
||||
fail_unless!(m.swap(1, 3) == Some(2));
|
||||
fail_unless!(m.swap(1, 4) == Some(3));
|
||||
assert!(m.swap(1, 2) == None);
|
||||
assert!(m.swap(1, 3) == Some(2));
|
||||
assert!(m.swap(1, 4) == Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_find_or_insert() {
|
||||
let mut m = LinearMap::new::<int, int>();
|
||||
fail_unless!(m.find_or_insert(1, 2) == &2);
|
||||
fail_unless!(m.find_or_insert(1, 3) == &2);
|
||||
assert!(m.find_or_insert(1, 2) == &2);
|
||||
assert!(m.find_or_insert(1, 3) == &2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_find_or_insert_with() {
|
||||
let mut m = LinearMap::new::<int, int>();
|
||||
fail_unless!(m.find_or_insert_with(1, |_| 2) == &2);
|
||||
fail_unless!(m.find_or_insert_with(1, |_| 3) == &2);
|
||||
assert!(m.find_or_insert_with(1, |_| 2) == &2);
|
||||
assert!(m.find_or_insert_with(1, |_| 3) == &2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_consume() {
|
||||
let mut m = LinearMap::new();
|
||||
fail_unless!(m.insert(1, 2));
|
||||
fail_unless!(m.insert(2, 3));
|
||||
assert!(m.insert(1, 2));
|
||||
assert!(m.insert(2, 3));
|
||||
let mut m2 = LinearMap::new();
|
||||
do m.consume |k, v| {
|
||||
m2.insert(k, v);
|
||||
}
|
||||
fail_unless!(m.len() == 0);
|
||||
fail_unless!(m2.len() == 2);
|
||||
fail_unless!(m2.get(&1) == &2);
|
||||
fail_unless!(m2.get(&2) == &3);
|
||||
assert!(m.len() == 0);
|
||||
assert!(m2.len() == 2);
|
||||
assert!(m2.get(&1) == &2);
|
||||
assert!(m2.get(&2) == &3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_iterate() {
|
||||
let mut m = linear::linear_map_with_capacity(4);
|
||||
for uint::range(0, 32) |i| {
|
||||
fail_unless!(m.insert(i, i*2));
|
||||
assert!(m.insert(i, i*2));
|
||||
}
|
||||
let mut observed = 0;
|
||||
for m.each |&(k, v)| {
|
||||
fail_unless!(*v == *k * 2);
|
||||
assert!(*v == *k * 2);
|
||||
observed |= (1 << *k);
|
||||
}
|
||||
fail_unless!(observed == 0xFFFF_FFFF);
|
||||
assert!(observed == 0xFFFF_FFFF);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_find() {
|
||||
let mut m = LinearMap::new();
|
||||
fail_unless!(m.find(&1).is_none());
|
||||
assert!(m.find(&1).is_none());
|
||||
m.insert(1, 2);
|
||||
match m.find(&1) {
|
||||
None => fail!(),
|
||||
Some(v) => fail_unless!(*v == 2)
|
||||
Some(v) => assert!(*v == 2)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -816,19 +816,19 @@ pub mod linear {
|
|||
m2.insert(1, 2);
|
||||
m2.insert(2, 3);
|
||||
|
||||
fail_unless!(m1 != m2);
|
||||
assert!(m1 != m2);
|
||||
|
||||
m2.insert(3, 4);
|
||||
|
||||
fail_unless!(m1 == m2);
|
||||
assert!(m1 == m2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_expand() {
|
||||
let mut m = LinearMap::new();
|
||||
|
||||
fail_unless!(m.len() == 0);
|
||||
fail_unless!(m.is_empty());
|
||||
assert!(m.len() == 0);
|
||||
assert!(m.is_empty());
|
||||
|
||||
let mut i = 0u;
|
||||
let old_resize_at = m.resize_at;
|
||||
|
@ -837,8 +837,8 @@ pub mod linear {
|
|||
i += 1;
|
||||
}
|
||||
|
||||
fail_unless!(m.len() == i);
|
||||
fail_unless!(!m.is_empty());
|
||||
assert!(m.len() == i);
|
||||
assert!(!m.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -852,51 +852,51 @@ pub mod linear {
|
|||
fn test_disjoint() {
|
||||
let mut xs = linear::LinearSet::new();
|
||||
let mut ys = linear::LinearSet::new();
|
||||
fail_unless!(xs.is_disjoint(&ys));
|
||||
fail_unless!(ys.is_disjoint(&xs));
|
||||
fail_unless!(xs.insert(5));
|
||||
fail_unless!(ys.insert(11));
|
||||
fail_unless!(xs.is_disjoint(&ys));
|
||||
fail_unless!(ys.is_disjoint(&xs));
|
||||
fail_unless!(xs.insert(7));
|
||||
fail_unless!(xs.insert(19));
|
||||
fail_unless!(xs.insert(4));
|
||||
fail_unless!(ys.insert(2));
|
||||
fail_unless!(ys.insert(-11));
|
||||
fail_unless!(xs.is_disjoint(&ys));
|
||||
fail_unless!(ys.is_disjoint(&xs));
|
||||
fail_unless!(ys.insert(7));
|
||||
fail_unless!(!xs.is_disjoint(&ys));
|
||||
fail_unless!(!ys.is_disjoint(&xs));
|
||||
assert!(xs.is_disjoint(&ys));
|
||||
assert!(ys.is_disjoint(&xs));
|
||||
assert!(xs.insert(5));
|
||||
assert!(ys.insert(11));
|
||||
assert!(xs.is_disjoint(&ys));
|
||||
assert!(ys.is_disjoint(&xs));
|
||||
assert!(xs.insert(7));
|
||||
assert!(xs.insert(19));
|
||||
assert!(xs.insert(4));
|
||||
assert!(ys.insert(2));
|
||||
assert!(ys.insert(-11));
|
||||
assert!(xs.is_disjoint(&ys));
|
||||
assert!(ys.is_disjoint(&xs));
|
||||
assert!(ys.insert(7));
|
||||
assert!(!xs.is_disjoint(&ys));
|
||||
assert!(!ys.is_disjoint(&xs));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_subset_and_superset() {
|
||||
let mut a = linear::LinearSet::new();
|
||||
fail_unless!(a.insert(0));
|
||||
fail_unless!(a.insert(5));
|
||||
fail_unless!(a.insert(11));
|
||||
fail_unless!(a.insert(7));
|
||||
assert!(a.insert(0));
|
||||
assert!(a.insert(5));
|
||||
assert!(a.insert(11));
|
||||
assert!(a.insert(7));
|
||||
|
||||
let mut b = linear::LinearSet::new();
|
||||
fail_unless!(b.insert(0));
|
||||
fail_unless!(b.insert(7));
|
||||
fail_unless!(b.insert(19));
|
||||
fail_unless!(b.insert(250));
|
||||
fail_unless!(b.insert(11));
|
||||
fail_unless!(b.insert(200));
|
||||
assert!(b.insert(0));
|
||||
assert!(b.insert(7));
|
||||
assert!(b.insert(19));
|
||||
assert!(b.insert(250));
|
||||
assert!(b.insert(11));
|
||||
assert!(b.insert(200));
|
||||
|
||||
fail_unless!(!a.is_subset(&b));
|
||||
fail_unless!(!a.is_superset(&b));
|
||||
fail_unless!(!b.is_subset(&a));
|
||||
fail_unless!(!b.is_superset(&a));
|
||||
assert!(!a.is_subset(&b));
|
||||
assert!(!a.is_superset(&b));
|
||||
assert!(!b.is_subset(&a));
|
||||
assert!(!b.is_superset(&a));
|
||||
|
||||
fail_unless!(b.insert(5));
|
||||
assert!(b.insert(5));
|
||||
|
||||
fail_unless!(a.is_subset(&b));
|
||||
fail_unless!(!a.is_superset(&b));
|
||||
fail_unless!(!b.is_subset(&a));
|
||||
fail_unless!(b.is_superset(&a));
|
||||
assert!(a.is_subset(&b));
|
||||
assert!(!a.is_superset(&b));
|
||||
assert!(!b.is_subset(&a));
|
||||
assert!(b.is_superset(&a));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -904,29 +904,29 @@ pub mod linear {
|
|||
let mut a = linear::LinearSet::new();
|
||||
let mut b = linear::LinearSet::new();
|
||||
|
||||
fail_unless!(a.insert(11));
|
||||
fail_unless!(a.insert(1));
|
||||
fail_unless!(a.insert(3));
|
||||
fail_unless!(a.insert(77));
|
||||
fail_unless!(a.insert(103));
|
||||
fail_unless!(a.insert(5));
|
||||
fail_unless!(a.insert(-5));
|
||||
assert!(a.insert(11));
|
||||
assert!(a.insert(1));
|
||||
assert!(a.insert(3));
|
||||
assert!(a.insert(77));
|
||||
assert!(a.insert(103));
|
||||
assert!(a.insert(5));
|
||||
assert!(a.insert(-5));
|
||||
|
||||
fail_unless!(b.insert(2));
|
||||
fail_unless!(b.insert(11));
|
||||
fail_unless!(b.insert(77));
|
||||
fail_unless!(b.insert(-9));
|
||||
fail_unless!(b.insert(-42));
|
||||
fail_unless!(b.insert(5));
|
||||
fail_unless!(b.insert(3));
|
||||
assert!(b.insert(2));
|
||||
assert!(b.insert(11));
|
||||
assert!(b.insert(77));
|
||||
assert!(b.insert(-9));
|
||||
assert!(b.insert(-42));
|
||||
assert!(b.insert(5));
|
||||
assert!(b.insert(3));
|
||||
|
||||
let mut i = 0;
|
||||
let expected = [3, 5, 11, 77];
|
||||
for a.intersection(&b) |x| {
|
||||
fail_unless!(vec::contains(expected, x));
|
||||
assert!(vec::contains(expected, x));
|
||||
i += 1
|
||||
}
|
||||
fail_unless!(i == expected.len());
|
||||
assert!(i == expected.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -934,22 +934,22 @@ pub mod linear {
|
|||
let mut a = linear::LinearSet::new();
|
||||
let mut b = linear::LinearSet::new();
|
||||
|
||||
fail_unless!(a.insert(1));
|
||||
fail_unless!(a.insert(3));
|
||||
fail_unless!(a.insert(5));
|
||||
fail_unless!(a.insert(9));
|
||||
fail_unless!(a.insert(11));
|
||||
assert!(a.insert(1));
|
||||
assert!(a.insert(3));
|
||||
assert!(a.insert(5));
|
||||
assert!(a.insert(9));
|
||||
assert!(a.insert(11));
|
||||
|
||||
fail_unless!(b.insert(3));
|
||||
fail_unless!(b.insert(9));
|
||||
assert!(b.insert(3));
|
||||
assert!(b.insert(9));
|
||||
|
||||
let mut i = 0;
|
||||
let expected = [1, 5, 11];
|
||||
for a.difference(&b) |x| {
|
||||
fail_unless!(vec::contains(expected, x));
|
||||
assert!(vec::contains(expected, x));
|
||||
i += 1
|
||||
}
|
||||
fail_unless!(i == expected.len());
|
||||
assert!(i == expected.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -957,25 +957,25 @@ pub mod linear {
|
|||
let mut a = linear::LinearSet::new();
|
||||
let mut b = linear::LinearSet::new();
|
||||
|
||||
fail_unless!(a.insert(1));
|
||||
fail_unless!(a.insert(3));
|
||||
fail_unless!(a.insert(5));
|
||||
fail_unless!(a.insert(9));
|
||||
fail_unless!(a.insert(11));
|
||||
assert!(a.insert(1));
|
||||
assert!(a.insert(3));
|
||||
assert!(a.insert(5));
|
||||
assert!(a.insert(9));
|
||||
assert!(a.insert(11));
|
||||
|
||||
fail_unless!(b.insert(-2));
|
||||
fail_unless!(b.insert(3));
|
||||
fail_unless!(b.insert(9));
|
||||
fail_unless!(b.insert(14));
|
||||
fail_unless!(b.insert(22));
|
||||
assert!(b.insert(-2));
|
||||
assert!(b.insert(3));
|
||||
assert!(b.insert(9));
|
||||
assert!(b.insert(14));
|
||||
assert!(b.insert(22));
|
||||
|
||||
let mut i = 0;
|
||||
let expected = [-2, 1, 5, 11, 14, 22];
|
||||
for a.symmetric_difference(&b) |x| {
|
||||
fail_unless!(vec::contains(expected, x));
|
||||
assert!(vec::contains(expected, x));
|
||||
i += 1
|
||||
}
|
||||
fail_unless!(i == expected.len());
|
||||
assert!(i == expected.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -983,29 +983,29 @@ pub mod linear {
|
|||
let mut a = linear::LinearSet::new();
|
||||
let mut b = linear::LinearSet::new();
|
||||
|
||||
fail_unless!(a.insert(1));
|
||||
fail_unless!(a.insert(3));
|
||||
fail_unless!(a.insert(5));
|
||||
fail_unless!(a.insert(9));
|
||||
fail_unless!(a.insert(11));
|
||||
fail_unless!(a.insert(16));
|
||||
fail_unless!(a.insert(19));
|
||||
fail_unless!(a.insert(24));
|
||||
assert!(a.insert(1));
|
||||
assert!(a.insert(3));
|
||||
assert!(a.insert(5));
|
||||
assert!(a.insert(9));
|
||||
assert!(a.insert(11));
|
||||
assert!(a.insert(16));
|
||||
assert!(a.insert(19));
|
||||
assert!(a.insert(24));
|
||||
|
||||
fail_unless!(b.insert(-2));
|
||||
fail_unless!(b.insert(1));
|
||||
fail_unless!(b.insert(5));
|
||||
fail_unless!(b.insert(9));
|
||||
fail_unless!(b.insert(13));
|
||||
fail_unless!(b.insert(19));
|
||||
assert!(b.insert(-2));
|
||||
assert!(b.insert(1));
|
||||
assert!(b.insert(5));
|
||||
assert!(b.insert(9));
|
||||
assert!(b.insert(13));
|
||||
assert!(b.insert(19));
|
||||
|
||||
let mut i = 0;
|
||||
let expected = [-2, 1, 3, 5, 9, 11, 13, 16, 19, 24];
|
||||
for a.union(&b) |x| {
|
||||
fail_unless!(vec::contains(expected, x));
|
||||
assert!(vec::contains(expected, x));
|
||||
i += 1
|
||||
}
|
||||
fail_unless!(i == expected.len());
|
||||
assert!(i == expected.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ impl<T:Reader> ReaderUtil for T {
|
|||
let w = str::utf8_char_width(b0);
|
||||
let end = i + w;
|
||||
i += 1;
|
||||
fail_unless!((w > 0));
|
||||
assert!((w > 0));
|
||||
if w == 1 {
|
||||
chars.push(b0 as char);
|
||||
loop;
|
||||
|
@ -265,8 +265,8 @@ impl<T:Reader> ReaderUtil for T {
|
|||
while i < end {
|
||||
let next = bytes[i] as int;
|
||||
i += 1;
|
||||
fail_unless!((next > -1));
|
||||
fail_unless!((next & 192 == 128));
|
||||
assert!((next > -1));
|
||||
assert!((next & 192 == 128));
|
||||
val <<= 6;
|
||||
val += (next & 63) as uint;
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ impl<T:Reader> ReaderUtil for T {
|
|||
if vec::len(c) == 0 {
|
||||
return -1 as char; // FIXME will this stay valid? // #2004
|
||||
}
|
||||
fail_unless!((vec::len(c) == 1));
|
||||
assert!((vec::len(c) == 1));
|
||||
return c[0];
|
||||
}
|
||||
|
||||
|
@ -364,7 +364,7 @@ impl<T:Reader> ReaderUtil for T {
|
|||
// FIXME int reading methods need to deal with eof - issue #2004
|
||||
|
||||
fn read_le_uint_n(&self, nbytes: uint) -> u64 {
|
||||
fail_unless!(nbytes > 0 && nbytes <= 8);
|
||||
assert!(nbytes > 0 && nbytes <= 8);
|
||||
|
||||
let mut val = 0u64, pos = 0, i = nbytes;
|
||||
while i > 0 {
|
||||
|
@ -380,7 +380,7 @@ impl<T:Reader> ReaderUtil for T {
|
|||
}
|
||||
|
||||
fn read_be_uint_n(&self, nbytes: uint) -> u64 {
|
||||
fail_unless!(nbytes > 0 && nbytes <= 8);
|
||||
assert!(nbytes > 0 && nbytes <= 8);
|
||||
|
||||
let mut val = 0u64, i = nbytes;
|
||||
while i > 0 {
|
||||
|
@ -510,7 +510,7 @@ impl Reader for *libc::FILE {
|
|||
fn read(&self, bytes: &mut [u8], len: uint) -> uint {
|
||||
unsafe {
|
||||
do vec::as_mut_buf(bytes) |buf_p, buf_len| {
|
||||
fail_unless!(buf_len >= len);
|
||||
assert!(buf_len >= len);
|
||||
|
||||
let count = libc::fread(buf_p as *mut c_void, 1u as size_t,
|
||||
len as size_t, *self);
|
||||
|
@ -531,7 +531,7 @@ impl Reader for *libc::FILE {
|
|||
}
|
||||
fn seek(&self, offset: int, whence: SeekStyle) {
|
||||
unsafe {
|
||||
fail_unless!(libc::fseek(*self,
|
||||
assert!(libc::fseek(*self,
|
||||
offset as c_long,
|
||||
convert_whence(whence)) == 0 as c_int);
|
||||
}
|
||||
|
@ -717,7 +717,7 @@ impl Writer for *libc::FILE {
|
|||
}
|
||||
fn seek(&self, offset: int, whence: SeekStyle) {
|
||||
unsafe {
|
||||
fail_unless!(libc::fseek(*self,
|
||||
assert!(libc::fseek(*self,
|
||||
offset as c_long,
|
||||
convert_whence(whence)) == 0 as c_int);
|
||||
}
|
||||
|
@ -845,7 +845,7 @@ pub fn mk_file_writer(path: &Path, flags: &[FileFlag])
|
|||
|
||||
pub fn u64_to_le_bytes<T>(n: u64, size: uint,
|
||||
f: &fn(v: &[u8]) -> T) -> T {
|
||||
fail_unless!(size <= 8u);
|
||||
assert!(size <= 8u);
|
||||
match size {
|
||||
1u => f(&[n as u8]),
|
||||
2u => f(&[n as u8,
|
||||
|
@ -877,7 +877,7 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint,
|
|||
|
||||
pub fn u64_to_be_bytes<T>(n: u64, size: uint,
|
||||
f: &fn(v: &[u8]) -> T) -> T {
|
||||
fail_unless!(size <= 8u);
|
||||
assert!(size <= 8u);
|
||||
match size {
|
||||
1u => f(&[n as u8]),
|
||||
2u => f(&[(n >> 8) as u8,
|
||||
|
@ -912,7 +912,7 @@ pub fn u64_from_be_bytes(data: &const [u8],
|
|||
size: uint)
|
||||
-> u64 {
|
||||
let mut sz = size;
|
||||
fail_unless!((sz <= 8u));
|
||||
assert!((sz <= 8u));
|
||||
let mut val = 0_u64;
|
||||
let mut pos = start;
|
||||
while sz > 0u {
|
||||
|
@ -1186,7 +1186,7 @@ pub fn with_str_writer(f: &fn(@Writer)) -> ~str {
|
|||
// Make sure the vector has a trailing null and is proper utf8.
|
||||
v.push(0);
|
||||
}
|
||||
fail_unless!(str::is_utf8(v));
|
||||
assert!(str::is_utf8(v));
|
||||
|
||||
unsafe { ::cast::transmute(v) }
|
||||
}
|
||||
|
@ -1261,7 +1261,7 @@ pub mod fsync {
|
|||
None => (),
|
||||
Some(level) => {
|
||||
// fail hard if not succesful
|
||||
fail_unless!(((self.arg.fsync_fn)(self.arg.val, level)
|
||||
assert!(((self.arg.fsync_fn)(self.arg.val, level)
|
||||
!= -1));
|
||||
}
|
||||
}
|
||||
|
@ -1346,14 +1346,14 @@ mod tests {
|
|||
let inp: @io::Reader = result::get(&io::file_reader(tmpfile));
|
||||
let frood2: ~str = inp.read_c_str();
|
||||
debug!(copy frood2);
|
||||
fail_unless!(frood == frood2);
|
||||
assert!(frood == frood2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_readchars_empty() {
|
||||
do io::with_str_reader(~"") |inp| {
|
||||
let res : ~[char] = inp.read_chars(128);
|
||||
fail_unless!((vec::len(res) == 0));
|
||||
assert!((vec::len(res) == 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1361,22 +1361,22 @@ mod tests {
|
|||
fn test_read_line_utf8() {
|
||||
do io::with_str_reader(~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤") |inp| {
|
||||
let line = inp.read_line();
|
||||
fail_unless!(line == ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤");
|
||||
assert!(line == ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_lines() {
|
||||
do io::with_str_reader(~"a\nb\nc\n") |inp| {
|
||||
fail_unless!(inp.read_lines() == ~[~"a", ~"b", ~"c"]);
|
||||
assert!(inp.read_lines() == ~[~"a", ~"b", ~"c"]);
|
||||
}
|
||||
|
||||
do io::with_str_reader(~"a\nb\nc") |inp| {
|
||||
fail_unless!(inp.read_lines() == ~[~"a", ~"b", ~"c"]);
|
||||
assert!(inp.read_lines() == ~[~"a", ~"b", ~"c"]);
|
||||
}
|
||||
|
||||
do io::with_str_reader(~"") |inp| {
|
||||
fail_unless!(inp.read_lines().is_empty());
|
||||
assert!(inp.read_lines().is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1393,9 +1393,9 @@ mod tests {
|
|||
do io::with_str_reader(s) |inp| {
|
||||
let res : ~[char] = inp.read_chars(len);
|
||||
if (len <= vec::len(ivals)) {
|
||||
fail_unless!((vec::len(res) == len));
|
||||
assert!((vec::len(res) == len));
|
||||
}
|
||||
fail_unless!(vec::slice(ivals, 0u, vec::len(res)) ==
|
||||
assert!(vec::slice(ivals, 0u, vec::len(res)) ==
|
||||
vec::map(res, |x| *x as int));
|
||||
}
|
||||
}
|
||||
|
@ -1412,7 +1412,7 @@ mod tests {
|
|||
fn test_readchar() {
|
||||
do io::with_str_reader(~"生") |inp| {
|
||||
let res : char = inp.read_char();
|
||||
fail_unless!((res as int == 29983));
|
||||
assert!((res as int == 29983));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1420,7 +1420,7 @@ mod tests {
|
|||
fn test_readchar_empty() {
|
||||
do io::with_str_reader(~"") |inp| {
|
||||
let res : char = inp.read_char();
|
||||
fail_unless!((res as int == -1));
|
||||
assert!((res as int == -1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1428,7 +1428,7 @@ mod tests {
|
|||
fn file_reader_not_exist() {
|
||||
match io::file_reader(&Path("not a file")) {
|
||||
result::Err(copy e) => {
|
||||
fail_unless!(e == ~"error opening not a file");
|
||||
assert!(e == ~"error opening not a file");
|
||||
}
|
||||
result::Ok(_) => fail!()
|
||||
}
|
||||
|
@ -1469,7 +1469,7 @@ mod tests {
|
|||
fn file_writer_bad_name() {
|
||||
match io::file_writer(&Path("?/?"), ~[]) {
|
||||
result::Err(copy e) => {
|
||||
fail_unless!(str::starts_with(e, "error opening"));
|
||||
assert!(str::starts_with(e, "error opening"));
|
||||
}
|
||||
result::Ok(_) => fail!()
|
||||
}
|
||||
|
@ -1479,7 +1479,7 @@ mod tests {
|
|||
fn buffered_file_writer_bad_name() {
|
||||
match io::buffered_file_writer(&Path("?/?")) {
|
||||
result::Err(copy e) => {
|
||||
fail_unless!(str::starts_with(e, "error opening"));
|
||||
assert!(str::starts_with(e, "error opening"));
|
||||
}
|
||||
result::Ok(_) => fail!()
|
||||
}
|
||||
|
@ -1489,15 +1489,15 @@ mod tests {
|
|||
fn bytes_buffer_overwrite() {
|
||||
let wr = BytesWriter();
|
||||
wr.write(~[0u8, 1u8, 2u8, 3u8]);
|
||||
fail_unless!(wr.bytes == ~[0u8, 1u8, 2u8, 3u8]);
|
||||
assert!(wr.bytes == ~[0u8, 1u8, 2u8, 3u8]);
|
||||
wr.seek(-2, SeekCur);
|
||||
wr.write(~[4u8, 5u8, 6u8, 7u8]);
|
||||
fail_unless!(wr.bytes == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]);
|
||||
assert!(wr.bytes == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]);
|
||||
wr.seek(-2, SeekEnd);
|
||||
wr.write(~[8u8]);
|
||||
wr.seek(1, SeekSet);
|
||||
wr.write(~[9u8]);
|
||||
fail_unless!(wr.bytes == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]);
|
||||
assert!(wr.bytes == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1517,7 +1517,7 @@ mod tests {
|
|||
{
|
||||
let file = io::file_reader(&path).get();
|
||||
for uints.each |i| {
|
||||
fail_unless!(file.read_le_u64() == *i);
|
||||
assert!(file.read_le_u64() == *i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1539,7 +1539,7 @@ mod tests {
|
|||
{
|
||||
let file = io::file_reader(&path).get();
|
||||
for uints.each |i| {
|
||||
fail_unless!(file.read_be_u64() == *i);
|
||||
assert!(file.read_be_u64() == *i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1563,7 +1563,7 @@ mod tests {
|
|||
for ints.each |i| {
|
||||
// this tests that the sign extension is working
|
||||
// (comparing the values as i32 would not test this)
|
||||
fail_unless!(file.read_be_int_n(4) == *i as i64);
|
||||
assert!(file.read_be_int_n(4) == *i as i64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1582,7 +1582,7 @@ mod tests {
|
|||
{
|
||||
let file = io::file_reader(&path).get();
|
||||
let f = file.read_be_f32();
|
||||
fail_unless!(f == 8.1250);
|
||||
assert!(f == 8.1250);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1599,8 +1599,8 @@ mod tests {
|
|||
|
||||
{
|
||||
let file = io::file_reader(&path).get();
|
||||
fail_unless!(file.read_be_f32() == 8.1250);
|
||||
fail_unless!(file.read_le_f32() == 8.1250);
|
||||
assert!(file.read_be_f32() == 8.1250);
|
||||
assert!(file.read_le_f32() == 8.1250);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,8 +91,8 @@ impl<T:Ord> Ord for @mut T {
|
|||
fn test() {
|
||||
let x = @3;
|
||||
let y = @3;
|
||||
fail_unless!((ptr_eq::<int>(x, x)));
|
||||
fail_unless!((ptr_eq::<int>(y, y)));
|
||||
fail_unless!((!ptr_eq::<int>(x, y)));
|
||||
fail_unless!((!ptr_eq::<int>(y, x)));
|
||||
assert!((ptr_eq::<int>(x, x)));
|
||||
assert!((ptr_eq::<int>(y, y)));
|
||||
assert!((!ptr_eq::<int>(x, y)));
|
||||
assert!((!ptr_eq::<int>(y, x)));
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ pub fn Mut<T>(t: T) -> Mut<T> {
|
|||
pub fn unwrap<T>(m: Mut<T>) -> T {
|
||||
// Borrowck should prevent us from calling unwrap while the value
|
||||
// is in use, as that would be a move from a borrowed value.
|
||||
fail_unless!((m.mode as uint) == (ReadOnly as uint));
|
||||
assert!((m.mode as uint) == (ReadOnly as uint));
|
||||
let Data {value: value, mode: _} = m;
|
||||
value
|
||||
}
|
||||
|
@ -103,9 +103,9 @@ pub fn test_const_in_mut() {
|
|||
let m = @Mut(1);
|
||||
do m.borrow_mut |p| {
|
||||
do m.borrow_const |q| {
|
||||
fail_unless!(*p == *q);
|
||||
assert!(*p == *q);
|
||||
*p += 1;
|
||||
fail_unless!(*p == *q);
|
||||
assert!(*p == *q);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,9 +115,9 @@ pub fn test_mut_in_const() {
|
|||
let m = @Mut(1);
|
||||
do m.borrow_const |p| {
|
||||
do m.borrow_mut |q| {
|
||||
fail_unless!(*p == *q);
|
||||
assert!(*p == *q);
|
||||
*q += 1;
|
||||
fail_unless!(*p == *q);
|
||||
assert!(*p == *q);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ pub fn test_imm_in_const() {
|
|||
let m = @Mut(1);
|
||||
do m.borrow_const |p| {
|
||||
do m.borrow_imm |q| {
|
||||
fail_unless!(*p == *q);
|
||||
assert!(*p == *q);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ pub fn test_const_in_imm() {
|
|||
let m = @Mut(1);
|
||||
do m.borrow_imm |p| {
|
||||
do m.borrow_const |q| {
|
||||
fail_unless!(*p == *q);
|
||||
assert!(*p == *q);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -585,56 +585,56 @@ pub fn test_num() {
|
|||
let ten: f32 = num::cast(10);
|
||||
let two: f32 = num::cast(2);
|
||||
|
||||
fail_unless!((ten.add(&two) == num::cast(12)));
|
||||
fail_unless!((ten.sub(&two) == num::cast(8)));
|
||||
fail_unless!((ten.mul(&two) == num::cast(20)));
|
||||
fail_unless!((ten.div(&two) == num::cast(5)));
|
||||
fail_unless!((ten.modulo(&two) == num::cast(0)));
|
||||
assert!((ten.add(&two) == num::cast(12)));
|
||||
assert!((ten.sub(&two) == num::cast(8)));
|
||||
assert!((ten.mul(&two) == num::cast(20)));
|
||||
assert!((ten.div(&two) == num::cast(5)));
|
||||
assert!((ten.modulo(&two) == num::cast(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20f32.to_uint()));
|
||||
fail_unless!((20u8 == 20f32.to_u8()));
|
||||
fail_unless!((20u16 == 20f32.to_u16()));
|
||||
fail_unless!((20u32 == 20f32.to_u32()));
|
||||
fail_unless!((20u64 == 20f32.to_u64()));
|
||||
fail_unless!((20i == 20f32.to_int()));
|
||||
fail_unless!((20i8 == 20f32.to_i8()));
|
||||
fail_unless!((20i16 == 20f32.to_i16()));
|
||||
fail_unless!((20i32 == 20f32.to_i32()));
|
||||
fail_unless!((20i64 == 20f32.to_i64()));
|
||||
fail_unless!((20f == 20f32.to_float()));
|
||||
fail_unless!((20f32 == 20f32.to_f32()));
|
||||
fail_unless!((20f64 == 20f32.to_f64()));
|
||||
assert!((20u == 20f32.to_uint()));
|
||||
assert!((20u8 == 20f32.to_u8()));
|
||||
assert!((20u16 == 20f32.to_u16()));
|
||||
assert!((20u32 == 20f32.to_u32()));
|
||||
assert!((20u64 == 20f32.to_u64()));
|
||||
assert!((20i == 20f32.to_int()));
|
||||
assert!((20i8 == 20f32.to_i8()));
|
||||
assert!((20i16 == 20f32.to_i16()));
|
||||
assert!((20i32 == 20f32.to_i32()));
|
||||
assert!((20i64 == 20f32.to_i64()));
|
||||
assert!((20f == 20f32.to_float()));
|
||||
assert!((20f32 == 20f32.to_f32()));
|
||||
assert!((20f64 == 20f32.to_f64()));
|
||||
|
||||
fail_unless!((20f32 == NumCast::from(20u)));
|
||||
fail_unless!((20f32 == NumCast::from(20u8)));
|
||||
fail_unless!((20f32 == NumCast::from(20u16)));
|
||||
fail_unless!((20f32 == NumCast::from(20u32)));
|
||||
fail_unless!((20f32 == NumCast::from(20u64)));
|
||||
fail_unless!((20f32 == NumCast::from(20i)));
|
||||
fail_unless!((20f32 == NumCast::from(20i8)));
|
||||
fail_unless!((20f32 == NumCast::from(20i16)));
|
||||
fail_unless!((20f32 == NumCast::from(20i32)));
|
||||
fail_unless!((20f32 == NumCast::from(20i64)));
|
||||
fail_unless!((20f32 == NumCast::from(20f)));
|
||||
fail_unless!((20f32 == NumCast::from(20f32)));
|
||||
fail_unless!((20f32 == NumCast::from(20f64)));
|
||||
assert!((20f32 == NumCast::from(20u)));
|
||||
assert!((20f32 == NumCast::from(20u8)));
|
||||
assert!((20f32 == NumCast::from(20u16)));
|
||||
assert!((20f32 == NumCast::from(20u32)));
|
||||
assert!((20f32 == NumCast::from(20u64)));
|
||||
assert!((20f32 == NumCast::from(20i)));
|
||||
assert!((20f32 == NumCast::from(20i8)));
|
||||
assert!((20f32 == NumCast::from(20i16)));
|
||||
assert!((20f32 == NumCast::from(20i32)));
|
||||
assert!((20f32 == NumCast::from(20i64)));
|
||||
assert!((20f32 == NumCast::from(20f)));
|
||||
assert!((20f32 == NumCast::from(20f32)));
|
||||
assert!((20f32 == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20f32 == num::cast(20u)));
|
||||
fail_unless!((20f32 == num::cast(20u8)));
|
||||
fail_unless!((20f32 == num::cast(20u16)));
|
||||
fail_unless!((20f32 == num::cast(20u32)));
|
||||
fail_unless!((20f32 == num::cast(20u64)));
|
||||
fail_unless!((20f32 == num::cast(20i)));
|
||||
fail_unless!((20f32 == num::cast(20i8)));
|
||||
fail_unless!((20f32 == num::cast(20i16)));
|
||||
fail_unless!((20f32 == num::cast(20i32)));
|
||||
fail_unless!((20f32 == num::cast(20i64)));
|
||||
fail_unless!((20f32 == num::cast(20f)));
|
||||
fail_unless!((20f32 == num::cast(20f32)));
|
||||
fail_unless!((20f32 == num::cast(20f64)));
|
||||
assert!((20f32 == num::cast(20u)));
|
||||
assert!((20f32 == num::cast(20u8)));
|
||||
assert!((20f32 == num::cast(20u16)));
|
||||
assert!((20f32 == num::cast(20u32)));
|
||||
assert!((20f32 == num::cast(20u64)));
|
||||
assert!((20f32 == num::cast(20i)));
|
||||
assert!((20f32 == num::cast(20i8)));
|
||||
assert!((20f32 == num::cast(20i16)));
|
||||
assert!((20f32 == num::cast(20i32)));
|
||||
assert!((20f32 == num::cast(20i64)));
|
||||
assert!((20f32 == num::cast(20f)));
|
||||
assert!((20f32 == num::cast(20f32)));
|
||||
assert!((20f32 == num::cast(20f64)));
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -607,56 +607,56 @@ pub fn test_num() {
|
|||
let ten: f64 = num::cast(10);
|
||||
let two: f64 = num::cast(2);
|
||||
|
||||
fail_unless!((ten.add(&two) == num::cast(12)));
|
||||
fail_unless!((ten.sub(&two) == num::cast(8)));
|
||||
fail_unless!((ten.mul(&two) == num::cast(20)));
|
||||
fail_unless!((ten.div(&two) == num::cast(5)));
|
||||
fail_unless!((ten.modulo(&two) == num::cast(0)));
|
||||
assert!((ten.add(&two) == num::cast(12)));
|
||||
assert!((ten.sub(&two) == num::cast(8)));
|
||||
assert!((ten.mul(&two) == num::cast(20)));
|
||||
assert!((ten.div(&two) == num::cast(5)));
|
||||
assert!((ten.modulo(&two) == num::cast(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20f64.to_uint()));
|
||||
fail_unless!((20u8 == 20f64.to_u8()));
|
||||
fail_unless!((20u16 == 20f64.to_u16()));
|
||||
fail_unless!((20u32 == 20f64.to_u32()));
|
||||
fail_unless!((20u64 == 20f64.to_u64()));
|
||||
fail_unless!((20i == 20f64.to_int()));
|
||||
fail_unless!((20i8 == 20f64.to_i8()));
|
||||
fail_unless!((20i16 == 20f64.to_i16()));
|
||||
fail_unless!((20i32 == 20f64.to_i32()));
|
||||
fail_unless!((20i64 == 20f64.to_i64()));
|
||||
fail_unless!((20f == 20f64.to_float()));
|
||||
fail_unless!((20f32 == 20f64.to_f32()));
|
||||
fail_unless!((20f64 == 20f64.to_f64()));
|
||||
assert!((20u == 20f64.to_uint()));
|
||||
assert!((20u8 == 20f64.to_u8()));
|
||||
assert!((20u16 == 20f64.to_u16()));
|
||||
assert!((20u32 == 20f64.to_u32()));
|
||||
assert!((20u64 == 20f64.to_u64()));
|
||||
assert!((20i == 20f64.to_int()));
|
||||
assert!((20i8 == 20f64.to_i8()));
|
||||
assert!((20i16 == 20f64.to_i16()));
|
||||
assert!((20i32 == 20f64.to_i32()));
|
||||
assert!((20i64 == 20f64.to_i64()));
|
||||
assert!((20f == 20f64.to_float()));
|
||||
assert!((20f32 == 20f64.to_f32()));
|
||||
assert!((20f64 == 20f64.to_f64()));
|
||||
|
||||
fail_unless!((20f64 == NumCast::from(20u)));
|
||||
fail_unless!((20f64 == NumCast::from(20u8)));
|
||||
fail_unless!((20f64 == NumCast::from(20u16)));
|
||||
fail_unless!((20f64 == NumCast::from(20u32)));
|
||||
fail_unless!((20f64 == NumCast::from(20u64)));
|
||||
fail_unless!((20f64 == NumCast::from(20i)));
|
||||
fail_unless!((20f64 == NumCast::from(20i8)));
|
||||
fail_unless!((20f64 == NumCast::from(20i16)));
|
||||
fail_unless!((20f64 == NumCast::from(20i32)));
|
||||
fail_unless!((20f64 == NumCast::from(20i64)));
|
||||
fail_unless!((20f64 == NumCast::from(20f)));
|
||||
fail_unless!((20f64 == NumCast::from(20f32)));
|
||||
fail_unless!((20f64 == NumCast::from(20f64)));
|
||||
assert!((20f64 == NumCast::from(20u)));
|
||||
assert!((20f64 == NumCast::from(20u8)));
|
||||
assert!((20f64 == NumCast::from(20u16)));
|
||||
assert!((20f64 == NumCast::from(20u32)));
|
||||
assert!((20f64 == NumCast::from(20u64)));
|
||||
assert!((20f64 == NumCast::from(20i)));
|
||||
assert!((20f64 == NumCast::from(20i8)));
|
||||
assert!((20f64 == NumCast::from(20i16)));
|
||||
assert!((20f64 == NumCast::from(20i32)));
|
||||
assert!((20f64 == NumCast::from(20i64)));
|
||||
assert!((20f64 == NumCast::from(20f)));
|
||||
assert!((20f64 == NumCast::from(20f32)));
|
||||
assert!((20f64 == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20f64 == num::cast(20u)));
|
||||
fail_unless!((20f64 == num::cast(20u8)));
|
||||
fail_unless!((20f64 == num::cast(20u16)));
|
||||
fail_unless!((20f64 == num::cast(20u32)));
|
||||
fail_unless!((20f64 == num::cast(20u64)));
|
||||
fail_unless!((20f64 == num::cast(20i)));
|
||||
fail_unless!((20f64 == num::cast(20i8)));
|
||||
fail_unless!((20f64 == num::cast(20i16)));
|
||||
fail_unless!((20f64 == num::cast(20i32)));
|
||||
fail_unless!((20f64 == num::cast(20i64)));
|
||||
fail_unless!((20f64 == num::cast(20f)));
|
||||
fail_unless!((20f64 == num::cast(20f32)));
|
||||
fail_unless!((20f64 == num::cast(20f64)));
|
||||
assert!((20f64 == num::cast(20u)));
|
||||
assert!((20f64 == num::cast(20u8)));
|
||||
assert!((20f64 == num::cast(20u16)));
|
||||
assert!((20f64 == num::cast(20u32)));
|
||||
assert!((20f64 == num::cast(20u64)));
|
||||
assert!((20f64 == num::cast(20i)));
|
||||
assert!((20f64 == num::cast(20i8)));
|
||||
assert!((20f64 == num::cast(20i16)));
|
||||
assert!((20f64 == num::cast(20i32)));
|
||||
assert!((20f64 == num::cast(20i64)));
|
||||
assert!((20f64 == num::cast(20f)));
|
||||
assert!((20f64 == num::cast(20f32)));
|
||||
assert!((20f64 == num::cast(20f64)));
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -181,7 +181,7 @@ pub fn to_str_exact(num: float, digits: uint) -> ~str {
|
|||
#[test]
|
||||
pub fn test_to_str_exact_do_decimal() {
|
||||
let s = to_str_exact(5.0, 4u);
|
||||
fail_unless!(s == ~"5.0000");
|
||||
assert!(s == ~"5.0000");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -501,191 +501,191 @@ impl ops::Neg<float> for float {
|
|||
|
||||
#[test]
|
||||
pub fn test_from_str() {
|
||||
fail_unless!(from_str(~"3") == Some(3.));
|
||||
fail_unless!(from_str(~"3.14") == Some(3.14));
|
||||
fail_unless!(from_str(~"+3.14") == Some(3.14));
|
||||
fail_unless!(from_str(~"-3.14") == Some(-3.14));
|
||||
fail_unless!(from_str(~"2.5E10") == Some(25000000000.));
|
||||
fail_unless!(from_str(~"2.5e10") == Some(25000000000.));
|
||||
fail_unless!(from_str(~"25000000000.E-10") == Some(2.5));
|
||||
fail_unless!(from_str(~".") == Some(0.));
|
||||
fail_unless!(from_str(~".e1") == Some(0.));
|
||||
fail_unless!(from_str(~".e-1") == Some(0.));
|
||||
fail_unless!(from_str(~"5.") == Some(5.));
|
||||
fail_unless!(from_str(~".5") == Some(0.5));
|
||||
fail_unless!(from_str(~"0.5") == Some(0.5));
|
||||
fail_unless!(from_str(~"-.5") == Some(-0.5));
|
||||
fail_unless!(from_str(~"-5") == Some(-5.));
|
||||
fail_unless!(from_str(~"inf") == Some(infinity));
|
||||
fail_unless!(from_str(~"+inf") == Some(infinity));
|
||||
fail_unless!(from_str(~"-inf") == Some(neg_infinity));
|
||||
assert!(from_str(~"3") == Some(3.));
|
||||
assert!(from_str(~"3.14") == Some(3.14));
|
||||
assert!(from_str(~"+3.14") == Some(3.14));
|
||||
assert!(from_str(~"-3.14") == Some(-3.14));
|
||||
assert!(from_str(~"2.5E10") == Some(25000000000.));
|
||||
assert!(from_str(~"2.5e10") == Some(25000000000.));
|
||||
assert!(from_str(~"25000000000.E-10") == Some(2.5));
|
||||
assert!(from_str(~".") == Some(0.));
|
||||
assert!(from_str(~".e1") == Some(0.));
|
||||
assert!(from_str(~".e-1") == Some(0.));
|
||||
assert!(from_str(~"5.") == Some(5.));
|
||||
assert!(from_str(~".5") == Some(0.5));
|
||||
assert!(from_str(~"0.5") == Some(0.5));
|
||||
assert!(from_str(~"-.5") == Some(-0.5));
|
||||
assert!(from_str(~"-5") == Some(-5.));
|
||||
assert!(from_str(~"inf") == Some(infinity));
|
||||
assert!(from_str(~"+inf") == Some(infinity));
|
||||
assert!(from_str(~"-inf") == Some(neg_infinity));
|
||||
// note: NaN != NaN, hence this slightly complex test
|
||||
match from_str(~"NaN") {
|
||||
Some(f) => fail_unless!(is_NaN(f)),
|
||||
Some(f) => assert!(is_NaN(f)),
|
||||
None => fail!()
|
||||
}
|
||||
// note: -0 == 0, hence these slightly more complex tests
|
||||
match from_str(~"-0") {
|
||||
Some(v) if is_zero(v) => fail_unless!(is_negative(v)),
|
||||
Some(v) if is_zero(v) => assert!(is_negative(v)),
|
||||
_ => fail!()
|
||||
}
|
||||
match from_str(~"0") {
|
||||
Some(v) if is_zero(v) => fail_unless!(is_positive(v)),
|
||||
Some(v) if is_zero(v) => assert!(is_positive(v)),
|
||||
_ => fail!()
|
||||
}
|
||||
|
||||
fail_unless!(from_str(~"").is_none());
|
||||
fail_unless!(from_str(~"x").is_none());
|
||||
fail_unless!(from_str(~" ").is_none());
|
||||
fail_unless!(from_str(~" ").is_none());
|
||||
fail_unless!(from_str(~"e").is_none());
|
||||
fail_unless!(from_str(~"E").is_none());
|
||||
fail_unless!(from_str(~"E1").is_none());
|
||||
fail_unless!(from_str(~"1e1e1").is_none());
|
||||
fail_unless!(from_str(~"1e1.1").is_none());
|
||||
fail_unless!(from_str(~"1e1-1").is_none());
|
||||
assert!(from_str(~"").is_none());
|
||||
assert!(from_str(~"x").is_none());
|
||||
assert!(from_str(~" ").is_none());
|
||||
assert!(from_str(~" ").is_none());
|
||||
assert!(from_str(~"e").is_none());
|
||||
assert!(from_str(~"E").is_none());
|
||||
assert!(from_str(~"E1").is_none());
|
||||
assert!(from_str(~"1e1e1").is_none());
|
||||
assert!(from_str(~"1e1.1").is_none());
|
||||
assert!(from_str(~"1e1-1").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_from_str_hex() {
|
||||
fail_unless!(from_str_hex(~"a4") == Some(164.));
|
||||
fail_unless!(from_str_hex(~"a4.fe") == Some(164.9921875));
|
||||
fail_unless!(from_str_hex(~"-a4.fe") == Some(-164.9921875));
|
||||
fail_unless!(from_str_hex(~"+a4.fe") == Some(164.9921875));
|
||||
fail_unless!(from_str_hex(~"ff0P4") == Some(0xff00 as float));
|
||||
fail_unless!(from_str_hex(~"ff0p4") == Some(0xff00 as float));
|
||||
fail_unless!(from_str_hex(~"ff0p-4") == Some(0xff as float));
|
||||
fail_unless!(from_str_hex(~".") == Some(0.));
|
||||
fail_unless!(from_str_hex(~".p1") == Some(0.));
|
||||
fail_unless!(from_str_hex(~".p-1") == Some(0.));
|
||||
fail_unless!(from_str_hex(~"f.") == Some(15.));
|
||||
fail_unless!(from_str_hex(~".f") == Some(0.9375));
|
||||
fail_unless!(from_str_hex(~"0.f") == Some(0.9375));
|
||||
fail_unless!(from_str_hex(~"-.f") == Some(-0.9375));
|
||||
fail_unless!(from_str_hex(~"-f") == Some(-15.));
|
||||
fail_unless!(from_str_hex(~"inf") == Some(infinity));
|
||||
fail_unless!(from_str_hex(~"+inf") == Some(infinity));
|
||||
fail_unless!(from_str_hex(~"-inf") == Some(neg_infinity));
|
||||
assert!(from_str_hex(~"a4") == Some(164.));
|
||||
assert!(from_str_hex(~"a4.fe") == Some(164.9921875));
|
||||
assert!(from_str_hex(~"-a4.fe") == Some(-164.9921875));
|
||||
assert!(from_str_hex(~"+a4.fe") == Some(164.9921875));
|
||||
assert!(from_str_hex(~"ff0P4") == Some(0xff00 as float));
|
||||
assert!(from_str_hex(~"ff0p4") == Some(0xff00 as float));
|
||||
assert!(from_str_hex(~"ff0p-4") == Some(0xff as float));
|
||||
assert!(from_str_hex(~".") == Some(0.));
|
||||
assert!(from_str_hex(~".p1") == Some(0.));
|
||||
assert!(from_str_hex(~".p-1") == Some(0.));
|
||||
assert!(from_str_hex(~"f.") == Some(15.));
|
||||
assert!(from_str_hex(~".f") == Some(0.9375));
|
||||
assert!(from_str_hex(~"0.f") == Some(0.9375));
|
||||
assert!(from_str_hex(~"-.f") == Some(-0.9375));
|
||||
assert!(from_str_hex(~"-f") == Some(-15.));
|
||||
assert!(from_str_hex(~"inf") == Some(infinity));
|
||||
assert!(from_str_hex(~"+inf") == Some(infinity));
|
||||
assert!(from_str_hex(~"-inf") == Some(neg_infinity));
|
||||
// note: NaN != NaN, hence this slightly complex test
|
||||
match from_str_hex(~"NaN") {
|
||||
Some(f) => fail_unless!(is_NaN(f)),
|
||||
Some(f) => assert!(is_NaN(f)),
|
||||
None => fail!()
|
||||
}
|
||||
// note: -0 == 0, hence these slightly more complex tests
|
||||
match from_str_hex(~"-0") {
|
||||
Some(v) if is_zero(v) => fail_unless!(is_negative(v)),
|
||||
Some(v) if is_zero(v) => assert!(is_negative(v)),
|
||||
_ => fail!()
|
||||
}
|
||||
match from_str_hex(~"0") {
|
||||
Some(v) if is_zero(v) => fail_unless!(is_positive(v)),
|
||||
Some(v) if is_zero(v) => assert!(is_positive(v)),
|
||||
_ => fail!()
|
||||
}
|
||||
fail_unless!(from_str_hex(~"e") == Some(14.));
|
||||
fail_unless!(from_str_hex(~"E") == Some(14.));
|
||||
fail_unless!(from_str_hex(~"E1") == Some(225.));
|
||||
fail_unless!(from_str_hex(~"1e1e1") == Some(123361.));
|
||||
fail_unless!(from_str_hex(~"1e1.1") == Some(481.0625));
|
||||
assert!(from_str_hex(~"e") == Some(14.));
|
||||
assert!(from_str_hex(~"E") == Some(14.));
|
||||
assert!(from_str_hex(~"E1") == Some(225.));
|
||||
assert!(from_str_hex(~"1e1e1") == Some(123361.));
|
||||
assert!(from_str_hex(~"1e1.1") == Some(481.0625));
|
||||
|
||||
fail_unless!(from_str_hex(~"").is_none());
|
||||
fail_unless!(from_str_hex(~"x").is_none());
|
||||
fail_unless!(from_str_hex(~" ").is_none());
|
||||
fail_unless!(from_str_hex(~" ").is_none());
|
||||
fail_unless!(from_str_hex(~"p").is_none());
|
||||
fail_unless!(from_str_hex(~"P").is_none());
|
||||
fail_unless!(from_str_hex(~"P1").is_none());
|
||||
fail_unless!(from_str_hex(~"1p1p1").is_none());
|
||||
fail_unless!(from_str_hex(~"1p1.1").is_none());
|
||||
fail_unless!(from_str_hex(~"1p1-1").is_none());
|
||||
assert!(from_str_hex(~"").is_none());
|
||||
assert!(from_str_hex(~"x").is_none());
|
||||
assert!(from_str_hex(~" ").is_none());
|
||||
assert!(from_str_hex(~" ").is_none());
|
||||
assert!(from_str_hex(~"p").is_none());
|
||||
assert!(from_str_hex(~"P").is_none());
|
||||
assert!(from_str_hex(~"P1").is_none());
|
||||
assert!(from_str_hex(~"1p1p1").is_none());
|
||||
assert!(from_str_hex(~"1p1.1").is_none());
|
||||
assert!(from_str_hex(~"1p1-1").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_to_str_hex() {
|
||||
fail_unless!(to_str_hex(164.) == ~"a4");
|
||||
fail_unless!(to_str_hex(164.9921875) == ~"a4.fe");
|
||||
fail_unless!(to_str_hex(-164.9921875) == ~"-a4.fe");
|
||||
fail_unless!(to_str_hex(0xff00 as float) == ~"ff00");
|
||||
fail_unless!(to_str_hex(-(0xff00 as float)) == ~"-ff00");
|
||||
fail_unless!(to_str_hex(0.) == ~"0");
|
||||
fail_unless!(to_str_hex(15.) == ~"f");
|
||||
fail_unless!(to_str_hex(-15.) == ~"-f");
|
||||
fail_unless!(to_str_hex(0.9375) == ~"0.f");
|
||||
fail_unless!(to_str_hex(-0.9375) == ~"-0.f");
|
||||
fail_unless!(to_str_hex(infinity) == ~"inf");
|
||||
fail_unless!(to_str_hex(neg_infinity) == ~"-inf");
|
||||
fail_unless!(to_str_hex(NaN) == ~"NaN");
|
||||
fail_unless!(to_str_hex(0.) == ~"0");
|
||||
fail_unless!(to_str_hex(-0.) == ~"-0");
|
||||
assert!(to_str_hex(164.) == ~"a4");
|
||||
assert!(to_str_hex(164.9921875) == ~"a4.fe");
|
||||
assert!(to_str_hex(-164.9921875) == ~"-a4.fe");
|
||||
assert!(to_str_hex(0xff00 as float) == ~"ff00");
|
||||
assert!(to_str_hex(-(0xff00 as float)) == ~"-ff00");
|
||||
assert!(to_str_hex(0.) == ~"0");
|
||||
assert!(to_str_hex(15.) == ~"f");
|
||||
assert!(to_str_hex(-15.) == ~"-f");
|
||||
assert!(to_str_hex(0.9375) == ~"0.f");
|
||||
assert!(to_str_hex(-0.9375) == ~"-0.f");
|
||||
assert!(to_str_hex(infinity) == ~"inf");
|
||||
assert!(to_str_hex(neg_infinity) == ~"-inf");
|
||||
assert!(to_str_hex(NaN) == ~"NaN");
|
||||
assert!(to_str_hex(0.) == ~"0");
|
||||
assert!(to_str_hex(-0.) == ~"-0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_to_str_radix() {
|
||||
fail_unless!(to_str_radix(36., 36u) == ~"10");
|
||||
fail_unless!(to_str_radix(8.125, 2u) == ~"1000.001");
|
||||
assert!(to_str_radix(36., 36u) == ~"10");
|
||||
assert!(to_str_radix(8.125, 2u) == ~"1000.001");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_from_str_radix() {
|
||||
fail_unless!(from_str_radix(~"10", 36u) == Some(36.));
|
||||
fail_unless!(from_str_radix(~"1000.001", 2u) == Some(8.125));
|
||||
assert!(from_str_radix(~"10", 36u) == Some(36.));
|
||||
assert!(from_str_radix(~"1000.001", 2u) == Some(8.125));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_positive() {
|
||||
fail_unless!((is_positive(infinity)));
|
||||
fail_unless!((is_positive(1.)));
|
||||
fail_unless!((is_positive(0.)));
|
||||
fail_unless!((!is_positive(-1.)));
|
||||
fail_unless!((!is_positive(neg_infinity)));
|
||||
fail_unless!((!is_positive(1./neg_infinity)));
|
||||
fail_unless!((!is_positive(NaN)));
|
||||
assert!((is_positive(infinity)));
|
||||
assert!((is_positive(1.)));
|
||||
assert!((is_positive(0.)));
|
||||
assert!((!is_positive(-1.)));
|
||||
assert!((!is_positive(neg_infinity)));
|
||||
assert!((!is_positive(1./neg_infinity)));
|
||||
assert!((!is_positive(NaN)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_negative() {
|
||||
fail_unless!((!is_negative(infinity)));
|
||||
fail_unless!((!is_negative(1.)));
|
||||
fail_unless!((!is_negative(0.)));
|
||||
fail_unless!((is_negative(-1.)));
|
||||
fail_unless!((is_negative(neg_infinity)));
|
||||
fail_unless!((is_negative(1./neg_infinity)));
|
||||
fail_unless!((!is_negative(NaN)));
|
||||
assert!((!is_negative(infinity)));
|
||||
assert!((!is_negative(1.)));
|
||||
assert!((!is_negative(0.)));
|
||||
assert!((is_negative(-1.)));
|
||||
assert!((is_negative(neg_infinity)));
|
||||
assert!((is_negative(1./neg_infinity)));
|
||||
assert!((!is_negative(NaN)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_nonpositive() {
|
||||
fail_unless!((!is_nonpositive(infinity)));
|
||||
fail_unless!((!is_nonpositive(1.)));
|
||||
fail_unless!((!is_nonpositive(0.)));
|
||||
fail_unless!((is_nonpositive(-1.)));
|
||||
fail_unless!((is_nonpositive(neg_infinity)));
|
||||
fail_unless!((is_nonpositive(1./neg_infinity)));
|
||||
fail_unless!((!is_nonpositive(NaN)));
|
||||
assert!((!is_nonpositive(infinity)));
|
||||
assert!((!is_nonpositive(1.)));
|
||||
assert!((!is_nonpositive(0.)));
|
||||
assert!((is_nonpositive(-1.)));
|
||||
assert!((is_nonpositive(neg_infinity)));
|
||||
assert!((is_nonpositive(1./neg_infinity)));
|
||||
assert!((!is_nonpositive(NaN)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_nonnegative() {
|
||||
fail_unless!((is_nonnegative(infinity)));
|
||||
fail_unless!((is_nonnegative(1.)));
|
||||
fail_unless!((is_nonnegative(0.)));
|
||||
fail_unless!((!is_nonnegative(-1.)));
|
||||
fail_unless!((!is_nonnegative(neg_infinity)));
|
||||
fail_unless!((!is_nonnegative(1./neg_infinity)));
|
||||
fail_unless!((!is_nonnegative(NaN)));
|
||||
assert!((is_nonnegative(infinity)));
|
||||
assert!((is_nonnegative(1.)));
|
||||
assert!((is_nonnegative(0.)));
|
||||
assert!((!is_nonnegative(-1.)));
|
||||
assert!((!is_nonnegative(neg_infinity)));
|
||||
assert!((!is_nonnegative(1./neg_infinity)));
|
||||
assert!((!is_nonnegative(NaN)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_to_str_inf() {
|
||||
fail_unless!(to_str_digits(infinity, 10u) == ~"inf");
|
||||
fail_unless!(to_str_digits(-infinity, 10u) == ~"-inf");
|
||||
assert!(to_str_digits(infinity, 10u) == ~"inf");
|
||||
assert!(to_str_digits(-infinity, 10u) == ~"-inf");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_round() {
|
||||
fail_unless!(round(5.8) == 6.0);
|
||||
fail_unless!(round(5.2) == 5.0);
|
||||
fail_unless!(round(3.0) == 3.0);
|
||||
fail_unless!(round(2.5) == 3.0);
|
||||
fail_unless!(round(-3.5) == -4.0);
|
||||
assert!(round(5.8) == 6.0);
|
||||
assert!(round(5.2) == 5.0);
|
||||
assert!(round(3.0) == 3.0);
|
||||
assert!(round(2.5) == 3.0);
|
||||
assert!(round(-3.5) == -4.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -693,56 +693,56 @@ pub fn test_num() {
|
|||
let ten: float = num::cast(10);
|
||||
let two: float = num::cast(2);
|
||||
|
||||
fail_unless!((ten.add(&two) == num::cast(12)));
|
||||
fail_unless!((ten.sub(&two) == num::cast(8)));
|
||||
fail_unless!((ten.mul(&two) == num::cast(20)));
|
||||
fail_unless!((ten.div(&two) == num::cast(5)));
|
||||
fail_unless!((ten.modulo(&two) == num::cast(0)));
|
||||
assert!((ten.add(&two) == num::cast(12)));
|
||||
assert!((ten.sub(&two) == num::cast(8)));
|
||||
assert!((ten.mul(&two) == num::cast(20)));
|
||||
assert!((ten.div(&two) == num::cast(5)));
|
||||
assert!((ten.modulo(&two) == num::cast(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20f.to_uint()));
|
||||
fail_unless!((20u8 == 20f.to_u8()));
|
||||
fail_unless!((20u16 == 20f.to_u16()));
|
||||
fail_unless!((20u32 == 20f.to_u32()));
|
||||
fail_unless!((20u64 == 20f.to_u64()));
|
||||
fail_unless!((20i == 20f.to_int()));
|
||||
fail_unless!((20i8 == 20f.to_i8()));
|
||||
fail_unless!((20i16 == 20f.to_i16()));
|
||||
fail_unless!((20i32 == 20f.to_i32()));
|
||||
fail_unless!((20i64 == 20f.to_i64()));
|
||||
fail_unless!((20f == 20f.to_float()));
|
||||
fail_unless!((20f32 == 20f.to_f32()));
|
||||
fail_unless!((20f64 == 20f.to_f64()));
|
||||
assert!((20u == 20f.to_uint()));
|
||||
assert!((20u8 == 20f.to_u8()));
|
||||
assert!((20u16 == 20f.to_u16()));
|
||||
assert!((20u32 == 20f.to_u32()));
|
||||
assert!((20u64 == 20f.to_u64()));
|
||||
assert!((20i == 20f.to_int()));
|
||||
assert!((20i8 == 20f.to_i8()));
|
||||
assert!((20i16 == 20f.to_i16()));
|
||||
assert!((20i32 == 20f.to_i32()));
|
||||
assert!((20i64 == 20f.to_i64()));
|
||||
assert!((20f == 20f.to_float()));
|
||||
assert!((20f32 == 20f.to_f32()));
|
||||
assert!((20f64 == 20f.to_f64()));
|
||||
|
||||
fail_unless!((20f == NumCast::from(20u)));
|
||||
fail_unless!((20f == NumCast::from(20u8)));
|
||||
fail_unless!((20f == NumCast::from(20u16)));
|
||||
fail_unless!((20f == NumCast::from(20u32)));
|
||||
fail_unless!((20f == NumCast::from(20u64)));
|
||||
fail_unless!((20f == NumCast::from(20i)));
|
||||
fail_unless!((20f == NumCast::from(20i8)));
|
||||
fail_unless!((20f == NumCast::from(20i16)));
|
||||
fail_unless!((20f == NumCast::from(20i32)));
|
||||
fail_unless!((20f == NumCast::from(20i64)));
|
||||
fail_unless!((20f == NumCast::from(20f)));
|
||||
fail_unless!((20f == NumCast::from(20f32)));
|
||||
fail_unless!((20f == NumCast::from(20f64)));
|
||||
assert!((20f == NumCast::from(20u)));
|
||||
assert!((20f == NumCast::from(20u8)));
|
||||
assert!((20f == NumCast::from(20u16)));
|
||||
assert!((20f == NumCast::from(20u32)));
|
||||
assert!((20f == NumCast::from(20u64)));
|
||||
assert!((20f == NumCast::from(20i)));
|
||||
assert!((20f == NumCast::from(20i8)));
|
||||
assert!((20f == NumCast::from(20i16)));
|
||||
assert!((20f == NumCast::from(20i32)));
|
||||
assert!((20f == NumCast::from(20i64)));
|
||||
assert!((20f == NumCast::from(20f)));
|
||||
assert!((20f == NumCast::from(20f32)));
|
||||
assert!((20f == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20f == num::cast(20u)));
|
||||
fail_unless!((20f == num::cast(20u8)));
|
||||
fail_unless!((20f == num::cast(20u16)));
|
||||
fail_unless!((20f == num::cast(20u32)));
|
||||
fail_unless!((20f == num::cast(20u64)));
|
||||
fail_unless!((20f == num::cast(20i)));
|
||||
fail_unless!((20f == num::cast(20i8)));
|
||||
fail_unless!((20f == num::cast(20i16)));
|
||||
fail_unless!((20f == num::cast(20i32)));
|
||||
fail_unless!((20f == num::cast(20i64)));
|
||||
fail_unless!((20f == num::cast(20f)));
|
||||
fail_unless!((20f == num::cast(20f32)));
|
||||
fail_unless!((20f == num::cast(20f64)));
|
||||
assert!((20f == num::cast(20u)));
|
||||
assert!((20f == num::cast(20u8)));
|
||||
assert!((20f == num::cast(20u16)));
|
||||
assert!((20f == num::cast(20u32)));
|
||||
assert!((20f == num::cast(20u64)));
|
||||
assert!((20f == num::cast(20i)));
|
||||
assert!((20f == num::cast(20i8)));
|
||||
assert!((20f == num::cast(20i16)));
|
||||
assert!((20f == num::cast(20i32)));
|
||||
assert!((20f == num::cast(20i64)));
|
||||
assert!((20f == num::cast(20f)));
|
||||
assert!((20f == num::cast(20f32)));
|
||||
assert!((20f == num::cast(20f64)));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -41,18 +41,18 @@ pub fn div(x: T, y: T) -> T { x / y }
|
|||
*
|
||||
* # Examples
|
||||
* ~~~
|
||||
* fail_unless!(int::rem(5 / 2) == 1);
|
||||
* assert!(int::rem(5 / 2) == 1);
|
||||
* ~~~
|
||||
*
|
||||
* When faced with negative numbers, the result copies the sign of the
|
||||
* dividend.
|
||||
*
|
||||
* ~~~
|
||||
* fail_unless!(int::rem(2 / -3) == 2);
|
||||
* assert!(int::rem(2 / -3) == 2);
|
||||
* ~~~
|
||||
*
|
||||
* ~~~
|
||||
* fail_unless!(int::rem(-2 / 3) == -2);
|
||||
* assert!(int::rem(-2 / 3) == -2);
|
||||
* ~~~
|
||||
*
|
||||
*/
|
||||
|
@ -95,7 +95,7 @@ pub fn is_nonnegative(x: T) -> bool { x >= 0 as T }
|
|||
* for int::range(1, 5) |i| {
|
||||
* sum += i;
|
||||
* }
|
||||
* fail_unless!(sum == 10);
|
||||
* assert!(sum == 10);
|
||||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
|
@ -275,122 +275,122 @@ impl ToStrRadix for T {
|
|||
|
||||
#[test]
|
||||
fn test_from_str() {
|
||||
fail_unless!(from_str(~"0") == Some(0 as T));
|
||||
fail_unless!(from_str(~"3") == Some(3 as T));
|
||||
fail_unless!(from_str(~"10") == Some(10 as T));
|
||||
fail_unless!(i32::from_str(~"123456789") == Some(123456789 as i32));
|
||||
fail_unless!(from_str(~"00100") == Some(100 as T));
|
||||
assert!(from_str(~"0") == Some(0 as T));
|
||||
assert!(from_str(~"3") == Some(3 as T));
|
||||
assert!(from_str(~"10") == Some(10 as T));
|
||||
assert!(i32::from_str(~"123456789") == Some(123456789 as i32));
|
||||
assert!(from_str(~"00100") == Some(100 as T));
|
||||
|
||||
fail_unless!(from_str(~"-1") == Some(-1 as T));
|
||||
fail_unless!(from_str(~"-3") == Some(-3 as T));
|
||||
fail_unless!(from_str(~"-10") == Some(-10 as T));
|
||||
fail_unless!(i32::from_str(~"-123456789") == Some(-123456789 as i32));
|
||||
fail_unless!(from_str(~"-00100") == Some(-100 as T));
|
||||
assert!(from_str(~"-1") == Some(-1 as T));
|
||||
assert!(from_str(~"-3") == Some(-3 as T));
|
||||
assert!(from_str(~"-10") == Some(-10 as T));
|
||||
assert!(i32::from_str(~"-123456789") == Some(-123456789 as i32));
|
||||
assert!(from_str(~"-00100") == Some(-100 as T));
|
||||
|
||||
fail_unless!(from_str(~" ").is_none());
|
||||
fail_unless!(from_str(~"x").is_none());
|
||||
assert!(from_str(~" ").is_none());
|
||||
assert!(from_str(~"x").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_bytes() {
|
||||
use str::to_bytes;
|
||||
fail_unless!(parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T));
|
||||
fail_unless!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T));
|
||||
fail_unless!(parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T));
|
||||
fail_unless!(i32::parse_bytes(to_bytes(~"123"), 16u) == Some(291 as i32));
|
||||
fail_unless!(i32::parse_bytes(to_bytes(~"ffff"), 16u) ==
|
||||
assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T));
|
||||
assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T));
|
||||
assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T));
|
||||
assert!(i32::parse_bytes(to_bytes(~"123"), 16u) == Some(291 as i32));
|
||||
assert!(i32::parse_bytes(to_bytes(~"ffff"), 16u) ==
|
||||
Some(65535 as i32));
|
||||
fail_unless!(i32::parse_bytes(to_bytes(~"FFFF"), 16u) ==
|
||||
assert!(i32::parse_bytes(to_bytes(~"FFFF"), 16u) ==
|
||||
Some(65535 as i32));
|
||||
fail_unless!(parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T));
|
||||
fail_unless!(parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T));
|
||||
assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T));
|
||||
assert!(parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T));
|
||||
|
||||
fail_unless!(parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T));
|
||||
fail_unless!(parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T));
|
||||
fail_unless!(parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T));
|
||||
fail_unless!(i32::parse_bytes(to_bytes(~"-123"), 16u) ==
|
||||
assert!(parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T));
|
||||
assert!(parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T));
|
||||
assert!(parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T));
|
||||
assert!(i32::parse_bytes(to_bytes(~"-123"), 16u) ==
|
||||
Some(-291 as i32));
|
||||
fail_unless!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) ==
|
||||
assert!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) ==
|
||||
Some(-65535 as i32));
|
||||
fail_unless!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u) ==
|
||||
assert!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u) ==
|
||||
Some(-65535 as i32));
|
||||
fail_unless!(parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T));
|
||||
fail_unless!(parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T));
|
||||
assert!(parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T));
|
||||
assert!(parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T));
|
||||
|
||||
fail_unless!(parse_bytes(to_bytes(~"Z"), 35u).is_none());
|
||||
fail_unless!(parse_bytes(to_bytes(~"-9"), 2u).is_none());
|
||||
assert!(parse_bytes(to_bytes(~"Z"), 35u).is_none());
|
||||
assert!(parse_bytes(to_bytes(~"-9"), 2u).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
fail_unless!((to_str_radix(0 as T, 10u) == ~"0"));
|
||||
fail_unless!((to_str_radix(1 as T, 10u) == ~"1"));
|
||||
fail_unless!((to_str_radix(-1 as T, 10u) == ~"-1"));
|
||||
fail_unless!((to_str_radix(127 as T, 16u) == ~"7f"));
|
||||
fail_unless!((to_str_radix(100 as T, 10u) == ~"100"));
|
||||
assert!((to_str_radix(0 as T, 10u) == ~"0"));
|
||||
assert!((to_str_radix(1 as T, 10u) == ~"1"));
|
||||
assert!((to_str_radix(-1 as T, 10u) == ~"-1"));
|
||||
assert!((to_str_radix(127 as T, 16u) == ~"7f"));
|
||||
assert!((to_str_radix(100 as T, 10u) == ~"100"));
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_int_to_str_overflow() {
|
||||
let mut i8_val: i8 = 127_i8;
|
||||
fail_unless!((i8::to_str(i8_val) == ~"127"));
|
||||
assert!((i8::to_str(i8_val) == ~"127"));
|
||||
|
||||
i8_val += 1 as i8;
|
||||
fail_unless!((i8::to_str(i8_val) == ~"-128"));
|
||||
assert!((i8::to_str(i8_val) == ~"-128"));
|
||||
|
||||
let mut i16_val: i16 = 32_767_i16;
|
||||
fail_unless!((i16::to_str(i16_val) == ~"32767"));
|
||||
assert!((i16::to_str(i16_val) == ~"32767"));
|
||||
|
||||
i16_val += 1 as i16;
|
||||
fail_unless!((i16::to_str(i16_val) == ~"-32768"));
|
||||
assert!((i16::to_str(i16_val) == ~"-32768"));
|
||||
|
||||
let mut i32_val: i32 = 2_147_483_647_i32;
|
||||
fail_unless!((i32::to_str(i32_val) == ~"2147483647"));
|
||||
assert!((i32::to_str(i32_val) == ~"2147483647"));
|
||||
|
||||
i32_val += 1 as i32;
|
||||
fail_unless!((i32::to_str(i32_val) == ~"-2147483648"));
|
||||
assert!((i32::to_str(i32_val) == ~"-2147483648"));
|
||||
|
||||
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
|
||||
fail_unless!((i64::to_str(i64_val) == ~"9223372036854775807"));
|
||||
assert!((i64::to_str(i64_val) == ~"9223372036854775807"));
|
||||
|
||||
i64_val += 1 as i64;
|
||||
fail_unless!((i64::to_str(i64_val) == ~"-9223372036854775808"));
|
||||
assert!((i64::to_str(i64_val) == ~"-9223372036854775808"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_int_from_str_overflow() {
|
||||
let mut i8_val: i8 = 127_i8;
|
||||
fail_unless!((i8::from_str(~"127") == Some(i8_val)));
|
||||
fail_unless!((i8::from_str(~"128").is_none()));
|
||||
assert!((i8::from_str(~"127") == Some(i8_val)));
|
||||
assert!((i8::from_str(~"128").is_none()));
|
||||
|
||||
i8_val += 1 as i8;
|
||||
fail_unless!((i8::from_str(~"-128") == Some(i8_val)));
|
||||
fail_unless!((i8::from_str(~"-129").is_none()));
|
||||
assert!((i8::from_str(~"-128") == Some(i8_val)));
|
||||
assert!((i8::from_str(~"-129").is_none()));
|
||||
|
||||
let mut i16_val: i16 = 32_767_i16;
|
||||
fail_unless!((i16::from_str(~"32767") == Some(i16_val)));
|
||||
fail_unless!((i16::from_str(~"32768").is_none()));
|
||||
assert!((i16::from_str(~"32767") == Some(i16_val)));
|
||||
assert!((i16::from_str(~"32768").is_none()));
|
||||
|
||||
i16_val += 1 as i16;
|
||||
fail_unless!((i16::from_str(~"-32768") == Some(i16_val)));
|
||||
fail_unless!((i16::from_str(~"-32769").is_none()));
|
||||
assert!((i16::from_str(~"-32768") == Some(i16_val)));
|
||||
assert!((i16::from_str(~"-32769").is_none()));
|
||||
|
||||
let mut i32_val: i32 = 2_147_483_647_i32;
|
||||
fail_unless!((i32::from_str(~"2147483647") == Some(i32_val)));
|
||||
fail_unless!((i32::from_str(~"2147483648").is_none()));
|
||||
assert!((i32::from_str(~"2147483647") == Some(i32_val)));
|
||||
assert!((i32::from_str(~"2147483648").is_none()));
|
||||
|
||||
i32_val += 1 as i32;
|
||||
fail_unless!((i32::from_str(~"-2147483648") == Some(i32_val)));
|
||||
fail_unless!((i32::from_str(~"-2147483649").is_none()));
|
||||
assert!((i32::from_str(~"-2147483648") == Some(i32_val)));
|
||||
assert!((i32::from_str(~"-2147483649").is_none()));
|
||||
|
||||
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
|
||||
fail_unless!((i64::from_str(~"9223372036854775807") == Some(i64_val)));
|
||||
fail_unless!((i64::from_str(~"9223372036854775808").is_none()));
|
||||
assert!((i64::from_str(~"9223372036854775807") == Some(i64_val)));
|
||||
assert!((i64::from_str(~"9223372036854775808").is_none()));
|
||||
|
||||
i64_val += 1 as i64;
|
||||
fail_unless!((i64::from_str(~"-9223372036854775808") == Some(i64_val)));
|
||||
fail_unless!((i64::from_str(~"-9223372036854775809").is_none()));
|
||||
assert!((i64::from_str(~"-9223372036854775808") == Some(i64_val)));
|
||||
assert!((i64::from_str(~"-9223372036854775809").is_none()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -398,11 +398,11 @@ pub fn test_num() {
|
|||
let ten: T = num::cast(10);
|
||||
let two: T = num::cast(2);
|
||||
|
||||
fail_unless!((ten.add(&two) == num::cast(12)));
|
||||
fail_unless!((ten.sub(&two) == num::cast(8)));
|
||||
fail_unless!((ten.mul(&two) == num::cast(20)));
|
||||
fail_unless!((ten.div(&two) == num::cast(5)));
|
||||
fail_unless!((ten.modulo(&two) == num::cast(0)));
|
||||
assert!((ten.add(&two) == num::cast(12)));
|
||||
assert!((ten.sub(&two) == num::cast(8)));
|
||||
assert!((ten.mul(&two) == num::cast(20)));
|
||||
assert!((ten.div(&two) == num::cast(5)));
|
||||
assert!((ten.modulo(&two) == num::cast(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -421,7 +421,7 @@ pub fn test_ranges() {
|
|||
for range_step(36,30,-2) |i| {
|
||||
l.push(i);
|
||||
}
|
||||
fail_unless!(l == ~[0,1,2,
|
||||
assert!(l == ~[0,1,2,
|
||||
13,12,11,
|
||||
20,22,24,
|
||||
36,34,32]);
|
||||
|
|
|
@ -43,45 +43,45 @@ impl NumCast for i16 {
|
|||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20i16.to_uint()));
|
||||
fail_unless!((20u8 == 20i16.to_u8()));
|
||||
fail_unless!((20u16 == 20i16.to_u16()));
|
||||
fail_unless!((20u32 == 20i16.to_u32()));
|
||||
fail_unless!((20u64 == 20i16.to_u64()));
|
||||
fail_unless!((20i == 20i16.to_int()));
|
||||
fail_unless!((20i8 == 20i16.to_i8()));
|
||||
fail_unless!((20i16 == 20i16.to_i16()));
|
||||
fail_unless!((20i32 == 20i16.to_i32()));
|
||||
fail_unless!((20i64 == 20i16.to_i64()));
|
||||
fail_unless!((20f == 20i16.to_float()));
|
||||
fail_unless!((20f32 == 20i16.to_f32()));
|
||||
fail_unless!((20f64 == 20i16.to_f64()));
|
||||
assert!((20u == 20i16.to_uint()));
|
||||
assert!((20u8 == 20i16.to_u8()));
|
||||
assert!((20u16 == 20i16.to_u16()));
|
||||
assert!((20u32 == 20i16.to_u32()));
|
||||
assert!((20u64 == 20i16.to_u64()));
|
||||
assert!((20i == 20i16.to_int()));
|
||||
assert!((20i8 == 20i16.to_i8()));
|
||||
assert!((20i16 == 20i16.to_i16()));
|
||||
assert!((20i32 == 20i16.to_i32()));
|
||||
assert!((20i64 == 20i16.to_i64()));
|
||||
assert!((20f == 20i16.to_float()));
|
||||
assert!((20f32 == 20i16.to_f32()));
|
||||
assert!((20f64 == 20i16.to_f64()));
|
||||
|
||||
fail_unless!((20i16 == NumCast::from(20u)));
|
||||
fail_unless!((20i16 == NumCast::from(20u8)));
|
||||
fail_unless!((20i16 == NumCast::from(20u16)));
|
||||
fail_unless!((20i16 == NumCast::from(20u32)));
|
||||
fail_unless!((20i16 == NumCast::from(20u64)));
|
||||
fail_unless!((20i16 == NumCast::from(20i)));
|
||||
fail_unless!((20i16 == NumCast::from(20i8)));
|
||||
fail_unless!((20i16 == NumCast::from(20i16)));
|
||||
fail_unless!((20i16 == NumCast::from(20i32)));
|
||||
fail_unless!((20i16 == NumCast::from(20i64)));
|
||||
fail_unless!((20i16 == NumCast::from(20f)));
|
||||
fail_unless!((20i16 == NumCast::from(20f32)));
|
||||
fail_unless!((20i16 == NumCast::from(20f64)));
|
||||
assert!((20i16 == NumCast::from(20u)));
|
||||
assert!((20i16 == NumCast::from(20u8)));
|
||||
assert!((20i16 == NumCast::from(20u16)));
|
||||
assert!((20i16 == NumCast::from(20u32)));
|
||||
assert!((20i16 == NumCast::from(20u64)));
|
||||
assert!((20i16 == NumCast::from(20i)));
|
||||
assert!((20i16 == NumCast::from(20i8)));
|
||||
assert!((20i16 == NumCast::from(20i16)));
|
||||
assert!((20i16 == NumCast::from(20i32)));
|
||||
assert!((20i16 == NumCast::from(20i64)));
|
||||
assert!((20i16 == NumCast::from(20f)));
|
||||
assert!((20i16 == NumCast::from(20f32)));
|
||||
assert!((20i16 == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20i16 == num::cast(20u)));
|
||||
fail_unless!((20i16 == num::cast(20u8)));
|
||||
fail_unless!((20i16 == num::cast(20u16)));
|
||||
fail_unless!((20i16 == num::cast(20u32)));
|
||||
fail_unless!((20i16 == num::cast(20u64)));
|
||||
fail_unless!((20i16 == num::cast(20i)));
|
||||
fail_unless!((20i16 == num::cast(20i8)));
|
||||
fail_unless!((20i16 == num::cast(20i16)));
|
||||
fail_unless!((20i16 == num::cast(20i32)));
|
||||
fail_unless!((20i16 == num::cast(20i64)));
|
||||
fail_unless!((20i16 == num::cast(20f)));
|
||||
fail_unless!((20i16 == num::cast(20f32)));
|
||||
fail_unless!((20i16 == num::cast(20f64)));
|
||||
assert!((20i16 == num::cast(20u)));
|
||||
assert!((20i16 == num::cast(20u8)));
|
||||
assert!((20i16 == num::cast(20u16)));
|
||||
assert!((20i16 == num::cast(20u32)));
|
||||
assert!((20i16 == num::cast(20u64)));
|
||||
assert!((20i16 == num::cast(20i)));
|
||||
assert!((20i16 == num::cast(20i8)));
|
||||
assert!((20i16 == num::cast(20i16)));
|
||||
assert!((20i16 == num::cast(20i32)));
|
||||
assert!((20i16 == num::cast(20i64)));
|
||||
assert!((20i16 == num::cast(20f)));
|
||||
assert!((20i16 == num::cast(20f32)));
|
||||
assert!((20i16 == num::cast(20f64)));
|
||||
}
|
||||
|
|
|
@ -43,45 +43,45 @@ impl NumCast for i32 {
|
|||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20i32.to_uint()));
|
||||
fail_unless!((20u8 == 20i32.to_u8()));
|
||||
fail_unless!((20u16 == 20i32.to_u16()));
|
||||
fail_unless!((20u32 == 20i32.to_u32()));
|
||||
fail_unless!((20u64 == 20i32.to_u64()));
|
||||
fail_unless!((20i == 20i32.to_int()));
|
||||
fail_unless!((20i8 == 20i32.to_i8()));
|
||||
fail_unless!((20i16 == 20i32.to_i16()));
|
||||
fail_unless!((20i32 == 20i32.to_i32()));
|
||||
fail_unless!((20i64 == 20i32.to_i64()));
|
||||
fail_unless!((20f == 20i32.to_float()));
|
||||
fail_unless!((20f32 == 20i32.to_f32()));
|
||||
fail_unless!((20f64 == 20i32.to_f64()));
|
||||
assert!((20u == 20i32.to_uint()));
|
||||
assert!((20u8 == 20i32.to_u8()));
|
||||
assert!((20u16 == 20i32.to_u16()));
|
||||
assert!((20u32 == 20i32.to_u32()));
|
||||
assert!((20u64 == 20i32.to_u64()));
|
||||
assert!((20i == 20i32.to_int()));
|
||||
assert!((20i8 == 20i32.to_i8()));
|
||||
assert!((20i16 == 20i32.to_i16()));
|
||||
assert!((20i32 == 20i32.to_i32()));
|
||||
assert!((20i64 == 20i32.to_i64()));
|
||||
assert!((20f == 20i32.to_float()));
|
||||
assert!((20f32 == 20i32.to_f32()));
|
||||
assert!((20f64 == 20i32.to_f64()));
|
||||
|
||||
fail_unless!((20i32 == NumCast::from(20u)));
|
||||
fail_unless!((20i32 == NumCast::from(20u8)));
|
||||
fail_unless!((20i32 == NumCast::from(20u16)));
|
||||
fail_unless!((20i32 == NumCast::from(20u32)));
|
||||
fail_unless!((20i32 == NumCast::from(20u64)));
|
||||
fail_unless!((20i32 == NumCast::from(20i)));
|
||||
fail_unless!((20i32 == NumCast::from(20i8)));
|
||||
fail_unless!((20i32 == NumCast::from(20i16)));
|
||||
fail_unless!((20i32 == NumCast::from(20i32)));
|
||||
fail_unless!((20i32 == NumCast::from(20i64)));
|
||||
fail_unless!((20i32 == NumCast::from(20f)));
|
||||
fail_unless!((20i32 == NumCast::from(20f32)));
|
||||
fail_unless!((20i32 == NumCast::from(20f64)));
|
||||
assert!((20i32 == NumCast::from(20u)));
|
||||
assert!((20i32 == NumCast::from(20u8)));
|
||||
assert!((20i32 == NumCast::from(20u16)));
|
||||
assert!((20i32 == NumCast::from(20u32)));
|
||||
assert!((20i32 == NumCast::from(20u64)));
|
||||
assert!((20i32 == NumCast::from(20i)));
|
||||
assert!((20i32 == NumCast::from(20i8)));
|
||||
assert!((20i32 == NumCast::from(20i16)));
|
||||
assert!((20i32 == NumCast::from(20i32)));
|
||||
assert!((20i32 == NumCast::from(20i64)));
|
||||
assert!((20i32 == NumCast::from(20f)));
|
||||
assert!((20i32 == NumCast::from(20f32)));
|
||||
assert!((20i32 == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20i32 == num::cast(20u)));
|
||||
fail_unless!((20i32 == num::cast(20u8)));
|
||||
fail_unless!((20i32 == num::cast(20u16)));
|
||||
fail_unless!((20i32 == num::cast(20u32)));
|
||||
fail_unless!((20i32 == num::cast(20u64)));
|
||||
fail_unless!((20i32 == num::cast(20i)));
|
||||
fail_unless!((20i32 == num::cast(20i8)));
|
||||
fail_unless!((20i32 == num::cast(20i16)));
|
||||
fail_unless!((20i32 == num::cast(20i32)));
|
||||
fail_unless!((20i32 == num::cast(20i64)));
|
||||
fail_unless!((20i32 == num::cast(20f)));
|
||||
fail_unless!((20i32 == num::cast(20f32)));
|
||||
fail_unless!((20i32 == num::cast(20f64)));
|
||||
assert!((20i32 == num::cast(20u)));
|
||||
assert!((20i32 == num::cast(20u8)));
|
||||
assert!((20i32 == num::cast(20u16)));
|
||||
assert!((20i32 == num::cast(20u32)));
|
||||
assert!((20i32 == num::cast(20u64)));
|
||||
assert!((20i32 == num::cast(20i)));
|
||||
assert!((20i32 == num::cast(20i8)));
|
||||
assert!((20i32 == num::cast(20i16)));
|
||||
assert!((20i32 == num::cast(20i32)));
|
||||
assert!((20i32 == num::cast(20i64)));
|
||||
assert!((20i32 == num::cast(20f)));
|
||||
assert!((20i32 == num::cast(20f32)));
|
||||
assert!((20i32 == num::cast(20f64)));
|
||||
}
|
||||
|
|
|
@ -43,45 +43,45 @@ impl NumCast for i64 {
|
|||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20i64.to_uint()));
|
||||
fail_unless!((20u8 == 20i64.to_u8()));
|
||||
fail_unless!((20u16 == 20i64.to_u16()));
|
||||
fail_unless!((20u32 == 20i64.to_u32()));
|
||||
fail_unless!((20u64 == 20i64.to_u64()));
|
||||
fail_unless!((20i == 20i64.to_int()));
|
||||
fail_unless!((20i8 == 20i64.to_i8()));
|
||||
fail_unless!((20i16 == 20i64.to_i16()));
|
||||
fail_unless!((20i32 == 20i64.to_i32()));
|
||||
fail_unless!((20i64 == 20i64.to_i64()));
|
||||
fail_unless!((20f == 20i64.to_float()));
|
||||
fail_unless!((20f32 == 20i64.to_f32()));
|
||||
fail_unless!((20f64 == 20i64.to_f64()));
|
||||
assert!((20u == 20i64.to_uint()));
|
||||
assert!((20u8 == 20i64.to_u8()));
|
||||
assert!((20u16 == 20i64.to_u16()));
|
||||
assert!((20u32 == 20i64.to_u32()));
|
||||
assert!((20u64 == 20i64.to_u64()));
|
||||
assert!((20i == 20i64.to_int()));
|
||||
assert!((20i8 == 20i64.to_i8()));
|
||||
assert!((20i16 == 20i64.to_i16()));
|
||||
assert!((20i32 == 20i64.to_i32()));
|
||||
assert!((20i64 == 20i64.to_i64()));
|
||||
assert!((20f == 20i64.to_float()));
|
||||
assert!((20f32 == 20i64.to_f32()));
|
||||
assert!((20f64 == 20i64.to_f64()));
|
||||
|
||||
fail_unless!((20i64 == NumCast::from(20u)));
|
||||
fail_unless!((20i64 == NumCast::from(20u8)));
|
||||
fail_unless!((20i64 == NumCast::from(20u16)));
|
||||
fail_unless!((20i64 == NumCast::from(20u32)));
|
||||
fail_unless!((20i64 == NumCast::from(20u64)));
|
||||
fail_unless!((20i64 == NumCast::from(20i)));
|
||||
fail_unless!((20i64 == NumCast::from(20i8)));
|
||||
fail_unless!((20i64 == NumCast::from(20i16)));
|
||||
fail_unless!((20i64 == NumCast::from(20i32)));
|
||||
fail_unless!((20i64 == NumCast::from(20i64)));
|
||||
fail_unless!((20i64 == NumCast::from(20f)));
|
||||
fail_unless!((20i64 == NumCast::from(20f32)));
|
||||
fail_unless!((20i64 == NumCast::from(20f64)));
|
||||
assert!((20i64 == NumCast::from(20u)));
|
||||
assert!((20i64 == NumCast::from(20u8)));
|
||||
assert!((20i64 == NumCast::from(20u16)));
|
||||
assert!((20i64 == NumCast::from(20u32)));
|
||||
assert!((20i64 == NumCast::from(20u64)));
|
||||
assert!((20i64 == NumCast::from(20i)));
|
||||
assert!((20i64 == NumCast::from(20i8)));
|
||||
assert!((20i64 == NumCast::from(20i16)));
|
||||
assert!((20i64 == NumCast::from(20i32)));
|
||||
assert!((20i64 == NumCast::from(20i64)));
|
||||
assert!((20i64 == NumCast::from(20f)));
|
||||
assert!((20i64 == NumCast::from(20f32)));
|
||||
assert!((20i64 == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20i64 == num::cast(20u)));
|
||||
fail_unless!((20i64 == num::cast(20u8)));
|
||||
fail_unless!((20i64 == num::cast(20u16)));
|
||||
fail_unless!((20i64 == num::cast(20u32)));
|
||||
fail_unless!((20i64 == num::cast(20u64)));
|
||||
fail_unless!((20i64 == num::cast(20i)));
|
||||
fail_unless!((20i64 == num::cast(20i8)));
|
||||
fail_unless!((20i64 == num::cast(20i16)));
|
||||
fail_unless!((20i64 == num::cast(20i32)));
|
||||
fail_unless!((20i64 == num::cast(20i64)));
|
||||
fail_unless!((20i64 == num::cast(20f)));
|
||||
fail_unless!((20i64 == num::cast(20f32)));
|
||||
fail_unless!((20i64 == num::cast(20f64)));
|
||||
assert!((20i64 == num::cast(20u)));
|
||||
assert!((20i64 == num::cast(20u8)));
|
||||
assert!((20i64 == num::cast(20u16)));
|
||||
assert!((20i64 == num::cast(20u32)));
|
||||
assert!((20i64 == num::cast(20u64)));
|
||||
assert!((20i64 == num::cast(20i)));
|
||||
assert!((20i64 == num::cast(20i8)));
|
||||
assert!((20i64 == num::cast(20i16)));
|
||||
assert!((20i64 == num::cast(20i32)));
|
||||
assert!((20i64 == num::cast(20i64)));
|
||||
assert!((20i64 == num::cast(20f)));
|
||||
assert!((20i64 == num::cast(20f32)));
|
||||
assert!((20i64 == num::cast(20f64)));
|
||||
}
|
||||
|
|
|
@ -43,45 +43,45 @@ impl NumCast for i8 {
|
|||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20i8.to_uint()));
|
||||
fail_unless!((20u8 == 20i8.to_u8()));
|
||||
fail_unless!((20u16 == 20i8.to_u16()));
|
||||
fail_unless!((20u32 == 20i8.to_u32()));
|
||||
fail_unless!((20u64 == 20i8.to_u64()));
|
||||
fail_unless!((20i == 20i8.to_int()));
|
||||
fail_unless!((20i8 == 20i8.to_i8()));
|
||||
fail_unless!((20i16 == 20i8.to_i16()));
|
||||
fail_unless!((20i32 == 20i8.to_i32()));
|
||||
fail_unless!((20i64 == 20i8.to_i64()));
|
||||
fail_unless!((20f == 20i8.to_float()));
|
||||
fail_unless!((20f32 == 20i8.to_f32()));
|
||||
fail_unless!((20f64 == 20i8.to_f64()));
|
||||
assert!((20u == 20i8.to_uint()));
|
||||
assert!((20u8 == 20i8.to_u8()));
|
||||
assert!((20u16 == 20i8.to_u16()));
|
||||
assert!((20u32 == 20i8.to_u32()));
|
||||
assert!((20u64 == 20i8.to_u64()));
|
||||
assert!((20i == 20i8.to_int()));
|
||||
assert!((20i8 == 20i8.to_i8()));
|
||||
assert!((20i16 == 20i8.to_i16()));
|
||||
assert!((20i32 == 20i8.to_i32()));
|
||||
assert!((20i64 == 20i8.to_i64()));
|
||||
assert!((20f == 20i8.to_float()));
|
||||
assert!((20f32 == 20i8.to_f32()));
|
||||
assert!((20f64 == 20i8.to_f64()));
|
||||
|
||||
fail_unless!((20i8 == NumCast::from(20u)));
|
||||
fail_unless!((20i8 == NumCast::from(20u8)));
|
||||
fail_unless!((20i8 == NumCast::from(20u16)));
|
||||
fail_unless!((20i8 == NumCast::from(20u32)));
|
||||
fail_unless!((20i8 == NumCast::from(20u64)));
|
||||
fail_unless!((20i8 == NumCast::from(20i)));
|
||||
fail_unless!((20i8 == NumCast::from(20i8)));
|
||||
fail_unless!((20i8 == NumCast::from(20i16)));
|
||||
fail_unless!((20i8 == NumCast::from(20i32)));
|
||||
fail_unless!((20i8 == NumCast::from(20i64)));
|
||||
fail_unless!((20i8 == NumCast::from(20f)));
|
||||
fail_unless!((20i8 == NumCast::from(20f32)));
|
||||
fail_unless!((20i8 == NumCast::from(20f64)));
|
||||
assert!((20i8 == NumCast::from(20u)));
|
||||
assert!((20i8 == NumCast::from(20u8)));
|
||||
assert!((20i8 == NumCast::from(20u16)));
|
||||
assert!((20i8 == NumCast::from(20u32)));
|
||||
assert!((20i8 == NumCast::from(20u64)));
|
||||
assert!((20i8 == NumCast::from(20i)));
|
||||
assert!((20i8 == NumCast::from(20i8)));
|
||||
assert!((20i8 == NumCast::from(20i16)));
|
||||
assert!((20i8 == NumCast::from(20i32)));
|
||||
assert!((20i8 == NumCast::from(20i64)));
|
||||
assert!((20i8 == NumCast::from(20f)));
|
||||
assert!((20i8 == NumCast::from(20f32)));
|
||||
assert!((20i8 == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20i8 == num::cast(20u)));
|
||||
fail_unless!((20i8 == num::cast(20u8)));
|
||||
fail_unless!((20i8 == num::cast(20u16)));
|
||||
fail_unless!((20i8 == num::cast(20u32)));
|
||||
fail_unless!((20i8 == num::cast(20u64)));
|
||||
fail_unless!((20i8 == num::cast(20i)));
|
||||
fail_unless!((20i8 == num::cast(20i8)));
|
||||
fail_unless!((20i8 == num::cast(20i16)));
|
||||
fail_unless!((20i8 == num::cast(20i32)));
|
||||
fail_unless!((20i8 == num::cast(20i64)));
|
||||
fail_unless!((20i8 == num::cast(20f)));
|
||||
fail_unless!((20i8 == num::cast(20f32)));
|
||||
fail_unless!((20i8 == num::cast(20f64)));
|
||||
assert!((20i8 == num::cast(20u)));
|
||||
assert!((20i8 == num::cast(20u8)));
|
||||
assert!((20i8 == num::cast(20u16)));
|
||||
assert!((20i8 == num::cast(20u32)));
|
||||
assert!((20i8 == num::cast(20u64)));
|
||||
assert!((20i8 == num::cast(20i)));
|
||||
assert!((20i8 == num::cast(20i8)));
|
||||
assert!((20i8 == num::cast(20i16)));
|
||||
assert!((20i8 == num::cast(20i32)));
|
||||
assert!((20i8 == num::cast(20i64)));
|
||||
assert!((20i8 == num::cast(20f)));
|
||||
assert!((20i8 == num::cast(20f32)));
|
||||
assert!((20i8 == num::cast(20f64)));
|
||||
}
|
||||
|
|
|
@ -40,21 +40,21 @@ mod inst {
|
|||
|
||||
#[test]
|
||||
fn test_pow() {
|
||||
fail_unless!((pow(0, 0u) == 1));
|
||||
fail_unless!((pow(0, 1u) == 0));
|
||||
fail_unless!((pow(0, 2u) == 0));
|
||||
fail_unless!((pow(-1, 0u) == 1));
|
||||
fail_unless!((pow(1, 0u) == 1));
|
||||
fail_unless!((pow(-3, 2u) == 9));
|
||||
fail_unless!((pow(-3, 3u) == -27));
|
||||
fail_unless!((pow(4, 9u) == 262144));
|
||||
assert!((pow(0, 0u) == 1));
|
||||
assert!((pow(0, 1u) == 0));
|
||||
assert!((pow(0, 2u) == 0));
|
||||
assert!((pow(-1, 0u) == 1));
|
||||
assert!((pow(1, 0u) == 1));
|
||||
assert!((pow(-3, 2u) == 9));
|
||||
assert!((pow(-3, 3u) == -27));
|
||||
assert!((pow(4, 9u) == 262144));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_overflows() {
|
||||
fail_unless!((::int::max_value > 0));
|
||||
fail_unless!((::int::min_value <= 0));
|
||||
fail_unless!((::int::min_value + ::int::max_value + 1 == 0));
|
||||
assert!((::int::max_value > 0));
|
||||
assert!((::int::min_value <= 0));
|
||||
assert!((::int::min_value + ::int::max_value + 1 == 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,45 +84,45 @@ impl NumCast for int {
|
|||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20i.to_uint()));
|
||||
fail_unless!((20u8 == 20i.to_u8()));
|
||||
fail_unless!((20u16 == 20i.to_u16()));
|
||||
fail_unless!((20u32 == 20i.to_u32()));
|
||||
fail_unless!((20u64 == 20i.to_u64()));
|
||||
fail_unless!((20i == 20i.to_int()));
|
||||
fail_unless!((20i8 == 20i.to_i8()));
|
||||
fail_unless!((20i16 == 20i.to_i16()));
|
||||
fail_unless!((20i32 == 20i.to_i32()));
|
||||
fail_unless!((20i64 == 20i.to_i64()));
|
||||
fail_unless!((20f == 20i.to_float()));
|
||||
fail_unless!((20f32 == 20i.to_f32()));
|
||||
fail_unless!((20f64 == 20i.to_f64()));
|
||||
assert!((20u == 20i.to_uint()));
|
||||
assert!((20u8 == 20i.to_u8()));
|
||||
assert!((20u16 == 20i.to_u16()));
|
||||
assert!((20u32 == 20i.to_u32()));
|
||||
assert!((20u64 == 20i.to_u64()));
|
||||
assert!((20i == 20i.to_int()));
|
||||
assert!((20i8 == 20i.to_i8()));
|
||||
assert!((20i16 == 20i.to_i16()));
|
||||
assert!((20i32 == 20i.to_i32()));
|
||||
assert!((20i64 == 20i.to_i64()));
|
||||
assert!((20f == 20i.to_float()));
|
||||
assert!((20f32 == 20i.to_f32()));
|
||||
assert!((20f64 == 20i.to_f64()));
|
||||
|
||||
fail_unless!((20i == NumCast::from(20u)));
|
||||
fail_unless!((20i == NumCast::from(20u8)));
|
||||
fail_unless!((20i == NumCast::from(20u16)));
|
||||
fail_unless!((20i == NumCast::from(20u32)));
|
||||
fail_unless!((20i == NumCast::from(20u64)));
|
||||
fail_unless!((20i == NumCast::from(20i)));
|
||||
fail_unless!((20i == NumCast::from(20i8)));
|
||||
fail_unless!((20i == NumCast::from(20i16)));
|
||||
fail_unless!((20i == NumCast::from(20i32)));
|
||||
fail_unless!((20i == NumCast::from(20i64)));
|
||||
fail_unless!((20i == NumCast::from(20f)));
|
||||
fail_unless!((20i == NumCast::from(20f32)));
|
||||
fail_unless!((20i == NumCast::from(20f64)));
|
||||
assert!((20i == NumCast::from(20u)));
|
||||
assert!((20i == NumCast::from(20u8)));
|
||||
assert!((20i == NumCast::from(20u16)));
|
||||
assert!((20i == NumCast::from(20u32)));
|
||||
assert!((20i == NumCast::from(20u64)));
|
||||
assert!((20i == NumCast::from(20i)));
|
||||
assert!((20i == NumCast::from(20i8)));
|
||||
assert!((20i == NumCast::from(20i16)));
|
||||
assert!((20i == NumCast::from(20i32)));
|
||||
assert!((20i == NumCast::from(20i64)));
|
||||
assert!((20i == NumCast::from(20f)));
|
||||
assert!((20i == NumCast::from(20f32)));
|
||||
assert!((20i == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20i == num::cast(20u)));
|
||||
fail_unless!((20i == num::cast(20u8)));
|
||||
fail_unless!((20i == num::cast(20u16)));
|
||||
fail_unless!((20i == num::cast(20u32)));
|
||||
fail_unless!((20i == num::cast(20u64)));
|
||||
fail_unless!((20i == num::cast(20i)));
|
||||
fail_unless!((20i == num::cast(20i8)));
|
||||
fail_unless!((20i == num::cast(20i16)));
|
||||
fail_unless!((20i == num::cast(20i32)));
|
||||
fail_unless!((20i == num::cast(20i64)));
|
||||
fail_unless!((20i == num::cast(20f)));
|
||||
fail_unless!((20i == num::cast(20f32)));
|
||||
fail_unless!((20i == num::cast(20f64)));
|
||||
assert!((20i == num::cast(20u)));
|
||||
assert!((20i == num::cast(20u8)));
|
||||
assert!((20i == num::cast(20u16)));
|
||||
assert!((20i == num::cast(20u32)));
|
||||
assert!((20i == num::cast(20u64)));
|
||||
assert!((20i == num::cast(20i)));
|
||||
assert!((20i == num::cast(20i8)));
|
||||
assert!((20i == num::cast(20i16)));
|
||||
assert!((20i == num::cast(20i32)));
|
||||
assert!((20i == num::cast(20i64)));
|
||||
assert!((20i == num::cast(20f)));
|
||||
assert!((20i == num::cast(20f32)));
|
||||
assert!((20i == num::cast(20f64)));
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ pub enum RoundMode {
|
|||
*
|
||||
* ~~~
|
||||
* let twenty: f32 = num::cast(0x14);
|
||||
* fail_unless!(twenty == 20f32);
|
||||
* assert!(twenty == 20f32);
|
||||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
|
|
|
@ -241,104 +241,104 @@ impl ToStrRadix for T {
|
|||
|
||||
#[test]
|
||||
pub fn test_to_str() {
|
||||
fail_unless!(to_str_radix(0 as T, 10u) == ~"0");
|
||||
fail_unless!(to_str_radix(1 as T, 10u) == ~"1");
|
||||
fail_unless!(to_str_radix(2 as T, 10u) == ~"2");
|
||||
fail_unless!(to_str_radix(11 as T, 10u) == ~"11");
|
||||
fail_unless!(to_str_radix(11 as T, 16u) == ~"b");
|
||||
fail_unless!(to_str_radix(255 as T, 16u) == ~"ff");
|
||||
fail_unless!(to_str_radix(0xff as T, 10u) == ~"255");
|
||||
assert!(to_str_radix(0 as T, 10u) == ~"0");
|
||||
assert!(to_str_radix(1 as T, 10u) == ~"1");
|
||||
assert!(to_str_radix(2 as T, 10u) == ~"2");
|
||||
assert!(to_str_radix(11 as T, 10u) == ~"11");
|
||||
assert!(to_str_radix(11 as T, 16u) == ~"b");
|
||||
assert!(to_str_radix(255 as T, 16u) == ~"ff");
|
||||
assert!(to_str_radix(0xff as T, 10u) == ~"255");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_from_str() {
|
||||
fail_unless!(from_str(~"0") == Some(0u as T));
|
||||
fail_unless!(from_str(~"3") == Some(3u as T));
|
||||
fail_unless!(from_str(~"10") == Some(10u as T));
|
||||
fail_unless!(u32::from_str(~"123456789") == Some(123456789 as u32));
|
||||
fail_unless!(from_str(~"00100") == Some(100u as T));
|
||||
assert!(from_str(~"0") == Some(0u as T));
|
||||
assert!(from_str(~"3") == Some(3u as T));
|
||||
assert!(from_str(~"10") == Some(10u as T));
|
||||
assert!(u32::from_str(~"123456789") == Some(123456789 as u32));
|
||||
assert!(from_str(~"00100") == Some(100u as T));
|
||||
|
||||
fail_unless!(from_str(~"").is_none());
|
||||
fail_unless!(from_str(~" ").is_none());
|
||||
fail_unless!(from_str(~"x").is_none());
|
||||
assert!(from_str(~"").is_none());
|
||||
assert!(from_str(~" ").is_none());
|
||||
assert!(from_str(~"x").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_parse_bytes() {
|
||||
use str::to_bytes;
|
||||
fail_unless!(parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T));
|
||||
fail_unless!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T));
|
||||
fail_unless!(parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T));
|
||||
fail_unless!(u16::parse_bytes(to_bytes(~"123"), 16u) ==
|
||||
assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T));
|
||||
assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T));
|
||||
assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T));
|
||||
assert!(u16::parse_bytes(to_bytes(~"123"), 16u) ==
|
||||
Some(291u as u16));
|
||||
fail_unless!(u16::parse_bytes(to_bytes(~"ffff"), 16u) ==
|
||||
assert!(u16::parse_bytes(to_bytes(~"ffff"), 16u) ==
|
||||
Some(65535u as u16));
|
||||
fail_unless!(parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T));
|
||||
assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T));
|
||||
|
||||
fail_unless!(parse_bytes(to_bytes(~"Z"), 10u).is_none());
|
||||
fail_unless!(parse_bytes(to_bytes(~"_"), 2u).is_none());
|
||||
assert!(parse_bytes(to_bytes(~"Z"), 10u).is_none());
|
||||
assert!(parse_bytes(to_bytes(~"_"), 2u).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint_to_str_overflow() {
|
||||
let mut u8_val: u8 = 255_u8;
|
||||
fail_unless!((u8::to_str(u8_val) == ~"255"));
|
||||
assert!((u8::to_str(u8_val) == ~"255"));
|
||||
|
||||
u8_val += 1 as u8;
|
||||
fail_unless!((u8::to_str(u8_val) == ~"0"));
|
||||
assert!((u8::to_str(u8_val) == ~"0"));
|
||||
|
||||
let mut u16_val: u16 = 65_535_u16;
|
||||
fail_unless!((u16::to_str(u16_val) == ~"65535"));
|
||||
assert!((u16::to_str(u16_val) == ~"65535"));
|
||||
|
||||
u16_val += 1 as u16;
|
||||
fail_unless!((u16::to_str(u16_val) == ~"0"));
|
||||
assert!((u16::to_str(u16_val) == ~"0"));
|
||||
|
||||
let mut u32_val: u32 = 4_294_967_295_u32;
|
||||
fail_unless!((u32::to_str(u32_val) == ~"4294967295"));
|
||||
assert!((u32::to_str(u32_val) == ~"4294967295"));
|
||||
|
||||
u32_val += 1 as u32;
|
||||
fail_unless!((u32::to_str(u32_val) == ~"0"));
|
||||
assert!((u32::to_str(u32_val) == ~"0"));
|
||||
|
||||
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
|
||||
fail_unless!((u64::to_str(u64_val) == ~"18446744073709551615"));
|
||||
assert!((u64::to_str(u64_val) == ~"18446744073709551615"));
|
||||
|
||||
u64_val += 1 as u64;
|
||||
fail_unless!((u64::to_str(u64_val) == ~"0"));
|
||||
assert!((u64::to_str(u64_val) == ~"0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint_from_str_overflow() {
|
||||
let mut u8_val: u8 = 255_u8;
|
||||
fail_unless!((u8::from_str(~"255") == Some(u8_val)));
|
||||
fail_unless!((u8::from_str(~"256").is_none()));
|
||||
assert!((u8::from_str(~"255") == Some(u8_val)));
|
||||
assert!((u8::from_str(~"256").is_none()));
|
||||
|
||||
u8_val += 1 as u8;
|
||||
fail_unless!((u8::from_str(~"0") == Some(u8_val)));
|
||||
fail_unless!((u8::from_str(~"-1").is_none()));
|
||||
assert!((u8::from_str(~"0") == Some(u8_val)));
|
||||
assert!((u8::from_str(~"-1").is_none()));
|
||||
|
||||
let mut u16_val: u16 = 65_535_u16;
|
||||
fail_unless!((u16::from_str(~"65535") == Some(u16_val)));
|
||||
fail_unless!((u16::from_str(~"65536").is_none()));
|
||||
assert!((u16::from_str(~"65535") == Some(u16_val)));
|
||||
assert!((u16::from_str(~"65536").is_none()));
|
||||
|
||||
u16_val += 1 as u16;
|
||||
fail_unless!((u16::from_str(~"0") == Some(u16_val)));
|
||||
fail_unless!((u16::from_str(~"-1").is_none()));
|
||||
assert!((u16::from_str(~"0") == Some(u16_val)));
|
||||
assert!((u16::from_str(~"-1").is_none()));
|
||||
|
||||
let mut u32_val: u32 = 4_294_967_295_u32;
|
||||
fail_unless!((u32::from_str(~"4294967295") == Some(u32_val)));
|
||||
fail_unless!((u32::from_str(~"4294967296").is_none()));
|
||||
assert!((u32::from_str(~"4294967295") == Some(u32_val)));
|
||||
assert!((u32::from_str(~"4294967296").is_none()));
|
||||
|
||||
u32_val += 1 as u32;
|
||||
fail_unless!((u32::from_str(~"0") == Some(u32_val)));
|
||||
fail_unless!((u32::from_str(~"-1").is_none()));
|
||||
assert!((u32::from_str(~"0") == Some(u32_val)));
|
||||
assert!((u32::from_str(~"-1").is_none()));
|
||||
|
||||
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
|
||||
fail_unless!((u64::from_str(~"18446744073709551615") == Some(u64_val)));
|
||||
fail_unless!((u64::from_str(~"18446744073709551616").is_none()));
|
||||
assert!((u64::from_str(~"18446744073709551615") == Some(u64_val)));
|
||||
assert!((u64::from_str(~"18446744073709551616").is_none()));
|
||||
|
||||
u64_val += 1 as u64;
|
||||
fail_unless!((u64::from_str(~"0") == Some(u64_val)));
|
||||
fail_unless!((u64::from_str(~"-1").is_none()));
|
||||
assert!((u64::from_str(~"0") == Some(u64_val)));
|
||||
assert!((u64::from_str(~"-1").is_none()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -372,7 +372,7 @@ pub fn test_ranges() {
|
|||
l.push(i);
|
||||
}
|
||||
|
||||
fail_unless!(l == ~[0,1,2,
|
||||
assert!(l == ~[0,1,2,
|
||||
13,12,11,
|
||||
20,22,24,
|
||||
36,34,32]);
|
||||
|
@ -397,11 +397,11 @@ pub fn test_num() {
|
|||
let ten: T = num::cast(10);
|
||||
let two: T = num::cast(2);
|
||||
|
||||
fail_unless!((ten.add(&two) == num::cast(12)));
|
||||
fail_unless!((ten.sub(&two) == num::cast(8)));
|
||||
fail_unless!((ten.mul(&two) == num::cast(20)));
|
||||
fail_unless!((ten.div(&two) == num::cast(5)));
|
||||
fail_unless!((ten.modulo(&two) == num::cast(0)));
|
||||
assert!((ten.add(&two) == num::cast(12)));
|
||||
assert!((ten.sub(&two) == num::cast(8)));
|
||||
assert!((ten.mul(&two) == num::cast(20)));
|
||||
assert!((ten.div(&two) == num::cast(5)));
|
||||
assert!((ten.modulo(&two) == num::cast(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -45,45 +45,45 @@ impl NumCast for u16 {
|
|||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20u16.to_uint()));
|
||||
fail_unless!((20u8 == 20u16.to_u8()));
|
||||
fail_unless!((20u16 == 20u16.to_u16()));
|
||||
fail_unless!((20u32 == 20u16.to_u32()));
|
||||
fail_unless!((20u64 == 20u16.to_u64()));
|
||||
fail_unless!((20i == 20u16.to_int()));
|
||||
fail_unless!((20i8 == 20u16.to_i8()));
|
||||
fail_unless!((20i16 == 20u16.to_i16()));
|
||||
fail_unless!((20i32 == 20u16.to_i32()));
|
||||
fail_unless!((20i64 == 20u16.to_i64()));
|
||||
fail_unless!((20f == 20u16.to_float()));
|
||||
fail_unless!((20f32 == 20u16.to_f32()));
|
||||
fail_unless!((20f64 == 20u16.to_f64()));
|
||||
assert!((20u == 20u16.to_uint()));
|
||||
assert!((20u8 == 20u16.to_u8()));
|
||||
assert!((20u16 == 20u16.to_u16()));
|
||||
assert!((20u32 == 20u16.to_u32()));
|
||||
assert!((20u64 == 20u16.to_u64()));
|
||||
assert!((20i == 20u16.to_int()));
|
||||
assert!((20i8 == 20u16.to_i8()));
|
||||
assert!((20i16 == 20u16.to_i16()));
|
||||
assert!((20i32 == 20u16.to_i32()));
|
||||
assert!((20i64 == 20u16.to_i64()));
|
||||
assert!((20f == 20u16.to_float()));
|
||||
assert!((20f32 == 20u16.to_f32()));
|
||||
assert!((20f64 == 20u16.to_f64()));
|
||||
|
||||
fail_unless!((20u16 == NumCast::from(20u)));
|
||||
fail_unless!((20u16 == NumCast::from(20u8)));
|
||||
fail_unless!((20u16 == NumCast::from(20u16)));
|
||||
fail_unless!((20u16 == NumCast::from(20u32)));
|
||||
fail_unless!((20u16 == NumCast::from(20u64)));
|
||||
fail_unless!((20u16 == NumCast::from(20i)));
|
||||
fail_unless!((20u16 == NumCast::from(20i8)));
|
||||
fail_unless!((20u16 == NumCast::from(20i16)));
|
||||
fail_unless!((20u16 == NumCast::from(20i32)));
|
||||
fail_unless!((20u16 == NumCast::from(20i64)));
|
||||
fail_unless!((20u16 == NumCast::from(20f)));
|
||||
fail_unless!((20u16 == NumCast::from(20f32)));
|
||||
fail_unless!((20u16 == NumCast::from(20f64)));
|
||||
assert!((20u16 == NumCast::from(20u)));
|
||||
assert!((20u16 == NumCast::from(20u8)));
|
||||
assert!((20u16 == NumCast::from(20u16)));
|
||||
assert!((20u16 == NumCast::from(20u32)));
|
||||
assert!((20u16 == NumCast::from(20u64)));
|
||||
assert!((20u16 == NumCast::from(20i)));
|
||||
assert!((20u16 == NumCast::from(20i8)));
|
||||
assert!((20u16 == NumCast::from(20i16)));
|
||||
assert!((20u16 == NumCast::from(20i32)));
|
||||
assert!((20u16 == NumCast::from(20i64)));
|
||||
assert!((20u16 == NumCast::from(20f)));
|
||||
assert!((20u16 == NumCast::from(20f32)));
|
||||
assert!((20u16 == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20u16 == num::cast(20u)));
|
||||
fail_unless!((20u16 == num::cast(20u8)));
|
||||
fail_unless!((20u16 == num::cast(20u16)));
|
||||
fail_unless!((20u16 == num::cast(20u32)));
|
||||
fail_unless!((20u16 == num::cast(20u64)));
|
||||
fail_unless!((20u16 == num::cast(20i)));
|
||||
fail_unless!((20u16 == num::cast(20i8)));
|
||||
fail_unless!((20u16 == num::cast(20i16)));
|
||||
fail_unless!((20u16 == num::cast(20i32)));
|
||||
fail_unless!((20u16 == num::cast(20i64)));
|
||||
fail_unless!((20u16 == num::cast(20f)));
|
||||
fail_unless!((20u16 == num::cast(20f32)));
|
||||
fail_unless!((20u16 == num::cast(20f64)));
|
||||
assert!((20u16 == num::cast(20u)));
|
||||
assert!((20u16 == num::cast(20u8)));
|
||||
assert!((20u16 == num::cast(20u16)));
|
||||
assert!((20u16 == num::cast(20u32)));
|
||||
assert!((20u16 == num::cast(20u64)));
|
||||
assert!((20u16 == num::cast(20i)));
|
||||
assert!((20u16 == num::cast(20i8)));
|
||||
assert!((20u16 == num::cast(20i16)));
|
||||
assert!((20u16 == num::cast(20i32)));
|
||||
assert!((20u16 == num::cast(20i64)));
|
||||
assert!((20u16 == num::cast(20f)));
|
||||
assert!((20u16 == num::cast(20f32)));
|
||||
assert!((20u16 == num::cast(20f64)));
|
||||
}
|
||||
|
|
|
@ -45,45 +45,45 @@ impl NumCast for u32 {
|
|||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20u64.to_uint()));
|
||||
fail_unless!((20u8 == 20u64.to_u8()));
|
||||
fail_unless!((20u16 == 20u64.to_u16()));
|
||||
fail_unless!((20u32 == 20u64.to_u32()));
|
||||
fail_unless!((20u64 == 20u64.to_u64()));
|
||||
fail_unless!((20i == 20u64.to_int()));
|
||||
fail_unless!((20i8 == 20u64.to_i8()));
|
||||
fail_unless!((20i16 == 20u64.to_i16()));
|
||||
fail_unless!((20i32 == 20u64.to_i32()));
|
||||
fail_unless!((20i64 == 20u64.to_i64()));
|
||||
fail_unless!((20f == 20u64.to_float()));
|
||||
fail_unless!((20f32 == 20u64.to_f32()));
|
||||
fail_unless!((20f64 == 20u64.to_f64()));
|
||||
assert!((20u == 20u64.to_uint()));
|
||||
assert!((20u8 == 20u64.to_u8()));
|
||||
assert!((20u16 == 20u64.to_u16()));
|
||||
assert!((20u32 == 20u64.to_u32()));
|
||||
assert!((20u64 == 20u64.to_u64()));
|
||||
assert!((20i == 20u64.to_int()));
|
||||
assert!((20i8 == 20u64.to_i8()));
|
||||
assert!((20i16 == 20u64.to_i16()));
|
||||
assert!((20i32 == 20u64.to_i32()));
|
||||
assert!((20i64 == 20u64.to_i64()));
|
||||
assert!((20f == 20u64.to_float()));
|
||||
assert!((20f32 == 20u64.to_f32()));
|
||||
assert!((20f64 == 20u64.to_f64()));
|
||||
|
||||
fail_unless!((20u64 == NumCast::from(20u)));
|
||||
fail_unless!((20u64 == NumCast::from(20u8)));
|
||||
fail_unless!((20u64 == NumCast::from(20u16)));
|
||||
fail_unless!((20u64 == NumCast::from(20u32)));
|
||||
fail_unless!((20u64 == NumCast::from(20u64)));
|
||||
fail_unless!((20u64 == NumCast::from(20i)));
|
||||
fail_unless!((20u64 == NumCast::from(20i8)));
|
||||
fail_unless!((20u64 == NumCast::from(20i16)));
|
||||
fail_unless!((20u64 == NumCast::from(20i32)));
|
||||
fail_unless!((20u64 == NumCast::from(20i64)));
|
||||
fail_unless!((20u64 == NumCast::from(20f)));
|
||||
fail_unless!((20u64 == NumCast::from(20f32)));
|
||||
fail_unless!((20u64 == NumCast::from(20f64)));
|
||||
assert!((20u64 == NumCast::from(20u)));
|
||||
assert!((20u64 == NumCast::from(20u8)));
|
||||
assert!((20u64 == NumCast::from(20u16)));
|
||||
assert!((20u64 == NumCast::from(20u32)));
|
||||
assert!((20u64 == NumCast::from(20u64)));
|
||||
assert!((20u64 == NumCast::from(20i)));
|
||||
assert!((20u64 == NumCast::from(20i8)));
|
||||
assert!((20u64 == NumCast::from(20i16)));
|
||||
assert!((20u64 == NumCast::from(20i32)));
|
||||
assert!((20u64 == NumCast::from(20i64)));
|
||||
assert!((20u64 == NumCast::from(20f)));
|
||||
assert!((20u64 == NumCast::from(20f32)));
|
||||
assert!((20u64 == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20u64 == num::cast(20u)));
|
||||
fail_unless!((20u64 == num::cast(20u8)));
|
||||
fail_unless!((20u64 == num::cast(20u16)));
|
||||
fail_unless!((20u64 == num::cast(20u32)));
|
||||
fail_unless!((20u64 == num::cast(20u64)));
|
||||
fail_unless!((20u64 == num::cast(20i)));
|
||||
fail_unless!((20u64 == num::cast(20i8)));
|
||||
fail_unless!((20u64 == num::cast(20i16)));
|
||||
fail_unless!((20u64 == num::cast(20i32)));
|
||||
fail_unless!((20u64 == num::cast(20i64)));
|
||||
fail_unless!((20u64 == num::cast(20f)));
|
||||
fail_unless!((20u64 == num::cast(20f32)));
|
||||
fail_unless!((20u64 == num::cast(20f64)));
|
||||
assert!((20u64 == num::cast(20u)));
|
||||
assert!((20u64 == num::cast(20u8)));
|
||||
assert!((20u64 == num::cast(20u16)));
|
||||
assert!((20u64 == num::cast(20u32)));
|
||||
assert!((20u64 == num::cast(20u64)));
|
||||
assert!((20u64 == num::cast(20i)));
|
||||
assert!((20u64 == num::cast(20i8)));
|
||||
assert!((20u64 == num::cast(20i16)));
|
||||
assert!((20u64 == num::cast(20i32)));
|
||||
assert!((20u64 == num::cast(20i64)));
|
||||
assert!((20u64 == num::cast(20f)));
|
||||
assert!((20u64 == num::cast(20f32)));
|
||||
assert!((20u64 == num::cast(20f64)));
|
||||
}
|
||||
|
|
|
@ -45,45 +45,45 @@ impl NumCast for u64 {
|
|||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20u64.to_uint()));
|
||||
fail_unless!((20u8 == 20u64.to_u8()));
|
||||
fail_unless!((20u16 == 20u64.to_u16()));
|
||||
fail_unless!((20u32 == 20u64.to_u32()));
|
||||
fail_unless!((20u64 == 20u64.to_u64()));
|
||||
fail_unless!((20i == 20u64.to_int()));
|
||||
fail_unless!((20i8 == 20u64.to_i8()));
|
||||
fail_unless!((20i16 == 20u64.to_i16()));
|
||||
fail_unless!((20i32 == 20u64.to_i32()));
|
||||
fail_unless!((20i64 == 20u64.to_i64()));
|
||||
fail_unless!((20f == 20u64.to_float()));
|
||||
fail_unless!((20f32 == 20u64.to_f32()));
|
||||
fail_unless!((20f64 == 20u64.to_f64()));
|
||||
assert!((20u == 20u64.to_uint()));
|
||||
assert!((20u8 == 20u64.to_u8()));
|
||||
assert!((20u16 == 20u64.to_u16()));
|
||||
assert!((20u32 == 20u64.to_u32()));
|
||||
assert!((20u64 == 20u64.to_u64()));
|
||||
assert!((20i == 20u64.to_int()));
|
||||
assert!((20i8 == 20u64.to_i8()));
|
||||
assert!((20i16 == 20u64.to_i16()));
|
||||
assert!((20i32 == 20u64.to_i32()));
|
||||
assert!((20i64 == 20u64.to_i64()));
|
||||
assert!((20f == 20u64.to_float()));
|
||||
assert!((20f32 == 20u64.to_f32()));
|
||||
assert!((20f64 == 20u64.to_f64()));
|
||||
|
||||
fail_unless!((20u64 == NumCast::from(20u)));
|
||||
fail_unless!((20u64 == NumCast::from(20u8)));
|
||||
fail_unless!((20u64 == NumCast::from(20u16)));
|
||||
fail_unless!((20u64 == NumCast::from(20u32)));
|
||||
fail_unless!((20u64 == NumCast::from(20u64)));
|
||||
fail_unless!((20u64 == NumCast::from(20i)));
|
||||
fail_unless!((20u64 == NumCast::from(20i8)));
|
||||
fail_unless!((20u64 == NumCast::from(20i16)));
|
||||
fail_unless!((20u64 == NumCast::from(20i32)));
|
||||
fail_unless!((20u64 == NumCast::from(20i64)));
|
||||
fail_unless!((20u64 == NumCast::from(20f)));
|
||||
fail_unless!((20u64 == NumCast::from(20f32)));
|
||||
fail_unless!((20u64 == NumCast::from(20f64)));
|
||||
assert!((20u64 == NumCast::from(20u)));
|
||||
assert!((20u64 == NumCast::from(20u8)));
|
||||
assert!((20u64 == NumCast::from(20u16)));
|
||||
assert!((20u64 == NumCast::from(20u32)));
|
||||
assert!((20u64 == NumCast::from(20u64)));
|
||||
assert!((20u64 == NumCast::from(20i)));
|
||||
assert!((20u64 == NumCast::from(20i8)));
|
||||
assert!((20u64 == NumCast::from(20i16)));
|
||||
assert!((20u64 == NumCast::from(20i32)));
|
||||
assert!((20u64 == NumCast::from(20i64)));
|
||||
assert!((20u64 == NumCast::from(20f)));
|
||||
assert!((20u64 == NumCast::from(20f32)));
|
||||
assert!((20u64 == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20u64 == num::cast(20u)));
|
||||
fail_unless!((20u64 == num::cast(20u8)));
|
||||
fail_unless!((20u64 == num::cast(20u16)));
|
||||
fail_unless!((20u64 == num::cast(20u32)));
|
||||
fail_unless!((20u64 == num::cast(20u64)));
|
||||
fail_unless!((20u64 == num::cast(20i)));
|
||||
fail_unless!((20u64 == num::cast(20i8)));
|
||||
fail_unless!((20u64 == num::cast(20i16)));
|
||||
fail_unless!((20u64 == num::cast(20i32)));
|
||||
fail_unless!((20u64 == num::cast(20i64)));
|
||||
fail_unless!((20u64 == num::cast(20f)));
|
||||
fail_unless!((20u64 == num::cast(20f32)));
|
||||
fail_unless!((20u64 == num::cast(20f64)));
|
||||
assert!((20u64 == num::cast(20u)));
|
||||
assert!((20u64 == num::cast(20u8)));
|
||||
assert!((20u64 == num::cast(20u16)));
|
||||
assert!((20u64 == num::cast(20u32)));
|
||||
assert!((20u64 == num::cast(20u64)));
|
||||
assert!((20u64 == num::cast(20i)));
|
||||
assert!((20u64 == num::cast(20i8)));
|
||||
assert!((20u64 == num::cast(20i16)));
|
||||
assert!((20u64 == num::cast(20i32)));
|
||||
assert!((20u64 == num::cast(20i64)));
|
||||
assert!((20u64 == num::cast(20f)));
|
||||
assert!((20u64 == num::cast(20f32)));
|
||||
assert!((20u64 == num::cast(20f64)));
|
||||
}
|
||||
|
|
|
@ -52,45 +52,45 @@ impl NumCast for u8 {
|
|||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20u8.to_uint()));
|
||||
fail_unless!((20u8 == 20u8.to_u8()));
|
||||
fail_unless!((20u16 == 20u8.to_u16()));
|
||||
fail_unless!((20u32 == 20u8.to_u32()));
|
||||
fail_unless!((20u64 == 20u8.to_u64()));
|
||||
fail_unless!((20i == 20u8.to_int()));
|
||||
fail_unless!((20i8 == 20u8.to_i8()));
|
||||
fail_unless!((20i16 == 20u8.to_i16()));
|
||||
fail_unless!((20i32 == 20u8.to_i32()));
|
||||
fail_unless!((20i64 == 20u8.to_i64()));
|
||||
fail_unless!((20f == 20u8.to_float()));
|
||||
fail_unless!((20f32 == 20u8.to_f32()));
|
||||
fail_unless!((20f64 == 20u8.to_f64()));
|
||||
assert!((20u == 20u8.to_uint()));
|
||||
assert!((20u8 == 20u8.to_u8()));
|
||||
assert!((20u16 == 20u8.to_u16()));
|
||||
assert!((20u32 == 20u8.to_u32()));
|
||||
assert!((20u64 == 20u8.to_u64()));
|
||||
assert!((20i == 20u8.to_int()));
|
||||
assert!((20i8 == 20u8.to_i8()));
|
||||
assert!((20i16 == 20u8.to_i16()));
|
||||
assert!((20i32 == 20u8.to_i32()));
|
||||
assert!((20i64 == 20u8.to_i64()));
|
||||
assert!((20f == 20u8.to_float()));
|
||||
assert!((20f32 == 20u8.to_f32()));
|
||||
assert!((20f64 == 20u8.to_f64()));
|
||||
|
||||
fail_unless!((20u8 == NumCast::from(20u)));
|
||||
fail_unless!((20u8 == NumCast::from(20u8)));
|
||||
fail_unless!((20u8 == NumCast::from(20u16)));
|
||||
fail_unless!((20u8 == NumCast::from(20u32)));
|
||||
fail_unless!((20u8 == NumCast::from(20u64)));
|
||||
fail_unless!((20u8 == NumCast::from(20i)));
|
||||
fail_unless!((20u8 == NumCast::from(20i8)));
|
||||
fail_unless!((20u8 == NumCast::from(20i16)));
|
||||
fail_unless!((20u8 == NumCast::from(20i32)));
|
||||
fail_unless!((20u8 == NumCast::from(20i64)));
|
||||
fail_unless!((20u8 == NumCast::from(20f)));
|
||||
fail_unless!((20u8 == NumCast::from(20f32)));
|
||||
fail_unless!((20u8 == NumCast::from(20f64)));
|
||||
assert!((20u8 == NumCast::from(20u)));
|
||||
assert!((20u8 == NumCast::from(20u8)));
|
||||
assert!((20u8 == NumCast::from(20u16)));
|
||||
assert!((20u8 == NumCast::from(20u32)));
|
||||
assert!((20u8 == NumCast::from(20u64)));
|
||||
assert!((20u8 == NumCast::from(20i)));
|
||||
assert!((20u8 == NumCast::from(20i8)));
|
||||
assert!((20u8 == NumCast::from(20i16)));
|
||||
assert!((20u8 == NumCast::from(20i32)));
|
||||
assert!((20u8 == NumCast::from(20i64)));
|
||||
assert!((20u8 == NumCast::from(20f)));
|
||||
assert!((20u8 == NumCast::from(20f32)));
|
||||
assert!((20u8 == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20u8 == num::cast(20u)));
|
||||
fail_unless!((20u8 == num::cast(20u8)));
|
||||
fail_unless!((20u8 == num::cast(20u16)));
|
||||
fail_unless!((20u8 == num::cast(20u32)));
|
||||
fail_unless!((20u8 == num::cast(20u64)));
|
||||
fail_unless!((20u8 == num::cast(20i)));
|
||||
fail_unless!((20u8 == num::cast(20i8)));
|
||||
fail_unless!((20u8 == num::cast(20i16)));
|
||||
fail_unless!((20u8 == num::cast(20i32)));
|
||||
fail_unless!((20u8 == num::cast(20i64)));
|
||||
fail_unless!((20u8 == num::cast(20f)));
|
||||
fail_unless!((20u8 == num::cast(20f32)));
|
||||
fail_unless!((20u8 == num::cast(20f64)));
|
||||
assert!((20u8 == num::cast(20u)));
|
||||
assert!((20u8 == num::cast(20u8)));
|
||||
assert!((20u8 == num::cast(20u16)));
|
||||
assert!((20u8 == num::cast(20u32)));
|
||||
assert!((20u8 == num::cast(20u64)));
|
||||
assert!((20u8 == num::cast(20i)));
|
||||
assert!((20u8 == num::cast(20i8)));
|
||||
assert!((20u8 == num::cast(20i16)));
|
||||
assert!((20u8 == num::cast(20i32)));
|
||||
assert!((20u8 == num::cast(20i64)));
|
||||
assert!((20u8 == num::cast(20f)));
|
||||
assert!((20u8 == num::cast(20f32)));
|
||||
assert!((20u8 == num::cast(20f64)));
|
||||
}
|
||||
|
|
|
@ -143,61 +143,61 @@ pub mod inst {
|
|||
|
||||
#[test]
|
||||
fn test_next_power_of_two() {
|
||||
fail_unless!((next_power_of_two(0u) == 0u));
|
||||
fail_unless!((next_power_of_two(1u) == 1u));
|
||||
fail_unless!((next_power_of_two(2u) == 2u));
|
||||
fail_unless!((next_power_of_two(3u) == 4u));
|
||||
fail_unless!((next_power_of_two(4u) == 4u));
|
||||
fail_unless!((next_power_of_two(5u) == 8u));
|
||||
fail_unless!((next_power_of_two(6u) == 8u));
|
||||
fail_unless!((next_power_of_two(7u) == 8u));
|
||||
fail_unless!((next_power_of_two(8u) == 8u));
|
||||
fail_unless!((next_power_of_two(9u) == 16u));
|
||||
fail_unless!((next_power_of_two(10u) == 16u));
|
||||
fail_unless!((next_power_of_two(11u) == 16u));
|
||||
fail_unless!((next_power_of_two(12u) == 16u));
|
||||
fail_unless!((next_power_of_two(13u) == 16u));
|
||||
fail_unless!((next_power_of_two(14u) == 16u));
|
||||
fail_unless!((next_power_of_two(15u) == 16u));
|
||||
fail_unless!((next_power_of_two(16u) == 16u));
|
||||
fail_unless!((next_power_of_two(17u) == 32u));
|
||||
fail_unless!((next_power_of_two(18u) == 32u));
|
||||
fail_unless!((next_power_of_two(19u) == 32u));
|
||||
fail_unless!((next_power_of_two(20u) == 32u));
|
||||
fail_unless!((next_power_of_two(21u) == 32u));
|
||||
fail_unless!((next_power_of_two(22u) == 32u));
|
||||
fail_unless!((next_power_of_two(23u) == 32u));
|
||||
fail_unless!((next_power_of_two(24u) == 32u));
|
||||
fail_unless!((next_power_of_two(25u) == 32u));
|
||||
fail_unless!((next_power_of_two(26u) == 32u));
|
||||
fail_unless!((next_power_of_two(27u) == 32u));
|
||||
fail_unless!((next_power_of_two(28u) == 32u));
|
||||
fail_unless!((next_power_of_two(29u) == 32u));
|
||||
fail_unless!((next_power_of_two(30u) == 32u));
|
||||
fail_unless!((next_power_of_two(31u) == 32u));
|
||||
fail_unless!((next_power_of_two(32u) == 32u));
|
||||
fail_unless!((next_power_of_two(33u) == 64u));
|
||||
fail_unless!((next_power_of_two(34u) == 64u));
|
||||
fail_unless!((next_power_of_two(35u) == 64u));
|
||||
fail_unless!((next_power_of_two(36u) == 64u));
|
||||
fail_unless!((next_power_of_two(37u) == 64u));
|
||||
fail_unless!((next_power_of_two(38u) == 64u));
|
||||
fail_unless!((next_power_of_two(39u) == 64u));
|
||||
assert!((next_power_of_two(0u) == 0u));
|
||||
assert!((next_power_of_two(1u) == 1u));
|
||||
assert!((next_power_of_two(2u) == 2u));
|
||||
assert!((next_power_of_two(3u) == 4u));
|
||||
assert!((next_power_of_two(4u) == 4u));
|
||||
assert!((next_power_of_two(5u) == 8u));
|
||||
assert!((next_power_of_two(6u) == 8u));
|
||||
assert!((next_power_of_two(7u) == 8u));
|
||||
assert!((next_power_of_two(8u) == 8u));
|
||||
assert!((next_power_of_two(9u) == 16u));
|
||||
assert!((next_power_of_two(10u) == 16u));
|
||||
assert!((next_power_of_two(11u) == 16u));
|
||||
assert!((next_power_of_two(12u) == 16u));
|
||||
assert!((next_power_of_two(13u) == 16u));
|
||||
assert!((next_power_of_two(14u) == 16u));
|
||||
assert!((next_power_of_two(15u) == 16u));
|
||||
assert!((next_power_of_two(16u) == 16u));
|
||||
assert!((next_power_of_two(17u) == 32u));
|
||||
assert!((next_power_of_two(18u) == 32u));
|
||||
assert!((next_power_of_two(19u) == 32u));
|
||||
assert!((next_power_of_two(20u) == 32u));
|
||||
assert!((next_power_of_two(21u) == 32u));
|
||||
assert!((next_power_of_two(22u) == 32u));
|
||||
assert!((next_power_of_two(23u) == 32u));
|
||||
assert!((next_power_of_two(24u) == 32u));
|
||||
assert!((next_power_of_two(25u) == 32u));
|
||||
assert!((next_power_of_two(26u) == 32u));
|
||||
assert!((next_power_of_two(27u) == 32u));
|
||||
assert!((next_power_of_two(28u) == 32u));
|
||||
assert!((next_power_of_two(29u) == 32u));
|
||||
assert!((next_power_of_two(30u) == 32u));
|
||||
assert!((next_power_of_two(31u) == 32u));
|
||||
assert!((next_power_of_two(32u) == 32u));
|
||||
assert!((next_power_of_two(33u) == 64u));
|
||||
assert!((next_power_of_two(34u) == 64u));
|
||||
assert!((next_power_of_two(35u) == 64u));
|
||||
assert!((next_power_of_two(36u) == 64u));
|
||||
assert!((next_power_of_two(37u) == 64u));
|
||||
assert!((next_power_of_two(38u) == 64u));
|
||||
assert!((next_power_of_two(39u) == 64u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_overflows() {
|
||||
use uint;
|
||||
fail_unless!((uint::max_value > 0u));
|
||||
fail_unless!((uint::min_value <= 0u));
|
||||
fail_unless!((uint::min_value + uint::max_value + 1u == 0u));
|
||||
assert!((uint::max_value > 0u));
|
||||
assert!((uint::min_value <= 0u));
|
||||
assert!((uint::min_value + uint::max_value + 1u == 0u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_div() {
|
||||
fail_unless!((div_floor(3u, 4u) == 0u));
|
||||
fail_unless!((div_ceil(3u, 4u) == 1u));
|
||||
fail_unless!((div_round(3u, 4u) == 1u));
|
||||
assert!((div_floor(3u, 4u) == 0u));
|
||||
assert!((div_ceil(3u, 4u) == 1u));
|
||||
assert!((div_round(3u, 4u) == 1u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -206,7 +206,7 @@ pub mod inst {
|
|||
let ten = 10 as uint;
|
||||
let mut accum = 0;
|
||||
for ten.times { accum += 1; }
|
||||
fail_unless!((accum == 10));
|
||||
assert!((accum == 10));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -236,45 +236,45 @@ impl NumCast for uint {
|
|||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
fail_unless!((20u == 20u.to_uint()));
|
||||
fail_unless!((20u8 == 20u.to_u8()));
|
||||
fail_unless!((20u16 == 20u.to_u16()));
|
||||
fail_unless!((20u32 == 20u.to_u32()));
|
||||
fail_unless!((20u64 == 20u.to_u64()));
|
||||
fail_unless!((20i == 20u.to_int()));
|
||||
fail_unless!((20i8 == 20u.to_i8()));
|
||||
fail_unless!((20i16 == 20u.to_i16()));
|
||||
fail_unless!((20i32 == 20u.to_i32()));
|
||||
fail_unless!((20i64 == 20u.to_i64()));
|
||||
fail_unless!((20f == 20u.to_float()));
|
||||
fail_unless!((20f32 == 20u.to_f32()));
|
||||
fail_unless!((20f64 == 20u.to_f64()));
|
||||
assert!((20u == 20u.to_uint()));
|
||||
assert!((20u8 == 20u.to_u8()));
|
||||
assert!((20u16 == 20u.to_u16()));
|
||||
assert!((20u32 == 20u.to_u32()));
|
||||
assert!((20u64 == 20u.to_u64()));
|
||||
assert!((20i == 20u.to_int()));
|
||||
assert!((20i8 == 20u.to_i8()));
|
||||
assert!((20i16 == 20u.to_i16()));
|
||||
assert!((20i32 == 20u.to_i32()));
|
||||
assert!((20i64 == 20u.to_i64()));
|
||||
assert!((20f == 20u.to_float()));
|
||||
assert!((20f32 == 20u.to_f32()));
|
||||
assert!((20f64 == 20u.to_f64()));
|
||||
|
||||
fail_unless!((20u == NumCast::from(20u)));
|
||||
fail_unless!((20u == NumCast::from(20u8)));
|
||||
fail_unless!((20u == NumCast::from(20u16)));
|
||||
fail_unless!((20u == NumCast::from(20u32)));
|
||||
fail_unless!((20u == NumCast::from(20u64)));
|
||||
fail_unless!((20u == NumCast::from(20i)));
|
||||
fail_unless!((20u == NumCast::from(20i8)));
|
||||
fail_unless!((20u == NumCast::from(20i16)));
|
||||
fail_unless!((20u == NumCast::from(20i32)));
|
||||
fail_unless!((20u == NumCast::from(20i64)));
|
||||
fail_unless!((20u == NumCast::from(20f)));
|
||||
fail_unless!((20u == NumCast::from(20f32)));
|
||||
fail_unless!((20u == NumCast::from(20f64)));
|
||||
assert!((20u == NumCast::from(20u)));
|
||||
assert!((20u == NumCast::from(20u8)));
|
||||
assert!((20u == NumCast::from(20u16)));
|
||||
assert!((20u == NumCast::from(20u32)));
|
||||
assert!((20u == NumCast::from(20u64)));
|
||||
assert!((20u == NumCast::from(20i)));
|
||||
assert!((20u == NumCast::from(20i8)));
|
||||
assert!((20u == NumCast::from(20i16)));
|
||||
assert!((20u == NumCast::from(20i32)));
|
||||
assert!((20u == NumCast::from(20i64)));
|
||||
assert!((20u == NumCast::from(20f)));
|
||||
assert!((20u == NumCast::from(20f32)));
|
||||
assert!((20u == NumCast::from(20f64)));
|
||||
|
||||
fail_unless!((20u == num::cast(20u)));
|
||||
fail_unless!((20u == num::cast(20u8)));
|
||||
fail_unless!((20u == num::cast(20u16)));
|
||||
fail_unless!((20u == num::cast(20u32)));
|
||||
fail_unless!((20u == num::cast(20u64)));
|
||||
fail_unless!((20u == num::cast(20i)));
|
||||
fail_unless!((20u == num::cast(20i8)));
|
||||
fail_unless!((20u == num::cast(20i16)));
|
||||
fail_unless!((20u == num::cast(20i32)));
|
||||
fail_unless!((20u == num::cast(20i64)));
|
||||
fail_unless!((20u == num::cast(20f)));
|
||||
fail_unless!((20u == num::cast(20f32)));
|
||||
fail_unless!((20u == num::cast(20f64)));
|
||||
assert!((20u == num::cast(20u)));
|
||||
assert!((20u == num::cast(20u8)));
|
||||
assert!((20u == num::cast(20u16)));
|
||||
assert!((20u == num::cast(20u32)));
|
||||
assert!((20u == num::cast(20u64)));
|
||||
assert!((20u == num::cast(20i)));
|
||||
assert!((20u == num::cast(20i8)));
|
||||
assert!((20u == num::cast(20i16)));
|
||||
assert!((20u == num::cast(20i32)));
|
||||
assert!((20u == num::cast(20i64)));
|
||||
assert!((20u == num::cast(20f)));
|
||||
assert!((20u == num::cast(20f32)));
|
||||
assert!((20u == num::cast(20f64)));
|
||||
}
|
||||
|
|
|
@ -356,7 +356,7 @@ fn test_unwrap_ptr() {
|
|||
let opt = Some(x);
|
||||
let y = opt.unwrap();
|
||||
let addr_y = ptr::addr_of(&(*y));
|
||||
fail_unless!(addr_x == addr_y);
|
||||
assert!(addr_x == addr_y);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -366,7 +366,7 @@ fn test_unwrap_str() {
|
|||
let opt = Some(x);
|
||||
let y = opt.unwrap();
|
||||
let addr_y = str::as_buf(y, |buf, _len| buf);
|
||||
fail_unless!(addr_x == addr_y);
|
||||
assert!(addr_x == addr_y);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -392,7 +392,7 @@ fn test_unwrap_resource() {
|
|||
let opt = Some(x);
|
||||
let _y = opt.unwrap();
|
||||
}
|
||||
fail_unless!(*i == 1);
|
||||
assert!(*i == 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -403,8 +403,8 @@ fn test_option_dance() {
|
|||
for x.each |_x| {
|
||||
y2 = y.swap_unwrap();
|
||||
}
|
||||
fail_unless!(y2 == 5);
|
||||
fail_unless!(y.is_none());
|
||||
assert!(y2 == 5);
|
||||
assert!(y.is_none());
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_option_too_much_dance() {
|
||||
|
@ -424,15 +424,15 @@ fn test_option_while_some() {
|
|||
None
|
||||
}
|
||||
}
|
||||
fail_unless!(i == 11);
|
||||
assert!(i == 11);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_or_zero() {
|
||||
let some_stuff = Some(42);
|
||||
fail_unless!(some_stuff.get_or_zero() == 42);
|
||||
assert!(some_stuff.get_or_zero() == 42);
|
||||
let no_stuff: Option<int> = None;
|
||||
fail_unless!(no_stuff.get_or_zero() == 0);
|
||||
assert!(no_stuff.get_or_zero() == 0);
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
|
|
@ -222,7 +222,7 @@ pub fn env() -> ~[(~str,~str)] {
|
|||
for str::each_splitn_char(*p, '=', 1) |s| { vs.push(s.to_owned()) }
|
||||
debug!("splitting: len: %u",
|
||||
vs.len());
|
||||
fail_unless!(vs.len() == 2);
|
||||
assert!(vs.len() == 2);
|
||||
pairs.push((copy vs[0], copy vs[1]));
|
||||
}
|
||||
pairs
|
||||
|
@ -366,7 +366,7 @@ pub fn waitpid(pid: pid_t) -> c_int {
|
|||
use libc::funcs::posix01::wait::*;
|
||||
let mut status = 0 as c_int;
|
||||
|
||||
fail_unless!((waitpid(pid, &mut status, 0 as c_int) !=
|
||||
assert!((waitpid(pid, &mut status, 0 as c_int) !=
|
||||
(-1 as c_int)));
|
||||
return status;
|
||||
}
|
||||
|
@ -380,7 +380,7 @@ pub fn pipe() -> Pipe {
|
|||
unsafe {
|
||||
let mut fds = Pipe {in: 0 as c_int,
|
||||
out: 0 as c_int };
|
||||
fail_unless!((libc::pipe(&mut fds.in) == (0 as c_int)));
|
||||
assert!((libc::pipe(&mut fds.in) == (0 as c_int)));
|
||||
return Pipe {in: fds.in, out: fds.out};
|
||||
}
|
||||
}
|
||||
|
@ -399,9 +399,9 @@ pub fn pipe() -> Pipe {
|
|||
out: 0 as c_int };
|
||||
let res = libc::pipe(&mut fds.in, 1024 as ::libc::c_uint,
|
||||
(libc::O_BINARY | libc::O_NOINHERIT) as c_int);
|
||||
fail_unless!((res == 0 as c_int));
|
||||
fail_unless!((fds.in != -1 as c_int && fds.in != 0 as c_int));
|
||||
fail_unless!((fds.out != -1 as c_int && fds.in != 0 as c_int));
|
||||
assert!((res == 0 as c_int));
|
||||
assert!((fds.in != -1 as c_int && fds.in != 0 as c_int));
|
||||
assert!((fds.out != -1 as c_int && fds.in != 0 as c_int));
|
||||
return Pipe {in: fds.in, out: fds.out};
|
||||
}
|
||||
}
|
||||
|
@ -1277,13 +1277,13 @@ mod tests {
|
|||
#[test]
|
||||
pub fn test_args() {
|
||||
let a = real_args();
|
||||
fail_unless!(a.len() >= 1);
|
||||
assert!(a.len() >= 1);
|
||||
}
|
||||
|
||||
fn make_rand_name() -> ~str {
|
||||
let rng: @rand::Rng = rand::Rng();
|
||||
let n = ~"TEST" + rng.gen_str(10u);
|
||||
fail_unless!(getenv(n).is_none());
|
||||
assert!(getenv(n).is_none());
|
||||
n
|
||||
}
|
||||
|
||||
|
@ -1291,7 +1291,7 @@ mod tests {
|
|||
fn test_setenv() {
|
||||
let n = make_rand_name();
|
||||
setenv(n, ~"VALUE");
|
||||
fail_unless!(getenv(n) == option::Some(~"VALUE"));
|
||||
assert!(getenv(n) == option::Some(~"VALUE"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1301,9 +1301,9 @@ mod tests {
|
|||
let n = make_rand_name();
|
||||
setenv(n, ~"1");
|
||||
setenv(n, ~"2");
|
||||
fail_unless!(getenv(n) == option::Some(~"2"));
|
||||
assert!(getenv(n) == option::Some(~"2"));
|
||||
setenv(n, ~"");
|
||||
fail_unless!(getenv(n) == option::Some(~""));
|
||||
assert!(getenv(n) == option::Some(~""));
|
||||
}
|
||||
|
||||
// Windows GetEnvironmentVariable requires some extra work to make sure
|
||||
|
@ -1318,25 +1318,25 @@ mod tests {
|
|||
let n = make_rand_name();
|
||||
setenv(n, s);
|
||||
debug!(copy s);
|
||||
fail_unless!(getenv(n) == option::Some(s));
|
||||
assert!(getenv(n) == option::Some(s));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_self_exe_path() {
|
||||
let path = os::self_exe_path();
|
||||
fail_unless!(path.is_some());
|
||||
assert!(path.is_some());
|
||||
let path = path.get();
|
||||
debug!(copy path);
|
||||
|
||||
// Hard to test this function
|
||||
fail_unless!(path.is_absolute);
|
||||
assert!(path.is_absolute);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_env_getenv() {
|
||||
let e = env();
|
||||
fail_unless!(vec::len(e) > 0u);
|
||||
assert!(vec::len(e) > 0u);
|
||||
for vec::each(e) |p| {
|
||||
let (n, v) = copy *p;
|
||||
debug!(copy n);
|
||||
|
@ -1344,7 +1344,7 @@ mod tests {
|
|||
// MingW seems to set some funky environment variables like
|
||||
// "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned
|
||||
// from env() but not visible from getenv().
|
||||
fail_unless!(v2.is_none() || v2 == option::Some(v));
|
||||
assert!(v2.is_none() || v2 == option::Some(v));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1354,15 +1354,15 @@ mod tests {
|
|||
|
||||
let mut e = env();
|
||||
setenv(n, ~"VALUE");
|
||||
fail_unless!(!vec::contains(e, &(copy n, ~"VALUE")));
|
||||
assert!(!vec::contains(e, &(copy n, ~"VALUE")));
|
||||
|
||||
e = env();
|
||||
fail_unless!(vec::contains(e, &(n, ~"VALUE")));
|
||||
assert!(vec::contains(e, &(n, ~"VALUE")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
fail_unless!((!Path("test-path").is_absolute));
|
||||
assert!((!Path("test-path").is_absolute));
|
||||
|
||||
debug!(~"Current working directory: " + getcwd().to_str());
|
||||
|
||||
|
@ -1376,10 +1376,10 @@ mod tests {
|
|||
let oldhome = getenv(~"HOME");
|
||||
|
||||
setenv(~"HOME", ~"/home/MountainView");
|
||||
fail_unless!(os::homedir() == Some(Path("/home/MountainView")));
|
||||
assert!(os::homedir() == Some(Path("/home/MountainView")));
|
||||
|
||||
setenv(~"HOME", ~"");
|
||||
fail_unless!(os::homedir().is_none());
|
||||
assert!(os::homedir().is_none());
|
||||
|
||||
for oldhome.each |s| { setenv(~"HOME", *s) }
|
||||
}
|
||||
|
@ -1394,19 +1394,19 @@ mod tests {
|
|||
setenv(~"HOME", ~"");
|
||||
setenv(~"USERPROFILE", ~"");
|
||||
|
||||
fail_unless!(os::homedir().is_none());
|
||||
assert!(os::homedir().is_none());
|
||||
|
||||
setenv(~"HOME", ~"/home/MountainView");
|
||||
fail_unless!(os::homedir() == Some(Path("/home/MountainView")));
|
||||
assert!(os::homedir() == Some(Path("/home/MountainView")));
|
||||
|
||||
setenv(~"HOME", ~"");
|
||||
|
||||
setenv(~"USERPROFILE", ~"/home/MountainView");
|
||||
fail_unless!(os::homedir() == Some(Path("/home/MountainView")));
|
||||
assert!(os::homedir() == Some(Path("/home/MountainView")));
|
||||
|
||||
setenv(~"HOME", ~"/home/MountainView");
|
||||
setenv(~"USERPROFILE", ~"/home/PaloAlto");
|
||||
fail_unless!(os::homedir() == Some(Path("/home/MountainView")));
|
||||
assert!(os::homedir() == Some(Path("/home/MountainView")));
|
||||
|
||||
oldhome.each(|s| {setenv(~"HOME", *s);true});
|
||||
olduserprofile.each(|s| {setenv(~"USERPROFILE", *s);true});
|
||||
|
@ -1414,7 +1414,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn tmpdir() {
|
||||
fail_unless!(!str::is_empty(os::tmpdir().to_str()));
|
||||
assert!(!str::is_empty(os::tmpdir().to_str()));
|
||||
}
|
||||
|
||||
// Issue #712
|
||||
|
@ -1427,7 +1427,7 @@ mod tests {
|
|||
fn list_dir() {
|
||||
let dirs = os::list_dir(&Path("."));
|
||||
// Just assuming that we've got some contents in the current directory
|
||||
fail_unless!((vec::len(dirs) > 0u));
|
||||
assert!((vec::len(dirs) > 0u));
|
||||
|
||||
for vec::each(dirs) |dir| {
|
||||
debug!(copy *dir);
|
||||
|
@ -1436,22 +1436,22 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn path_is_dir() {
|
||||
fail_unless!((os::path_is_dir(&Path("."))));
|
||||
fail_unless!((!os::path_is_dir(&Path("test/stdtest/fs.rs"))));
|
||||
assert!((os::path_is_dir(&Path("."))));
|
||||
assert!((!os::path_is_dir(&Path("test/stdtest/fs.rs"))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn path_exists() {
|
||||
fail_unless!((os::path_exists(&Path("."))));
|
||||
fail_unless!((!os::path_exists(&Path(
|
||||
assert!((os::path_exists(&Path("."))));
|
||||
assert!((!os::path_exists(&Path(
|
||||
"test/nonexistent-bogus-path"))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copy_file_does_not_exist() {
|
||||
fail_unless!(!os::copy_file(&Path("test/nonexistent-bogus-path"),
|
||||
assert!(!os::copy_file(&Path("test/nonexistent-bogus-path"),
|
||||
&Path("test/other-bogus-path")));
|
||||
fail_unless!(!os::path_exists(&Path("test/other-bogus-path")));
|
||||
assert!(!os::path_exists(&Path("test/other-bogus-path")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1459,7 +1459,7 @@ mod tests {
|
|||
unsafe {
|
||||
let tempdir = getcwd(); // would like to use $TMPDIR,
|
||||
// doesn't seem to work on Linux
|
||||
fail_unless!((str::len(tempdir.to_str()) > 0u));
|
||||
assert!((str::len(tempdir.to_str()) > 0u));
|
||||
let in = tempdir.push("in.txt");
|
||||
let out = tempdir.push("out.txt");
|
||||
|
||||
|
@ -1469,24 +1469,24 @@ mod tests {
|
|||
libc::fopen(fromp, modebuf)
|
||||
}
|
||||
};
|
||||
fail_unless!((ostream as uint != 0u));
|
||||
assert!((ostream as uint != 0u));
|
||||
let s = ~"hello";
|
||||
let mut buf = str::to_bytes(s) + ~[0 as u8];
|
||||
do vec::as_mut_buf(buf) |b, _len| {
|
||||
fail_unless!((libc::fwrite(b as *c_void, 1u as size_t,
|
||||
assert!((libc::fwrite(b as *c_void, 1u as size_t,
|
||||
(str::len(s) + 1u) as size_t, ostream)
|
||||
== buf.len() as size_t))
|
||||
}
|
||||
fail_unless!((libc::fclose(ostream) == (0u as c_int)));
|
||||
assert!((libc::fclose(ostream) == (0u as c_int)));
|
||||
let rs = os::copy_file(&in, &out);
|
||||
if (!os::path_exists(&in)) {
|
||||
fail!(fmt!("%s doesn't exist", in.to_str()));
|
||||
}
|
||||
fail_unless!((rs));
|
||||
assert!((rs));
|
||||
let rslt = run::run_program(~"diff", ~[in.to_str(), out.to_str()]);
|
||||
fail_unless!((rslt == 0));
|
||||
fail_unless!((remove_file(&in)));
|
||||
fail_unless!((remove_file(&out)));
|
||||
assert!((rslt == 0));
|
||||
assert!((remove_file(&in)));
|
||||
assert!((remove_file(&out)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -440,7 +440,7 @@ impl GenericPath for PosixPath {
|
|||
|
||||
fn with_filename(&self, f: &str) -> PosixPath {
|
||||
unsafe {
|
||||
fail_unless!(! str::any(f, |c| windows::is_sep(c as u8)));
|
||||
assert!(! str::any(f, |c| windows::is_sep(c as u8)));
|
||||
self.dir_path().push(f)
|
||||
}
|
||||
}
|
||||
|
@ -485,7 +485,7 @@ impl GenericPath for PosixPath {
|
|||
}
|
||||
|
||||
fn push_rel(&self, other: &PosixPath) -> PosixPath {
|
||||
fail_unless!(!other.is_absolute);
|
||||
assert!(!other.is_absolute);
|
||||
self.push_many(other.components)
|
||||
}
|
||||
|
||||
|
@ -657,7 +657,7 @@ impl GenericPath for WindowsPath {
|
|||
}
|
||||
|
||||
fn with_filename(&self, f: &str) -> WindowsPath {
|
||||
fail_unless!(! str::any(f, |c| windows::is_sep(c as u8)));
|
||||
assert!(! str::any(f, |c| windows::is_sep(c as u8)));
|
||||
self.dir_path().push(f)
|
||||
}
|
||||
|
||||
|
@ -704,7 +704,7 @@ impl GenericPath for WindowsPath {
|
|||
}
|
||||
|
||||
fn push_rel(&self, other: &WindowsPath) -> WindowsPath {
|
||||
fail_unless!(!other.is_absolute);
|
||||
assert!(!other.is_absolute);
|
||||
self.push_many(other.components)
|
||||
}
|
||||
|
||||
|
@ -891,30 +891,30 @@ mod tests {
|
|||
let path = PosixPath("tmp/");
|
||||
let path = path.push("/hmm");
|
||||
let path = path.normalize();
|
||||
fail_unless!(~"tmp/hmm" == path.to_str());
|
||||
assert!(~"tmp/hmm" == path.to_str());
|
||||
|
||||
let path = WindowsPath("tmp/");
|
||||
let path = path.push("/hmm");
|
||||
let path = path.normalize();
|
||||
fail_unless!(~"tmp\\hmm" == path.to_str());
|
||||
assert!(~"tmp\\hmm" == path.to_str());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filetype_foo_bar() {
|
||||
let wp = PosixPath("foo.bar");
|
||||
fail_unless!(wp.filetype() == Some(~".bar"));
|
||||
assert!(wp.filetype() == Some(~".bar"));
|
||||
|
||||
let wp = WindowsPath("foo.bar");
|
||||
fail_unless!(wp.filetype() == Some(~".bar"));
|
||||
assert!(wp.filetype() == Some(~".bar"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filetype_foo() {
|
||||
let wp = PosixPath("foo");
|
||||
fail_unless!(wp.filetype() == None);
|
||||
assert!(wp.filetype() == None);
|
||||
|
||||
let wp = WindowsPath("foo");
|
||||
fail_unless!(wp.filetype() == None);
|
||||
assert!(wp.filetype() == None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -925,7 +925,7 @@ mod tests {
|
|||
if (ss != sss) {
|
||||
debug!("got %s", ss);
|
||||
debug!("expected %s", sss);
|
||||
fail_unless!(ss == sss);
|
||||
assert!(ss == sss);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -983,7 +983,7 @@ mod tests {
|
|||
if (ss != sss) {
|
||||
debug!("got %s", ss);
|
||||
debug!("expected %s", sss);
|
||||
fail_unless!(ss == sss);
|
||||
assert!(ss == sss);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -999,42 +999,42 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_extract_unc_prefixes() {
|
||||
fail_unless!(windows::extract_unc_prefix("\\\\").is_none());
|
||||
fail_unless!(windows::extract_unc_prefix("//").is_none());
|
||||
fail_unless!(windows::extract_unc_prefix("\\\\hi").is_none());
|
||||
fail_unless!(windows::extract_unc_prefix("//hi").is_none());
|
||||
fail_unless!(windows::extract_unc_prefix("\\\\hi\\") ==
|
||||
assert!(windows::extract_unc_prefix("\\\\").is_none());
|
||||
assert!(windows::extract_unc_prefix("//").is_none());
|
||||
assert!(windows::extract_unc_prefix("\\\\hi").is_none());
|
||||
assert!(windows::extract_unc_prefix("//hi").is_none());
|
||||
assert!(windows::extract_unc_prefix("\\\\hi\\") ==
|
||||
Some((~"hi", ~"\\")));
|
||||
fail_unless!(windows::extract_unc_prefix("//hi\\") ==
|
||||
assert!(windows::extract_unc_prefix("//hi\\") ==
|
||||
Some((~"hi", ~"\\")));
|
||||
fail_unless!(windows::extract_unc_prefix("\\\\hi\\there") ==
|
||||
assert!(windows::extract_unc_prefix("\\\\hi\\there") ==
|
||||
Some((~"hi", ~"\\there")));
|
||||
fail_unless!(windows::extract_unc_prefix("//hi/there") ==
|
||||
assert!(windows::extract_unc_prefix("//hi/there") ==
|
||||
Some((~"hi", ~"/there")));
|
||||
fail_unless!(windows::extract_unc_prefix(
|
||||
assert!(windows::extract_unc_prefix(
|
||||
"\\\\hi\\there\\friends.txt") ==
|
||||
Some((~"hi", ~"\\there\\friends.txt")));
|
||||
fail_unless!(windows::extract_unc_prefix(
|
||||
assert!(windows::extract_unc_prefix(
|
||||
"//hi\\there\\friends.txt") ==
|
||||
Some((~"hi", ~"\\there\\friends.txt")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_drive_prefixes() {
|
||||
fail_unless!(windows::extract_drive_prefix("c").is_none());
|
||||
fail_unless!(windows::extract_drive_prefix("c:") ==
|
||||
assert!(windows::extract_drive_prefix("c").is_none());
|
||||
assert!(windows::extract_drive_prefix("c:") ==
|
||||
Some((~"c", ~"")));
|
||||
fail_unless!(windows::extract_drive_prefix("d:") ==
|
||||
assert!(windows::extract_drive_prefix("d:") ==
|
||||
Some((~"d", ~"")));
|
||||
fail_unless!(windows::extract_drive_prefix("z:") ==
|
||||
assert!(windows::extract_drive_prefix("z:") ==
|
||||
Some((~"z", ~"")));
|
||||
fail_unless!(windows::extract_drive_prefix("c:\\hi") ==
|
||||
assert!(windows::extract_drive_prefix("c:\\hi") ==
|
||||
Some((~"c", ~"\\hi")));
|
||||
fail_unless!(windows::extract_drive_prefix("d:hi") ==
|
||||
assert!(windows::extract_drive_prefix("d:hi") ==
|
||||
Some((~"d", ~"hi")));
|
||||
fail_unless!(windows::extract_drive_prefix("c:hi\\there.txt") ==
|
||||
assert!(windows::extract_drive_prefix("c:hi\\there.txt") ==
|
||||
Some((~"c", ~"hi\\there.txt")));
|
||||
fail_unless!(windows::extract_drive_prefix("c:\\hi\\there.txt") ==
|
||||
assert!(windows::extract_drive_prefix("c:\\hi\\there.txt") ==
|
||||
Some((~"c", ~"\\hi\\there.txt")));
|
||||
}
|
||||
|
||||
|
@ -1046,7 +1046,7 @@ mod tests {
|
|||
if (ss != sss) {
|
||||
debug!("got %s", ss);
|
||||
debug!("expected %s", sss);
|
||||
fail_unless!(ss == sss);
|
||||
assert!(ss == sss);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1131,9 +1131,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_windows_path_restrictions() {
|
||||
fail_unless!(WindowsPath("hi").is_restricted() == false);
|
||||
fail_unless!(WindowsPath("C:\\NUL").is_restricted() == true);
|
||||
fail_unless!(WindowsPath("C:\\COM1.TXT").is_restricted() == true);
|
||||
fail_unless!(WindowsPath("c:\\prn.exe").is_restricted() == true);
|
||||
assert!(WindowsPath("hi").is_restricted() == false);
|
||||
assert!(WindowsPath("C:\\NUL").is_restricted() == true);
|
||||
assert!(WindowsPath("C:\\COM1.TXT").is_restricted() == true);
|
||||
assert!(WindowsPath("c:\\prn.exe").is_restricted() == true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ pub impl PacketHeader {
|
|||
unsafe fn mark_blocked(&self, this: *rust_task) -> State {
|
||||
rustrt::rust_task_ref(this);
|
||||
let old_task = swap_task(&mut self.blocked_task, this);
|
||||
fail_unless!(old_task.is_null());
|
||||
assert!(old_task.is_null());
|
||||
swap_state_acq(&mut self.state, Blocked)
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ pub impl PacketHeader {
|
|||
// continuum. It ends making multiple unique pointers to the same
|
||||
// thing. You'll proobably want to forget them when you're done.
|
||||
unsafe fn buf_header(&self) -> ~BufferHeader {
|
||||
fail_unless!(self.buffer.is_not_null());
|
||||
assert!(self.buffer.is_not_null());
|
||||
reinterpret_cast(&self.buffer)
|
||||
}
|
||||
|
||||
|
@ -379,8 +379,8 @@ pub fn send<T,Tbuffer>(p: SendPacketBuffered<T,Tbuffer>, payload: T) -> bool {
|
|||
let header = p.header();
|
||||
let p_ = p.unwrap();
|
||||
let p = unsafe { &*p_ };
|
||||
fail_unless!(ptr::addr_of(&(p.header)) == header);
|
||||
fail_unless!(p.payload.is_none());
|
||||
assert!(ptr::addr_of(&(p.header)) == header);
|
||||
assert!(p.payload.is_none());
|
||||
p.payload = Some(payload);
|
||||
let old_state = swap_state_rel(&mut p.header.state, Full);
|
||||
match old_state {
|
||||
|
@ -482,7 +482,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
|
|||
debug!("blocked = %x this = %x old_task = %x",
|
||||
p.header.blocked_task as uint,
|
||||
this as uint, old_task as uint);
|
||||
fail_unless!(old_task.is_null());
|
||||
assert!(old_task.is_null());
|
||||
let mut first = true;
|
||||
let mut count = SPIN_COUNT;
|
||||
loop {
|
||||
|
@ -527,7 +527,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
|
|||
Terminated => {
|
||||
// This assert detects when we've accidentally unsafely
|
||||
// casted too big of a number to a state.
|
||||
fail_unless!(old_state == Terminated);
|
||||
assert!(old_state == Terminated);
|
||||
|
||||
let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
|
||||
if !old_task.is_null() {
|
||||
|
@ -576,7 +576,7 @@ fn sender_terminate<T:Owned>(p: *Packet<T>) {
|
|||
fail!(~"you dun goofed")
|
||||
}
|
||||
Terminated => {
|
||||
fail_unless!(p.header.blocked_task.is_null());
|
||||
assert!(p.header.blocked_task.is_null());
|
||||
// I have to clean up, use drop_glue
|
||||
}
|
||||
}
|
||||
|
@ -587,7 +587,7 @@ fn receiver_terminate<T:Owned>(p: *Packet<T>) {
|
|||
let p = unsafe { &*p };
|
||||
match swap_state_rel(&mut p.header.state, Terminated) {
|
||||
Empty => {
|
||||
fail_unless!(p.header.blocked_task.is_null());
|
||||
assert!(p.header.blocked_task.is_null());
|
||||
// the sender will clean up
|
||||
}
|
||||
Blocked => {
|
||||
|
@ -595,12 +595,12 @@ fn receiver_terminate<T:Owned>(p: *Packet<T>) {
|
|||
if !old_task.is_null() {
|
||||
unsafe {
|
||||
rustrt::rust_task_deref(old_task);
|
||||
fail_unless!(old_task == rustrt::rust_get_task());
|
||||
assert!(old_task == rustrt::rust_get_task());
|
||||
}
|
||||
}
|
||||
}
|
||||
Terminated | Full => {
|
||||
fail_unless!(p.header.blocked_task.is_null());
|
||||
assert!(p.header.blocked_task.is_null());
|
||||
// I have to clean up, use drop_glue
|
||||
}
|
||||
}
|
||||
|
@ -663,7 +663,7 @@ pub fn wait_many<T: Selectable>(pkts: &[T]) -> uint {
|
|||
debug!("%?, %?", ready_packet, pkts[ready_packet]);
|
||||
|
||||
unsafe {
|
||||
fail_unless!((*pkts[ready_packet].header()).state == Full
|
||||
assert!((*pkts[ready_packet].header()).state == Full
|
||||
|| (*pkts[ready_packet].header()).state == Terminated);
|
||||
}
|
||||
|
||||
|
@ -995,6 +995,6 @@ pub mod test {
|
|||
let _chan = chan;
|
||||
}
|
||||
|
||||
fail_unless!(!port.peek());
|
||||
assert!(!port.peek());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -352,29 +352,29 @@ pub fn test() {
|
|||
let mut p = Pair {fst: 10, snd: 20};
|
||||
let pptr: *mut Pair = &mut p;
|
||||
let iptr: *mut int = cast::reinterpret_cast(&pptr);
|
||||
fail_unless!((*iptr == 10));;
|
||||
assert!((*iptr == 10));;
|
||||
*iptr = 30;
|
||||
fail_unless!((*iptr == 30));
|
||||
fail_unless!((p.fst == 30));;
|
||||
assert!((*iptr == 30));
|
||||
assert!((p.fst == 30));;
|
||||
|
||||
*pptr = Pair {fst: 50, snd: 60};
|
||||
fail_unless!((*iptr == 50));
|
||||
fail_unless!((p.fst == 50));
|
||||
fail_unless!((p.snd == 60));
|
||||
assert!((*iptr == 50));
|
||||
assert!((p.fst == 50));
|
||||
assert!((p.snd == 60));
|
||||
|
||||
let mut v0 = ~[32000u16, 32001u16, 32002u16];
|
||||
let mut v1 = ~[0u16, 0u16, 0u16];
|
||||
|
||||
copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 1u),
|
||||
offset(vec::raw::to_ptr(v0), 1u), 1u);
|
||||
fail_unless!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16));
|
||||
assert!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16));
|
||||
copy_memory(vec::raw::to_mut_ptr(v1),
|
||||
offset(vec::raw::to_ptr(v0), 2u), 1u);
|
||||
fail_unless!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
|
||||
assert!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
|
||||
v1[2] == 0u16));
|
||||
copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 2u),
|
||||
vec::raw::to_ptr(v0), 1u);
|
||||
fail_unless!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
|
||||
assert!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
|
||||
v1[2] == 32000u16));
|
||||
}
|
||||
}
|
||||
|
@ -386,11 +386,11 @@ pub fn test_position() {
|
|||
|
||||
let s = ~"hello";
|
||||
unsafe {
|
||||
fail_unless!(2u == as_c_str(s, |p| position(p,
|
||||
assert!(2u == as_c_str(s, |p| position(p,
|
||||
|c| *c == 'l' as c_char)));
|
||||
fail_unless!(4u == as_c_str(s, |p| position(p,
|
||||
assert!(4u == as_c_str(s, |p| position(p,
|
||||
|c| *c == 'o' as c_char)));
|
||||
fail_unless!(5u == as_c_str(s, |p| position(p,
|
||||
assert!(5u == as_c_str(s, |p| position(p,
|
||||
|c| *c == 0 as c_char)));
|
||||
}
|
||||
}
|
||||
|
@ -405,8 +405,8 @@ pub fn test_buf_len() {
|
|||
do str::as_c_str(s2) |p2| {
|
||||
let v = ~[p0, p1, p2, null()];
|
||||
do vec::as_imm_buf(v) |vp, len| {
|
||||
fail_unless!(unsafe { buf_len(vp) } == 3u);
|
||||
fail_unless!(len == 4u);
|
||||
assert!(unsafe { buf_len(vp) } == 3u);
|
||||
assert!(len == 4u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -416,20 +416,20 @@ pub fn test_buf_len() {
|
|||
#[test]
|
||||
pub fn test_is_null() {
|
||||
let p: *int = null();
|
||||
fail_unless!(p.is_null());
|
||||
fail_unless!(!p.is_not_null());
|
||||
assert!(p.is_null());
|
||||
assert!(!p.is_not_null());
|
||||
|
||||
let q = offset(p, 1u);
|
||||
fail_unless!(!q.is_null());
|
||||
fail_unless!(q.is_not_null());
|
||||
assert!(!q.is_null());
|
||||
assert!(q.is_not_null());
|
||||
|
||||
let mp: *mut int = mut_null();
|
||||
fail_unless!(mp.is_null());
|
||||
fail_unless!(!mp.is_not_null());
|
||||
assert!(mp.is_null());
|
||||
assert!(!mp.is_not_null());
|
||||
|
||||
let mq = mp.offset(1u);
|
||||
fail_unless!(!mq.is_null());
|
||||
fail_unless!(mq.is_not_null());
|
||||
assert!(!mq.is_null());
|
||||
assert!(mq.is_not_null());
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -462,11 +462,11 @@ pub mod ptr_tests {
|
|||
debug!(
|
||||
"test_ptr_array_each e: %s, a: %s",
|
||||
expected, actual);
|
||||
fail_unless!(actual == expected);
|
||||
assert!(actual == expected);
|
||||
ctr += 1;
|
||||
iteration_count += 1;
|
||||
});
|
||||
fail_unless!(iteration_count == 3u);
|
||||
assert!(iteration_count == 3u);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
|
@ -494,11 +494,11 @@ pub mod ptr_tests {
|
|||
debug!(
|
||||
"test_ptr_array_each e: %s, a: %s",
|
||||
expected, actual);
|
||||
fail_unless!(actual == expected);
|
||||
assert!(actual == expected);
|
||||
ctr += 1;
|
||||
iteration_count += 1;
|
||||
});
|
||||
fail_unless!(iteration_count == 3);
|
||||
assert!(iteration_count == 3);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
|
|
|
@ -240,7 +240,7 @@ impl RngUtil for @Rng {
|
|||
* failing if start >= end
|
||||
*/
|
||||
fn gen_int_range(&self, start: int, end: int) -> int {
|
||||
fail_unless!(start < end);
|
||||
assert!(start < end);
|
||||
start + int::abs(self.gen_int() % (end - start))
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ impl RngUtil for @Rng {
|
|||
* failing if start >= end
|
||||
*/
|
||||
fn gen_uint_range(&self, start: uint, end: uint) -> uint {
|
||||
fail_unless!(start < end);
|
||||
assert!(start < end);
|
||||
start + (self.gen_uint() % (end - start))
|
||||
}
|
||||
|
||||
|
@ -326,7 +326,7 @@ impl RngUtil for @Rng {
|
|||
* Return a char randomly chosen from chars, failing if chars is empty
|
||||
*/
|
||||
fn gen_char_from(&self, chars: &str) -> char {
|
||||
fail_unless!(!chars.is_empty());
|
||||
assert!(!chars.is_empty());
|
||||
let mut cs = ~[];
|
||||
for str::each_char(chars) |c| { cs.push(c) }
|
||||
self.choose(cs)
|
||||
|
@ -582,7 +582,7 @@ pub mod tests {
|
|||
let seed = rand::seed();
|
||||
let ra = rand::seeded_rng(seed);
|
||||
let rb = rand::seeded_rng(seed);
|
||||
fail_unless!(ra.gen_str(100u) == rb.gen_str(100u));
|
||||
assert!(ra.gen_str(100u) == rb.gen_str(100u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -591,7 +591,7 @@ pub mod tests {
|
|||
let seed = [2u8, 32u8, 4u8, 32u8, 51u8];
|
||||
let ra = rand::seeded_rng(seed);
|
||||
let rb = rand::seeded_rng(seed);
|
||||
fail_unless!(ra.gen_str(100u) == rb.gen_str(100u));
|
||||
assert!(ra.gen_str(100u) == rb.gen_str(100u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -601,7 +601,7 @@ pub mod tests {
|
|||
// Regression test that isaac is actually using the above vector
|
||||
let r = ra.next();
|
||||
error!("%?", r);
|
||||
fail_unless!(r == 890007737u32 // on x86_64
|
||||
assert!(r == 890007737u32 // on x86_64
|
||||
|| r == 2935188040u32); // on x86
|
||||
}
|
||||
|
||||
|
@ -609,9 +609,9 @@ pub mod tests {
|
|||
pub fn gen_int_range() {
|
||||
let r = rand::Rng();
|
||||
let a = r.gen_int_range(-3, 42);
|
||||
fail_unless!(a >= -3 && a < 42);
|
||||
fail_unless!(r.gen_int_range(0, 1) == 0);
|
||||
fail_unless!(r.gen_int_range(-12, -11) == -12);
|
||||
assert!(a >= -3 && a < 42);
|
||||
assert!(r.gen_int_range(0, 1) == 0);
|
||||
assert!(r.gen_int_range(-12, -11) == -12);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -625,9 +625,9 @@ pub mod tests {
|
|||
pub fn gen_uint_range() {
|
||||
let r = rand::Rng();
|
||||
let a = r.gen_uint_range(3u, 42u);
|
||||
fail_unless!(a >= 3u && a < 42u);
|
||||
fail_unless!(r.gen_uint_range(0u, 1u) == 0u);
|
||||
fail_unless!(r.gen_uint_range(12u, 13u) == 12u);
|
||||
assert!(a >= 3u && a < 42u);
|
||||
assert!(r.gen_uint_range(0u, 1u) == 0u);
|
||||
assert!(r.gen_uint_range(12u, 13u) == 12u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -648,8 +648,8 @@ pub mod tests {
|
|||
#[test]
|
||||
pub fn gen_weighted_bool() {
|
||||
let r = rand::Rng();
|
||||
fail_unless!(r.gen_weighted_bool(0u) == true);
|
||||
fail_unless!(r.gen_weighted_bool(1u) == true);
|
||||
assert!(r.gen_weighted_bool(0u) == true);
|
||||
assert!(r.gen_weighted_bool(1u) == true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -658,40 +658,40 @@ pub mod tests {
|
|||
debug!(r.gen_str(10u));
|
||||
debug!(r.gen_str(10u));
|
||||
debug!(r.gen_str(10u));
|
||||
fail_unless!(r.gen_str(0u).len() == 0u);
|
||||
fail_unless!(r.gen_str(10u).len() == 10u);
|
||||
fail_unless!(r.gen_str(16u).len() == 16u);
|
||||
assert!(r.gen_str(0u).len() == 0u);
|
||||
assert!(r.gen_str(10u).len() == 10u);
|
||||
assert!(r.gen_str(16u).len() == 16u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn gen_bytes() {
|
||||
let r = rand::Rng();
|
||||
fail_unless!(r.gen_bytes(0u).len() == 0u);
|
||||
fail_unless!(r.gen_bytes(10u).len() == 10u);
|
||||
fail_unless!(r.gen_bytes(16u).len() == 16u);
|
||||
assert!(r.gen_bytes(0u).len() == 0u);
|
||||
assert!(r.gen_bytes(10u).len() == 10u);
|
||||
assert!(r.gen_bytes(16u).len() == 16u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn choose() {
|
||||
let r = rand::Rng();
|
||||
fail_unless!(r.choose([1, 1, 1]) == 1);
|
||||
assert!(r.choose([1, 1, 1]) == 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn choose_option() {
|
||||
let r = rand::Rng();
|
||||
let x: Option<int> = r.choose_option([]);
|
||||
fail_unless!(x.is_none());
|
||||
fail_unless!(r.choose_option([1, 1, 1]) == Some(1));
|
||||
assert!(x.is_none());
|
||||
assert!(r.choose_option([1, 1, 1]) == Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn choose_weighted() {
|
||||
let r = rand::Rng();
|
||||
fail_unless!(r.choose_weighted(~[
|
||||
assert!(r.choose_weighted(~[
|
||||
rand::Weighted { weight: 1u, item: 42 },
|
||||
]) == 42);
|
||||
fail_unless!(r.choose_weighted(~[
|
||||
assert!(r.choose_weighted(~[
|
||||
rand::Weighted { weight: 0u, item: 42 },
|
||||
rand::Weighted { weight: 1u, item: 43 },
|
||||
]) == 43);
|
||||
|
@ -700,23 +700,23 @@ pub mod tests {
|
|||
#[test]
|
||||
pub fn choose_weighted_option() {
|
||||
let r = rand::Rng();
|
||||
fail_unless!(r.choose_weighted_option(~[
|
||||
assert!(r.choose_weighted_option(~[
|
||||
rand::Weighted { weight: 1u, item: 42 },
|
||||
]) == Some(42));
|
||||
fail_unless!(r.choose_weighted_option(~[
|
||||
assert!(r.choose_weighted_option(~[
|
||||
rand::Weighted { weight: 0u, item: 42 },
|
||||
rand::Weighted { weight: 1u, item: 43 },
|
||||
]) == Some(43));
|
||||
let v: Option<int> = r.choose_weighted_option([]);
|
||||
fail_unless!(v.is_none());
|
||||
assert!(v.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn weighted_vec() {
|
||||
let r = rand::Rng();
|
||||
let empty: ~[int] = ~[];
|
||||
fail_unless!(r.weighted_vec(~[]) == empty);
|
||||
fail_unless!(r.weighted_vec(~[
|
||||
assert!(r.weighted_vec(~[]) == empty);
|
||||
assert!(r.weighted_vec(~[
|
||||
rand::Weighted { weight: 0u, item: 3u },
|
||||
rand::Weighted { weight: 1u, item: 2u },
|
||||
rand::Weighted { weight: 2u, item: 1u },
|
||||
|
@ -727,16 +727,16 @@ pub mod tests {
|
|||
pub fn shuffle() {
|
||||
let r = rand::Rng();
|
||||
let empty: ~[int] = ~[];
|
||||
fail_unless!(r.shuffle(~[]) == empty);
|
||||
fail_unless!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]);
|
||||
assert!(r.shuffle(~[]) == empty);
|
||||
assert!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn task_rng() {
|
||||
let r = rand::task_rng();
|
||||
r.gen_int();
|
||||
fail_unless!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]);
|
||||
fail_unless!(r.gen_uint_range(0u, 1u) == 0u);
|
||||
assert!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]);
|
||||
assert!(r.gen_uint_range(0u, 1u) == 0u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -229,7 +229,7 @@ pub impl ReprVisitor {
|
|||
} else if mtbl == 1 {
|
||||
// skip, this is ast::m_imm
|
||||
} else {
|
||||
fail_unless!(mtbl == 2);
|
||||
assert!(mtbl == 2);
|
||||
self.writer.write_str("const ");
|
||||
}
|
||||
}
|
||||
|
@ -591,7 +591,7 @@ fn test_repr() {
|
|||
error!("expected '%s', got '%s'",
|
||||
e, s);
|
||||
}
|
||||
fail_unless!(s == e);
|
||||
assert!(s == e);
|
||||
}
|
||||
|
||||
exact_test(&10, "10");
|
||||
|
|
|
@ -294,7 +294,7 @@ pub impl<T, E: Copy> Result<T, E> {
|
|||
* else { return ok(x+1u); }
|
||||
* }
|
||||
* map(~[1u, 2u, 3u], inc_conditionally).chain {|incd|
|
||||
* fail_unless!(incd == ~[2u, 3u, 4u]);
|
||||
* assert!(incd == ~[2u, 3u, 4u]);
|
||||
* }
|
||||
*/
|
||||
#[inline(always)]
|
||||
|
@ -337,7 +337,7 @@ pub fn map_opt<T,U:Copy,V:Copy>(
|
|||
pub fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
|
||||
op: &fn(&S,&T) -> Result<V,U>) -> Result<~[V],U> {
|
||||
|
||||
fail_unless!(vec::same_length(ss, ts));
|
||||
assert!(vec::same_length(ss, ts));
|
||||
let n = vec::len(ts);
|
||||
let mut vs = vec::with_capacity(n);
|
||||
let mut i = 0u;
|
||||
|
@ -360,7 +360,7 @@ pub fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
|
|||
pub fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
|
||||
op: &fn(&S,&T) -> Result<(),U>) -> Result<(),U> {
|
||||
|
||||
fail_unless!(vec::same_length(ss, ts));
|
||||
assert!(vec::same_length(ss, ts));
|
||||
let n = vec::len(ts);
|
||||
let mut i = 0u;
|
||||
while i < n {
|
||||
|
@ -407,50 +407,50 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn chain_success() {
|
||||
fail_unless!(get(&chain(op1(), op2)) == 667u);
|
||||
assert!(get(&chain(op1(), op2)) == 667u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn chain_failure() {
|
||||
fail_unless!(get_err(&chain(op3(), op2)) == ~"sadface");
|
||||
assert!(get_err(&chain(op3(), op2)) == ~"sadface");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_impl_iter() {
|
||||
let mut valid = false;
|
||||
Ok::<~str, ~str>(~"a").iter(|_x| valid = true);
|
||||
fail_unless!(valid);
|
||||
assert!(valid);
|
||||
|
||||
Err::<~str, ~str>(~"b").iter(|_x| valid = false);
|
||||
fail_unless!(valid);
|
||||
assert!(valid);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_impl_iter_err() {
|
||||
let mut valid = true;
|
||||
Ok::<~str, ~str>(~"a").iter_err(|_x| valid = false);
|
||||
fail_unless!(valid);
|
||||
assert!(valid);
|
||||
|
||||
valid = false;
|
||||
Err::<~str, ~str>(~"b").iter_err(|_x| valid = true);
|
||||
fail_unless!(valid);
|
||||
assert!(valid);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_impl_map() {
|
||||
fail_unless!(Ok::<~str, ~str>(~"a").map(|_x| ~"b") == Ok(~"b"));
|
||||
fail_unless!(Err::<~str, ~str>(~"a").map(|_x| ~"b") == Err(~"a"));
|
||||
assert!(Ok::<~str, ~str>(~"a").map(|_x| ~"b") == Ok(~"b"));
|
||||
assert!(Err::<~str, ~str>(~"a").map(|_x| ~"b") == Err(~"a"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_impl_map_err() {
|
||||
fail_unless!(Ok::<~str, ~str>(~"a").map_err(|_x| ~"b") == Ok(~"a"));
|
||||
fail_unless!(Err::<~str, ~str>(~"a").map_err(|_x| ~"b") == Err(~"b"));
|
||||
assert!(Ok::<~str, ~str>(~"a").map_err(|_x| ~"b") == Ok(~"a"));
|
||||
assert!(Err::<~str, ~str>(~"a").map_err(|_x| ~"b") == Err(~"b"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_get_ref_method() {
|
||||
let foo: Result<int, ()> = Ok(100);
|
||||
fail_unless!(*foo.get_ref() == 100);
|
||||
assert!(*foo.get_ref() == 100);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ pub impl Scheduler {
|
|||
// That will be important for embedding the runtime into external
|
||||
// event loops.
|
||||
fn run(~self) -> ~Scheduler {
|
||||
fail_unless!(!self.in_task_context());
|
||||
assert!(!self.in_task_context());
|
||||
|
||||
// Give ownership of the scheduler (self) to the thread
|
||||
do self.install |scheduler| {
|
||||
|
@ -129,7 +129,7 @@ pub impl Scheduler {
|
|||
// * Scheduler-context operations
|
||||
|
||||
fn resume_task_from_queue(&mut self) -> bool {
|
||||
fail_unless!(!self.in_task_context());
|
||||
assert!(!self.in_task_context());
|
||||
|
||||
let mut self = self;
|
||||
match self.task_queue.pop_front() {
|
||||
|
@ -145,7 +145,7 @@ pub impl Scheduler {
|
|||
}
|
||||
|
||||
fn resume_task_immediately(&mut self, task: ~Task) {
|
||||
fail_unless!(!self.in_task_context());
|
||||
assert!(!self.in_task_context());
|
||||
|
||||
rtdebug!("scheduling a task");
|
||||
|
||||
|
@ -153,7 +153,7 @@ pub impl Scheduler {
|
|||
self.current_task = Some(task);
|
||||
self.swap_in_task();
|
||||
// The running task should have passed ownership elsewhere
|
||||
fail_unless!(self.current_task.is_none());
|
||||
assert!(self.current_task.is_none());
|
||||
|
||||
// Running tasks may have asked us to do some cleanup
|
||||
self.run_cleanup_jobs();
|
||||
|
@ -165,7 +165,7 @@ pub impl Scheduler {
|
|||
/// Called by a running task to end execution, after which it will
|
||||
/// be recycled by the scheduler for reuse in a new task.
|
||||
fn terminate_current_task(&mut self) {
|
||||
fail_unless!(self.in_task_context());
|
||||
assert!(self.in_task_context());
|
||||
|
||||
rtdebug!("ending running task");
|
||||
|
||||
|
@ -184,7 +184,7 @@ pub impl Scheduler {
|
|||
/// running task. It gets transmuted to the scheduler's lifetime
|
||||
/// and called while the task is blocked.
|
||||
fn block_running_task_and_then(&mut self, f: &fn(&mut Scheduler, ~Task)) {
|
||||
fail_unless!(self.in_task_context());
|
||||
assert!(self.in_task_context());
|
||||
|
||||
rtdebug!("blocking task");
|
||||
|
||||
|
@ -203,7 +203,7 @@ pub impl Scheduler {
|
|||
/// You would want to think hard about doing this, e.g. if there are
|
||||
/// pending I/O events it would be a bad idea.
|
||||
fn resume_task_from_running_task_direct(&mut self, next_task: ~Task) {
|
||||
fail_unless!(self.in_task_context());
|
||||
assert!(self.in_task_context());
|
||||
|
||||
rtdebug!("switching tasks");
|
||||
|
||||
|
@ -255,7 +255,7 @@ pub impl Scheduler {
|
|||
}
|
||||
|
||||
fn run_cleanup_jobs(&mut self) {
|
||||
fail_unless!(!self.in_task_context());
|
||||
assert!(!self.in_task_context());
|
||||
rtdebug!("running cleanup jobs");
|
||||
|
||||
while !self.cleanup_jobs.is_empty() {
|
||||
|
@ -273,7 +273,7 @@ pub impl Scheduler {
|
|||
// XXX: Hack. This should return &'self mut but I don't know how to
|
||||
// make the borrowcheck happy
|
||||
fn task_from_last_cleanup_job(&mut self) -> &mut Task {
|
||||
fail_unless!(!self.cleanup_jobs.is_empty());
|
||||
assert!(!self.cleanup_jobs.is_empty());
|
||||
let last_job: &'self mut CleanupJob = &mut self.cleanup_jobs[0];
|
||||
let last_task: &'self Task = match last_job {
|
||||
&RescheduleTask(~ref task) => task,
|
||||
|
@ -358,7 +358,7 @@ impl ThreadLocalScheduler {
|
|||
unsafe {
|
||||
let key = match self { &ThreadLocalScheduler(key) => key };
|
||||
let mut value: *mut c_void = tls::get(key);
|
||||
fail_unless!(value.is_not_null());
|
||||
assert!(value.is_not_null());
|
||||
{
|
||||
let value_ptr = &mut value;
|
||||
let sched: &mut ~Scheduler = {
|
||||
|
@ -374,7 +374,7 @@ impl ThreadLocalScheduler {
|
|||
unsafe {
|
||||
let key = match self { &ThreadLocalScheduler(key) => key };
|
||||
let value: *mut c_void = tls::get(key);
|
||||
fail_unless!(value.is_not_null());
|
||||
assert!(value.is_not_null());
|
||||
let sched = transmute(value);
|
||||
tls::set(key, mut_null());
|
||||
return sched;
|
||||
|
@ -430,7 +430,7 @@ fn test_simple_scheduling() {
|
|||
};
|
||||
sched.task_queue.push_back(task);
|
||||
sched.run();
|
||||
fail_unless!(task_ran);
|
||||
assert!(task_ran);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -449,7 +449,7 @@ fn test_several_tasks() {
|
|||
sched.task_queue.push_back(task);
|
||||
}
|
||||
sched.run();
|
||||
fail_unless!(task_count == total);
|
||||
assert!(task_count == total);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -473,7 +473,7 @@ fn test_swap_tasks() {
|
|||
};
|
||||
sched.task_queue.push_back(task1);
|
||||
sched.run();
|
||||
fail_unless!(count == 3);
|
||||
assert!(count == 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -492,7 +492,7 @@ fn test_run_a_lot_of_tasks_queued() {
|
|||
sched.task_queue.push_back(start_task);
|
||||
sched.run();
|
||||
|
||||
fail_unless!(count == MAX);
|
||||
assert!(count == MAX);
|
||||
|
||||
fn run_task(count_ptr: *mut int) {
|
||||
do Scheduler::local |sched| {
|
||||
|
@ -525,7 +525,7 @@ fn test_run_a_lot_of_tasks_direct() {
|
|||
sched.task_queue.push_back(start_task);
|
||||
sched.run();
|
||||
|
||||
fail_unless!(count == MAX);
|
||||
assert!(count == MAX);
|
||||
|
||||
fn run_task(count_ptr: *mut int) {
|
||||
do Scheduler::local |sched| {
|
||||
|
@ -550,9 +550,9 @@ fn test_block_task() {
|
|||
let mut sched = ~UvEventLoop::new_scheduler();
|
||||
let task = ~do Task::new(&mut sched.stack_pool) {
|
||||
do Scheduler::local |sched| {
|
||||
fail_unless!(sched.in_task_context());
|
||||
assert!(sched.in_task_context());
|
||||
do sched.block_running_task_and_then() |sched, task| {
|
||||
fail_unless!(!sched.in_task_context());
|
||||
assert!(!sched.in_task_context());
|
||||
sched.task_queue.push_back(task);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,12 +21,12 @@ pub type Key = pthread_key_t;
|
|||
|
||||
#[cfg(unix)]
|
||||
pub unsafe fn create(key: &mut Key) {
|
||||
unsafe { fail_unless!(0 == pthread_key_create(key, null())); }
|
||||
unsafe { assert!(0 == pthread_key_create(key, null())); }
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub unsafe fn set(key: Key, value: *mut c_void) {
|
||||
unsafe { fail_unless!(0 == pthread_setspecific(key, value)); }
|
||||
unsafe { assert!(0 == pthread_setspecific(key, value)); }
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
|
@ -58,12 +58,12 @@ pub type Key = DWORD;
|
|||
pub unsafe fn create(key: &mut Key) {
|
||||
static TLS_OUT_OF_INDEXES: DWORD = 0xFFFFFFFF;
|
||||
*key = unsafe { TlsAlloc() };
|
||||
fail_unless!(*key != TLS_OUT_OF_INDEXES);
|
||||
assert!(*key != TLS_OUT_OF_INDEXES);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub unsafe fn set(key: Key, value: *mut c_void) {
|
||||
unsafe { fail_unless!(0 != TlsSetValue(key, value)) }
|
||||
unsafe { assert!(0 != TlsSetValue(key, value)) }
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
|
@ -88,10 +88,10 @@ fn tls_smoke_test() {
|
|||
create(&mut key);
|
||||
set(key, transmute(value));
|
||||
let value: ~int = transmute(get(key));
|
||||
fail_unless!(value == ~20);
|
||||
assert!(value == ~20);
|
||||
let value = ~30;
|
||||
set(key, transmute(value));
|
||||
let value: ~int = transmute(get(key));
|
||||
fail_unless!(value == ~30);
|
||||
assert!(value == ~30);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ impl Request for FsRequest;
|
|||
impl FsRequest {
|
||||
fn new() -> FsRequest {
|
||||
let fs_req = unsafe { malloc_req(UV_FS) };
|
||||
fail_unless!(fs_req.is_not_null());
|
||||
assert!(fs_req.is_not_null());
|
||||
let fs_req = fs_req as *uvll::uv_write_t;
|
||||
unsafe { uvll::set_data_for_req(fs_req, null::<()>()); }
|
||||
NativeHandle::from_native_handle(fs_req)
|
||||
|
|
|
@ -89,7 +89,7 @@ pub struct Loop {
|
|||
pub impl Loop {
|
||||
fn new() -> Loop {
|
||||
let handle = unsafe { uvll::loop_new() };
|
||||
fail_unless!(handle.is_not_null());
|
||||
assert!(handle.is_not_null());
|
||||
NativeHandle::from_native_handle(handle)
|
||||
}
|
||||
|
||||
|
@ -126,8 +126,8 @@ pub impl IdleWatcher {
|
|||
fn new(loop_: &mut Loop) -> IdleWatcher {
|
||||
unsafe {
|
||||
let handle = uvll::idle_new();
|
||||
fail_unless!(handle.is_not_null());
|
||||
fail_unless!(0 == uvll::idle_init(loop_.native_handle(), handle));
|
||||
assert!(handle.is_not_null());
|
||||
assert!(0 == uvll::idle_init(loop_.native_handle(), handle));
|
||||
uvll::set_data_for_uv_handle(handle, null::<()>());
|
||||
NativeHandle::from_native_handle(handle)
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ pub impl IdleWatcher {
|
|||
|
||||
set_watcher_callback(self, cb);
|
||||
unsafe {
|
||||
fail_unless!(0 == uvll::idle_start(self.native_handle(), idle_cb))
|
||||
assert!(0 == uvll::idle_start(self.native_handle(), idle_cb))
|
||||
};
|
||||
|
||||
extern fn idle_cb(handle: *uvll::uv_idle_t, status: c_int) {
|
||||
|
@ -149,7 +149,7 @@ pub impl IdleWatcher {
|
|||
}
|
||||
|
||||
fn stop(&mut self) {
|
||||
unsafe { fail_unless!(0 == uvll::idle_stop(self.native_handle())); }
|
||||
unsafe { assert!(0 == uvll::idle_stop(self.native_handle())); }
|
||||
}
|
||||
|
||||
fn close(self) {
|
||||
|
@ -183,7 +183,7 @@ pub impl UvError {
|
|||
unsafe {
|
||||
let inner = match self { &UvError(ref a) => a };
|
||||
let name_str = uvll::err_name(inner);
|
||||
fail_unless!(name_str.is_not_null());
|
||||
assert!(name_str.is_not_null());
|
||||
from_c_str(name_str)
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ pub impl UvError {
|
|||
unsafe {
|
||||
let inner = match self { &UvError(ref a) => a };
|
||||
let desc_str = uvll::strerror(inner);
|
||||
fail_unless!(desc_str.is_not_null());
|
||||
assert!(desc_str.is_not_null());
|
||||
from_c_str(desc_str)
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ impl ToStr for UvError {
|
|||
fn error_smoke_test() {
|
||||
let err = uvll::uv_err_t { code: 1, sys_errno_: 1 };
|
||||
let err: UvError = UvError(err);
|
||||
fail_unless!(err.to_str() == ~"EOF: end of file");
|
||||
assert!(err.to_str() == ~"EOF: end of file");
|
||||
}
|
||||
|
||||
|
||||
|
@ -274,7 +274,7 @@ pub fn borrow_callback_from_watcher<H, W: Watcher + NativeHandle<*H>,
|
|||
unsafe {
|
||||
let handle = watcher.native_handle();
|
||||
let handle_data: *c_void = uvll::get_data_for_uv_handle(handle);
|
||||
fail_unless!(handle_data.is_not_null());
|
||||
assert!(handle_data.is_not_null());
|
||||
let cb = transmute::<&*c_void, &~CB>(&handle_data);
|
||||
return &**cb;
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ pub fn take_callback_from_watcher<H, W: Watcher + NativeHandle<*H>, CB: Callback
|
|||
unsafe {
|
||||
let handle = watcher.native_handle();
|
||||
let handle_data: *c_void = uvll::get_data_for_uv_handle(handle);
|
||||
fail_unless!(handle_data.is_not_null());
|
||||
assert!(handle_data.is_not_null());
|
||||
uvll::set_data_for_uv_handle(handle, null::<()>());
|
||||
let cb: ~CB = transmute::<*c_void, ~CB>(handle_data);
|
||||
let cb = match cb { ~cb => cb };
|
||||
|
@ -341,7 +341,7 @@ fn test_slice_to_uv_buf() {
|
|||
let slice = [0, .. 20];
|
||||
let buf = slice_to_uv_buf(slice);
|
||||
|
||||
fail_unless!(buf.len == 20);
|
||||
assert!(buf.len == 20);
|
||||
|
||||
unsafe {
|
||||
let base = transmute::<*u8, *mut u8>(buf.base);
|
||||
|
@ -349,8 +349,8 @@ fn test_slice_to_uv_buf() {
|
|||
(*ptr::mut_offset(base, 1)) = 2;
|
||||
}
|
||||
|
||||
fail_unless!(slice[0] == 1);
|
||||
fail_unless!(slice[1] == 2);
|
||||
assert!(slice[0] == 1);
|
||||
assert!(slice[1] == 2);
|
||||
}
|
||||
|
||||
/// The uv buffer type
|
||||
|
@ -367,7 +367,7 @@ pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
|
|||
/// Transmute an owned vector to a Buf
|
||||
pub fn vec_to_uv_buf(v: ~[u8]) -> Buf {
|
||||
let data = unsafe { malloc(v.len() as size_t) } as *u8;
|
||||
fail_unless!(data.is_not_null());
|
||||
assert!(data.is_not_null());
|
||||
do vec::as_imm_buf(v) |b, l| {
|
||||
let data = data as *mut u8;
|
||||
unsafe { ptr::copy_memory(data, b, l) }
|
||||
|
@ -416,7 +416,7 @@ fn idle_smoke_test() {
|
|||
let count_ptr: *mut int = &mut count;
|
||||
do idle_watcher.start |idle_watcher, status| {
|
||||
let mut idle_watcher = idle_watcher;
|
||||
fail_unless!(status.is_none());
|
||||
assert!(status.is_none());
|
||||
if unsafe { *count_ptr == 10 } {
|
||||
idle_watcher.stop();
|
||||
idle_watcher.close();
|
||||
|
@ -426,7 +426,7 @@ fn idle_smoke_test() {
|
|||
}
|
||||
loop_.run();
|
||||
loop_.close();
|
||||
fail_unless!(count == 10);
|
||||
assert!(count == 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -437,10 +437,10 @@ fn idle_start_stop_start() {
|
|||
let mut idle_watcher = { IdleWatcher::new(&mut loop_) };
|
||||
do idle_watcher.start |idle_watcher, status| {
|
||||
let mut idle_watcher = idle_watcher;
|
||||
fail_unless!(status.is_none());
|
||||
assert!(status.is_none());
|
||||
idle_watcher.stop();
|
||||
do idle_watcher.start |idle_watcher, status| {
|
||||
fail_unless!(status.is_none());
|
||||
assert!(status.is_none());
|
||||
let mut idle_watcher = idle_watcher;
|
||||
idle_watcher.stop();
|
||||
idle_watcher.close();
|
||||
|
|
|
@ -104,7 +104,7 @@ pub impl StreamWatcher {
|
|||
fn write(&mut self, msg: ~[u8], cb: ConnectionCallback) {
|
||||
// XXX: Borrowck
|
||||
let data = get_watcher_data(unsafe { transmute_mut_region(self) });
|
||||
fail_unless!(data.write_cb.is_none());
|
||||
assert!(data.write_cb.is_none());
|
||||
data.write_cb = Some(cb);
|
||||
|
||||
let req = WriteRequest::new();
|
||||
|
@ -112,7 +112,7 @@ pub impl StreamWatcher {
|
|||
// XXX: Allocation
|
||||
let bufs = ~[buf];
|
||||
unsafe {
|
||||
fail_unless!(0 == uvll::write(req.native_handle(),
|
||||
assert!(0 == uvll::write(req.native_handle(),
|
||||
self.native_handle(),
|
||||
&bufs, write_cb));
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ pub impl StreamWatcher {
|
|||
let self_handle = self.native_handle() as *c_void;
|
||||
let stream_handle = stream.native_handle() as *c_void;
|
||||
unsafe {
|
||||
fail_unless!(0 == uvll::accept(self_handle, stream_handle));
|
||||
assert!(0 == uvll::accept(self_handle, stream_handle));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ pub impl StreamWatcher {
|
|||
{
|
||||
let mut self = self;
|
||||
let data = get_watcher_data(&mut self);
|
||||
fail_unless!(data.close_cb.is_none());
|
||||
assert!(data.close_cb.is_none());
|
||||
data.close_cb = Some(cb);
|
||||
}
|
||||
|
||||
|
@ -184,8 +184,8 @@ pub impl TcpWatcher {
|
|||
fn new(loop_: &mut Loop) -> TcpWatcher {
|
||||
unsafe {
|
||||
let handle = malloc_handle(UV_TCP);
|
||||
fail_unless!(handle.is_not_null());
|
||||
fail_unless!(0 == uvll::tcp_init(loop_.native_handle(), handle));
|
||||
assert!(handle.is_not_null());
|
||||
assert!(0 == uvll::tcp_init(loop_.native_handle(), handle));
|
||||
let mut watcher = NativeHandle::from_native_handle(handle);
|
||||
install_watcher_data(&mut watcher);
|
||||
return watcher;
|
||||
|
@ -200,7 +200,7 @@ pub impl TcpWatcher {
|
|||
uvll::tcp_bind(self.native_handle(), addr)
|
||||
};
|
||||
// XXX: bind is likely to fail. need real error handling
|
||||
fail_unless!(result == 0);
|
||||
assert!(result == 0);
|
||||
}
|
||||
}
|
||||
_ => fail!()
|
||||
|
@ -209,7 +209,7 @@ pub impl TcpWatcher {
|
|||
|
||||
fn connect(&mut self, address: IpAddr, cb: ConnectionCallback) {
|
||||
unsafe {
|
||||
fail_unless!(get_watcher_data(self).connect_cb.is_none());
|
||||
assert!(get_watcher_data(self).connect_cb.is_none());
|
||||
get_watcher_data(self).connect_cb = Some(cb);
|
||||
|
||||
let mut connect_watcher = ConnectRequest::new();
|
||||
|
@ -218,7 +218,7 @@ pub impl TcpWatcher {
|
|||
Ipv4(*) => {
|
||||
do ip4_as_uv_ip4(address) |addr| {
|
||||
rtdebug!("connect_t: %x", connect_handle as uint);
|
||||
fail_unless!(0 == uvll::tcp_connect(connect_handle,
|
||||
assert!(0 == uvll::tcp_connect(connect_handle,
|
||||
self.native_handle(),
|
||||
addr, connect_cb));
|
||||
}
|
||||
|
@ -244,13 +244,13 @@ pub impl TcpWatcher {
|
|||
fn listen(&mut self, cb: ConnectionCallback) {
|
||||
// XXX: Borrowck
|
||||
let data = get_watcher_data(unsafe { transmute_mut_region(self) });
|
||||
fail_unless!(data.connect_cb.is_none());
|
||||
assert!(data.connect_cb.is_none());
|
||||
data.connect_cb = Some(cb);
|
||||
|
||||
unsafe {
|
||||
static BACKLOG: c_int = 128; // XXX should be configurable
|
||||
// XXX: This can probably fail
|
||||
fail_unless!(0 == uvll::listen(self.native_handle(),
|
||||
assert!(0 == uvll::listen(self.native_handle(),
|
||||
BACKLOG, connection_cb));
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@ impl ConnectRequest {
|
|||
let connect_handle = unsafe {
|
||||
malloc_req(UV_CONNECT)
|
||||
};
|
||||
fail_unless!(connect_handle.is_not_null());
|
||||
assert!(connect_handle.is_not_null());
|
||||
let connect_handle = connect_handle as *uvll::uv_connect_t;
|
||||
ConnectRequest(connect_handle)
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ pub impl WriteRequest {
|
|||
let write_handle = unsafe {
|
||||
malloc_req(UV_WRITE)
|
||||
};
|
||||
fail_unless!(write_handle.is_not_null());
|
||||
assert!(write_handle.is_not_null());
|
||||
let write_handle = write_handle as *uvll::uv_write_t;
|
||||
WriteRequest(write_handle)
|
||||
}
|
||||
|
@ -365,8 +365,8 @@ fn connect_close() {
|
|||
let addr = Ipv4(127, 0, 0, 1, 2923);
|
||||
do tcp_watcher.connect(addr) |stream_watcher, status| {
|
||||
rtdebug!("tcp_watcher.connect!");
|
||||
fail_unless!(status.is_some());
|
||||
fail_unless!(status.get().name() == ~"ECONNREFUSED");
|
||||
assert!(status.is_some());
|
||||
assert!(status.get().name() == ~"ECONNREFUSED");
|
||||
stream_watcher.close(||());
|
||||
}
|
||||
loop_.run();
|
||||
|
@ -384,7 +384,7 @@ fn connect_read() {
|
|||
do tcp_watcher.connect(addr) |stream_watcher, status| {
|
||||
let mut stream_watcher = stream_watcher;
|
||||
rtdebug!("tcp_watcher.connect!");
|
||||
fail_unless!(status.is_none());
|
||||
assert!(status.is_none());
|
||||
let alloc: AllocCallback = |size| {
|
||||
vec_to_uv_buf(vec::from_elem(size, 0))
|
||||
};
|
||||
|
@ -421,7 +421,7 @@ fn listen() {
|
|||
rtdebug!("listening");
|
||||
do server_tcp_watcher.listen |server_stream_watcher, status| {
|
||||
rtdebug!("listened!");
|
||||
fail_unless!(status.is_none());
|
||||
assert!(status.is_none());
|
||||
let mut server_stream_watcher = server_stream_watcher;
|
||||
let mut loop_ = loop_;
|
||||
let mut client_tcp_watcher = TcpWatcher::new(&mut loop_);
|
||||
|
@ -443,12 +443,12 @@ fn listen() {
|
|||
rtdebug!("got %d bytes", nread);
|
||||
let buf = buf.unwrap();
|
||||
for buf.slice(0, nread as uint).each |byte| {
|
||||
fail_unless!(*byte == count as u8);
|
||||
assert!(*byte == count as u8);
|
||||
rtdebug!("%u", *byte as uint);
|
||||
count += 1;
|
||||
}
|
||||
} else {
|
||||
fail_unless!(count == MAX);
|
||||
assert!(count == MAX);
|
||||
do stream_watcher.close {
|
||||
server_stream_watcher.close(||());
|
||||
}
|
||||
|
@ -463,12 +463,12 @@ fn listen() {
|
|||
let mut tcp_watcher = { TcpWatcher::new(&mut loop_) };
|
||||
do tcp_watcher.connect(addr) |stream_watcher, status| {
|
||||
rtdebug!("connecting");
|
||||
fail_unless!(status.is_none());
|
||||
assert!(status.is_none());
|
||||
let mut stream_watcher = stream_watcher;
|
||||
let msg = ~[0, 1, 2, 3, 4, 5, 6 ,7 ,8, 9];
|
||||
do stream_watcher.write(msg) |stream_watcher, status| {
|
||||
rtdebug!("writing");
|
||||
fail_unless!(status.is_none());
|
||||
assert!(status.is_none());
|
||||
stream_watcher.close(||());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ impl EventLoop for UvEventLoop {
|
|||
fn callback(&mut self, f: ~fn()) {
|
||||
let mut idle_watcher = IdleWatcher::new(self.uvio.uv_loop());
|
||||
do idle_watcher.start |idle_watcher, status| {
|
||||
fail_unless!(status.is_none());
|
||||
assert!(status.is_none());
|
||||
let mut idle_watcher = idle_watcher;
|
||||
idle_watcher.stop();
|
||||
idle_watcher.close();
|
||||
|
@ -82,7 +82,7 @@ fn test_callback_run_once() {
|
|||
unsafe { *count_ptr += 1 }
|
||||
}
|
||||
event_loop.run();
|
||||
fail_unless!(count == 1);
|
||||
assert!(count == 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,13 +105,13 @@ impl IoFactory for UvIoFactory {
|
|||
let result_cell_ptr: *Cell<Option<~StreamObject>> = &result_cell;
|
||||
|
||||
do Scheduler::local |scheduler| {
|
||||
fail_unless!(scheduler.in_task_context());
|
||||
assert!(scheduler.in_task_context());
|
||||
|
||||
// Block this task and take ownership, switch to scheduler context
|
||||
do scheduler.block_running_task_and_then |scheduler, task| {
|
||||
|
||||
rtdebug!("connect: entered scheduler context");
|
||||
fail_unless!(!scheduler.in_task_context());
|
||||
assert!(!scheduler.in_task_context());
|
||||
let mut tcp_watcher = TcpWatcher::new(self.uv_loop());
|
||||
let task_cell = Cell(task);
|
||||
|
||||
|
@ -138,7 +138,7 @@ impl IoFactory for UvIoFactory {
|
|||
}
|
||||
}
|
||||
|
||||
fail_unless!(!result_cell.is_empty());
|
||||
assert!(!result_cell.is_empty());
|
||||
return result_cell.take();
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ impl TcpListener for UvTcpListener {
|
|||
let server_tcp_watcher = self.watcher();
|
||||
|
||||
do Scheduler::local |scheduler| {
|
||||
fail_unless!(scheduler.in_task_context());
|
||||
assert!(scheduler.in_task_context());
|
||||
|
||||
do scheduler.block_running_task_and_then |_, task| {
|
||||
let task_cell = Cell(task);
|
||||
|
@ -208,7 +208,7 @@ impl TcpListener for UvTcpListener {
|
|||
}
|
||||
}
|
||||
|
||||
fail_unless!(!result_cell.is_empty());
|
||||
assert!(!result_cell.is_empty());
|
||||
return result_cell.take();
|
||||
}
|
||||
}
|
||||
|
@ -244,12 +244,12 @@ impl Stream for UvStream {
|
|||
let result_cell_ptr: *Cell<Result<uint, ()>> = &result_cell;
|
||||
|
||||
do Scheduler::local |scheduler| {
|
||||
fail_unless!(scheduler.in_task_context());
|
||||
assert!(scheduler.in_task_context());
|
||||
let watcher = self.watcher();
|
||||
let buf_ptr: *&mut [u8] = &buf;
|
||||
do scheduler.block_running_task_and_then |scheduler, task| {
|
||||
rtdebug!("read: entered scheduler context");
|
||||
fail_unless!(!scheduler.in_task_context());
|
||||
assert!(!scheduler.in_task_context());
|
||||
let mut watcher = watcher;
|
||||
let task_cell = Cell(task);
|
||||
// XXX: We shouldn't reallocate these callbacks every
|
||||
|
@ -267,7 +267,7 @@ impl Stream for UvStream {
|
|||
watcher.read_stop();
|
||||
|
||||
let result = if status.is_none() {
|
||||
fail_unless!(nread >= 0);
|
||||
assert!(nread >= 0);
|
||||
Ok(nread as uint)
|
||||
} else {
|
||||
Err(())
|
||||
|
@ -282,7 +282,7 @@ impl Stream for UvStream {
|
|||
}
|
||||
}
|
||||
|
||||
fail_unless!(!result_cell.is_empty());
|
||||
assert!(!result_cell.is_empty());
|
||||
return result_cell.take();
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,7 @@ impl Stream for UvStream {
|
|||
let result_cell = empty_cell();
|
||||
let result_cell_ptr: *Cell<Result<(), ()>> = &result_cell;
|
||||
do Scheduler::local |scheduler| {
|
||||
fail_unless!(scheduler.in_task_context());
|
||||
assert!(scheduler.in_task_context());
|
||||
let watcher = self.watcher();
|
||||
let buf_ptr: *&[u8] = &buf;
|
||||
do scheduler.block_running_task_and_then |_, task| {
|
||||
|
@ -315,7 +315,7 @@ impl Stream for UvStream {
|
|||
}
|
||||
}
|
||||
|
||||
fail_unless!(!result_cell.is_empty());
|
||||
assert!(!result_cell.is_empty());
|
||||
return result_cell.take();
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ fn test_simple_io_no_connect() {
|
|||
let io = sched.event_loop.io().unwrap();
|
||||
let addr = Ipv4(127, 0, 0, 1, 2926);
|
||||
let maybe_chan = io.connect(addr);
|
||||
fail_unless!(maybe_chan.is_none());
|
||||
assert!(maybe_chan.is_none());
|
||||
}
|
||||
};
|
||||
sched.task_queue.push_back(task);
|
||||
|
@ -361,10 +361,10 @@ fn test_simple_tcp_server_and_client() {
|
|||
let mut stream = listener.listen().unwrap();
|
||||
let mut buf = [0, .. 2048];
|
||||
let nread = stream.read(buf).unwrap();
|
||||
fail_unless!(nread == 8);
|
||||
assert!(nread == 8);
|
||||
for uint::range(0, nread) |i| {
|
||||
rtdebug!("%u", buf[i] as uint);
|
||||
fail_unless!(buf[i] == i as u8);
|
||||
assert!(buf[i] == i as u8);
|
||||
}
|
||||
stream.close();
|
||||
listener.close();
|
||||
|
@ -411,7 +411,7 @@ fn test_read_and_block() {
|
|||
let nread = stream.read(buf).unwrap();
|
||||
for uint::range(0, nread) |i| {
|
||||
let val = buf[i] as uint;
|
||||
fail_unless!(val == current % 8);
|
||||
assert!(val == current % 8);
|
||||
current += 1;
|
||||
}
|
||||
reads += 1;
|
||||
|
@ -427,7 +427,7 @@ fn test_read_and_block() {
|
|||
}
|
||||
|
||||
// Make sure we had multiple reads
|
||||
fail_unless!(reads > 1);
|
||||
assert!(reads > 1);
|
||||
|
||||
stream.close();
|
||||
listener.close();
|
||||
|
|
|
@ -97,10 +97,10 @@ pub enum uv_req_type {
|
|||
}
|
||||
|
||||
pub unsafe fn malloc_handle(handle: uv_handle_type) -> *c_void {
|
||||
fail_unless!(handle != UV_UNKNOWN_HANDLE && handle != UV_HANDLE_TYPE_MAX);
|
||||
assert!(handle != UV_UNKNOWN_HANDLE && handle != UV_HANDLE_TYPE_MAX);
|
||||
let size = unsafe { rust_uv_handle_size(handle as uint) };
|
||||
let p = malloc(size);
|
||||
fail_unless!(p.is_not_null());
|
||||
assert!(p.is_not_null());
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -109,10 +109,10 @@ pub unsafe fn free_handle(v: *c_void) {
|
|||
}
|
||||
|
||||
pub unsafe fn malloc_req(req: uv_req_type) -> *c_void {
|
||||
fail_unless!(req != UV_UNKNOWN_REQ && req != UV_REQ_TYPE_MAX);
|
||||
assert!(req != UV_UNKNOWN_REQ && req != UV_REQ_TYPE_MAX);
|
||||
let size = unsafe { rust_uv_req_size(req as uint) };
|
||||
let p = malloc(size);
|
||||
fail_unless!(p.is_not_null());
|
||||
assert!(p.is_not_null());
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -123,14 +123,14 @@ pub unsafe fn free_req(v: *c_void) {
|
|||
#[test]
|
||||
fn handle_sanity_check() {
|
||||
unsafe {
|
||||
fail_unless!(UV_HANDLE_TYPE_MAX as uint == rust_uv_handle_type_max());
|
||||
assert!(UV_HANDLE_TYPE_MAX as uint == rust_uv_handle_type_max());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn request_sanity_check() {
|
||||
unsafe {
|
||||
fail_unless!(UV_REQ_TYPE_MAX as uint == rust_uv_req_type_max());
|
||||
assert!(UV_REQ_TYPE_MAX as uint == rust_uv_req_type_max());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -495,7 +495,7 @@ mod tests {
|
|||
|
||||
debug!(copy expected);
|
||||
debug!(copy actual);
|
||||
fail_unless!((expected == actual));
|
||||
assert!((expected == actual));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -504,7 +504,7 @@ mod tests {
|
|||
&None, &None,
|
||||
0i32, 0i32, 0i32);
|
||||
let status = run::waitpid(pid);
|
||||
fail_unless!(status == 1);
|
||||
assert!(status == 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -170,10 +170,10 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn size_of_basic() {
|
||||
fail_unless!(size_of::<u8>() == 1u);
|
||||
fail_unless!(size_of::<u16>() == 2u);
|
||||
fail_unless!(size_of::<u32>() == 4u);
|
||||
fail_unless!(size_of::<u64>() == 8u);
|
||||
assert!(size_of::<u8>() == 1u);
|
||||
assert!(size_of::<u16>() == 2u);
|
||||
assert!(size_of::<u32>() == 4u);
|
||||
assert!(size_of::<u64>() == 8u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -181,30 +181,30 @@ pub mod tests {
|
|||
#[cfg(target_arch = "arm")]
|
||||
#[cfg(target_arch = "mips")]
|
||||
pub fn size_of_32() {
|
||||
fail_unless!(size_of::<uint>() == 4u);
|
||||
fail_unless!(size_of::<*uint>() == 4u);
|
||||
assert!(size_of::<uint>() == 4u);
|
||||
assert!(size_of::<*uint>() == 4u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub fn size_of_64() {
|
||||
fail_unless!(size_of::<uint>() == 8u);
|
||||
fail_unless!(size_of::<*uint>() == 8u);
|
||||
assert!(size_of::<uint>() == 8u);
|
||||
assert!(size_of::<*uint>() == 8u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn nonzero_size_of_basic() {
|
||||
type Z = [i8, ..0];
|
||||
fail_unless!(size_of::<Z>() == 0u);
|
||||
fail_unless!(nonzero_size_of::<Z>() == 1u);
|
||||
fail_unless!(nonzero_size_of::<uint>() == size_of::<uint>());
|
||||
assert!(size_of::<Z>() == 0u);
|
||||
assert!(nonzero_size_of::<Z>() == 1u);
|
||||
assert!(nonzero_size_of::<uint>() == size_of::<uint>());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn align_of_basic() {
|
||||
fail_unless!(pref_align_of::<u8>() == 1u);
|
||||
fail_unless!(pref_align_of::<u16>() == 2u);
|
||||
fail_unless!(pref_align_of::<u32>() == 4u);
|
||||
assert!(pref_align_of::<u8>() == 1u);
|
||||
assert!(pref_align_of::<u16>() == 2u);
|
||||
assert!(pref_align_of::<u32>() == 4u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -212,15 +212,15 @@ pub mod tests {
|
|||
#[cfg(target_arch = "arm")]
|
||||
#[cfg(target_arch = "mips")]
|
||||
pub fn align_of_32() {
|
||||
fail_unless!(pref_align_of::<uint>() == 4u);
|
||||
fail_unless!(pref_align_of::<*uint>() == 4u);
|
||||
assert!(pref_align_of::<uint>() == 4u);
|
||||
assert!(pref_align_of::<*uint>() == 4u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub fn align_of_64() {
|
||||
fail_unless!(pref_align_of::<uint>() == 8u);
|
||||
fail_unless!(pref_align_of::<*uint>() == 8u);
|
||||
assert!(pref_align_of::<uint>() == 8u);
|
||||
assert!(pref_align_of::<*uint>() == 8u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -229,7 +229,7 @@ pub mod tests {
|
|||
let x = 10;
|
||||
let f: &fn(int) -> int = |y| x + y;
|
||||
|
||||
fail_unless!(f(20) == 30);
|
||||
assert!(f(20) == 30);
|
||||
|
||||
let original_closure: Closure = cast::transmute(f);
|
||||
|
||||
|
@ -242,7 +242,7 @@ pub mod tests {
|
|||
};
|
||||
|
||||
let new_f: &fn(int) -> int = cast::transmute(new_closure);
|
||||
fail_unless!(new_f(20) == 30);
|
||||
assert!(new_f(20) == 30);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,17 +92,17 @@ fn test_tls_multitask() {
|
|||
do task::spawn {
|
||||
unsafe {
|
||||
// TLS shouldn't carry over.
|
||||
fail_unless!(local_data_get(my_key).is_none());
|
||||
assert!(local_data_get(my_key).is_none());
|
||||
local_data_set(my_key, @~"child data");
|
||||
fail_unless!(*(local_data_get(my_key).get()) ==
|
||||
assert!(*(local_data_get(my_key).get()) ==
|
||||
~"child data");
|
||||
// should be cleaned up for us
|
||||
}
|
||||
}
|
||||
// Must work multiple times
|
||||
fail_unless!(*(local_data_get(my_key).get()) == ~"parent data");
|
||||
fail_unless!(*(local_data_get(my_key).get()) == ~"parent data");
|
||||
fail_unless!(*(local_data_get(my_key).get()) == ~"parent data");
|
||||
assert!(*(local_data_get(my_key).get()) == ~"parent data");
|
||||
assert!(*(local_data_get(my_key).get()) == ~"parent data");
|
||||
assert!(*(local_data_get(my_key).get()) == ~"parent data");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ fn test_tls_overwrite() {
|
|||
fn my_key(_x: @~str) { }
|
||||
local_data_set(my_key, @~"first data");
|
||||
local_data_set(my_key, @~"next data"); // Shouldn't leak.
|
||||
fail_unless!(*(local_data_get(my_key).get()) == ~"next data");
|
||||
assert!(*(local_data_get(my_key).get()) == ~"next data");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,9 +121,9 @@ fn test_tls_pop() {
|
|||
unsafe {
|
||||
fn my_key(_x: @~str) { }
|
||||
local_data_set(my_key, @~"weasel");
|
||||
fail_unless!(*(local_data_pop(my_key).get()) == ~"weasel");
|
||||
assert!(*(local_data_pop(my_key).get()) == ~"weasel");
|
||||
// Pop must remove the data from the map.
|
||||
fail_unless!(local_data_pop(my_key).is_none());
|
||||
assert!(local_data_pop(my_key).is_none());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ fn test_tls_modify() {
|
|||
None => fail!(~"missing value")
|
||||
}
|
||||
});
|
||||
fail_unless!(*(local_data_pop(my_key).get()) == ~"next data");
|
||||
assert!(*(local_data_pop(my_key).get()) == ~"next data");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ type TaskLocalMap = @mut ~[Option<TaskLocalElement>];
|
|||
|
||||
extern fn cleanup_task_local_map(map_ptr: *libc::c_void) {
|
||||
unsafe {
|
||||
fail_unless!(!map_ptr.is_null());
|
||||
assert!(!map_ptr.is_null());
|
||||
// Get and keep the single reference that was created at the
|
||||
// beginning.
|
||||
let _map: TaskLocalMap = cast::reinterpret_cast(&map_ptr);
|
||||
|
|
|
@ -840,14 +840,14 @@ fn test_add_wrapper() {
|
|||
fn test_future_result() {
|
||||
let mut result = None;
|
||||
do task().future_result(|+r| { result = Some(r); }).spawn { }
|
||||
fail_unless!(result.unwrap().recv() == Success);
|
||||
assert!(result.unwrap().recv() == Success);
|
||||
|
||||
result = None;
|
||||
do task().future_result(|+r|
|
||||
{ result = Some(r); }).unlinked().spawn {
|
||||
fail!();
|
||||
}
|
||||
fail_unless!(result.unwrap().recv() == Failure);
|
||||
assert!(result.unwrap().recv() == Failure);
|
||||
}
|
||||
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
|
@ -893,7 +893,7 @@ fn test_spawn_sched() {
|
|||
|
||||
do spawn_sched(SingleThreaded) {
|
||||
let child_sched_id = unsafe { rt::rust_get_sched_id() };
|
||||
fail_unless!(parent_sched_id != child_sched_id);
|
||||
assert!(parent_sched_id != child_sched_id);
|
||||
|
||||
if (i == 0) {
|
||||
ch.send(());
|
||||
|
@ -921,8 +921,8 @@ fn test_spawn_sched_childs_on_default_sched() {
|
|||
do spawn {
|
||||
let ch = ch.f.swap_unwrap();
|
||||
let child_sched_id = unsafe { rt::rust_get_sched_id() };
|
||||
fail_unless!(parent_sched_id != child_sched_id);
|
||||
fail_unless!(child_sched_id == default_id);
|
||||
assert!(parent_sched_id != child_sched_id);
|
||||
assert!(child_sched_id == default_id);
|
||||
ch.send(());
|
||||
};
|
||||
};
|
||||
|
@ -1016,7 +1016,7 @@ fn avoid_copying_the_body(spawnfn: &fn(v: ~fn())) {
|
|||
}
|
||||
|
||||
let x_in_child = p.recv();
|
||||
fail_unless!(x_in_parent == x_in_child);
|
||||
assert!(x_in_parent == x_in_child);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1171,7 +1171,7 @@ fn test_sched_thread_per_core() {
|
|||
unsafe {
|
||||
let cores = rt::rust_num_threads();
|
||||
let reported_threads = rt::rust_sched_threads();
|
||||
fail_unless!((cores as uint == reported_threads as uint));
|
||||
assert!((cores as uint == reported_threads as uint));
|
||||
chan.send(());
|
||||
}
|
||||
}
|
||||
|
@ -1186,9 +1186,9 @@ fn test_spawn_thread_on_demand() {
|
|||
do spawn_sched(ManualThreads(2)) || {
|
||||
unsafe {
|
||||
let max_threads = rt::rust_sched_threads();
|
||||
fail_unless!((max_threads as int == 2));
|
||||
assert!((max_threads as int == 2));
|
||||
let running_threads = rt::rust_sched_current_nonlazy_threads();
|
||||
fail_unless!((running_threads as int == 1));
|
||||
assert!((running_threads as int == 1));
|
||||
|
||||
let (port2, chan2) = comm::stream();
|
||||
|
||||
|
@ -1197,7 +1197,7 @@ fn test_spawn_thread_on_demand() {
|
|||
}
|
||||
|
||||
let running_threads2 = rt::rust_sched_current_nonlazy_threads();
|
||||
fail_unless!((running_threads2 as int == 2));
|
||||
assert!((running_threads2 as int == 2));
|
||||
|
||||
port2.recv();
|
||||
chan.send(());
|
||||
|
|
|
@ -103,11 +103,11 @@ fn new_taskset() -> TaskSet {
|
|||
}
|
||||
fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) {
|
||||
let didnt_overwrite = tasks.insert(task);
|
||||
fail_unless!(didnt_overwrite);
|
||||
assert!(didnt_overwrite);
|
||||
}
|
||||
fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) {
|
||||
let was_present = tasks.remove(&task);
|
||||
fail_unless!(was_present);
|
||||
assert!(was_present);
|
||||
}
|
||||
pub fn taskset_each(tasks: &TaskSet, blk: &fn(v: *rust_task) -> bool) {
|
||||
tasks.each(|k| blk(*k))
|
||||
|
@ -231,7 +231,7 @@ fn each_ancestor(list: &mut AncestorList,
|
|||
// NB: Takes a lock! (this ancestor node)
|
||||
do access_ancestors(ancestor_arc) |nobe| {
|
||||
// Check monotonicity
|
||||
fail_unless!(last_generation > nobe.generation);
|
||||
assert!(last_generation > nobe.generation);
|
||||
/*##########################################################*
|
||||
* Step 1: Look at this ancestor group (call iterator block).
|
||||
*##########################################################*/
|
||||
|
@ -423,7 +423,7 @@ fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) {
|
|||
}
|
||||
}
|
||||
for taskset_each(&group.descendants) |child| {
|
||||
fail_unless!(child != me);
|
||||
assert!(child != me);
|
||||
rt::rust_task_kill_other(child);
|
||||
}
|
||||
// Only one task should ever do this.
|
||||
|
@ -498,7 +498,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
|||
}
|
||||
None => 0 // the actual value doesn't really matter.
|
||||
};
|
||||
fail_unless!(new_generation < uint::max_value);
|
||||
assert!(new_generation < uint::max_value);
|
||||
// Build a new node in the ancestor list.
|
||||
AncestorList(Some(unstable::exclusive(AncestorNode {
|
||||
generation: new_generation,
|
||||
|
@ -545,7 +545,7 @@ pub fn spawn_raw(opts: TaskOpts, f: ~fn()) {
|
|||
DefaultScheduler => rt::new_task(),
|
||||
_ => new_task_in_sched(opts.sched)
|
||||
};
|
||||
fail_unless!(!new_task.is_null());
|
||||
assert!(!new_task.is_null());
|
||||
// Getting killed after here would leak the task.
|
||||
let mut notify_chan = if opts.notify_chan.is_none() {
|
||||
None
|
||||
|
@ -717,7 +717,7 @@ fn test_spawn_raw_notify_success() {
|
|||
};
|
||||
do spawn_raw(opts) {
|
||||
}
|
||||
fail_unless!(notify_po.recv() == Success);
|
||||
assert!(notify_po.recv() == Success);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -734,5 +734,5 @@ fn test_spawn_raw_notify_failure() {
|
|||
do spawn_raw(opts) {
|
||||
fail!();
|
||||
}
|
||||
fail_unless!(notify_po.recv() == Failure);
|
||||
assert!(notify_po.recv() == Failure);
|
||||
}
|
||||
|
|
|
@ -137,31 +137,31 @@ impl<A:ToStr> ToStr for @[A] {
|
|||
mod tests {
|
||||
#[test]
|
||||
fn test_simple_types() {
|
||||
fail_unless!(1i.to_str() == ~"1");
|
||||
fail_unless!((-1i).to_str() == ~"-1");
|
||||
fail_unless!(200u.to_str() == ~"200");
|
||||
fail_unless!(2u8.to_str() == ~"2");
|
||||
fail_unless!(true.to_str() == ~"true");
|
||||
fail_unless!(false.to_str() == ~"false");
|
||||
fail_unless!(().to_str() == ~"()");
|
||||
fail_unless!((~"hi").to_str() == ~"hi");
|
||||
fail_unless!((@"hi").to_str() == ~"hi");
|
||||
assert!(1i.to_str() == ~"1");
|
||||
assert!((-1i).to_str() == ~"-1");
|
||||
assert!(200u.to_str() == ~"200");
|
||||
assert!(2u8.to_str() == ~"2");
|
||||
assert!(true.to_str() == ~"true");
|
||||
assert!(false.to_str() == ~"false");
|
||||
assert!(().to_str() == ~"()");
|
||||
assert!((~"hi").to_str() == ~"hi");
|
||||
assert!((@"hi").to_str() == ~"hi");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tuple_types() {
|
||||
fail_unless!((1, 2).to_str() == ~"(1, 2)");
|
||||
fail_unless!((~"a", ~"b", false).to_str() == ~"(a, b, false)");
|
||||
fail_unless!(((), ((), 100)).to_str() == ~"((), ((), 100))");
|
||||
assert!((1, 2).to_str() == ~"(1, 2)");
|
||||
assert!((~"a", ~"b", false).to_str() == ~"(a, b, false)");
|
||||
assert!(((), ((), 100)).to_str() == ~"((), ((), 100))");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vectors() {
|
||||
let x: ~[int] = ~[];
|
||||
fail_unless!(x.to_str() == ~"[]");
|
||||
fail_unless!((~[1]).to_str() == ~"[1]");
|
||||
fail_unless!((~[1, 2, 3]).to_str() == ~"[1, 2, 3]");
|
||||
fail_unless!((~[~[], ~[1], ~[1, 1]]).to_str() ==
|
||||
assert!(x.to_str() == ~"[]");
|
||||
assert!((~[1]).to_str() == ~"[1]");
|
||||
assert!((~[1, 2, 3]).to_str() == ~"[1, 2, 3]");
|
||||
assert!((~[~[], ~[1], ~[1, 1]]).to_str() ==
|
||||
~"[[], [1], [1, 1]]");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -354,7 +354,7 @@ fn remove<T>(count: &mut uint, child: &mut Child<T>, key: uint,
|
|||
|
||||
#[cfg(test)]
|
||||
pub fn check_integrity<T>(trie: &TrieNode<T>) {
|
||||
fail_unless!(trie.count != 0);
|
||||
assert!(trie.count != 0);
|
||||
|
||||
let mut sum = 0;
|
||||
|
||||
|
@ -369,7 +369,7 @@ pub fn check_integrity<T>(trie: &TrieNode<T>) {
|
|||
}
|
||||
}
|
||||
|
||||
fail_unless!(sum == trie.count);
|
||||
assert!(sum == trie.count);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -381,9 +381,9 @@ mod tests {
|
|||
#[test]
|
||||
fn test_find_mut() {
|
||||
let mut m = TrieMap::new();
|
||||
fail_unless!(m.insert(1, 12));
|
||||
fail_unless!(m.insert(2, 8));
|
||||
fail_unless!(m.insert(5, 14));
|
||||
assert!(m.insert(1, 12));
|
||||
assert!(m.insert(2, 8));
|
||||
assert!(m.insert(5, 14));
|
||||
let new = 100;
|
||||
match m.find_mut(&5) {
|
||||
None => fail!(), Some(x) => *x = new
|
||||
|
@ -397,32 +397,32 @@ mod tests {
|
|||
let n = 300;
|
||||
|
||||
for uint::range_step(1, n, 2) |x| {
|
||||
fail_unless!(trie.insert(x, x + 1));
|
||||
fail_unless!(trie.contains_key(&x));
|
||||
assert!(trie.insert(x, x + 1));
|
||||
assert!(trie.contains_key(&x));
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
|
||||
for uint::range_step(0, n, 2) |x| {
|
||||
fail_unless!(!trie.contains_key(&x));
|
||||
fail_unless!(trie.insert(x, x + 1));
|
||||
assert!(!trie.contains_key(&x));
|
||||
assert!(trie.insert(x, x + 1));
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
|
||||
for uint::range(0, n) |x| {
|
||||
fail_unless!(trie.contains_key(&x));
|
||||
fail_unless!(!trie.insert(x, x + 1));
|
||||
assert!(trie.contains_key(&x));
|
||||
assert!(!trie.insert(x, x + 1));
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
|
||||
for uint::range_step(1, n, 2) |x| {
|
||||
fail_unless!(trie.remove(&x));
|
||||
fail_unless!(!trie.contains_key(&x));
|
||||
assert!(trie.remove(&x));
|
||||
assert!(!trie.contains_key(&x));
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
|
||||
for uint::range_step(0, n, 2) |x| {
|
||||
fail_unless!(trie.contains_key(&x));
|
||||
fail_unless!(!trie.insert(x, x + 1));
|
||||
assert!(trie.contains_key(&x));
|
||||
assert!(!trie.insert(x, x + 1));
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
}
|
||||
|
@ -431,16 +431,16 @@ mod tests {
|
|||
fn test_each() {
|
||||
let mut m = TrieMap::new();
|
||||
|
||||
fail_unless!(m.insert(3, 6));
|
||||
fail_unless!(m.insert(0, 0));
|
||||
fail_unless!(m.insert(4, 8));
|
||||
fail_unless!(m.insert(2, 4));
|
||||
fail_unless!(m.insert(1, 2));
|
||||
assert!(m.insert(3, 6));
|
||||
assert!(m.insert(0, 0));
|
||||
assert!(m.insert(4, 8));
|
||||
assert!(m.insert(2, 4));
|
||||
assert!(m.insert(1, 2));
|
||||
|
||||
let mut n = 0;
|
||||
for m.each |&(k, v)| {
|
||||
fail_unless!(k == n);
|
||||
fail_unless!(*v == n * 2);
|
||||
assert!(k == n);
|
||||
assert!(*v == n * 2);
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
|
@ -456,10 +456,10 @@ mod tests {
|
|||
let mut n = uint::max_value - 9999;
|
||||
for m.each |&(k, v)| {
|
||||
if n == uint::max_value - 5000 { break }
|
||||
fail_unless!(n < uint::max_value - 5000);
|
||||
assert!(n < uint::max_value - 5000);
|
||||
|
||||
fail_unless!(k == n);
|
||||
fail_unless!(*v == n / 2);
|
||||
assert!(k == n);
|
||||
assert!(*v == n / 2);
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
|
@ -468,16 +468,16 @@ mod tests {
|
|||
fn test_each_reverse() {
|
||||
let mut m = TrieMap::new();
|
||||
|
||||
fail_unless!(m.insert(3, 6));
|
||||
fail_unless!(m.insert(0, 0));
|
||||
fail_unless!(m.insert(4, 8));
|
||||
fail_unless!(m.insert(2, 4));
|
||||
fail_unless!(m.insert(1, 2));
|
||||
assert!(m.insert(3, 6));
|
||||
assert!(m.insert(0, 0));
|
||||
assert!(m.insert(4, 8));
|
||||
assert!(m.insert(2, 4));
|
||||
assert!(m.insert(1, 2));
|
||||
|
||||
let mut n = 4;
|
||||
for m.each_reverse |&(k, v)| {
|
||||
fail_unless!(k == n);
|
||||
fail_unless!(*v == n * 2);
|
||||
assert!(k == n);
|
||||
assert!(*v == n * 2);
|
||||
n -= 1;
|
||||
}
|
||||
}
|
||||
|
@ -493,10 +493,10 @@ mod tests {
|
|||
let mut n = uint::max_value;
|
||||
for m.each_reverse |&(k, v)| {
|
||||
if n == uint::max_value - 5000 { break }
|
||||
fail_unless!(n > uint::max_value - 5000);
|
||||
assert!(n > uint::max_value - 5000);
|
||||
|
||||
fail_unless!(k == n);
|
||||
fail_unless!(*v == n / 2);
|
||||
assert!(k == n);
|
||||
assert!(*v == n / 2);
|
||||
n -= 1;
|
||||
}
|
||||
}
|
||||
|
@ -508,17 +508,17 @@ mod tests {
|
|||
|
||||
let mut trie = TrieSet::new();
|
||||
|
||||
fail_unless!(trie.insert(x));
|
||||
fail_unless!(trie.insert(y));
|
||||
assert!(trie.insert(x));
|
||||
assert!(trie.insert(y));
|
||||
|
||||
fail_unless!(trie.len() == 2);
|
||||
assert!(trie.len() == 2);
|
||||
|
||||
let expected = [x, y];
|
||||
|
||||
let mut i = 0;
|
||||
|
||||
for trie.each |x| {
|
||||
fail_unless!(expected[i] == *x);
|
||||
assert!(expected[i] == *x);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -240,15 +240,15 @@ impl<A:Ord,B:Ord,C:Ord> Ord for (A, B, C) {
|
|||
#[test]
|
||||
fn test_tuple_ref() {
|
||||
let x = (~"foo", ~"bar");
|
||||
fail_unless!(x.first_ref() == &~"foo");
|
||||
fail_unless!(x.second_ref() == &~"bar");
|
||||
assert!(x.first_ref() == &~"foo");
|
||||
assert!(x.second_ref() == &~"bar");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(non_implicitly_copyable_typarams)]
|
||||
fn test_tuple() {
|
||||
fail_unless!((948, 4039.48).first() == 948);
|
||||
fail_unless!((34.5, ~"foo").second() == ~"foo");
|
||||
fail_unless!(('a', 2).swap() == (2, 'a'));
|
||||
assert!((948, 4039.48).first() == 948);
|
||||
assert!((34.5, ~"foo").second() == ~"foo");
|
||||
assert!(('a', 2).swap() == (2, 'a'));
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ pub fn run_in_bare_thread(f: ~fn()) {
|
|||
fn test_run_in_bare_thread() {
|
||||
let i = 100;
|
||||
do run_in_bare_thread {
|
||||
fail_unless!(i == 100);
|
||||
assert!(i == 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ fn test_run_in_bare_thread_exchange() {
|
|||
// Does the exchange heap work without the runtime?
|
||||
let i = ~100;
|
||||
do run_in_bare_thread {
|
||||
fail_unless!(i == ~100);
|
||||
assert!(i == ~100);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ impl<T> Drop for ArcDestruct<T>{
|
|||
let data: ~ArcData<T> = cast::reinterpret_cast(&self.data);
|
||||
let new_count =
|
||||
intrinsics::atomic_xsub(&mut data.count, 1) - 1;
|
||||
fail_unless!(new_count >= 0);
|
||||
assert!(new_count >= 0);
|
||||
if new_count == 0 {
|
||||
// drop glue takes over.
|
||||
} else {
|
||||
|
@ -163,7 +163,7 @@ pub unsafe fn get_shared_mutable_state<T:Owned>(
|
|||
{
|
||||
unsafe {
|
||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
||||
fail_unless!(ptr.count > 0);
|
||||
assert!(ptr.count > 0);
|
||||
let r = cast::transmute(ptr.data.get_ref());
|
||||
cast::forget(ptr);
|
||||
return r;
|
||||
|
@ -174,7 +174,7 @@ pub unsafe fn get_shared_immutable_state<'a,T:Owned>(
|
|||
rc: &'a SharedMutableState<T>) -> &'a T {
|
||||
unsafe {
|
||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
||||
fail_unless!(ptr.count > 0);
|
||||
assert!(ptr.count > 0);
|
||||
// Cast us back into the correct region
|
||||
let r = cast::transmute_region(ptr.data.get_ref());
|
||||
cast::forget(ptr);
|
||||
|
@ -187,7 +187,7 @@ pub unsafe fn clone_shared_mutable_state<T:Owned>(rc: &SharedMutableState<T>)
|
|||
unsafe {
|
||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
||||
let new_count = intrinsics::atomic_xadd(&mut ptr.count, 1) + 1;
|
||||
fail_unless!(new_count >= 2);
|
||||
assert!(new_count >= 2);
|
||||
cast::forget(ptr);
|
||||
}
|
||||
ArcDestruct((*rc).data)
|
||||
|
@ -338,7 +338,7 @@ pub mod tests {
|
|||
for futures.each |f| { f.recv() }
|
||||
|
||||
do total.with |total| {
|
||||
fail_unless!(**total == num_tasks * count)
|
||||
assert!(**total == num_tasks * count)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -350,11 +350,11 @@ pub mod tests {
|
|||
let x2 = x.clone();
|
||||
do task::try || {
|
||||
do x2.with |one| {
|
||||
fail_unless!(*one == 2);
|
||||
assert!(*one == 2);
|
||||
}
|
||||
};
|
||||
do x.with |one| {
|
||||
fail_unless!(*one == 1);
|
||||
assert!(*one == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ fn test_at_exit() {
|
|||
let i = 10;
|
||||
do at_exit {
|
||||
debug!("at_exit1");
|
||||
fail_unless!(i == 10);
|
||||
assert!(i == 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,8 +90,8 @@ fn test_at_exit_many() {
|
|||
for uint::range(20, 100) |j| {
|
||||
do at_exit {
|
||||
debug!("at_exit2");
|
||||
fail_unless!(i == 10);
|
||||
fail_unless!(j > i);
|
||||
assert!(i == 10);
|
||||
assert!(j > i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ use intrinsic::TyDesc;
|
|||
|
||||
pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
|
||||
unsafe {
|
||||
fail_unless!(td.is_not_null());
|
||||
assert!(td.is_not_null());
|
||||
|
||||
let total_size = get_box_size(size, (*td).align);
|
||||
let p = c_malloc(total_size as size_t);
|
||||
fail_unless!(p.is_not_null());
|
||||
assert!(p.is_not_null());
|
||||
|
||||
// FIXME #3475: Converting between our two different tydesc types
|
||||
let td: *TyDesc = transmute(td);
|
||||
|
@ -57,7 +57,7 @@ pub unsafe fn free(ptr: *c_void) {
|
|||
let exchange_count = &mut *rust_get_exchange_count_ptr();
|
||||
atomic_xsub(exchange_count, 1);
|
||||
|
||||
fail_unless!(ptr.is_not_null());
|
||||
assert!(ptr.is_not_null());
|
||||
c_free(ptr);
|
||||
}
|
||||
///Thin wrapper around libc::free, as with exchange_alloc::malloc_raw
|
||||
|
@ -75,7 +75,7 @@ fn get_box_size(body_size: uint, body_align: uint) -> uint {
|
|||
// Rounds |size| to the nearest |alignment|. Invariant: |alignment| is a power
|
||||
// of two.
|
||||
fn align_to(size: uint, align: uint) -> uint {
|
||||
fail_unless!(align != 0);
|
||||
assert!(align != 0);
|
||||
(size + align - 1) & !(align - 1)
|
||||
}
|
||||
|
||||
|
|
|
@ -340,11 +340,11 @@ pub mod ct {
|
|||
parse_count(s, 0, s.len()) == Parsed::new(count, next)
|
||||
}
|
||||
|
||||
fail_unless!(test("", CountImplied, 0));
|
||||
fail_unless!(test("*", CountIsNextParam, 1));
|
||||
fail_unless!(test("*1", CountIsNextParam, 1));
|
||||
fail_unless!(test("*1$", CountIsParam(1), 3));
|
||||
fail_unless!(test("123", CountIs(123), 3));
|
||||
assert!(test("", CountImplied, 0));
|
||||
assert!(test("*", CountIsNextParam, 1));
|
||||
assert!(test("*1", CountIsNextParam, 1));
|
||||
assert!(test("*1$", CountIsParam(1), 3));
|
||||
assert!(test("123", CountIs(123), 3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -355,8 +355,8 @@ pub mod ct {
|
|||
|
||||
fn test(s: &str, flags: &[Flag], next: uint) {
|
||||
let f = parse_flags(s, 0, s.len());
|
||||
fail_unless!(pack(f.val) == pack(flags));
|
||||
fail_unless!(f.next == next);
|
||||
assert!(pack(f.val) == pack(flags));
|
||||
assert!(f.next == next);
|
||||
}
|
||||
|
||||
test("", [], 0);
|
||||
|
@ -367,7 +367,7 @@ pub mod ct {
|
|||
|
||||
#[test]
|
||||
fn test_parse_fmt_string() {
|
||||
fail_unless!(parse_fmt_string("foo %s bar", die) == ~[
|
||||
assert!(parse_fmt_string("foo %s bar", die) == ~[
|
||||
PieceString(~"foo "),
|
||||
PieceConv(Conv {
|
||||
param: None,
|
||||
|
@ -378,7 +378,7 @@ pub mod ct {
|
|||
}),
|
||||
PieceString(~" bar")]);
|
||||
|
||||
fail_unless!(parse_fmt_string("%s", die) == ~[
|
||||
assert!(parse_fmt_string("%s", die) == ~[
|
||||
PieceConv(Conv {
|
||||
param: None,
|
||||
flags: ~[],
|
||||
|
@ -387,7 +387,7 @@ pub mod ct {
|
|||
ty: TyStr,
|
||||
})]);
|
||||
|
||||
fail_unless!(parse_fmt_string("%%%%", die) == ~[
|
||||
assert!(parse_fmt_string("%%%%", die) == ~[
|
||||
PieceString(~"%"), PieceString(~"%")]);
|
||||
}
|
||||
|
||||
|
@ -397,10 +397,10 @@ pub mod ct {
|
|||
parse_parameter(s, 0, s.len()) == Parsed::new(param, next)
|
||||
}
|
||||
|
||||
fail_unless!(test("", None, 0));
|
||||
fail_unless!(test("foo", None, 0));
|
||||
fail_unless!(test("123", None, 0));
|
||||
fail_unless!(test("123$", Some(123), 4));
|
||||
assert!(test("", None, 0));
|
||||
assert!(test("foo", None, 0));
|
||||
assert!(test("123", None, 0));
|
||||
assert!(test("123$", Some(123), 4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -409,12 +409,12 @@ pub mod ct {
|
|||
parse_precision(s, 0, s.len()) == Parsed::new(count, next)
|
||||
}
|
||||
|
||||
fail_unless!(test("", CountImplied, 0));
|
||||
fail_unless!(test(".", CountIs(0), 1));
|
||||
fail_unless!(test(".*", CountIsNextParam, 2));
|
||||
fail_unless!(test(".*1", CountIsNextParam, 2));
|
||||
fail_unless!(test(".*1$", CountIsParam(1), 4));
|
||||
fail_unless!(test(".123", CountIs(123), 4));
|
||||
assert!(test("", CountImplied, 0));
|
||||
assert!(test(".", CountIs(0), 1));
|
||||
assert!(test(".*", CountIsNextParam, 2));
|
||||
assert!(test(".*1", CountIsNextParam, 2));
|
||||
assert!(test(".*1$", CountIsParam(1), 4));
|
||||
assert!(test(".123", CountIs(123), 4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -423,17 +423,17 @@ pub mod ct {
|
|||
parse_type(s, 0, s.len(), die) == Parsed::new(ty, 1)
|
||||
}
|
||||
|
||||
fail_unless!(test("b", TyBool));
|
||||
fail_unless!(test("c", TyChar));
|
||||
fail_unless!(test("d", TyInt(Signed)));
|
||||
fail_unless!(test("f", TyFloat));
|
||||
fail_unless!(test("i", TyInt(Signed)));
|
||||
fail_unless!(test("o", TyOctal));
|
||||
fail_unless!(test("s", TyStr));
|
||||
fail_unless!(test("t", TyBits));
|
||||
fail_unless!(test("x", TyHex(CaseLower)));
|
||||
fail_unless!(test("X", TyHex(CaseUpper)));
|
||||
fail_unless!(test("?", TyPoly));
|
||||
assert!(test("b", TyBool));
|
||||
assert!(test("c", TyChar));
|
||||
assert!(test("d", TyInt(Signed)));
|
||||
assert!(test("f", TyFloat));
|
||||
assert!(test("i", TyInt(Signed)));
|
||||
assert!(test("o", TyOctal));
|
||||
assert!(test("s", TyStr));
|
||||
assert!(test("t", TyBits));
|
||||
assert!(test("x", TyHex(CaseLower)));
|
||||
assert!(test("X", TyHex(CaseUpper)));
|
||||
assert!(test("?", TyPoly));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -453,16 +453,16 @@ pub mod ct {
|
|||
#[test]
|
||||
fn test_peek_num() {
|
||||
let s1 = "";
|
||||
fail_unless!(peek_num(s1, 0, s1.len()).is_none());
|
||||
assert!(peek_num(s1, 0, s1.len()).is_none());
|
||||
|
||||
let s2 = "foo";
|
||||
fail_unless!(peek_num(s2, 0, s2.len()).is_none());
|
||||
assert!(peek_num(s2, 0, s2.len()).is_none());
|
||||
|
||||
let s3 = "123";
|
||||
fail_unless!(peek_num(s3, 0, s3.len()) == Some(Parsed::new(123, 3)));
|
||||
assert!(peek_num(s3, 0, s3.len()) == Some(Parsed::new(123, 3)));
|
||||
|
||||
let s4 = "123foo";
|
||||
fail_unless!(peek_num(s4, 0, s4.len()) == Some(Parsed::new(123, 3)));
|
||||
assert!(peek_num(s4, 0, s4.len()) == Some(Parsed::new(123, 3)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,11 +58,11 @@ fn test_success() {
|
|||
do (|| {
|
||||
i = 10;
|
||||
}).finally {
|
||||
fail_unless!(!failing());
|
||||
fail_unless!(i == 10);
|
||||
assert!(!failing());
|
||||
assert!(i == 10);
|
||||
i = 20;
|
||||
}
|
||||
fail_unless!(i == 20);
|
||||
assert!(i == 20);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -74,8 +74,8 @@ fn test_fail() {
|
|||
i = 10;
|
||||
fail!();
|
||||
}).finally {
|
||||
fail_unless!(failing());
|
||||
fail_unless!(i == 10);
|
||||
assert!(failing());
|
||||
assert!(i == 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ fn test_fail() {
|
|||
fn test_retval() {
|
||||
let closure: &fn() -> int = || 10;
|
||||
let i = do closure.finally { };
|
||||
fail_unless!(i == 10);
|
||||
assert!(i == 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -187,7 +187,7 @@ fn get_global_state() -> Exclusive<GlobalState> {
|
|||
let prev_i = unsafe { atomic_cxchg(&mut *global_ptr, 0, state_i) };
|
||||
|
||||
// Sanity check that we're not trying to reinitialize after shutdown
|
||||
fail_unless!(prev_i != POISON);
|
||||
assert!(prev_i != POISON);
|
||||
|
||||
if prev_i == 0 {
|
||||
// Successfully installed the global pointer
|
||||
|
@ -201,7 +201,7 @@ fn get_global_state() -> Exclusive<GlobalState> {
|
|||
let prev_i = unsafe {
|
||||
atomic_cxchg(&mut *global_ptr, state_i, POISON)
|
||||
};
|
||||
fail_unless!(prev_i == state_i);
|
||||
assert!(prev_i == state_i);
|
||||
|
||||
// Capture the global state object in the at_exit closure
|
||||
// so that it is destroyed at the right time
|
||||
|
@ -245,7 +245,7 @@ fn test_clone_rc() {
|
|||
~shared_mutable_state(10)
|
||||
};
|
||||
|
||||
fail_unless!(get_shared_immutable_state(&val) == &10);
|
||||
assert!(get_shared_immutable_state(&val) == &10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ fn test_modify() {
|
|||
match v {
|
||||
Some(sms) => {
|
||||
let v = get_shared_immutable_state(sms);
|
||||
fail_unless!(*v == 10);
|
||||
assert!(*v == 10);
|
||||
None
|
||||
},
|
||||
_ => fail!()
|
||||
|
|
|
@ -42,7 +42,7 @@ pub unsafe fn weaken_task(f: &fn(Port<ShutdownMsg>)) {
|
|||
let shutdown_port = Cell(shutdown_port);
|
||||
let task = get_task_id();
|
||||
// Expect the weak task service to be alive
|
||||
fail_unless!(service.try_send(RegisterWeakTask(task, shutdown_chan)));
|
||||
assert!(service.try_send(RegisterWeakTask(task, shutdown_chan)));
|
||||
unsafe { rust_dec_kernel_live_count(); }
|
||||
do (|| {
|
||||
f(shutdown_port.take())
|
||||
|
@ -104,7 +104,7 @@ fn run_weak_task_service(port: Port<ServiceMsg>) {
|
|||
RegisterWeakTask(task, shutdown_chan) => {
|
||||
let previously_unregistered =
|
||||
shutdown_map.insert(task, shutdown_chan);
|
||||
fail_unless!(previously_unregistered);
|
||||
assert!(previously_unregistered);
|
||||
}
|
||||
UnregisterWeakTask(task) => {
|
||||
match shutdown_map.pop(&task) {
|
||||
|
|
|
@ -82,7 +82,7 @@ terminate normally, but instead directly return from a function.
|
|||
|
||||
~~~
|
||||
fn choose_weighted_item(v: &[Item]) -> Item {
|
||||
fail_unless!(!v.is_empty());
|
||||
assert!(!v.is_empty());
|
||||
let mut so_far = 0u;
|
||||
for v.each |item| {
|
||||
so_far += item.weight;
|
||||
|
@ -110,23 +110,23 @@ mod tests {
|
|||
pub fn identity_crisis() {
|
||||
// Writing a test for the identity function. How did it come to this?
|
||||
let x = ~[(5, false)];
|
||||
//FIXME #3387 fail_unless!(x.eq(id(copy x)));
|
||||
//FIXME #3387 assert!(x.eq(id(copy x)));
|
||||
let y = copy x;
|
||||
fail_unless!(x.eq(&id(y)));
|
||||
assert!(x.eq(&id(y)));
|
||||
}
|
||||
#[test]
|
||||
pub fn test_swap() {
|
||||
let mut x = 31337;
|
||||
let mut y = 42;
|
||||
swap(&mut x, &mut y);
|
||||
fail_unless!(x == 42);
|
||||
fail_unless!(y == 31337);
|
||||
assert!(x == 42);
|
||||
assert!(y == 31337);
|
||||
}
|
||||
#[test]
|
||||
pub fn test_replace() {
|
||||
let mut x = Some(NonCopyable());
|
||||
let y = replace(&mut x, None);
|
||||
fail_unless!(x.is_none());
|
||||
fail_unless!(y.is_some());
|
||||
assert!(x.is_none());
|
||||
assert!(y.is_some());
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -29,13 +29,13 @@ fn builtin_equal<T>(&&a: T, &&b: T) -> bool { return a == b; }
|
|||
fn builtin_equal_int(&&a: int, &&b: int) -> bool { return a == b; }
|
||||
|
||||
fn main() {
|
||||
fail_unless!((builtin_equal(5, 5)));
|
||||
fail_unless!((!builtin_equal(5, 4)));
|
||||
fail_unless!((!vec_equal(~[5, 5], ~[5], bind builtin_equal(_, _))));
|
||||
fail_unless!((!vec_equal(~[5, 5], ~[5], builtin_equal_int)));
|
||||
fail_unless!((!vec_equal(~[5, 5], ~[5, 4], builtin_equal_int)));
|
||||
fail_unless!((!vec_equal(~[5, 5], ~[4, 5], builtin_equal_int)));
|
||||
fail_unless!((vec_equal(~[5, 5], ~[5, 5], builtin_equal_int)));
|
||||
assert!((builtin_equal(5, 5)));
|
||||
assert!((!builtin_equal(5, 4)));
|
||||
assert!((!vec_equal(~[5, 5], ~[5], bind builtin_equal(_, _))));
|
||||
assert!((!vec_equal(~[5, 5], ~[5], builtin_equal_int)));
|
||||
assert!((!vec_equal(~[5, 5], ~[5, 4], builtin_equal_int)));
|
||||
assert!((!vec_equal(~[5, 5], ~[4, 5], builtin_equal_int)));
|
||||
assert!((vec_equal(~[5, 5], ~[5, 5], builtin_equal_int)));
|
||||
|
||||
error!("Pass");
|
||||
}
|
||||
|
|
|
@ -14,12 +14,12 @@ use uint::range;
|
|||
|
||||
// random uint less than n
|
||||
fn under(r : rand::rng, n : uint) -> uint {
|
||||
fail_unless!(n != 0u); r.next() as uint % n
|
||||
assert!(n != 0u); r.next() as uint % n
|
||||
}
|
||||
|
||||
// random choice from a vec
|
||||
fn choice<T:copy>(r : rand::rng, v : ~[const T]) -> T {
|
||||
fail_unless!(vec::len(v) != 0u); v[under(r, vec::len(v))]
|
||||
assert!(vec::len(v) != 0u); v[under(r, vec::len(v))]
|
||||
}
|
||||
|
||||
// k in n chance of being true
|
||||
|
|
|
@ -377,13 +377,13 @@ pub fn check_whole_compiler(code: ~str, suggested_filename_prefix: &Path,
|
|||
|
||||
pub fn removeIfExists(filename: &Path) {
|
||||
// So sketchy!
|
||||
fail_unless!(!contains(filename.to_str(), ~" "));
|
||||
assert!(!contains(filename.to_str(), ~" "));
|
||||
run::program_output(~"bash", ~[~"-c", ~"rm " + filename.to_str()]);
|
||||
}
|
||||
|
||||
pub fn removeDirIfExists(filename: &Path) {
|
||||
// So sketchy!
|
||||
fail_unless!(!contains(filename.to_str(), ~" "));
|
||||
assert!(!contains(filename.to_str(), ~" "));
|
||||
run::program_output(~"bash", ~[~"-c", ~"rm -r " + filename.to_str()]);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,12 @@ use std::rand;
|
|||
|
||||
// random uint less than n
|
||||
fn under(r : rand::rng, n : uint) -> uint {
|
||||
fail_unless!(n != 0u); r.next() as uint % n
|
||||
assert!(n != 0u); r.next() as uint % n
|
||||
}
|
||||
|
||||
// random choice from a vec
|
||||
fn choice<T:copy>(r : rand::rng, v : ~[T]) -> T {
|
||||
fail_unless!(vec::len(v) != 0u); v[under(r, vec::len(v))]
|
||||
assert!(vec::len(v) != 0u); v[under(r, vec::len(v))]
|
||||
}
|
||||
|
||||
// 1 in n chance of being true
|
||||
|
@ -49,12 +49,12 @@ fn shuffled<T:copy>(r : rand::rng, v : ~[T]) -> ~[T] {
|
|||
// * weighted_vec is O(total weight) space
|
||||
type weighted<T> = { weight: uint, item: T };
|
||||
fn weighted_choice<T:copy>(r : rand::rng, v : ~[weighted<T>]) -> T {
|
||||
fail_unless!(vec::len(v) != 0u);
|
||||
assert!(vec::len(v) != 0u);
|
||||
let total = 0u;
|
||||
for {weight: weight, item: _} in v {
|
||||
total += weight;
|
||||
}
|
||||
fail_unless!(total >= 0u);
|
||||
assert!(total >= 0u);
|
||||
let chosen = under(r, total);
|
||||
let so_far = 0u;
|
||||
for {weight: weight, item: item} in v {
|
||||
|
|
|
@ -118,7 +118,7 @@ pub fn get_rpath_relative_to_output(os: session::os,
|
|||
-> Path {
|
||||
use core::os;
|
||||
|
||||
fail_unless!(not_win32(os));
|
||||
assert!(not_win32(os));
|
||||
|
||||
// Mac doesn't appear to support $ORIGIN
|
||||
let prefix = match os {
|
||||
|
@ -134,8 +134,8 @@ pub fn get_rpath_relative_to_output(os: session::os,
|
|||
|
||||
// Find the relative path from one file to another
|
||||
pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
|
||||
fail_unless!(abs1.is_absolute);
|
||||
fail_unless!(abs2.is_absolute);
|
||||
assert!(abs1.is_absolute);
|
||||
assert!(abs2.is_absolute);
|
||||
let abs1 = abs1.normalize();
|
||||
let abs2 = abs2.normalize();
|
||||
debug!("finding relative path from %s to %s",
|
||||
|
@ -144,8 +144,8 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
|
|||
let split2: &[~str] = abs2.components;
|
||||
let len1 = vec::len(split1);
|
||||
let len2 = vec::len(split2);
|
||||
fail_unless!(len1 > 0);
|
||||
fail_unless!(len2 > 0);
|
||||
assert!(len1 > 0);
|
||||
assert!(len2 > 0);
|
||||
|
||||
let max_common_path = uint::min(len1, len2) - 1;
|
||||
let mut start_idx = 0;
|
||||
|
@ -215,7 +215,7 @@ mod test {
|
|||
pub fn test_rpaths_to_flags() {
|
||||
let flags = rpaths_to_flags(~[Path("path1"),
|
||||
Path("path2")]);
|
||||
fail_unless!(flags == ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"]);
|
||||
assert!(flags == ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -226,13 +226,13 @@ mod test {
|
|||
debug!("test_prefix_path: %s vs. %s",
|
||||
res.to_str(),
|
||||
d.to_str());
|
||||
fail_unless!(str::ends_with(res.to_str(), d.to_str()));
|
||||
assert!(str::ends_with(res.to_str(), d.to_str()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_prefix_rpath_abs() {
|
||||
let res = get_install_prefix_rpath("triple");
|
||||
fail_unless!(res.is_absolute);
|
||||
assert!(res.is_absolute);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -240,7 +240,7 @@ mod test {
|
|||
let res = minimize_rpaths([Path("rpath1"),
|
||||
Path("rpath2"),
|
||||
Path("rpath1")]);
|
||||
fail_unless!(res == ~[Path("rpath1"), Path("rpath2")]);
|
||||
assert!(res == ~[Path("rpath1"), Path("rpath2")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -249,7 +249,7 @@ mod test {
|
|||
Path("1a"), Path("4a"),Path("1a"),
|
||||
Path("2"), Path("3"), Path("4a"),
|
||||
Path("3")]);
|
||||
fail_unless!(res == ~[Path("1a"), Path("2"), Path("4a"), Path("3")]);
|
||||
assert!(res == ~[Path("1a"), Path("2"), Path("4a"), Path("3")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -257,7 +257,7 @@ mod test {
|
|||
let p1 = Path("/usr/bin/rustc");
|
||||
let p2 = Path("/usr/lib/mylib");
|
||||
let res = get_relative_to(&p1, &p2);
|
||||
fail_unless!(res == Path("../lib"));
|
||||
assert!(res == Path("../lib"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -265,7 +265,7 @@ mod test {
|
|||
let p1 = Path("/usr/bin/rustc");
|
||||
let p2 = Path("/usr/bin/../lib/mylib");
|
||||
let res = get_relative_to(&p1, &p2);
|
||||
fail_unless!(res == Path("../lib"));
|
||||
assert!(res == Path("../lib"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -273,7 +273,7 @@ mod test {
|
|||
let p1 = Path("/usr/bin/whatever/rustc");
|
||||
let p2 = Path("/usr/lib/whatever/mylib");
|
||||
let res = get_relative_to(&p1, &p2);
|
||||
fail_unless!(res == Path("../../lib/whatever"));
|
||||
assert!(res == Path("../../lib/whatever"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -281,7 +281,7 @@ mod test {
|
|||
let p1 = Path("/usr/bin/whatever/../rustc");
|
||||
let p2 = Path("/usr/lib/whatever/mylib");
|
||||
let res = get_relative_to(&p1, &p2);
|
||||
fail_unless!(res == Path("../lib/whatever"));
|
||||
assert!(res == Path("../lib/whatever"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -289,7 +289,7 @@ mod test {
|
|||
let p1 = Path("/usr/bin/whatever/../rustc");
|
||||
let p2 = Path("/usr/lib/whatever/../mylib");
|
||||
let res = get_relative_to(&p1, &p2);
|
||||
fail_unless!(res == Path("../lib"));
|
||||
assert!(res == Path("../lib"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -297,7 +297,7 @@ mod test {
|
|||
let p1 = Path("/1");
|
||||
let p2 = Path("/2/3");
|
||||
let res = get_relative_to(&p1, &p2);
|
||||
fail_unless!(res == Path("2"));
|
||||
assert!(res == Path("2"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -305,7 +305,7 @@ mod test {
|
|||
let p1 = Path("/1/2");
|
||||
let p2 = Path("/3");
|
||||
let res = get_relative_to(&p1, &p2);
|
||||
fail_unless!(res == Path(".."));
|
||||
assert!(res == Path(".."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -318,7 +318,7 @@ mod test {
|
|||
debug!("test_relative_tu8: %s vs. %s",
|
||||
res.to_str(),
|
||||
Path(".").to_str());
|
||||
fail_unless!(res == Path("."));
|
||||
assert!(res == Path("."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -328,7 +328,7 @@ mod test {
|
|||
let o = session::os_linux;
|
||||
let res = get_rpath_relative_to_output(o,
|
||||
&Path("bin/rustc"), &Path("lib/libstd.so"));
|
||||
fail_unless!(res.to_str() == ~"$ORIGIN/../lib");
|
||||
assert!(res.to_str() == ~"$ORIGIN/../lib");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -337,7 +337,7 @@ mod test {
|
|||
let o = session::os_freebsd;
|
||||
let res = get_rpath_relative_to_output(o,
|
||||
&Path("bin/rustc"), &Path("lib/libstd.so"));
|
||||
fail_unless!(res.to_str() == ~"$ORIGIN/../lib");
|
||||
assert!(res.to_str() == ~"$ORIGIN/../lib");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -348,7 +348,7 @@ mod test {
|
|||
let res = get_rpath_relative_to_output(o,
|
||||
&Path("bin/rustc"),
|
||||
&Path("lib/libstd.so"));
|
||||
fail_unless!(res.to_str() == ~"@executable_path/../lib");
|
||||
assert!(res.to_str() == ~"@executable_path/../lib");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -358,6 +358,6 @@ mod test {
|
|||
res.to_str(),
|
||||
os::make_absolute(&Path("lib")).to_str());
|
||||
|
||||
fail_unless!(res == os::make_absolute(&Path("lib")));
|
||||
assert!(res == os::make_absolute(&Path("lib")));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -899,7 +899,7 @@ pub mod test {
|
|||
~"rustc", matches, diagnostic::emit);
|
||||
let sess = build_session(sessopts, diagnostic::emit);
|
||||
let cfg = build_configuration(sess, ~"whatever", str_input(~""));
|
||||
fail_unless!((attr::contains_name(cfg, ~"test")));
|
||||
assert!((attr::contains_name(cfg, ~"test")));
|
||||
}
|
||||
|
||||
// When the user supplies --test and --cfg test, don't implicitly add
|
||||
|
@ -919,7 +919,7 @@ pub mod test {
|
|||
let sess = build_session(sessopts, diagnostic::emit);
|
||||
let cfg = build_configuration(sess, ~"whatever", str_input(~""));
|
||||
let test_items = attr::find_meta_items_by_name(cfg, ~"test");
|
||||
fail_unless!((vec::len(test_items) == 1u));
|
||||
assert!((vec::len(test_items) == 1u));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -378,43 +378,43 @@ pub mod test {
|
|||
#[test]
|
||||
pub fn bin_crate_type_attr_results_in_bin_output() {
|
||||
let crate = make_crate(true, false);
|
||||
fail_unless!(!building_library(unknown_crate, crate, false));
|
||||
assert!(!building_library(unknown_crate, crate, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn lib_crate_type_attr_results_in_lib_output() {
|
||||
let crate = make_crate(false, true);
|
||||
fail_unless!(building_library(unknown_crate, crate, false));
|
||||
assert!(building_library(unknown_crate, crate, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn bin_option_overrides_lib_crate_type() {
|
||||
let crate = make_crate(false, true);
|
||||
fail_unless!(!building_library(bin_crate, crate, false));
|
||||
assert!(!building_library(bin_crate, crate, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn lib_option_overrides_bin_crate_type() {
|
||||
let crate = make_crate(true, false);
|
||||
fail_unless!(building_library(lib_crate, crate, false));
|
||||
assert!(building_library(lib_crate, crate, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn bin_crate_type_is_default() {
|
||||
let crate = make_crate(false, false);
|
||||
fail_unless!(!building_library(unknown_crate, crate, false));
|
||||
assert!(!building_library(unknown_crate, crate, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_option_overrides_lib_crate_type() {
|
||||
let crate = make_crate(false, true);
|
||||
fail_unless!(!building_library(unknown_crate, crate, true));
|
||||
assert!(!building_library(unknown_crate, crate, true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_option_does_not_override_requested_lib_type() {
|
||||
let crate = make_crate(false, false);
|
||||
fail_unless!(building_library(lib_crate, crate, true));
|
||||
assert!(building_library(lib_crate, crate, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1472,8 +1472,8 @@ pub struct TypeNames {
|
|||
}
|
||||
|
||||
pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) {
|
||||
fail_unless!(tn.type_names.insert(t, s));
|
||||
fail_unless!(tn.named_types.insert(s, t));
|
||||
assert!(tn.type_names.insert(t, s));
|
||||
assert!(tn.named_types.insert(s, t));
|
||||
}
|
||||
|
||||
pub fn type_has_name(tn: @TypeNames, t: TypeRef) -> Option<@str> {
|
||||
|
|
|
@ -97,7 +97,7 @@ fn warn_if_multiple_versions(e: @mut Env,
|
|||
}
|
||||
}));
|
||||
|
||||
fail_unless!(!matches.is_empty());
|
||||
assert!(!matches.is_empty());
|
||||
|
||||
if matches.len() != 1u {
|
||||
diag.handler().warn(
|
||||
|
|
|
@ -102,7 +102,7 @@ pub fn get_used_crate_files(cstore: &CStore) -> ~[Path] {
|
|||
}
|
||||
|
||||
pub fn add_used_library(cstore: &mut CStore, lib: @~str) -> bool {
|
||||
fail_unless!(*lib != ~"");
|
||||
assert!(*lib != ~"");
|
||||
|
||||
if cstore.used_libraries.contains(&*lib) { return false; }
|
||||
cstore.used_libraries.push(/*bad*/ copy *lib);
|
||||
|
|
|
@ -1003,7 +1003,7 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] {
|
|||
let meta_items = get_meta_items(attr_doc);
|
||||
// Currently it's only possible to have a single meta item on
|
||||
// an attribute
|
||||
fail_unless!((vec::len(meta_items) == 1u));
|
||||
assert!((vec::len(meta_items) == 1u));
|
||||
let meta_item = meta_items[0];
|
||||
attrs.push(
|
||||
codemap::spanned {
|
||||
|
|
|
@ -1082,7 +1082,7 @@ fn encode_index<T>(ebml_w: writer::Encoder, buckets: ~[@~[entry<T>]],
|
|||
ebml_w.start_tag(tag_index_buckets_bucket);
|
||||
for vec::each(**bucket) |elt| {
|
||||
ebml_w.start_tag(tag_index_buckets_bucket_elt);
|
||||
fail_unless!(elt.pos < 0xffff_ffff);
|
||||
assert!(elt.pos < 0xffff_ffff);
|
||||
writer.write_be_u32(elt.pos as u32);
|
||||
write_fn(writer, elt.val);
|
||||
ebml_w.end_tag();
|
||||
|
@ -1092,7 +1092,7 @@ fn encode_index<T>(ebml_w: writer::Encoder, buckets: ~[@~[entry<T>]],
|
|||
ebml_w.end_tag();
|
||||
ebml_w.start_tag(tag_index_table);
|
||||
for bucket_locs.each |pos| {
|
||||
fail_unless!(*pos < 0xffff_ffff);
|
||||
assert!(*pos < 0xffff_ffff);
|
||||
writer.write_be_u32(*pos as u32);
|
||||
}
|
||||
ebml_w.end_tag();
|
||||
|
@ -1102,7 +1102,7 @@ fn encode_index<T>(ebml_w: writer::Encoder, buckets: ~[@~[entry<T>]],
|
|||
fn write_str(writer: @io::Writer, &&s: ~str) { writer.write_str(s); }
|
||||
|
||||
fn write_int(writer: @io::Writer, &&n: int) {
|
||||
fail_unless!(n < 0x7fff_ffff);
|
||||
assert!(n < 0x7fff_ffff);
|
||||
writer.write_be_u32(n as u32);
|
||||
}
|
||||
|
||||
|
@ -1163,8 +1163,8 @@ fn synthesize_crate_attrs(ecx: @EncodeContext,
|
|||
fn synthesize_link_attr(ecx: @EncodeContext, +items: ~[@meta_item]) ->
|
||||
attribute {
|
||||
|
||||
fail_unless!(!ecx.link_meta.name.is_empty());
|
||||
fail_unless!(!ecx.link_meta.vers.is_empty());
|
||||
assert!(!ecx.link_meta.name.is_empty());
|
||||
assert!(!ecx.link_meta.vers.is_empty());
|
||||
|
||||
let name_item =
|
||||
attr::mk_name_value_item_str(@~"name",
|
||||
|
@ -1230,7 +1230,7 @@ fn encode_crate_deps(ecx: @EncodeContext,
|
|||
// Sanity-check the crate numbers
|
||||
let mut expected_cnum = 1;
|
||||
for deps.each |n| {
|
||||
fail_unless!((n.cnum == expected_cnum));
|
||||
assert!((n.cnum == expected_cnum));
|
||||
expected_cnum += 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -142,12 +142,12 @@ fn parse_sigil(st: @mut PState) -> ast::Sigil {
|
|||
}
|
||||
|
||||
fn parse_vstore(st: @mut PState) -> ty::vstore {
|
||||
fail_unless!(next(st) == '/');
|
||||
assert!(next(st) == '/');
|
||||
|
||||
let c = peek(st);
|
||||
if '0' <= c && c <= '9' {
|
||||
let n = parse_int(st) as uint;
|
||||
fail_unless!(next(st) == '|');
|
||||
assert!(next(st) == '|');
|
||||
return ty::vstore_fixed(n);
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ fn parse_substs(st: @mut PState, conv: conv_did) -> ty::substs {
|
|||
|
||||
let self_ty = parse_opt(st, || parse_ty(st, conv) );
|
||||
|
||||
fail_unless!(next(st) == '[');
|
||||
assert!(next(st) == '[');
|
||||
let mut params: ~[ty::t] = ~[];
|
||||
while peek(st) != ']' { params.push(parse_ty(st, conv)); }
|
||||
st.pos = st.pos + 1u;
|
||||
|
@ -191,13 +191,13 @@ fn parse_bound_region(st: @mut PState) -> ty::bound_region {
|
|||
's' => ty::br_self,
|
||||
'a' => {
|
||||
let id = parse_int(st) as uint;
|
||||
fail_unless!(next(st) == '|');
|
||||
assert!(next(st) == '|');
|
||||
ty::br_anon(id)
|
||||
}
|
||||
'[' => ty::br_named(st.tcx.sess.ident_of(parse_str(st, ']'))),
|
||||
'c' => {
|
||||
let id = parse_int(st);
|
||||
fail_unless!(next(st) == '|');
|
||||
assert!(next(st) == '|');
|
||||
ty::br_cap_avoid(id, @parse_bound_region(st))
|
||||
},
|
||||
_ => fail!(~"parse_bound_region: bad input")
|
||||
|
@ -210,16 +210,16 @@ fn parse_region(st: @mut PState) -> ty::Region {
|
|||
ty::re_bound(parse_bound_region(st))
|
||||
}
|
||||
'f' => {
|
||||
fail_unless!(next(st) == '[');
|
||||
assert!(next(st) == '[');
|
||||
let id = parse_int(st);
|
||||
fail_unless!(next(st) == '|');
|
||||
assert!(next(st) == '|');
|
||||
let br = parse_bound_region(st);
|
||||
fail_unless!(next(st) == ']');
|
||||
assert!(next(st) == ']');
|
||||
ty::re_free(id, br)
|
||||
}
|
||||
's' => {
|
||||
let id = parse_int(st);
|
||||
fail_unless!(next(st) == '|');
|
||||
assert!(next(st) == '|');
|
||||
ty::re_scope(id)
|
||||
}
|
||||
't' => {
|
||||
|
@ -271,18 +271,18 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
|
|||
}
|
||||
'c' => return ty::mk_char(st.tcx),
|
||||
't' => {
|
||||
fail_unless!((next(st) == '['));
|
||||
assert!((next(st) == '['));
|
||||
let def = parse_def(st, NominalType, conv);
|
||||
let substs = parse_substs(st, conv);
|
||||
fail_unless!(next(st) == ']');
|
||||
assert!(next(st) == ']');
|
||||
return ty::mk_enum(st.tcx, def, substs);
|
||||
}
|
||||
'x' => {
|
||||
fail_unless!(next(st) == '[');
|
||||
assert!(next(st) == '[');
|
||||
let def = parse_def(st, NominalType, conv);
|
||||
let substs = parse_substs(st, conv);
|
||||
let store = parse_trait_store(st);
|
||||
fail_unless!(next(st) == ']');
|
||||
assert!(next(st) == ']');
|
||||
return ty::mk_trait(st.tcx, def, substs, store);
|
||||
}
|
||||
'p' => {
|
||||
|
@ -313,7 +313,7 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
|
|||
return ty::mk_estr(st.tcx, v);
|
||||
}
|
||||
'T' => {
|
||||
fail_unless!((next(st) == '['));
|
||||
assert!((next(st) == '['));
|
||||
let mut params = ~[];
|
||||
while peek(st) != ']' { params.push(parse_ty(st, conv)); }
|
||||
st.pos = st.pos + 1u;
|
||||
|
@ -332,9 +332,9 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
|
|||
}
|
||||
'#' => {
|
||||
let pos = parse_hex(st);
|
||||
fail_unless!((next(st) == ':'));
|
||||
assert!((next(st) == ':'));
|
||||
let len = parse_hex(st);
|
||||
fail_unless!((next(st) == '#'));
|
||||
assert!((next(st) == '#'));
|
||||
let key = ty::creader_cache_key {cnum: st.crate,
|
||||
pos: pos,
|
||||
len: len };
|
||||
|
@ -355,10 +355,10 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
|
|||
}
|
||||
'B' => ty::mk_opaque_box(st.tcx),
|
||||
'a' => {
|
||||
fail_unless!((next(st) == '['));
|
||||
assert!((next(st) == '['));
|
||||
let did = parse_def(st, NominalType, conv);
|
||||
let substs = parse_substs(st, conv);
|
||||
fail_unless!((next(st) == ']'));
|
||||
assert!((next(st) == ']'));
|
||||
return ty::mk_struct(st.tcx, did, substs);
|
||||
}
|
||||
c => { error!("unexpected char in type string: %c", c); fail!();}
|
||||
|
@ -472,7 +472,7 @@ fn parse_bare_fn_ty(st: @mut PState, conv: conv_did) -> ty::BareFnTy {
|
|||
}
|
||||
|
||||
fn parse_sig(st: @mut PState, conv: conv_did) -> ty::FnSig {
|
||||
fail_unless!((next(st) == '['));
|
||||
assert!((next(st) == '['));
|
||||
let mut inputs: ~[ty::arg] = ~[];
|
||||
while peek(st) != ']' {
|
||||
let mode = parse_mode(st);
|
||||
|
|
|
@ -175,7 +175,7 @@ pub impl ExtendedDecodeContext {
|
|||
*/
|
||||
|
||||
// from_id_range should be non-empty
|
||||
fail_unless!(!ast_util::empty(self.from_id_range));
|
||||
assert!(!ast_util::empty(self.from_id_range));
|
||||
(id - self.from_id_range.min + self.to_id_range.min)
|
||||
}
|
||||
fn tr_def_id(&self, did: ast::def_id) -> ast::def_id {
|
||||
|
@ -212,7 +212,7 @@ pub impl ExtendedDecodeContext {
|
|||
* refer to the current crate and to the new, inlined node-id.
|
||||
*/
|
||||
|
||||
fail_unless!(did.crate == ast::local_crate);
|
||||
assert!(did.crate == ast::local_crate);
|
||||
ast::def_id { crate: ast::local_crate, node: self.tr_id(did.node) }
|
||||
}
|
||||
fn tr_span(&self, _span: span) -> span {
|
||||
|
@ -1232,7 +1232,7 @@ fn roundtrip(in_item: Option<@ast::item>) {
|
|||
debug!("expected string: %s", exp_str);
|
||||
debug!("actual string : %s", out_str);
|
||||
|
||||
fail_unless!(exp_str == out_str);
|
||||
assert!(exp_str == out_str);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1279,7 +1279,7 @@ fn test_simplification() {
|
|||
).get());
|
||||
match (item_out, item_exp) {
|
||||
(ast::ii_item(item_out), ast::ii_item(item_exp)) => {
|
||||
fail_unless!(pprust::item_to_str(item_out,
|
||||
assert!(pprust::item_to_str(item_out,
|
||||
ext_cx.parse_sess().interner)
|
||||
== pprust::item_to_str(item_exp,
|
||||
ext_cx.parse_sess().interner));
|
||||
|
|
|
@ -132,7 +132,7 @@ pub fn raw_pat(p: @pat) -> @pat {
|
|||
}
|
||||
|
||||
pub fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) {
|
||||
fail_unless!((!pats.is_empty()));
|
||||
assert!((!pats.is_empty()));
|
||||
let ext = match is_useful(cx, &pats.map(|p| ~[*p]), ~[wild()]) {
|
||||
not_useful => {
|
||||
// This is good, wildcard pattern isn't reachable
|
||||
|
|
|
@ -882,7 +882,7 @@ fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) {
|
|||
fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
|
||||
fn is_camel_case(cx: ty::ctxt, ident: ast::ident) -> bool {
|
||||
let ident = cx.sess.str_of(ident);
|
||||
fail_unless!(!ident.is_empty());
|
||||
assert!(!ident.is_empty());
|
||||
let ident = ident_without_trailing_underscores(*ident);
|
||||
let ident = ident_without_leading_underscores(ident);
|
||||
char::is_uppercase(str::char_at(ident, 0)) &&
|
||||
|
|
|
@ -733,7 +733,7 @@ pub impl Liveness {
|
|||
fn live_on_entry(&self, ln: LiveNode, var: Variable)
|
||||
-> Option<LiveNodeKind> {
|
||||
|
||||
fail_unless!(ln.is_valid());
|
||||
assert!(ln.is_valid());
|
||||
let reader = self.users[self.idx(ln, var)].reader;
|
||||
if reader.is_valid() {Some(self.ir.lnk(reader))} else {None}
|
||||
}
|
||||
|
@ -748,14 +748,14 @@ pub impl Liveness {
|
|||
}
|
||||
|
||||
fn used_on_entry(&self, ln: LiveNode, var: Variable) -> bool {
|
||||
fail_unless!(ln.is_valid());
|
||||
assert!(ln.is_valid());
|
||||
self.users[self.idx(ln, var)].used
|
||||
}
|
||||
|
||||
fn assigned_on_entry(&self, ln: LiveNode, var: Variable)
|
||||
-> Option<LiveNodeKind> {
|
||||
|
||||
fail_unless!(ln.is_valid());
|
||||
assert!(ln.is_valid());
|
||||
let writer = self.users[self.idx(ln, var)].writer;
|
||||
if writer.is_valid() {Some(self.ir.lnk(writer))} else {None}
|
||||
}
|
||||
|
@ -1465,9 +1465,9 @@ pub impl Liveness {
|
|||
// repeat until fixed point is reached:
|
||||
while self.merge_from_succ(ln, body_ln, first_merge) {
|
||||
first_merge = false;
|
||||
fail_unless!(cond_ln == self.propagate_through_opt_expr(cond,
|
||||
assert!(cond_ln == self.propagate_through_opt_expr(cond,
|
||||
ln));
|
||||
fail_unless!(body_ln == self.with_loop_nodes(expr.id, succ, ln,
|
||||
assert!(body_ln == self.with_loop_nodes(expr.id, succ, ln,
|
||||
|| {
|
||||
self.propagate_through_block(body, cond_ln)
|
||||
}));
|
||||
|
|
|
@ -463,7 +463,7 @@ pub impl DetermineRpCtxt {
|
|||
/// variance `variance`. If `id` was already parameterized, then
|
||||
/// the new variance is joined with the old variance.
|
||||
fn add_rp(&mut self, id: ast::node_id, variance: region_variance) {
|
||||
fail_unless!(id != 0);
|
||||
assert!(id != 0);
|
||||
let old_variance = self.region_paramd_items.find(&id).
|
||||
map_consume(|x| *x);
|
||||
let joined_variance = match old_variance {
|
||||
|
|
|
@ -1407,7 +1407,7 @@ pub impl Resolver {
|
|||
match view_path.node {
|
||||
view_path_simple(_, full_path, _, _) => {
|
||||
let path_len = full_path.idents.len();
|
||||
fail_unless!(path_len != 0);
|
||||
assert!(path_len != 0);
|
||||
|
||||
for full_path.idents.eachi |i, ident| {
|
||||
if i != path_len - 1 {
|
||||
|
@ -2083,7 +2083,7 @@ pub impl Resolver {
|
|||
// Decrement the count of unresolved imports.
|
||||
match resolution_result {
|
||||
Success(()) => {
|
||||
fail_unless!(self.unresolved_imports >= 1);
|
||||
assert!(self.unresolved_imports >= 1);
|
||||
self.unresolved_imports -= 1;
|
||||
}
|
||||
_ => {
|
||||
|
@ -2099,7 +2099,7 @@ pub impl Resolver {
|
|||
if !resolution_result.indeterminate() {
|
||||
match *import_directive.subclass {
|
||||
GlobImport => {
|
||||
fail_unless!(module_.glob_count >= 1);
|
||||
assert!(module_.glob_count >= 1);
|
||||
module_.glob_count -= 1;
|
||||
}
|
||||
SingleImport(*) => {
|
||||
|
@ -2266,7 +2266,7 @@ pub impl Resolver {
|
|||
}
|
||||
|
||||
// We've successfully resolved the import. Write the results in.
|
||||
fail_unless!(module_.import_resolutions.contains_key(&target));
|
||||
assert!(module_.import_resolutions.contains_key(&target));
|
||||
let import_resolution = module_.import_resolutions.get(&target);
|
||||
|
||||
match value_result {
|
||||
|
@ -2329,7 +2329,7 @@ pub impl Resolver {
|
|||
}
|
||||
}
|
||||
|
||||
fail_unless!(import_resolution.outstanding_references >= 1);
|
||||
assert!(import_resolution.outstanding_references >= 1);
|
||||
import_resolution.outstanding_references -= 1;
|
||||
|
||||
debug!("(resolving single import) successfully resolved import");
|
||||
|
@ -2359,7 +2359,7 @@ pub impl Resolver {
|
|||
return Indeterminate;
|
||||
}
|
||||
|
||||
fail_unless!(containing_module.glob_count == 0);
|
||||
assert!(containing_module.glob_count == 0);
|
||||
|
||||
// Add all resolved imports from the containing module.
|
||||
for containing_module.import_resolutions.each
|
||||
|
@ -2560,7 +2560,7 @@ pub impl Resolver {
|
|||
span: span)
|
||||
-> ResolveResult<@mut Module> {
|
||||
let module_path_len = module_path.len();
|
||||
fail_unless!(module_path_len > 0);
|
||||
assert!(module_path_len > 0);
|
||||
|
||||
debug!("(resolving module path for import) processing `%s` rooted at \
|
||||
`%s`",
|
||||
|
@ -2923,7 +2923,7 @@ pub impl Resolver {
|
|||
// If this is a search of all imports, we should be done with glob
|
||||
// resolution at this point.
|
||||
if name_search_type == SearchItemsAndAllImports {
|
||||
fail_unless!(module_.glob_count == 0);
|
||||
assert!(module_.glob_count == 0);
|
||||
}
|
||||
|
||||
// Check the list of resolved imports.
|
||||
|
|
|
@ -1259,7 +1259,7 @@ pub fn compile_submatch(bcx: block,
|
|||
/*
|
||||
For an empty match, a fall-through case must exist
|
||||
*/
|
||||
fail_unless!((m.len() > 0u || chk.is_some()));
|
||||
assert!((m.len() > 0u || chk.is_some()));
|
||||
let _icx = bcx.insn_ctxt("match::compile_submatch");
|
||||
let mut bcx = bcx;
|
||||
let tcx = bcx.tcx(), dm = tcx.def_map;
|
||||
|
|
|
@ -139,7 +139,7 @@ pub fn represent_type(cx: @CrateContext, t: ty::t) -> @Repr {
|
|||
CEnum(discrs.min(), discrs.max())
|
||||
} else if cases.len() == 1 {
|
||||
// Equivalent to a struct/tuple/newtype.
|
||||
fail_unless!(cases[0].discr == 0);
|
||||
assert!(cases[0].discr == 0);
|
||||
Univariant(mk_struct(cx, cases[0].tys), false)
|
||||
} else {
|
||||
// The general case. Since there's at least one
|
||||
|
@ -191,7 +191,7 @@ fn generic_fields_of(cx: @CrateContext, r: &Repr, sizing: bool)
|
|||
// To get "the" type of a general enum, we pick the case
|
||||
// with the largest alignment (so it will always align
|
||||
// correctly in containing structures) and pad it out.
|
||||
fail_unless!(sts.len() >= 1);
|
||||
assert!(sts.len() >= 1);
|
||||
let mut most_aligned = None;
|
||||
let mut largest_align = 0;
|
||||
let mut largest_size = 0;
|
||||
|
@ -300,16 +300,16 @@ pub fn trans_case(bcx: block, r: &Repr, discr: int) -> _match::opt_result {
|
|||
pub fn trans_start_init(bcx: block, r: &Repr, val: ValueRef, discr: int) {
|
||||
match *r {
|
||||
CEnum(min, max) => {
|
||||
fail_unless!(min <= discr && discr <= max);
|
||||
assert!(min <= discr && discr <= max);
|
||||
Store(bcx, C_int(bcx.ccx(), discr), GEPi(bcx, val, [0, 0]))
|
||||
}
|
||||
Univariant(ref st, true) => {
|
||||
fail_unless!(discr == 0);
|
||||
assert!(discr == 0);
|
||||
Store(bcx, C_bool(true),
|
||||
GEPi(bcx, val, [0, st.fields.len() - 1]))
|
||||
}
|
||||
Univariant(*) => {
|
||||
fail_unless!(discr == 0);
|
||||
assert!(discr == 0);
|
||||
}
|
||||
General(*) => {
|
||||
Store(bcx, C_int(bcx.ccx(), discr), GEPi(bcx, val, [0, 0]))
|
||||
|
@ -325,7 +325,7 @@ pub fn num_args(r: &Repr, discr: int) -> uint {
|
|||
match *r {
|
||||
CEnum(*) => 0,
|
||||
Univariant(ref st, dtor) => {
|
||||
fail_unless!(discr == 0);
|
||||
assert!(discr == 0);
|
||||
st.fields.len() - (if dtor { 1 } else { 0 })
|
||||
}
|
||||
General(ref cases) => cases[discr as uint].fields.len() - 1
|
||||
|
@ -343,7 +343,7 @@ pub fn trans_field_ptr(bcx: block, r: &Repr, val: ValueRef, discr: int,
|
|||
bcx.ccx().sess.bug(~"element access in C-like enum")
|
||||
}
|
||||
Univariant(ref st, _dtor) => {
|
||||
fail_unless!(discr == 0);
|
||||
assert!(discr == 0);
|
||||
struct_field_ptr(bcx, st, val, ix, false)
|
||||
}
|
||||
General(ref cases) => {
|
||||
|
@ -401,12 +401,12 @@ pub fn trans_const(ccx: @CrateContext, r: &Repr, discr: int,
|
|||
vals: &[ValueRef]) -> ValueRef {
|
||||
match *r {
|
||||
CEnum(min, max) => {
|
||||
fail_unless!(vals.len() == 0);
|
||||
fail_unless!(min <= discr && discr <= max);
|
||||
assert!(vals.len() == 0);
|
||||
assert!(min <= discr && discr <= max);
|
||||
C_int(ccx, discr)
|
||||
}
|
||||
Univariant(ref st, _dro) => {
|
||||
fail_unless!(discr == 0);
|
||||
assert!(discr == 0);
|
||||
C_struct(build_const_struct(ccx, st, vals))
|
||||
}
|
||||
General(ref cases) => {
|
||||
|
@ -431,7 +431,7 @@ pub fn trans_const(ccx: @CrateContext, r: &Repr, discr: int,
|
|||
*/
|
||||
fn build_const_struct(ccx: @CrateContext, st: &Struct, vals: &[ValueRef])
|
||||
-> ~[ValueRef] {
|
||||
fail_unless!(vals.len() == st.fields.len());
|
||||
assert!(vals.len() == st.fields.len());
|
||||
|
||||
let mut offset = 0;
|
||||
let mut cfields = ~[];
|
||||
|
@ -447,7 +447,7 @@ fn build_const_struct(ccx: @CrateContext, st: &Struct, vals: &[ValueRef])
|
|||
cfields.push(padding(target_offset - offset));
|
||||
offset = target_offset;
|
||||
}
|
||||
fail_unless!(!is_undef(vals[i]));
|
||||
assert!(!is_undef(vals[i]));
|
||||
// If that assert fails, could change it to wrap in a struct?
|
||||
// (See `const_struct_field` for why real fields must not be undef.)
|
||||
cfields.push(vals[i]);
|
||||
|
|
|
@ -314,7 +314,7 @@ pub fn non_gc_box_cast(bcx: block, val: ValueRef) -> ValueRef {
|
|||
unsafe {
|
||||
debug!("non_gc_box_cast");
|
||||
add_comment(bcx, ~"non_gc_box_cast");
|
||||
fail_unless!(llvm::LLVMGetPointerAddressSpace(val_ty(val)) ==
|
||||
assert!(llvm::LLVMGetPointerAddressSpace(val_ty(val)) ==
|
||||
gc_box_addrspace || bcx.unreachable);
|
||||
let non_gc_t = T_ptr(llvm::LLVMGetElementType(val_ty(val)));
|
||||
PointerCast(bcx, val, non_gc_t)
|
||||
|
@ -489,7 +489,7 @@ pub fn get_res_dtor(ccx: @CrateContext, did: ast::def_id,
|
|||
let did = if did.crate != ast::local_crate {
|
||||
inline::maybe_instantiate_inline(ccx, did, true)
|
||||
} else { did };
|
||||
fail_unless!(did.crate == ast::local_crate);
|
||||
assert!(did.crate == ast::local_crate);
|
||||
let (val, _) =
|
||||
monomorphize::monomorphic_fn(ccx, did, substs, None, None, None);
|
||||
|
||||
|
@ -1336,7 +1336,7 @@ pub fn cleanup_and_leave(bcx: block,
|
|||
}
|
||||
cur = match cur.parent {
|
||||
Some(next) => next,
|
||||
None => { fail_unless!(upto.is_none()); break; }
|
||||
None => { assert!(upto.is_none()); break; }
|
||||
};
|
||||
}
|
||||
match leave {
|
||||
|
@ -1523,7 +1523,7 @@ pub fn alloc_ty(bcx: block, t: ty::t) -> ValueRef {
|
|||
let ccx = bcx.ccx();
|
||||
let llty = type_of::type_of(ccx, t);
|
||||
if ty::type_has_params(t) { debug!("%s", ty_to_str(ccx.tcx, t)); }
|
||||
fail_unless!(!ty::type_has_params(t));
|
||||
assert!(!ty::type_has_params(t));
|
||||
let val = alloca(bcx, llty);
|
||||
return val;
|
||||
}
|
||||
|
@ -2471,7 +2471,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
|
|||
// Want parent_id and not id, because id is the dtor's type
|
||||
let class_ty = ty::lookup_item_type(tcx, parent_id).ty;
|
||||
// This code shouldn't be reached if the class is generic
|
||||
fail_unless!(!ty::type_has_params(class_ty));
|
||||
assert!(!ty::type_has_params(class_ty));
|
||||
let lldty = unsafe {
|
||||
T_fn(~[
|
||||
T_ptr(type_of(ccx, ty::mk_nil(tcx))),
|
||||
|
@ -2491,7 +2491,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
|
|||
let llfn;
|
||||
match v.node.kind {
|
||||
ast::tuple_variant_kind(ref args) => {
|
||||
fail_unless!(args.len() != 0u);
|
||||
assert!(args.len() != 0u);
|
||||
let pth = vec::append(/*bad*/copy *pth,
|
||||
~[path_name(enm.ident),
|
||||
path_name((*v).node.name)]);
|
||||
|
|
|
@ -813,7 +813,7 @@ pub fn Phi(cx: block, Ty: TypeRef, vals: &[ValueRef], bbs: &[BasicBlockRef])
|
|||
-> ValueRef {
|
||||
unsafe {
|
||||
if cx.unreachable { return llvm::LLVMGetUndef(Ty); }
|
||||
fail_unless!(vals.len() == bbs.len());
|
||||
assert!(vals.len() == bbs.len());
|
||||
let phi = EmptyPhi(cx, Ty);
|
||||
count_insn(cx, "addincoming");
|
||||
llvm::LLVMAddIncoming(phi, vec::raw::to_ptr(vals),
|
||||
|
@ -1033,7 +1033,7 @@ pub fn Trap(cx: block) {
|
|||
let T: ValueRef = str::as_c_str(~"llvm.trap", |buf| {
|
||||
llvm::LLVMGetNamedFunction(M, buf)
|
||||
});
|
||||
fail_unless!((T as int != 0));
|
||||
assert!((T as int != 0));
|
||||
let Args: ~[ValueRef] = ~[];
|
||||
unsafe {
|
||||
count_insn(cx, "trap");
|
||||
|
@ -1047,7 +1047,7 @@ pub fn LandingPad(cx: block, Ty: TypeRef, PersFn: ValueRef,
|
|||
NumClauses: uint) -> ValueRef {
|
||||
unsafe {
|
||||
check_not_terminated(cx);
|
||||
fail_unless!(!cx.unreachable);
|
||||
assert!(!cx.unreachable);
|
||||
count_insn(cx, "landingpad");
|
||||
return llvm::LLVMBuildLandingPad(B(cx), Ty, PersFn,
|
||||
NumClauses as c_uint, noname());
|
||||
|
|
|
@ -133,7 +133,7 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee {
|
|||
}
|
||||
ast::def_variant(tid, vid) => {
|
||||
// nullary variants are not callable
|
||||
fail_unless!(ty::enum_variant_with_id(bcx.tcx(),
|
||||
assert!(ty::enum_variant_with_id(bcx.tcx(),
|
||||
tid,
|
||||
vid).args.len() > 0u);
|
||||
fn_callee(bcx, trans_fn_ref(bcx, vid, ref_expr.id))
|
||||
|
@ -231,7 +231,7 @@ pub fn trans_fn_ref_with_vtables(
|
|||
vtables);
|
||||
let _indenter = indenter();
|
||||
|
||||
fail_unless!(type_params.all(|t| !ty::type_needs_infer(*t)));
|
||||
assert!(type_params.all(|t| !ty::type_needs_infer(*t)));
|
||||
|
||||
// Polytype of the function item (may have type params)
|
||||
let fn_tpt = ty::lookup_item_type(tcx, def_id);
|
||||
|
@ -286,7 +286,7 @@ pub fn trans_fn_ref_with_vtables(
|
|||
// Create a monomorphic verison of generic functions
|
||||
if must_monomorphise {
|
||||
// Should be either intra-crate or inlined.
|
||||
fail_unless!(def_id.crate == ast::local_crate);
|
||||
assert!(def_id.crate == ast::local_crate);
|
||||
|
||||
let mut (val, must_cast) =
|
||||
monomorphize::monomorphic_fn(ccx, def_id, type_params,
|
||||
|
@ -705,7 +705,7 @@ pub fn trans_arg_expr(bcx: block,
|
|||
// FIXME(#3548) use the adjustments table
|
||||
match autoref_arg {
|
||||
DoAutorefArg => {
|
||||
fail_unless!(!
|
||||
assert!(!
|
||||
bcx.ccx().maps.moves_map.contains(&arg_expr.id));
|
||||
val = arg_datum.to_ref_llval(bcx);
|
||||
}
|
||||
|
|
|
@ -271,7 +271,7 @@ pub fn build_closure(bcx0: block,
|
|||
let datum = expr::trans_local_var(bcx, cap_var.def);
|
||||
match cap_var.mode {
|
||||
moves::CapRef => {
|
||||
fail_unless!(sigil == ast::BorrowedSigil);
|
||||
assert!(sigil == ast::BorrowedSigil);
|
||||
env_vals.push(EnvValue {action: EnvRef,
|
||||
datum: datum});
|
||||
}
|
||||
|
|
|
@ -255,8 +255,8 @@ pub struct param_substs {
|
|||
|
||||
pub impl param_substs {
|
||||
fn validate(&self) {
|
||||
for self.tys.each |t| { fail_unless!(!ty::type_needs_infer(*t)); }
|
||||
for self.self_ty.each |t| { fail_unless!(!ty::type_needs_infer(*t)); }
|
||||
for self.tys.each |t| { assert!(!ty::type_needs_infer(*t)); }
|
||||
for self.self_ty.each |t| { assert!(!ty::type_needs_infer(*t)); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1359,7 +1359,7 @@ pub fn monomorphize_type(bcx: block, t: ty::t) -> ty::t {
|
|||
Some(substs) => {
|
||||
ty::subst_tps(bcx.tcx(), substs.tys, substs.self_ty, t)
|
||||
}
|
||||
_ => { fail_unless!(!ty::type_has_params(t)); t }
|
||||
_ => { assert!(!ty::type_has_params(t)); t }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ pub fn const_lit(cx: @CrateContext, e: @ast::expr, lit: ast::lit)
|
|||
pub fn const_ptrcast(cx: @CrateContext, a: ValueRef, t: TypeRef) -> ValueRef {
|
||||
unsafe {
|
||||
let b = llvm::LLVMConstPointerCast(a, T_ptr(t));
|
||||
fail_unless!(cx.const_globals.insert(b as int, a));
|
||||
assert!(cx.const_globals.insert(b as int, a));
|
||||
b
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ fn const_deref_ptr(cx: @CrateContext, v: ValueRef) -> ValueRef {
|
|||
None => v
|
||||
};
|
||||
unsafe {
|
||||
fail_unless!(llvm::LLVMIsGlobalConstant(v) == True);
|
||||
assert!(llvm::LLVMIsGlobalConstant(v) == True);
|
||||
llvm::LLVMGetInitializer(v)
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ fn const_deref(cx: @CrateContext, v: ValueRef, t: ty::t, explicit: bool)
|
|||
-> (ValueRef, ty::t) {
|
||||
match ty::deref(cx.tcx, t, explicit) {
|
||||
Some(ref mt) => {
|
||||
fail_unless!(mt.mutbl != ast::m_mutbl);
|
||||
assert!(mt.mutbl != ast::m_mutbl);
|
||||
let dv = match ty::get(t).sty {
|
||||
ty::ty_ptr(*) | ty::ty_rptr(*) => {
|
||||
const_deref_ptr(cx, v)
|
||||
|
@ -197,8 +197,8 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
|
|||
match adj.autoref {
|
||||
None => { }
|
||||
Some(ref autoref) => {
|
||||
fail_unless!(autoref.region == ty::re_static);
|
||||
fail_unless!(autoref.mutbl != ast::m_mutbl);
|
||||
assert!(autoref.region == ty::re_static);
|
||||
assert!(autoref.mutbl != ast::m_mutbl);
|
||||
// Don't copy data to do a deref+ref.
|
||||
let llptr = match maybe_ptr {
|
||||
Some(ptr) => ptr,
|
||||
|
@ -211,8 +211,8 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
|
|||
ty::AutoBorrowVec => {
|
||||
let size = machine::llsize_of(cx,
|
||||
val_ty(llconst));
|
||||
fail_unless!(abi::slice_elt_base == 0);
|
||||
fail_unless!(abi::slice_elt_len == 1);
|
||||
assert!(abi::slice_elt_base == 0);
|
||||
assert!(abi::slice_elt_len == 1);
|
||||
llconst = C_struct(~[llptr, size]);
|
||||
}
|
||||
_ => {
|
||||
|
@ -375,7 +375,7 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
|
|||
|
||||
let len = llvm::LLVMConstIntGetZExtValue(len) as u64;
|
||||
let len = match ty::get(bt).sty {
|
||||
ty::ty_estr(*) => {fail_unless!(len > 0); len - 1},
|
||||
ty::ty_estr(*) => {assert!(len > 0); len - 1},
|
||||
_ => len
|
||||
};
|
||||
if iv >= len {
|
||||
|
@ -494,14 +494,14 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
|
|||
}
|
||||
}
|
||||
ast::expr_path(pth) => {
|
||||
fail_unless!(pth.types.len() == 0);
|
||||
assert!(pth.types.len() == 0);
|
||||
match cx.tcx.def_map.find(&e.id) {
|
||||
Some(&ast::def_fn(def_id, _purity)) => {
|
||||
if !ast_util::is_local(def_id) {
|
||||
let ty = csearch::get_type(cx.tcx, def_id).ty;
|
||||
base::trans_external_path(cx, def_id, ty)
|
||||
} else {
|
||||
fail_unless!(ast_util::is_local(def_id));
|
||||
assert!(ast_util::is_local(def_id));
|
||||
base::get_item_val(cx, def_id.node)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ pub fn trans_block(bcx: block, b: &ast::blk, dest: expr::Dest) -> block {
|
|||
bcx = expr::trans_into(bcx, e, dest);
|
||||
}
|
||||
None => {
|
||||
fail_unless!(dest == expr::Ignore || bcx.unreachable);
|
||||
assert!(dest == expr::Ignore || bcx.unreachable);
|
||||
}
|
||||
}
|
||||
return bcx;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue