mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
commit
647a94d01a
21
doc/rust.md
21
doc/rust.md
@ -205,7 +205,7 @@ grammar as double-quoted strings. Other tokens have exact rules given.
|
||||
The keywords are the following strings:
|
||||
|
||||
~~~~~~~~ {.keyword}
|
||||
as assert
|
||||
as
|
||||
break
|
||||
const copy
|
||||
do drop
|
||||
@ -2000,7 +2000,7 @@ let v = ~[1,2,3];
|
||||
|
||||
mutate(copy v); // Pass a copy
|
||||
|
||||
assert v[0] == 1; // Original was not modified
|
||||
fail_unless!(v[0] == 1); // Original was not modified
|
||||
~~~~
|
||||
|
||||
### Unary move expressions
|
||||
@ -2450,17 +2450,6 @@ In the future, logging will move into a library, and will no longer be a core ex
|
||||
It is therefore recommended to use the macro forms of logging (`error!`, `debug!`, etc.) to minimize disruption in code that uses logging.
|
||||
|
||||
|
||||
### Assert expressions
|
||||
|
||||
~~~~~~~~{.ebnf .gram}
|
||||
assert_expr : "assert" expr ;
|
||||
~~~~~~~~
|
||||
|
||||
> **Note:** In future versions of Rust, `assert` will be changed from a full expression to a macro.
|
||||
|
||||
An `assert` expression causes the program to fail if its `expr` argument evaluates to `false`.
|
||||
The failure carries string representation of the false expression.
|
||||
|
||||
# Type system
|
||||
|
||||
## Types
|
||||
@ -2560,7 +2549,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;
|
||||
assert b != "world";
|
||||
fail_unless!(b != "world");
|
||||
~~~~
|
||||
|
||||
|
||||
@ -2581,7 +2570,7 @@ An example of a vector type and its use:
|
||||
~~~~
|
||||
let v: &[int] = &[7, 5, 3];
|
||||
let i: int = v[2];
|
||||
assert (i == 3);
|
||||
fail_unless!(i == 3);
|
||||
~~~~
|
||||
|
||||
All accessible elements of a vector are always initialized, and access to a vector is always bounds-checked.
|
||||
@ -2986,7 +2975,7 @@ example of an _implicit dereference_ operation performed on box values:
|
||||
~~~~~~~~
|
||||
struct Foo { y: int }
|
||||
let x = @Foo{y: 10};
|
||||
assert x.y == 10;
|
||||
fail_unless!(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() { assert fmt!("%?", unix_time_in_microseconds()) != ~""; }
|
||||
# fn main() { fail_unless!(fmt!("%?", unix_time_in_microseconds()) != ~""); }
|
||||
~~~~
|
||||
|
||||
The `#[nolink]` attribute indicates that there's no foreign library to
|
||||
|
@ -297,9 +297,9 @@ 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 `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
|
||||
~reason)`) and the `fail_unless!` 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++,
|
||||
exceptions in Rust are unrecoverable within a single task: once a task fails,
|
||||
there is no way to "catch" the exception.
|
||||
@ -339,7 +339,7 @@ let result: Result<int, ()> = do task::try {
|
||||
fail!(~"oops!");
|
||||
}
|
||||
};
|
||||
assert result.is_err();
|
||||
fail_unless!(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.
|
||||
assert message != 42;
|
||||
fail_unless!(message != 42);
|
||||
}
|
||||
do try { // Unidirectionally linked
|
||||
sender.send(42);
|
||||
@ -507,13 +507,13 @@ do spawn {
|
||||
};
|
||||
|
||||
from_child.send(22);
|
||||
assert from_child.recv() == ~"22";
|
||||
fail_unless!(from_child.recv() == ~"22");
|
||||
|
||||
from_child.send(23);
|
||||
from_child.send(0);
|
||||
|
||||
assert from_child.recv() == ~"23";
|
||||
assert from_child.recv() == ~"0";
|
||||
fail_unless!(from_child.recv() == ~"23");
|
||||
fail_unless!(from_child.recv() == ~"0");
|
||||
|
||||
# }
|
||||
~~~~
|
||||
|
@ -381,7 +381,7 @@ expression to the given type.
|
||||
~~~~
|
||||
let x: float = 4.0;
|
||||
let y: uint = x as uint;
|
||||
assert y == 4u;
|
||||
fail_unless!(y == 4u);
|
||||
~~~~
|
||||
|
||||
## Syntax extensions
|
||||
@ -849,8 +849,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; }
|
||||
|
||||
assert 8 == line(5, 3, 1);
|
||||
assert () == oops(5, 3, 1);
|
||||
fail_unless!(8 == line(5, 3, 1));
|
||||
fail_unless!(() == oops(5, 3, 1));
|
||||
~~~~
|
||||
|
||||
As with `match` expressions and `let` bindings, function arguments support
|
||||
@ -1000,7 +1000,7 @@ let x = ~10;
|
||||
let y = copy x;
|
||||
|
||||
let z = *x + *y;
|
||||
assert z == 20;
|
||||
fail_unless!(z == 20);
|
||||
~~~~
|
||||
|
||||
When they do not contain any managed boxes, owned boxes can be sent
|
||||
@ -1327,8 +1327,8 @@ and [`core::str`]. Here are some examples.
|
||||
let crayons = [Almond, AntiqueBrass, Apricot];
|
||||
|
||||
// Check the length of the vector
|
||||
assert crayons.len() == 3;
|
||||
assert !crayons.is_empty();
|
||||
fail_unless!(crayons.len() == 3);
|
||||
fail_unless!(!crayons.is_empty());
|
||||
|
||||
// Iterate over a vector, obtaining a pointer to each element
|
||||
for crayons.each |crayon| {
|
||||
|
@ -63,7 +63,7 @@ pub fn parse_config(args: ~[~str]) -> config {
|
||||
getopts::optopt(~"logfile"),
|
||||
getopts::optflag(~"jit")];
|
||||
|
||||
assert !args.is_empty();
|
||||
fail_unless!(!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
|
||||
assert prog.ends_with(~".exe");
|
||||
fail_unless!(prog.ends_with(~".exe"));
|
||||
let aux_path = prog.slice(0u, prog.len() - 4u) + ~".libaux";
|
||||
|
||||
env = do vec::map(env) |pair| {
|
||||
|
@ -23,11 +23,18 @@ use vec;
|
||||
/// Code for dealing with @-vectors. This is pretty incomplete, and
|
||||
/// contains a bunch of duplication from the code for ~-vectors.
|
||||
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod rustrt {
|
||||
pub mod rustrt {
|
||||
use libc;
|
||||
use sys;
|
||||
use vec;
|
||||
|
||||
#[abi = "cdecl"]
|
||||
#[link_name = "rustrt"]
|
||||
pub extern {
|
||||
pub unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
|
||||
++v: **vec::raw::VecRepr,
|
||||
++n: libc::size_t);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the number of elements the vector can hold without reallocating
|
||||
@ -285,31 +292,31 @@ pub fn test() {
|
||||
}
|
||||
}
|
||||
|
||||
assert seq_range(10, 15) == @[10, 11, 12, 13, 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];
|
||||
fail_unless!(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]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn append_test() {
|
||||
assert @[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6];
|
||||
fail_unless!(@[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_from_owned() {
|
||||
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]];
|
||||
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]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_from_slice() {
|
||||
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]];
|
||||
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]]);
|
||||
}
|
||||
|
||||
|
@ -86,20 +86,20 @@ pub fn test_bool_from_str() {
|
||||
use from_str::FromStr;
|
||||
|
||||
do all_values |v| {
|
||||
assert Some(v) == FromStr::from_str(to_str(v))
|
||||
fail_unless!(Some(v) == FromStr::from_str(to_str(v)))
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_bool_to_str() {
|
||||
assert to_str(false) == ~"false";
|
||||
assert to_str(true) == ~"true";
|
||||
fail_unless!(to_str(false) == ~"false");
|
||||
fail_unless!(to_str(true) == ~"true");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_bool_to_bit() {
|
||||
do all_values |v| {
|
||||
assert to_bit(v) == if is_true(v) { 1u8 } else { 0u8 };
|
||||
fail_unless!(to_bit(v) == if is_true(v) { 1u8 } else { 0u8 });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,13 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[abi = "rust-intrinsic"]
|
||||
extern mod rusti {
|
||||
pub mod rusti {
|
||||
#[abi = "rust-intrinsic"]
|
||||
#[link_name = "rusti"]
|
||||
pub extern {
|
||||
fn forget<T>(-x: T);
|
||||
fn reinterpret_cast<T, U>(&&e: T) -> U;
|
||||
}
|
||||
}
|
||||
|
||||
/// Casts the value at `src` to U. The two types must have the same length.
|
||||
@ -45,7 +48,7 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
|
||||
*
|
||||
* # Example
|
||||
*
|
||||
* assert transmute("L") == ~[76u8, 0u8];
|
||||
* fail_unless!(transmute("L") == ~[76u8, 0u8]);
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub unsafe fn transmute<L, G>(thing: L) -> G {
|
||||
@ -109,7 +112,7 @@ pub mod tests {
|
||||
|
||||
#[test]
|
||||
pub fn test_reinterpret_cast() {
|
||||
assert 1u == unsafe { reinterpret_cast(&1) };
|
||||
fail_unless!(1u == unsafe { reinterpret_cast(&1) });
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -120,8 +123,8 @@ pub mod tests {
|
||||
let ptr: *int = transmute(box); // refcount 2
|
||||
let _box1: @~str = reinterpret_cast(&ptr);
|
||||
let _box2: @~str = reinterpret_cast(&ptr);
|
||||
assert *_box1 == ~"box box box";
|
||||
assert *_box2 == ~"box box box";
|
||||
fail_unless!(*_box1 == ~"box box box");
|
||||
fail_unless!(*_box2 == ~"box box box");
|
||||
// Will destroy _box1 and _box2. Without the bump, this would
|
||||
// use-after-free. With too many bumps, it would leak.
|
||||
}
|
||||
@ -133,7 +136,7 @@ pub mod tests {
|
||||
unsafe {
|
||||
let x = @100u8;
|
||||
let x: *BoxRepr = transmute(x);
|
||||
assert (*x).data == 100;
|
||||
fail_unless!((*x).data == 100);
|
||||
let _x: @int = transmute(x);
|
||||
}
|
||||
}
|
||||
@ -141,7 +144,7 @@ pub mod tests {
|
||||
#[test]
|
||||
pub fn test_transmute2() {
|
||||
unsafe {
|
||||
assert ~[76u8, 0u8] == transmute(~"L");
|
||||
fail_unless!(~[76u8, 0u8] == transmute(~"L"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,12 +65,12 @@ pub impl<T> Cell<T> {
|
||||
#[test]
|
||||
fn test_basic() {
|
||||
let value_cell = Cell(~10);
|
||||
assert !value_cell.is_empty();
|
||||
fail_unless!(!value_cell.is_empty());
|
||||
let value = value_cell.take();
|
||||
assert value == ~10;
|
||||
assert value_cell.is_empty();
|
||||
fail_unless!(value == ~10);
|
||||
fail_unless!(value_cell.is_empty());
|
||||
value_cell.put_back(value);
|
||||
assert !value_cell.is_empty();
|
||||
fail_unless!(!value_cell.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -200,7 +200,7 @@ pub pure fn escape_unicode(c: char) -> ~str {
|
||||
let (c, pad) = (if c <= '\xff' { ('x', 2u) }
|
||||
else if c <= '\uffff' { ('u', 4u) }
|
||||
else { ('U', 8u) });
|
||||
assert str::len(s) <= pad;
|
||||
fail_unless!(str::len(s) <= pad);
|
||||
let mut out = ~"\\";
|
||||
unsafe {
|
||||
str::push_str(&mut out, str::from_char(c));
|
||||
@ -258,91 +258,91 @@ impl Eq for char {
|
||||
|
||||
#[test]
|
||||
fn test_is_lowercase() {
|
||||
assert is_lowercase('a');
|
||||
assert is_lowercase('ö');
|
||||
assert is_lowercase('ß');
|
||||
assert !is_lowercase('Ü');
|
||||
assert !is_lowercase('P');
|
||||
fail_unless!(is_lowercase('a'));
|
||||
fail_unless!(is_lowercase('ö'));
|
||||
fail_unless!(is_lowercase('ß'));
|
||||
fail_unless!(!is_lowercase('Ü'));
|
||||
fail_unless!(!is_lowercase('P'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_uppercase() {
|
||||
assert !is_uppercase('h');
|
||||
assert !is_uppercase('ä');
|
||||
assert !is_uppercase('ß');
|
||||
assert is_uppercase('Ö');
|
||||
assert is_uppercase('T');
|
||||
fail_unless!(!is_uppercase('h'));
|
||||
fail_unless!(!is_uppercase('ä'));
|
||||
fail_unless!(!is_uppercase('ß'));
|
||||
fail_unless!(is_uppercase('Ö'));
|
||||
fail_unless!(is_uppercase('T'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_whitespace() {
|
||||
assert is_whitespace(' ');
|
||||
assert is_whitespace('\u2007');
|
||||
assert is_whitespace('\t');
|
||||
assert is_whitespace('\n');
|
||||
fail_unless!(is_whitespace(' '));
|
||||
fail_unless!(is_whitespace('\u2007'));
|
||||
fail_unless!(is_whitespace('\t'));
|
||||
fail_unless!(is_whitespace('\n'));
|
||||
|
||||
assert !is_whitespace('a');
|
||||
assert !is_whitespace('_');
|
||||
assert !is_whitespace('\u0000');
|
||||
fail_unless!(!is_whitespace('a'));
|
||||
fail_unless!(!is_whitespace('_'));
|
||||
fail_unless!(!is_whitespace('\u0000'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_digit() {
|
||||
assert to_digit('0', 10u) == Some(0u);
|
||||
assert to_digit('1', 2u) == Some(1u);
|
||||
assert to_digit('2', 3u) == Some(2u);
|
||||
assert to_digit('9', 10u) == Some(9u);
|
||||
assert to_digit('a', 16u) == Some(10u);
|
||||
assert to_digit('A', 16u) == Some(10u);
|
||||
assert to_digit('b', 16u) == Some(11u);
|
||||
assert to_digit('B', 16u) == Some(11u);
|
||||
assert to_digit('z', 36u) == Some(35u);
|
||||
assert to_digit('Z', 36u) == Some(35u);
|
||||
fail_unless!(to_digit('0', 10u) == Some(0u));
|
||||
fail_unless!(to_digit('1', 2u) == Some(1u));
|
||||
fail_unless!(to_digit('2', 3u) == Some(2u));
|
||||
fail_unless!(to_digit('9', 10u) == Some(9u));
|
||||
fail_unless!(to_digit('a', 16u) == Some(10u));
|
||||
fail_unless!(to_digit('A', 16u) == Some(10u));
|
||||
fail_unless!(to_digit('b', 16u) == Some(11u));
|
||||
fail_unless!(to_digit('B', 16u) == Some(11u));
|
||||
fail_unless!(to_digit('z', 36u) == Some(35u));
|
||||
fail_unless!(to_digit('Z', 36u) == Some(35u));
|
||||
|
||||
assert to_digit(' ', 10u).is_none();
|
||||
assert to_digit('$', 36u).is_none();
|
||||
fail_unless!(to_digit(' ', 10u).is_none());
|
||||
fail_unless!(to_digit('$', 36u).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_ascii() {
|
||||
assert str::all(~"banana", is_ascii);
|
||||
assert ! str::all(~"ประเทศไทย中华Việt Nam", is_ascii);
|
||||
fail_unless!(str::all(~"banana", is_ascii));
|
||||
fail_unless!(! str::all(~"ประเทศไทย中华Việt Nam", is_ascii));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_digit() {
|
||||
assert is_digit('2');
|
||||
assert is_digit('7');
|
||||
assert ! is_digit('c');
|
||||
assert ! is_digit('i');
|
||||
assert ! is_digit('z');
|
||||
assert ! is_digit('Q');
|
||||
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'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_default() {
|
||||
assert escape_default('\n') == ~"\\n";
|
||||
assert escape_default('\r') == ~"\\r";
|
||||
assert escape_default('\'') == ~"\\'";
|
||||
assert escape_default('"') == ~"\\\"";
|
||||
assert escape_default(' ') == ~" ";
|
||||
assert escape_default('a') == ~"a";
|
||||
assert escape_default('~') == ~"~";
|
||||
assert escape_default('\x00') == ~"\\x00";
|
||||
assert escape_default('\x1f') == ~"\\x1f";
|
||||
assert escape_default('\x7f') == ~"\\x7f";
|
||||
assert escape_default('\xff') == ~"\\xff";
|
||||
assert escape_default('\u011b') == ~"\\u011b";
|
||||
assert escape_default('\U0001d4b6') == ~"\\U0001d4b6";
|
||||
fail_unless!(escape_default('\n') == ~"\\n");
|
||||
fail_unless!(escape_default('\r') == ~"\\r");
|
||||
fail_unless!(escape_default('\'') == ~"\\'");
|
||||
fail_unless!(escape_default('"') == ~"\\\"");
|
||||
fail_unless!(escape_default(' ') == ~" ");
|
||||
fail_unless!(escape_default('a') == ~"a");
|
||||
fail_unless!(escape_default('~') == ~"~");
|
||||
fail_unless!(escape_default('\x00') == ~"\\x00");
|
||||
fail_unless!(escape_default('\x1f') == ~"\\x1f");
|
||||
fail_unless!(escape_default('\x7f') == ~"\\x7f");
|
||||
fail_unless!(escape_default('\xff') == ~"\\xff");
|
||||
fail_unless!(escape_default('\u011b') == ~"\\u011b");
|
||||
fail_unless!(escape_default('\U0001d4b6') == ~"\\U0001d4b6");
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_escape_unicode() {
|
||||
assert escape_unicode('\x00') == ~"\\x00";
|
||||
assert escape_unicode('\n') == ~"\\x0a";
|
||||
assert escape_unicode(' ') == ~"\\x20";
|
||||
assert escape_unicode('a') == ~"\\x61";
|
||||
assert escape_unicode('\u011b') == ~"\\u011b";
|
||||
assert escape_unicode('\U0001d4b6') == ~"\\U0001d4b6";
|
||||
fail_unless!(escape_unicode('\x00') == ~"\\x00");
|
||||
fail_unless!(escape_unicode('\n') == ~"\\x0a");
|
||||
fail_unless!(escape_unicode(' ') == ~"\\x20");
|
||||
fail_unless!(escape_unicode('a') == ~"\\x61");
|
||||
fail_unless!(escape_unicode('\u011b') == ~"\\u011b");
|
||||
fail_unless!(escape_unicode('\U0001d4b6') == ~"\\U0001d4b6");
|
||||
}
|
||||
|
@ -218,9 +218,14 @@ pub unsafe fn annihilate() {
|
||||
}
|
||||
|
||||
/// Bindings to the runtime
|
||||
extern mod rustrt {
|
||||
pub mod rustrt {
|
||||
use libc::c_void;
|
||||
|
||||
#[link_name = "rustrt"]
|
||||
pub extern {
|
||||
#[rust_stack]
|
||||
// FIXME (#4386): Unable to make following method private.
|
||||
pub unsafe fn rust_get_task() -> *c_void;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,10 +172,10 @@ pub pure fn max<T:Ord>(v1: T, v2: T) -> T {
|
||||
mod test {
|
||||
#[test]
|
||||
fn test_int() {
|
||||
assert 5.cmp(&10) == Less;
|
||||
assert 10.cmp(&5) == Greater;
|
||||
assert 5.cmp(&5) == Equal;
|
||||
assert (-5).cmp(&12) == Less;
|
||||
assert 12.cmp(-5) == Greater;
|
||||
fail_unless!(5.cmp(&10) == Less);
|
||||
fail_unless!(10.cmp(&5) == Greater);
|
||||
fail_unless!(5.cmp(&5) == Equal);
|
||||
fail_unless!((-5).cmp(&12) == Less);
|
||||
fail_unless!(12.cmp(-5) == Greater);
|
||||
}
|
||||
}
|
||||
|
@ -464,6 +464,6 @@ pub mod test {
|
||||
let _chan = chan;
|
||||
}
|
||||
|
||||
assert !port.peek();
|
||||
fail_unless!(!port.peek());
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ mod test {
|
||||
trouble(1);
|
||||
}
|
||||
|
||||
assert inner_trapped;
|
||||
fail_unless!(inner_trapped);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -140,7 +140,7 @@ mod test {
|
||||
trouble(1);
|
||||
}
|
||||
|
||||
assert outer_trapped;
|
||||
fail_unless!(outer_trapped);
|
||||
}
|
||||
|
||||
fn nested_reraise_trap_test_inner() {
|
||||
@ -157,7 +157,7 @@ mod test {
|
||||
trouble(1);
|
||||
}
|
||||
|
||||
assert inner_trapped;
|
||||
fail_unless!(inner_trapped);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -172,7 +172,7 @@ mod test {
|
||||
nested_reraise_trap_test_inner();
|
||||
}
|
||||
|
||||
assert outer_trapped;
|
||||
fail_unless!(outer_trapped);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -187,6 +187,6 @@ mod test {
|
||||
trouble(1);
|
||||
}
|
||||
|
||||
assert trapped;
|
||||
fail_unless!(trapped);
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,14 @@ Implicitly, all crates behave as if they included the following prologue:
|
||||
#[deny(non_camel_case_types)];
|
||||
#[allow(deprecated_mutable_fields)];
|
||||
|
||||
// On Linux, link to the runtime with -lrt.
|
||||
#[cfg(target_os = "linux")]
|
||||
pub mod linkhack {
|
||||
#[link_args="-lrustrt -lrt"]
|
||||
extern {
|
||||
}
|
||||
}
|
||||
|
||||
/* The Prelude. */
|
||||
|
||||
pub mod prelude;
|
||||
|
@ -170,7 +170,7 @@ priv impl<T> DList<T> {
|
||||
// Remove a node from the list.
|
||||
fn unlink(@mut self, nobe: @mut DListNode<T>) {
|
||||
self.assert_mine(nobe);
|
||||
assert self.size > 0;
|
||||
fail_unless!(self.size > 0);
|
||||
self.link(nobe.prev, nobe.next);
|
||||
nobe.prev = None; // Release extraneous references.
|
||||
nobe.next = None;
|
||||
@ -192,7 +192,7 @@ priv impl<T> DList<T> {
|
||||
nobe: DListLink<T>,
|
||||
neighbour: @mut DListNode<T>) {
|
||||
self.assert_mine(neighbour);
|
||||
assert self.size > 0;
|
||||
fail_unless!(self.size > 0);
|
||||
self.link(neighbour.prev, nobe);
|
||||
self.link(nobe, Some(neighbour));
|
||||
self.size += 1;
|
||||
@ -201,7 +201,7 @@ priv impl<T> DList<T> {
|
||||
neighbour: @mut DListNode<T>,
|
||||
nobe: DListLink<T>) {
|
||||
self.assert_mine(neighbour);
|
||||
assert self.size > 0;
|
||||
fail_unless!(self.size > 0);
|
||||
self.link(nobe, neighbour.next);
|
||||
self.link(Some(neighbour), nobe);
|
||||
self.size += 1;
|
||||
@ -409,7 +409,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() {
|
||||
assert self.hd.is_none() && self.tl.is_none();
|
||||
fail_unless!(self.hd.is_none() && self.tl.is_none());
|
||||
}
|
||||
// iterate forwards
|
||||
let mut count = 0;
|
||||
@ -417,7 +417,7 @@ pub impl<T> DList<T> {
|
||||
let mut rabbit = link;
|
||||
while link.is_some() {
|
||||
let nobe = link.get();
|
||||
assert nobe.linked;
|
||||
fail_unless!(nobe.linked);
|
||||
// check cycle
|
||||
if rabbit.is_some() {
|
||||
rabbit = rabbit.get().next;
|
||||
@ -426,19 +426,19 @@ pub impl<T> DList<T> {
|
||||
rabbit = rabbit.get().next;
|
||||
}
|
||||
if rabbit.is_some() {
|
||||
assert !managed::mut_ptr_eq(rabbit.get(), nobe);
|
||||
fail_unless!(!managed::mut_ptr_eq(rabbit.get(), nobe));
|
||||
}
|
||||
// advance
|
||||
link = nobe.next_link();
|
||||
count += 1;
|
||||
}
|
||||
assert count == self.len();
|
||||
fail_unless!(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();
|
||||
assert nobe.linked;
|
||||
fail_unless!(nobe.linked);
|
||||
// check cycle
|
||||
if rabbit.is_some() {
|
||||
rabbit = rabbit.get().prev;
|
||||
@ -447,13 +447,13 @@ pub impl<T> DList<T> {
|
||||
rabbit = rabbit.get().prev;
|
||||
}
|
||||
if rabbit.is_some() {
|
||||
assert !managed::mut_ptr_eq(rabbit.get(), nobe);
|
||||
fail_unless!(!managed::mut_ptr_eq(rabbit.get(), nobe));
|
||||
}
|
||||
// advance
|
||||
link = nobe.prev_link();
|
||||
count -= 1;
|
||||
}
|
||||
assert count == 0;
|
||||
fail_unless!(count == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -513,66 +513,66 @@ mod tests {
|
||||
let ab = from_vec(~[a,b]);
|
||||
let cd = from_vec(~[c,d]);
|
||||
let abcd = concat(concat(from_vec(~[ab,cd])));
|
||||
abcd.assert_consistent(); assert abcd.len() == 8;
|
||||
abcd.assert_consistent(); assert abcd.pop().get() == 1;
|
||||
abcd.assert_consistent(); assert abcd.pop().get() == 2;
|
||||
abcd.assert_consistent(); assert abcd.pop().get() == 3;
|
||||
abcd.assert_consistent(); assert abcd.pop().get() == 4;
|
||||
abcd.assert_consistent(); assert abcd.pop().get() == 5;
|
||||
abcd.assert_consistent(); assert abcd.pop().get() == 6;
|
||||
abcd.assert_consistent(); assert abcd.pop().get() == 7;
|
||||
abcd.assert_consistent(); assert abcd.pop().get() == 8;
|
||||
abcd.assert_consistent(); assert abcd.is_empty();
|
||||
abcd.assert_consistent(); fail_unless!(abcd.len() == 8);
|
||||
abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 1);
|
||||
abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 2);
|
||||
abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 3);
|
||||
abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 4);
|
||||
abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 5);
|
||||
abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 6);
|
||||
abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 7);
|
||||
abcd.assert_consistent(); fail_unless!(abcd.pop().get() == 8);
|
||||
abcd.assert_consistent(); fail_unless!(abcd.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_append() {
|
||||
let a = from_vec(~[1,2,3]);
|
||||
let b = from_vec(~[4,5,6]);
|
||||
a.append(b);
|
||||
assert a.len() == 6;
|
||||
assert b.len() == 0;
|
||||
fail_unless!(a.len() == 6);
|
||||
fail_unless!(b.len() == 0);
|
||||
b.assert_consistent();
|
||||
a.assert_consistent(); assert a.pop().get() == 1;
|
||||
a.assert_consistent(); assert a.pop().get() == 2;
|
||||
a.assert_consistent(); assert a.pop().get() == 3;
|
||||
a.assert_consistent(); assert a.pop().get() == 4;
|
||||
a.assert_consistent(); assert a.pop().get() == 5;
|
||||
a.assert_consistent(); assert a.pop().get() == 6;
|
||||
a.assert_consistent(); assert a.is_empty();
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 1);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 2);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 3);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 4);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 5);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 6);
|
||||
a.assert_consistent(); fail_unless!(a.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_append_empty() {
|
||||
let a = from_vec(~[1,2,3]);
|
||||
let b = DList::<int>();
|
||||
a.append(b);
|
||||
assert a.len() == 3;
|
||||
assert b.len() == 0;
|
||||
fail_unless!(a.len() == 3);
|
||||
fail_unless!(b.len() == 0);
|
||||
b.assert_consistent();
|
||||
a.assert_consistent(); assert a.pop().get() == 1;
|
||||
a.assert_consistent(); assert a.pop().get() == 2;
|
||||
a.assert_consistent(); assert a.pop().get() == 3;
|
||||
a.assert_consistent(); assert a.is_empty();
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 1);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 2);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 3);
|
||||
a.assert_consistent(); fail_unless!(a.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_append_to_empty() {
|
||||
let a = DList::<int>();
|
||||
let b = from_vec(~[4,5,6]);
|
||||
a.append(b);
|
||||
assert a.len() == 3;
|
||||
assert b.len() == 0;
|
||||
fail_unless!(a.len() == 3);
|
||||
fail_unless!(b.len() == 0);
|
||||
b.assert_consistent();
|
||||
a.assert_consistent(); assert a.pop().get() == 4;
|
||||
a.assert_consistent(); assert a.pop().get() == 5;
|
||||
a.assert_consistent(); assert a.pop().get() == 6;
|
||||
a.assert_consistent(); assert a.is_empty();
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 4);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 5);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 6);
|
||||
a.assert_consistent(); fail_unless!(a.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_append_two_empty() {
|
||||
let a = DList::<int>();
|
||||
let b = DList::<int>();
|
||||
a.append(b);
|
||||
assert a.len() == 0;
|
||||
assert b.len() == 0;
|
||||
fail_unless!(a.len() == 0);
|
||||
fail_unless!(b.len() == 0);
|
||||
b.assert_consistent();
|
||||
a.assert_consistent();
|
||||
}
|
||||
@ -595,34 +595,34 @@ mod tests {
|
||||
let a = from_vec(~[1,2,3]);
|
||||
let b = from_vec(~[4,5,6]);
|
||||
b.prepend(a);
|
||||
assert a.len() == 0;
|
||||
assert b.len() == 6;
|
||||
fail_unless!(a.len() == 0);
|
||||
fail_unless!(b.len() == 6);
|
||||
a.assert_consistent();
|
||||
b.assert_consistent(); assert b.pop().get() == 1;
|
||||
b.assert_consistent(); assert b.pop().get() == 2;
|
||||
b.assert_consistent(); assert b.pop().get() == 3;
|
||||
b.assert_consistent(); assert b.pop().get() == 4;
|
||||
b.assert_consistent(); assert b.pop().get() == 5;
|
||||
b.assert_consistent(); assert b.pop().get() == 6;
|
||||
b.assert_consistent(); assert b.is_empty();
|
||||
b.assert_consistent(); fail_unless!(b.pop().get() == 1);
|
||||
b.assert_consistent(); fail_unless!(b.pop().get() == 2);
|
||||
b.assert_consistent(); fail_unless!(b.pop().get() == 3);
|
||||
b.assert_consistent(); fail_unless!(b.pop().get() == 4);
|
||||
b.assert_consistent(); fail_unless!(b.pop().get() == 5);
|
||||
b.assert_consistent(); fail_unless!(b.pop().get() == 6);
|
||||
b.assert_consistent(); fail_unless!(b.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_reverse() {
|
||||
let a = from_vec(~[5,4,3,2,1]);
|
||||
a.reverse();
|
||||
assert a.len() == 5;
|
||||
a.assert_consistent(); assert a.pop().get() == 1;
|
||||
a.assert_consistent(); assert a.pop().get() == 2;
|
||||
a.assert_consistent(); assert a.pop().get() == 3;
|
||||
a.assert_consistent(); assert a.pop().get() == 4;
|
||||
a.assert_consistent(); assert a.pop().get() == 5;
|
||||
a.assert_consistent(); assert a.is_empty();
|
||||
fail_unless!(a.len() == 5);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 1);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 2);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 3);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 4);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 5);
|
||||
a.assert_consistent(); fail_unless!(a.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_reverse_empty() {
|
||||
let a = DList::<int>();
|
||||
a.reverse();
|
||||
assert a.len() == 0;
|
||||
fail_unless!(a.len() == 0);
|
||||
a.assert_consistent();
|
||||
}
|
||||
#[test]
|
||||
@ -633,94 +633,94 @@ mod tests {
|
||||
a.insert_before(3, nobe);
|
||||
}
|
||||
}
|
||||
assert a.len() == 6;
|
||||
a.assert_consistent(); assert a.pop().get() == 1;
|
||||
a.assert_consistent(); assert a.pop().get() == 2;
|
||||
a.assert_consistent(); assert a.pop().get() == 3;
|
||||
a.assert_consistent(); assert a.pop().get() == 4;
|
||||
a.assert_consistent(); assert a.pop().get() == 3;
|
||||
a.assert_consistent(); assert a.pop().get() == 5;
|
||||
a.assert_consistent(); assert a.is_empty();
|
||||
fail_unless!(a.len() == 6);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 1);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 2);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 3);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 4);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 3);
|
||||
a.assert_consistent(); fail_unless!(a.pop().get() == 5);
|
||||
a.assert_consistent(); fail_unless!(a.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_clear() {
|
||||
let a = from_vec(~[5,4,3,2,1]);
|
||||
a.clear();
|
||||
assert a.len() == 0;
|
||||
fail_unless!(a.len() == 0);
|
||||
a.assert_consistent();
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_is_empty() {
|
||||
let empty = DList::<int>();
|
||||
let full1 = from_vec(~[1,2,3]);
|
||||
assert empty.is_empty();
|
||||
assert !full1.is_empty();
|
||||
fail_unless!(empty.is_empty());
|
||||
fail_unless!(!full1.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_head_tail() {
|
||||
let l = from_vec(~[1,2,3]);
|
||||
assert l.head() == 1;
|
||||
assert l.tail() == 3;
|
||||
assert l.len() == 3;
|
||||
fail_unless!(l.head() == 1);
|
||||
fail_unless!(l.tail() == 3);
|
||||
fail_unless!(l.len() == 3);
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_pop() {
|
||||
let l = from_vec(~[1,2,3]);
|
||||
assert l.pop().get() == 1;
|
||||
assert l.tail() == 3;
|
||||
assert l.head() == 2;
|
||||
assert l.pop().get() == 2;
|
||||
assert l.tail() == 3;
|
||||
assert l.head() == 3;
|
||||
assert l.pop().get() == 3;
|
||||
assert l.is_empty();
|
||||
assert l.pop().is_none();
|
||||
fail_unless!(l.pop().get() == 1);
|
||||
fail_unless!(l.tail() == 3);
|
||||
fail_unless!(l.head() == 2);
|
||||
fail_unless!(l.pop().get() == 2);
|
||||
fail_unless!(l.tail() == 3);
|
||||
fail_unless!(l.head() == 3);
|
||||
fail_unless!(l.pop().get() == 3);
|
||||
fail_unless!(l.is_empty());
|
||||
fail_unless!(l.pop().is_none());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_pop_tail() {
|
||||
let l = from_vec(~[1,2,3]);
|
||||
assert l.pop_tail().get() == 3;
|
||||
assert l.tail() == 2;
|
||||
assert l.head() == 1;
|
||||
assert l.pop_tail().get() == 2;
|
||||
assert l.tail() == 1;
|
||||
assert l.head() == 1;
|
||||
assert l.pop_tail().get() == 1;
|
||||
assert l.is_empty();
|
||||
assert l.pop_tail().is_none();
|
||||
fail_unless!(l.pop_tail().get() == 3);
|
||||
fail_unless!(l.tail() == 2);
|
||||
fail_unless!(l.head() == 1);
|
||||
fail_unless!(l.pop_tail().get() == 2);
|
||||
fail_unless!(l.tail() == 1);
|
||||
fail_unless!(l.head() == 1);
|
||||
fail_unless!(l.pop_tail().get() == 1);
|
||||
fail_unless!(l.is_empty());
|
||||
fail_unless!(l.pop_tail().is_none());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_push() {
|
||||
let l = DList::<int>();
|
||||
l.push(1);
|
||||
assert l.head() == 1;
|
||||
assert l.tail() == 1;
|
||||
fail_unless!(l.head() == 1);
|
||||
fail_unless!(l.tail() == 1);
|
||||
l.push(2);
|
||||
assert l.head() == 1;
|
||||
assert l.tail() == 2;
|
||||
fail_unless!(l.head() == 1);
|
||||
fail_unless!(l.tail() == 2);
|
||||
l.push(3);
|
||||
assert l.head() == 1;
|
||||
assert l.tail() == 3;
|
||||
assert l.len() == 3;
|
||||
fail_unless!(l.head() == 1);
|
||||
fail_unless!(l.tail() == 3);
|
||||
fail_unless!(l.len() == 3);
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_push_head() {
|
||||
let l = DList::<int>();
|
||||
l.push_head(3);
|
||||
assert l.head() == 3;
|
||||
assert l.tail() == 3;
|
||||
fail_unless!(l.head() == 3);
|
||||
fail_unless!(l.tail() == 3);
|
||||
l.push_head(2);
|
||||
assert l.head() == 2;
|
||||
assert l.tail() == 3;
|
||||
fail_unless!(l.head() == 2);
|
||||
fail_unless!(l.tail() == 3);
|
||||
l.push_head(1);
|
||||
assert l.head() == 1;
|
||||
assert l.tail() == 3;
|
||||
assert l.len() == 3;
|
||||
fail_unless!(l.head() == 1);
|
||||
fail_unless!(l.tail() == 3);
|
||||
fail_unless!(l.len() == 3);
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_foldl() {
|
||||
let l = from_vec(vec::from_fn(101, |x|x));
|
||||
assert iter::foldl(&l, 0, |accum,elem| *accum+*elem) == 5050;
|
||||
fail_unless!(iter::foldl(&l, 0, |accum,elem| *accum+*elem) == 5050);
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_break_early() {
|
||||
@ -730,7 +730,7 @@ mod tests {
|
||||
x += 1;
|
||||
if (*i == 3) { break; }
|
||||
}
|
||||
assert x == 3;
|
||||
fail_unless!(x == 3);
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_head() {
|
||||
@ -738,14 +738,14 @@ mod tests {
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
l.assert_consistent(); let _two = l.push_n(2);
|
||||
l.assert_consistent(); let _three = l.push_n(3);
|
||||
l.assert_consistent(); assert l.len() == 3;
|
||||
l.assert_consistent(); fail_unless!(l.len() == 3);
|
||||
l.assert_consistent(); l.remove(one);
|
||||
l.assert_consistent(); assert l.len() == 2;
|
||||
l.assert_consistent(); assert l.head() == 2;
|
||||
l.assert_consistent(); assert l.tail() == 3;
|
||||
l.assert_consistent(); assert l.pop().get() == 2;
|
||||
l.assert_consistent(); assert l.pop().get() == 3;
|
||||
l.assert_consistent(); assert l.is_empty();
|
||||
l.assert_consistent(); fail_unless!(l.len() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.head() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.tail() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_mid() {
|
||||
@ -753,14 +753,14 @@ mod tests {
|
||||
l.assert_consistent(); let _one = l.push_n(1);
|
||||
l.assert_consistent(); let two = l.push_n(2);
|
||||
l.assert_consistent(); let _three = l.push_n(3);
|
||||
l.assert_consistent(); assert l.len() == 3;
|
||||
l.assert_consistent(); fail_unless!(l.len() == 3);
|
||||
l.assert_consistent(); l.remove(two);
|
||||
l.assert_consistent(); assert l.len() == 2;
|
||||
l.assert_consistent(); assert l.head() == 1;
|
||||
l.assert_consistent(); assert l.tail() == 3;
|
||||
l.assert_consistent(); assert l.pop().get() == 1;
|
||||
l.assert_consistent(); assert l.pop().get() == 3;
|
||||
l.assert_consistent(); assert l.is_empty();
|
||||
l.assert_consistent(); fail_unless!(l.len() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.head() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.tail() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_tail() {
|
||||
@ -768,14 +768,14 @@ mod tests {
|
||||
l.assert_consistent(); let _one = l.push_n(1);
|
||||
l.assert_consistent(); let _two = l.push_n(2);
|
||||
l.assert_consistent(); let three = l.push_n(3);
|
||||
l.assert_consistent(); assert l.len() == 3;
|
||||
l.assert_consistent(); fail_unless!(l.len() == 3);
|
||||
l.assert_consistent(); l.remove(three);
|
||||
l.assert_consistent(); assert l.len() == 2;
|
||||
l.assert_consistent(); assert l.head() == 1;
|
||||
l.assert_consistent(); assert l.tail() == 2;
|
||||
l.assert_consistent(); assert l.pop().get() == 1;
|
||||
l.assert_consistent(); assert l.pop().get() == 2;
|
||||
l.assert_consistent(); assert l.is_empty();
|
||||
l.assert_consistent(); fail_unless!(l.len() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.head() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.tail() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_one_two() {
|
||||
@ -783,15 +783,15 @@ mod tests {
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
l.assert_consistent(); let two = l.push_n(2);
|
||||
l.assert_consistent(); let _three = l.push_n(3);
|
||||
l.assert_consistent(); assert l.len() == 3;
|
||||
l.assert_consistent(); fail_unless!(l.len() == 3);
|
||||
l.assert_consistent(); l.remove(one);
|
||||
l.assert_consistent(); l.remove(two);
|
||||
// and through and through, the vorpal blade went snicker-snack
|
||||
l.assert_consistent(); assert l.len() == 1;
|
||||
l.assert_consistent(); assert l.head() == 3;
|
||||
l.assert_consistent(); assert l.tail() == 3;
|
||||
l.assert_consistent(); assert l.pop().get() == 3;
|
||||
l.assert_consistent(); assert l.is_empty();
|
||||
l.assert_consistent(); fail_unless!(l.len() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.head() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.tail() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_one_three() {
|
||||
@ -799,14 +799,14 @@ mod tests {
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
l.assert_consistent(); let _two = l.push_n(2);
|
||||
l.assert_consistent(); let three = l.push_n(3);
|
||||
l.assert_consistent(); assert l.len() == 3;
|
||||
l.assert_consistent(); fail_unless!(l.len() == 3);
|
||||
l.assert_consistent(); l.remove(one);
|
||||
l.assert_consistent(); l.remove(three);
|
||||
l.assert_consistent(); assert l.len() == 1;
|
||||
l.assert_consistent(); assert l.head() == 2;
|
||||
l.assert_consistent(); assert l.tail() == 2;
|
||||
l.assert_consistent(); assert l.pop().get() == 2;
|
||||
l.assert_consistent(); assert l.is_empty();
|
||||
l.assert_consistent(); fail_unless!(l.len() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.head() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.tail() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_two_three() {
|
||||
@ -814,14 +814,14 @@ mod tests {
|
||||
l.assert_consistent(); let _one = l.push_n(1);
|
||||
l.assert_consistent(); let two = l.push_n(2);
|
||||
l.assert_consistent(); let three = l.push_n(3);
|
||||
l.assert_consistent(); assert l.len() == 3;
|
||||
l.assert_consistent(); fail_unless!(l.len() == 3);
|
||||
l.assert_consistent(); l.remove(two);
|
||||
l.assert_consistent(); l.remove(three);
|
||||
l.assert_consistent(); assert l.len() == 1;
|
||||
l.assert_consistent(); assert l.head() == 1;
|
||||
l.assert_consistent(); assert l.tail() == 1;
|
||||
l.assert_consistent(); assert l.pop().get() == 1;
|
||||
l.assert_consistent(); assert l.is_empty();
|
||||
l.assert_consistent(); fail_unless!(l.len() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.head() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.tail() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_remove_all() {
|
||||
@ -829,12 +829,12 @@ mod tests {
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
l.assert_consistent(); let two = l.push_n(2);
|
||||
l.assert_consistent(); let three = l.push_n(3);
|
||||
l.assert_consistent(); assert l.len() == 3;
|
||||
l.assert_consistent(); fail_unless!(l.len() == 3);
|
||||
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(); assert l.peek().is_none();
|
||||
l.assert_consistent(); assert l.is_empty();
|
||||
l.assert_consistent(); fail_unless!(l.peek().is_none());
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_insert_n_before() {
|
||||
@ -842,15 +842,15 @@ mod tests {
|
||||
l.assert_consistent(); let _one = l.push_n(1);
|
||||
l.assert_consistent(); let two = l.push_n(2);
|
||||
l.assert_consistent(); let three = new_dlist_node(3);
|
||||
l.assert_consistent(); assert l.len() == 2;
|
||||
l.assert_consistent(); fail_unless!(l.len() == 2);
|
||||
l.assert_consistent(); l.insert_n_before(three, two);
|
||||
l.assert_consistent(); assert l.len() == 3;
|
||||
l.assert_consistent(); assert l.head() == 1;
|
||||
l.assert_consistent(); assert l.tail() == 2;
|
||||
l.assert_consistent(); assert l.pop().get() == 1;
|
||||
l.assert_consistent(); assert l.pop().get() == 3;
|
||||
l.assert_consistent(); assert l.pop().get() == 2;
|
||||
l.assert_consistent(); assert l.is_empty();
|
||||
l.assert_consistent(); fail_unless!(l.len() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.head() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.tail() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_insert_n_after() {
|
||||
@ -858,45 +858,45 @@ mod tests {
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
l.assert_consistent(); let _two = l.push_n(2);
|
||||
l.assert_consistent(); let three = new_dlist_node(3);
|
||||
l.assert_consistent(); assert l.len() == 2;
|
||||
l.assert_consistent(); fail_unless!(l.len() == 2);
|
||||
l.assert_consistent(); l.insert_n_after(three, one);
|
||||
l.assert_consistent(); assert l.len() == 3;
|
||||
l.assert_consistent(); assert l.head() == 1;
|
||||
l.assert_consistent(); assert l.tail() == 2;
|
||||
l.assert_consistent(); assert l.pop().get() == 1;
|
||||
l.assert_consistent(); assert l.pop().get() == 3;
|
||||
l.assert_consistent(); assert l.pop().get() == 2;
|
||||
l.assert_consistent(); assert l.is_empty();
|
||||
l.assert_consistent(); fail_unless!(l.len() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.head() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.tail() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_insert_before_head() {
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
l.assert_consistent(); let _two = l.push_n(2);
|
||||
l.assert_consistent(); assert l.len() == 2;
|
||||
l.assert_consistent(); fail_unless!(l.len() == 2);
|
||||
l.assert_consistent(); l.insert_before(3, one);
|
||||
l.assert_consistent(); assert l.len() == 3;
|
||||
l.assert_consistent(); assert l.head() == 3;
|
||||
l.assert_consistent(); assert l.tail() == 2;
|
||||
l.assert_consistent(); assert l.pop().get() == 3;
|
||||
l.assert_consistent(); assert l.pop().get() == 1;
|
||||
l.assert_consistent(); assert l.pop().get() == 2;
|
||||
l.assert_consistent(); assert l.is_empty();
|
||||
l.assert_consistent(); fail_unless!(l.len() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.head() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.tail() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.is_empty());
|
||||
}
|
||||
#[test]
|
||||
pub fn test_dlist_insert_after_tail() {
|
||||
let l = DList::<int>();
|
||||
l.assert_consistent(); let _one = l.push_n(1);
|
||||
l.assert_consistent(); let two = l.push_n(2);
|
||||
l.assert_consistent(); assert l.len() == 2;
|
||||
l.assert_consistent(); fail_unless!(l.len() == 2);
|
||||
l.assert_consistent(); l.insert_after(3, two);
|
||||
l.assert_consistent(); assert l.len() == 3;
|
||||
l.assert_consistent(); assert l.head() == 1;
|
||||
l.assert_consistent(); assert l.tail() == 3;
|
||||
l.assert_consistent(); assert l.pop().get() == 1;
|
||||
l.assert_consistent(); assert l.pop().get() == 2;
|
||||
l.assert_consistent(); assert l.pop().get() == 3;
|
||||
l.assert_consistent(); assert l.is_empty();
|
||||
l.assert_consistent(); fail_unless!(l.len() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.head() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.tail() == 3);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 1);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 2);
|
||||
l.assert_consistent(); fail_unless!(l.pop().get() == 3);
|
||||
l.assert_consistent(); fail_unless!(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 }
|
||||
assert (either(f_left, f_right, &val));
|
||||
fail_unless!((either(f_left, f_right, &val)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -184,84 +184,84 @@ fn test_either_right() {
|
||||
let val = Right(10u);
|
||||
fn f_left(_x: &int) -> bool { false }
|
||||
fn f_right(x: &uint) -> bool { *x == 10u }
|
||||
assert (either(f_left, f_right, &val));
|
||||
fail_unless!((either(f_left, f_right, &val)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lefts() {
|
||||
let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)];
|
||||
let result = lefts(input);
|
||||
assert (result == ~[10, 12, 14]);
|
||||
fail_unless!((result == ~[10, 12, 14]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lefts_none() {
|
||||
let input: ~[Either<int, int>] = ~[Right(10), Right(10)];
|
||||
let result = lefts(input);
|
||||
assert (vec::len(result) == 0u);
|
||||
fail_unless!((vec::len(result) == 0u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lefts_empty() {
|
||||
let input: ~[Either<int, int>] = ~[];
|
||||
let result = lefts(input);
|
||||
assert (vec::len(result) == 0u);
|
||||
fail_unless!((vec::len(result) == 0u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rights() {
|
||||
let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)];
|
||||
let result = rights(input);
|
||||
assert (result == ~[11, 13]);
|
||||
fail_unless!((result == ~[11, 13]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rights_none() {
|
||||
let input: ~[Either<int, int>] = ~[Left(10), Left(10)];
|
||||
let result = rights(input);
|
||||
assert (vec::len(result) == 0u);
|
||||
fail_unless!((vec::len(result) == 0u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rights_empty() {
|
||||
let input: ~[Either<int, int>] = ~[];
|
||||
let result = rights(input);
|
||||
assert (vec::len(result) == 0u);
|
||||
fail_unless!((vec::len(result) == 0u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_partition() {
|
||||
let input = ~[Left(10), Right(11), Left(12), Right(13), Left(14)];
|
||||
let (lefts, rights) = partition(input);
|
||||
assert (lefts[0] == 10);
|
||||
assert (lefts[1] == 12);
|
||||
assert (lefts[2] == 14);
|
||||
assert (rights[0] == 11);
|
||||
assert (rights[1] == 13);
|
||||
fail_unless!((lefts[0] == 10));
|
||||
fail_unless!((lefts[1] == 12));
|
||||
fail_unless!((lefts[2] == 14));
|
||||
fail_unless!((rights[0] == 11));
|
||||
fail_unless!((rights[1] == 13));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_partition_no_lefts() {
|
||||
let input: ~[Either<int, int>] = ~[Right(10), Right(11)];
|
||||
let (lefts, rights) = partition(input);
|
||||
assert (vec::len(lefts) == 0u);
|
||||
assert (vec::len(rights) == 2u);
|
||||
fail_unless!((vec::len(lefts) == 0u));
|
||||
fail_unless!((vec::len(rights) == 2u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_partition_no_rights() {
|
||||
let input: ~[Either<int, int>] = ~[Left(10), Left(11)];
|
||||
let (lefts, rights) = partition(input);
|
||||
assert (vec::len(lefts) == 2u);
|
||||
assert (vec::len(rights) == 0u);
|
||||
fail_unless!((vec::len(lefts) == 2u));
|
||||
fail_unless!((vec::len(rights) == 0u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_partition_empty() {
|
||||
let input: ~[Either<int, int>] = ~[];
|
||||
let (lefts, rights) = partition(input);
|
||||
assert (vec::len(lefts) == 0u);
|
||||
assert (vec::len(rights) == 0u);
|
||||
fail_unless!((vec::len(lefts) == 0u));
|
||||
fail_unless!((vec::len(rights) == 0u));
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -21,16 +21,23 @@ use vec;
|
||||
|
||||
#[cfg(test)] use rand;
|
||||
|
||||
extern mod rustrt {
|
||||
pub mod rustrt {
|
||||
use libc::{c_int, c_void, size_t};
|
||||
|
||||
#[link_name = "rustrt"]
|
||||
pub extern {
|
||||
unsafe fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
|
||||
src_buf_len: size_t,
|
||||
pout_len: *size_t,
|
||||
flags: c_int) -> *c_void;
|
||||
flags: c_int)
|
||||
-> *c_void;
|
||||
|
||||
unsafe fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
|
||||
src_buf_len: size_t,
|
||||
pout_len: *size_t,
|
||||
flags: c_int) -> *c_void;
|
||||
flags: c_int)
|
||||
-> *c_void;
|
||||
}
|
||||
}
|
||||
|
||||
const lz_none : c_int = 0x0; // Huffman-coding only.
|
||||
@ -47,7 +54,7 @@ pub fn deflate_bytes(bytes: &[const u8]) -> ~[u8] {
|
||||
len as size_t,
|
||||
ptr::addr_of(&outsz),
|
||||
lz_norm);
|
||||
assert res as int != 0;
|
||||
fail_unless!(res as int != 0);
|
||||
let out = vec::raw::from_buf_raw(res as *u8,
|
||||
outsz as uint);
|
||||
libc::free(res);
|
||||
@ -65,7 +72,7 @@ pub fn inflate_bytes(bytes: &[const u8]) -> ~[u8] {
|
||||
len as size_t,
|
||||
ptr::addr_of(&outsz),
|
||||
0);
|
||||
assert res as int != 0;
|
||||
fail_unless!(res as int != 0);
|
||||
let out = vec::raw::from_buf_raw(res as *u8,
|
||||
outsz as uint);
|
||||
libc::free(res);
|
||||
@ -94,6 +101,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)));
|
||||
assert(in == out);
|
||||
fail_unless!((in == out));
|
||||
}
|
||||
}
|
||||
|
@ -48,14 +48,20 @@ use sys;
|
||||
pub use stackwalk::Word;
|
||||
|
||||
// Mirrors rust_stack.h stk_seg
|
||||
struct StackSegment {
|
||||
pub struct StackSegment {
|
||||
prev: *StackSegment,
|
||||
next: *StackSegment,
|
||||
end: uintptr_t,
|
||||
// And other fields which we don't care about...
|
||||
}
|
||||
|
||||
extern mod rustrt {
|
||||
pub mod rustrt {
|
||||
use libc::size_t;
|
||||
use stackwalk::Word;
|
||||
use super::StackSegment;
|
||||
|
||||
#[link_name = "rustrt"]
|
||||
pub extern {
|
||||
#[rust_stack]
|
||||
pub unsafe fn rust_call_tydesc_glue(root: *Word,
|
||||
tydesc: *Word,
|
||||
@ -65,6 +71,7 @@ extern mod rustrt {
|
||||
pub unsafe fn rust_gc_metadata() -> *Word;
|
||||
|
||||
pub unsafe fn rust_get_stack_segment() -> *StackSegment;
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn bump<T, U>(ptr: *T, count: uint) -> *U {
|
||||
|
@ -458,7 +458,7 @@ pub fn test_siphash() {
|
||||
let vec = u8to64_le!(vecs[t], 0);
|
||||
let out = buf.hash_keyed(k0, k1);
|
||||
debug!("got %?, expected %?", out, vec);
|
||||
assert vec == out;
|
||||
fail_unless!(vec == out);
|
||||
|
||||
stream_full.reset();
|
||||
stream_full.input(buf);
|
||||
@ -467,7 +467,7 @@ pub fn test_siphash() {
|
||||
let v = to_hex_str(&vecs[t]);
|
||||
debug!("%d: (%s) => inc=%s full=%s", t, v, i, f);
|
||||
|
||||
assert f == i && f == v;
|
||||
fail_unless!(f == i && f == v);
|
||||
|
||||
buf += ~[t as u8];
|
||||
stream_inc.input(~[t as u8]);
|
||||
@ -479,20 +479,20 @@ pub fn test_siphash() {
|
||||
#[test] #[cfg(target_arch = "arm")]
|
||||
pub fn test_hash_uint() {
|
||||
let val = 0xdeadbeef_deadbeef_u64;
|
||||
assert (val as u64).hash() != (val as uint).hash();
|
||||
assert (val as u32).hash() == (val as uint).hash();
|
||||
fail_unless!((val as u64).hash() != (val as uint).hash());
|
||||
fail_unless!((val as u32).hash() == (val as uint).hash());
|
||||
}
|
||||
#[test] #[cfg(target_arch = "x86_64")]
|
||||
pub fn test_hash_uint() {
|
||||
let val = 0xdeadbeef_deadbeef_u64;
|
||||
assert (val as u64).hash() == (val as uint).hash();
|
||||
assert (val as u32).hash() != (val as uint).hash();
|
||||
fail_unless!((val as u64).hash() == (val as uint).hash());
|
||||
fail_unless!((val as u32).hash() != (val as uint).hash());
|
||||
}
|
||||
#[test] #[cfg(target_arch = "x86")]
|
||||
pub fn test_hash_uint() {
|
||||
let val = 0xdeadbeef_deadbeef_u64;
|
||||
assert (val as u64).hash() != (val as uint).hash();
|
||||
assert (val as u32).hash() == (val as uint).hash();
|
||||
fail_unless!((val as u64).hash() != (val as uint).hash());
|
||||
fail_unless!((val as u32).hash() == (val as uint).hash());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -507,17 +507,17 @@ pub fn test_hash_idempotent() {
|
||||
pub fn test_hash_no_bytes_dropped_64() {
|
||||
let val = 0xdeadbeef_deadbeef_u64;
|
||||
|
||||
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();
|
||||
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());
|
||||
|
||||
fn zero_byte(val: u64, byte: uint) -> u64 {
|
||||
assert byte < 8;
|
||||
fail_unless!(byte < 8);
|
||||
val & !(0xff << (byte * 8))
|
||||
}
|
||||
}
|
||||
@ -526,13 +526,13 @@ pub fn test_hash_no_bytes_dropped_64() {
|
||||
pub fn test_hash_no_bytes_dropped_32() {
|
||||
let val = 0xdeadbeef_u32;
|
||||
|
||||
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();
|
||||
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());
|
||||
|
||||
fn zero_byte(val: u32, byte: uint) -> u32 {
|
||||
assert byte < 4;
|
||||
fail_unless!(byte < 4);
|
||||
val & !(0xff << (byte * 8))
|
||||
}
|
||||
}
|
||||
|
@ -642,119 +642,119 @@ pub mod linear {
|
||||
#[test]
|
||||
pub fn test_insert() {
|
||||
let mut m = LinearMap::new();
|
||||
assert m.insert(1, 2);
|
||||
assert m.insert(2, 4);
|
||||
assert *m.get(&1) == 2;
|
||||
assert *m.get(&2) == 4;
|
||||
fail_unless!(m.insert(1, 2));
|
||||
fail_unless!(m.insert(2, 4));
|
||||
fail_unless!(*m.get(&1) == 2);
|
||||
fail_unless!(*m.get(&2) == 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_insert_overwrite() {
|
||||
let mut m = LinearMap::new();
|
||||
assert m.insert(1, 2);
|
||||
assert *m.get(&1) == 2;
|
||||
assert !m.insert(1, 3);
|
||||
assert *m.get(&1) == 3;
|
||||
fail_unless!(m.insert(1, 2));
|
||||
fail_unless!(*m.get(&1) == 2);
|
||||
fail_unless!(!m.insert(1, 3));
|
||||
fail_unless!(*m.get(&1) == 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_insert_conflicts() {
|
||||
let mut m = linear::linear_map_with_capacity(4);
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_conflict_remove() {
|
||||
let mut m = linear::linear_map_with_capacity(4);
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_is_empty() {
|
||||
let mut m = linear::linear_map_with_capacity(4);
|
||||
assert m.insert(1, 2);
|
||||
assert !m.is_empty();
|
||||
assert m.remove(&1);
|
||||
assert m.is_empty();
|
||||
fail_unless!(m.insert(1, 2));
|
||||
fail_unless!(!m.is_empty());
|
||||
fail_unless!(m.remove(&1));
|
||||
fail_unless!(m.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_pop() {
|
||||
let mut m = LinearMap::new();
|
||||
m.insert(1, 2);
|
||||
assert m.pop(&1) == Some(2);
|
||||
assert m.pop(&1) == None;
|
||||
fail_unless!(m.pop(&1) == Some(2));
|
||||
fail_unless!(m.pop(&1) == None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_swap() {
|
||||
let mut m = LinearMap::new();
|
||||
assert m.swap(1, 2) == None;
|
||||
assert m.swap(1, 3) == Some(2);
|
||||
assert m.swap(1, 4) == Some(3);
|
||||
fail_unless!(m.swap(1, 2) == None);
|
||||
fail_unless!(m.swap(1, 3) == Some(2));
|
||||
fail_unless!(m.swap(1, 4) == Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_find_or_insert() {
|
||||
let mut m = LinearMap::new::<int, int>();
|
||||
assert m.find_or_insert(1, 2) == &2;
|
||||
assert m.find_or_insert(1, 3) == &2;
|
||||
fail_unless!(m.find_or_insert(1, 2) == &2);
|
||||
fail_unless!(m.find_or_insert(1, 3) == &2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_find_or_insert_with() {
|
||||
let mut m = LinearMap::new::<int, int>();
|
||||
assert m.find_or_insert_with(1, |_| 2) == &2;
|
||||
assert m.find_or_insert_with(1, |_| 3) == &2;
|
||||
fail_unless!(m.find_or_insert_with(1, |_| 2) == &2);
|
||||
fail_unless!(m.find_or_insert_with(1, |_| 3) == &2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_consume() {
|
||||
let mut m = LinearMap::new();
|
||||
assert m.insert(1, 2);
|
||||
assert m.insert(2, 3);
|
||||
fail_unless!(m.insert(1, 2));
|
||||
fail_unless!(m.insert(2, 3));
|
||||
let mut m2 = LinearMap::new();
|
||||
do m.consume |k, v| {
|
||||
m2.insert(k, v);
|
||||
}
|
||||
assert m.len() == 0;
|
||||
assert m2.len() == 2;
|
||||
assert m2.get(&1) == &2;
|
||||
assert m2.get(&2) == &3;
|
||||
fail_unless!(m.len() == 0);
|
||||
fail_unless!(m2.len() == 2);
|
||||
fail_unless!(m2.get(&1) == &2);
|
||||
fail_unless!(m2.get(&2) == &3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_iterate() {
|
||||
let mut m = linear::linear_map_with_capacity(4);
|
||||
for uint::range(0, 32) |i| {
|
||||
assert m.insert(i, i*2);
|
||||
fail_unless!(m.insert(i, i*2));
|
||||
}
|
||||
let mut observed = 0;
|
||||
for m.each |&(k, v)| {
|
||||
assert *v == *k * 2;
|
||||
fail_unless!(*v == *k * 2);
|
||||
observed |= (1 << *k);
|
||||
}
|
||||
assert observed == 0xFFFF_FFFF;
|
||||
fail_unless!(observed == 0xFFFF_FFFF);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_find() {
|
||||
let mut m = LinearMap::new();
|
||||
assert m.find(&1).is_none();
|
||||
fail_unless!(m.find(&1).is_none());
|
||||
m.insert(1, 2);
|
||||
match m.find(&1) {
|
||||
None => fail!(),
|
||||
Some(v) => assert *v == 2
|
||||
Some(v) => fail_unless!(*v == 2)
|
||||
}
|
||||
}
|
||||
|
||||
@ -769,19 +769,19 @@ pub mod linear {
|
||||
m2.insert(1, 2);
|
||||
m2.insert(2, 3);
|
||||
|
||||
assert m1 != m2;
|
||||
fail_unless!(m1 != m2);
|
||||
|
||||
m2.insert(3, 4);
|
||||
|
||||
assert m1 == m2;
|
||||
fail_unless!(m1 == m2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_expand() {
|
||||
let mut m = LinearMap::new();
|
||||
|
||||
assert m.len() == 0;
|
||||
assert m.is_empty();
|
||||
fail_unless!(m.len() == 0);
|
||||
fail_unless!(m.is_empty());
|
||||
|
||||
let mut i = 0u;
|
||||
let old_resize_at = m.resize_at;
|
||||
@ -790,8 +790,8 @@ pub mod linear {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
assert m.len() == i;
|
||||
assert !m.is_empty();
|
||||
fail_unless!(m.len() == i);
|
||||
fail_unless!(!m.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
@ -805,51 +805,51 @@ pub mod linear {
|
||||
fn test_disjoint() {
|
||||
let mut xs = linear::LinearSet::new();
|
||||
let mut ys = linear::LinearSet::new();
|
||||
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);
|
||||
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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_subset_and_superset() {
|
||||
let mut a = linear::LinearSet::new();
|
||||
assert a.insert(0);
|
||||
assert a.insert(5);
|
||||
assert a.insert(11);
|
||||
assert a.insert(7);
|
||||
fail_unless!(a.insert(0));
|
||||
fail_unless!(a.insert(5));
|
||||
fail_unless!(a.insert(11));
|
||||
fail_unless!(a.insert(7));
|
||||
|
||||
let mut b = linear::LinearSet::new();
|
||||
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!(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 !a.is_subset(&b);
|
||||
assert !a.is_superset(&b);
|
||||
assert !b.is_subset(&a);
|
||||
assert !b.is_superset(&a);
|
||||
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 b.insert(5);
|
||||
fail_unless!(b.insert(5));
|
||||
|
||||
assert a.is_subset(&b);
|
||||
assert !a.is_superset(&b);
|
||||
assert !b.is_subset(&a);
|
||||
assert b.is_superset(&a);
|
||||
fail_unless!(a.is_subset(&b));
|
||||
fail_unless!(!a.is_superset(&b));
|
||||
fail_unless!(!b.is_subset(&a));
|
||||
fail_unless!(b.is_superset(&a));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -857,29 +857,29 @@ pub mod linear {
|
||||
let mut a = linear::LinearSet::new();
|
||||
let mut b = linear::LinearSet::new();
|
||||
|
||||
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!(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 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);
|
||||
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));
|
||||
|
||||
let mut i = 0;
|
||||
let expected = [3, 5, 11, 77];
|
||||
for a.intersection(&b) |x| {
|
||||
assert vec::contains(expected, x);
|
||||
fail_unless!(vec::contains(expected, x));
|
||||
i += 1
|
||||
}
|
||||
assert i == expected.len();
|
||||
fail_unless!(i == expected.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -887,22 +887,22 @@ pub mod linear {
|
||||
let mut a = linear::LinearSet::new();
|
||||
let mut b = linear::LinearSet::new();
|
||||
|
||||
assert a.insert(1);
|
||||
assert a.insert(3);
|
||||
assert a.insert(5);
|
||||
assert a.insert(9);
|
||||
assert a.insert(11);
|
||||
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 b.insert(3);
|
||||
assert b.insert(9);
|
||||
fail_unless!(b.insert(3));
|
||||
fail_unless!(b.insert(9));
|
||||
|
||||
let mut i = 0;
|
||||
let expected = [1, 5, 11];
|
||||
for a.difference(&b) |x| {
|
||||
assert vec::contains(expected, x);
|
||||
fail_unless!(vec::contains(expected, x));
|
||||
i += 1
|
||||
}
|
||||
assert i == expected.len();
|
||||
fail_unless!(i == expected.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -910,25 +910,25 @@ pub mod linear {
|
||||
let mut a = linear::LinearSet::new();
|
||||
let mut b = linear::LinearSet::new();
|
||||
|
||||
assert a.insert(1);
|
||||
assert a.insert(3);
|
||||
assert a.insert(5);
|
||||
assert a.insert(9);
|
||||
assert a.insert(11);
|
||||
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 b.insert(-2);
|
||||
assert b.insert(3);
|
||||
assert b.insert(9);
|
||||
assert b.insert(14);
|
||||
assert b.insert(22);
|
||||
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));
|
||||
|
||||
let mut i = 0;
|
||||
let expected = [-2, 1, 5, 11, 14, 22];
|
||||
for a.symmetric_difference(&b) |x| {
|
||||
assert vec::contains(expected, x);
|
||||
fail_unless!(vec::contains(expected, x));
|
||||
i += 1
|
||||
}
|
||||
assert i == expected.len();
|
||||
fail_unless!(i == expected.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -936,29 +936,29 @@ pub mod linear {
|
||||
let mut a = linear::LinearSet::new();
|
||||
let mut b = linear::LinearSet::new();
|
||||
|
||||
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!(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 b.insert(-2);
|
||||
assert b.insert(1);
|
||||
assert b.insert(5);
|
||||
assert b.insert(9);
|
||||
assert b.insert(13);
|
||||
assert b.insert(19);
|
||||
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));
|
||||
|
||||
let mut i = 0;
|
||||
let expected = [-2, 1, 3, 5, 9, 11, 13, 16, 19, 24];
|
||||
for a.union(&b) |x| {
|
||||
assert vec::contains(expected, x);
|
||||
fail_unless!(vec::contains(expected, x));
|
||||
i += 1
|
||||
}
|
||||
assert i == expected.len();
|
||||
fail_unless!(i == expected.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,11 +32,16 @@ use vec;
|
||||
#[allow(non_camel_case_types)] // not sure what to do about this
|
||||
pub type fd_t = c_int;
|
||||
|
||||
#[abi = "cdecl"]
|
||||
extern mod rustrt {
|
||||
pub mod rustrt {
|
||||
use libc;
|
||||
|
||||
#[abi = "cdecl"]
|
||||
#[link_name = "rustrt"]
|
||||
pub extern {
|
||||
unsafe fn rust_get_stdin() -> *libc::FILE;
|
||||
unsafe fn rust_get_stdout() -> *libc::FILE;
|
||||
unsafe fn rust_get_stderr() -> *libc::FILE;
|
||||
}
|
||||
}
|
||||
|
||||
// Reading
|
||||
@ -242,7 +247,7 @@ impl<T:Reader> ReaderUtil for T {
|
||||
let w = str::utf8_char_width(b0);
|
||||
let end = i + w;
|
||||
i += 1;
|
||||
assert (w > 0);
|
||||
fail_unless!((w > 0));
|
||||
if w == 1 {
|
||||
chars.push(b0 as char);
|
||||
loop;
|
||||
@ -255,8 +260,8 @@ impl<T:Reader> ReaderUtil for T {
|
||||
while i < end {
|
||||
let next = bytes[i] as int;
|
||||
i += 1;
|
||||
assert (next > -1);
|
||||
assert (next & 192 == 128);
|
||||
fail_unless!((next > -1));
|
||||
fail_unless!((next & 192 == 128));
|
||||
val <<= 6;
|
||||
val += (next & 63) as uint;
|
||||
}
|
||||
@ -297,7 +302,7 @@ impl<T:Reader> ReaderUtil for T {
|
||||
if vec::len(c) == 0 {
|
||||
return -1 as char; // FIXME will this stay valid? // #2004
|
||||
}
|
||||
assert(vec::len(c) == 1);
|
||||
fail_unless!((vec::len(c) == 1));
|
||||
return c[0];
|
||||
}
|
||||
|
||||
@ -332,7 +337,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 {
|
||||
assert nbytes > 0 && nbytes <= 8;
|
||||
fail_unless!(nbytes > 0 && nbytes <= 8);
|
||||
|
||||
let mut val = 0u64, pos = 0, i = nbytes;
|
||||
while i > 0 {
|
||||
@ -348,7 +353,7 @@ impl<T:Reader> ReaderUtil for T {
|
||||
}
|
||||
|
||||
fn read_be_uint_n(&self, nbytes: uint) -> u64 {
|
||||
assert nbytes > 0 && nbytes <= 8;
|
||||
fail_unless!(nbytes > 0 && nbytes <= 8);
|
||||
|
||||
let mut val = 0u64, i = nbytes;
|
||||
while i > 0 {
|
||||
@ -478,7 +483,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| {
|
||||
assert buf_len >= len;
|
||||
fail_unless!(buf_len >= len);
|
||||
|
||||
let count = libc::fread(buf_p as *mut c_void, 1u as size_t,
|
||||
len as size_t, *self);
|
||||
@ -499,9 +504,9 @@ impl Reader for *libc::FILE {
|
||||
}
|
||||
fn seek(&self, offset: int, whence: SeekStyle) {
|
||||
unsafe {
|
||||
assert libc::fseek(*self,
|
||||
fail_unless!(libc::fseek(*self,
|
||||
offset as c_long,
|
||||
convert_whence(whence)) == 0 as c_int;
|
||||
convert_whence(whence)) == 0 as c_int);
|
||||
}
|
||||
}
|
||||
fn tell(&self) -> uint {
|
||||
@ -687,9 +692,9 @@ impl Writer for *libc::FILE {
|
||||
}
|
||||
fn seek(&self, offset: int, whence: SeekStyle) {
|
||||
unsafe {
|
||||
assert libc::fseek(*self,
|
||||
fail_unless!(libc::fseek(*self,
|
||||
offset as c_long,
|
||||
convert_whence(whence)) == 0 as c_int;
|
||||
convert_whence(whence)) == 0 as c_int);
|
||||
}
|
||||
}
|
||||
fn tell(&self) -> uint {
|
||||
@ -816,7 +821,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 {
|
||||
assert size <= 8u;
|
||||
fail_unless!(size <= 8u);
|
||||
match size {
|
||||
1u => f(&[n as u8]),
|
||||
2u => f(&[n as u8,
|
||||
@ -848,7 +853,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 {
|
||||
assert size <= 8u;
|
||||
fail_unless!(size <= 8u);
|
||||
match size {
|
||||
1u => f(&[n as u8]),
|
||||
2u => f(&[(n >> 8) as u8,
|
||||
@ -881,7 +886,7 @@ pub fn u64_to_be_bytes<T>(n: u64, size: uint,
|
||||
pub fn u64_from_be_bytes(data: &[const u8],
|
||||
start: uint, size: uint) -> u64 {
|
||||
let mut sz = size;
|
||||
assert (sz <= 8u);
|
||||
fail_unless!((sz <= 8u));
|
||||
let mut val = 0_u64;
|
||||
let mut pos = start;
|
||||
while sz > 0u {
|
||||
@ -1158,7 +1163,7 @@ pub pure fn with_str_writer(f: fn(Writer)) -> ~str {
|
||||
// Make sure the vector has a trailing null and is proper utf8.
|
||||
v.push(0);
|
||||
}
|
||||
assert str::is_utf8(v);
|
||||
fail_unless!(str::is_utf8(v));
|
||||
|
||||
unsafe { ::cast::transmute(v) }
|
||||
}
|
||||
@ -1230,7 +1235,7 @@ pub mod fsync {
|
||||
None => (),
|
||||
Some(level) => {
|
||||
// fail hard if not succesful
|
||||
assert((self.arg.fsync_fn)(self.arg.val, level) != -1);
|
||||
fail_unless!(((self.arg.fsync_fn)(self.arg.val, level) != -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1315,14 +1320,14 @@ mod tests {
|
||||
let inp: io::Reader = result::get(&io::file_reader(tmpfile));
|
||||
let frood2: ~str = inp.read_c_str();
|
||||
log(debug, copy frood2);
|
||||
assert frood == frood2;
|
||||
fail_unless!(frood == frood2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_readchars_empty() {
|
||||
do io::with_str_reader(~"") |inp| {
|
||||
let res : ~[char] = inp.read_chars(128);
|
||||
assert(vec::len(res) == 0);
|
||||
fail_unless!((vec::len(res) == 0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1330,7 +1335,7 @@ mod tests {
|
||||
fn test_read_line_utf8() {
|
||||
do io::with_str_reader(~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤") |inp| {
|
||||
let line = inp.read_line();
|
||||
assert line == ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤";
|
||||
fail_unless!(line == ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1347,9 +1352,9 @@ mod tests {
|
||||
do io::with_str_reader(s) |inp| {
|
||||
let res : ~[char] = inp.read_chars(len);
|
||||
if (len <= vec::len(ivals)) {
|
||||
assert(vec::len(res) == len);
|
||||
fail_unless!((vec::len(res) == len));
|
||||
}
|
||||
assert(vec::slice(ivals, 0u, vec::len(res)) ==
|
||||
fail_unless!(vec::slice(ivals, 0u, vec::len(res)) ==
|
||||
vec::map(res, |x| *x as int));
|
||||
}
|
||||
}
|
||||
@ -1366,7 +1371,7 @@ mod tests {
|
||||
fn test_readchar() {
|
||||
do io::with_str_reader(~"生") |inp| {
|
||||
let res : char = inp.read_char();
|
||||
assert(res as int == 29983);
|
||||
fail_unless!((res as int == 29983));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1374,7 +1379,7 @@ mod tests {
|
||||
fn test_readchar_empty() {
|
||||
do io::with_str_reader(~"") |inp| {
|
||||
let res : char = inp.read_char();
|
||||
assert(res as int == -1);
|
||||
fail_unless!((res as int == -1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1382,7 +1387,7 @@ mod tests {
|
||||
fn file_reader_not_exist() {
|
||||
match io::file_reader(&Path("not a file")) {
|
||||
result::Err(copy e) => {
|
||||
assert e == ~"error opening not a file";
|
||||
fail_unless!(e == ~"error opening not a file");
|
||||
}
|
||||
result::Ok(_) => fail!()
|
||||
}
|
||||
@ -1423,7 +1428,7 @@ mod tests {
|
||||
fn file_writer_bad_name() {
|
||||
match io::file_writer(&Path("?/?"), ~[]) {
|
||||
result::Err(copy e) => {
|
||||
assert str::starts_with(e, "error opening");
|
||||
fail_unless!(str::starts_with(e, "error opening"));
|
||||
}
|
||||
result::Ok(_) => fail!()
|
||||
}
|
||||
@ -1433,7 +1438,7 @@ mod tests {
|
||||
fn buffered_file_writer_bad_name() {
|
||||
match io::buffered_file_writer(&Path("?/?")) {
|
||||
result::Err(copy e) => {
|
||||
assert str::starts_with(e, "error opening");
|
||||
fail_unless!(str::starts_with(e, "error opening"));
|
||||
}
|
||||
result::Ok(_) => fail!()
|
||||
}
|
||||
@ -1443,17 +1448,17 @@ mod tests {
|
||||
fn bytes_buffer_overwrite() {
|
||||
let wr = BytesWriter();
|
||||
wr.write(~[0u8, 1u8, 2u8, 3u8]);
|
||||
assert wr.bytes.borrow(|bytes| bytes == ~[0u8, 1u8, 2u8, 3u8]);
|
||||
fail_unless!(wr.bytes.borrow(|bytes| bytes == ~[0u8, 1u8, 2u8, 3u8]));
|
||||
wr.seek(-2, SeekCur);
|
||||
wr.write(~[4u8, 5u8, 6u8, 7u8]);
|
||||
assert wr.bytes.borrow(|bytes| bytes ==
|
||||
~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]);
|
||||
fail_unless!(wr.bytes.borrow(|bytes| bytes ==
|
||||
~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]));
|
||||
wr.seek(-2, SeekEnd);
|
||||
wr.write(~[8u8]);
|
||||
wr.seek(1, SeekSet);
|
||||
wr.write(~[9u8]);
|
||||
assert wr.bytes.borrow(|bytes| bytes ==
|
||||
~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]);
|
||||
fail_unless!(wr.bytes.borrow(|bytes| bytes ==
|
||||
~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1473,7 +1478,7 @@ mod tests {
|
||||
{
|
||||
let file = io::file_reader(&path).get();
|
||||
for uints.each |i| {
|
||||
assert file.read_le_u64() == *i;
|
||||
fail_unless!(file.read_le_u64() == *i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1495,7 +1500,7 @@ mod tests {
|
||||
{
|
||||
let file = io::file_reader(&path).get();
|
||||
for uints.each |i| {
|
||||
assert file.read_be_u64() == *i;
|
||||
fail_unless!(file.read_be_u64() == *i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1519,7 +1524,7 @@ mod tests {
|
||||
for ints.each |i| {
|
||||
// this tests that the sign extension is working
|
||||
// (comparing the values as i32 would not test this)
|
||||
assert file.read_be_int_n(4) == *i as i64;
|
||||
fail_unless!(file.read_be_int_n(4) == *i as i64);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1538,7 +1543,7 @@ mod tests {
|
||||
{
|
||||
let file = io::file_reader(&path).get();
|
||||
let f = file.read_be_f32();
|
||||
assert f == 8.1250;
|
||||
fail_unless!(f == 8.1250);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1555,8 +1560,8 @@ mod tests {
|
||||
|
||||
{
|
||||
let file = io::file_reader(&path).get();
|
||||
assert file.read_be_f32() == 8.1250;
|
||||
assert file.read_le_f32() == 8.1250;
|
||||
fail_unless!(file.read_be_f32() == 8.1250);
|
||||
fail_unless!(file.read_le_f32() == 8.1250);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ mod inst {
|
||||
let mut link = self.peek_n();
|
||||
while option::is_some(&link) {
|
||||
let nobe = option::get(link);
|
||||
assert nobe.linked;
|
||||
fail_unless!(nobe.linked);
|
||||
|
||||
{
|
||||
let frozen_nobe = &*nobe;
|
||||
|
@ -1006,13 +1006,12 @@ pub mod funcs {
|
||||
// or anything. The same is not true of POSIX.
|
||||
|
||||
pub mod c95 {
|
||||
use libc::types::common::c95::{FILE, c_void, fpos_t};
|
||||
use libc::types::os::arch::c95::{c_char, c_double, c_int, c_long};
|
||||
use libc::types::os::arch::c95::{c_uint, c_ulong, c_void, size_t};
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod ctype {
|
||||
pub mod ctype {
|
||||
use libc::types::os::arch::c95::{c_char, c_int};
|
||||
|
||||
pub extern {
|
||||
unsafe fn isalnum(c: c_int) -> c_int;
|
||||
unsafe fn isalpha(c: c_int) -> c_int;
|
||||
unsafe fn iscntrl(c: c_int) -> c_int;
|
||||
@ -1027,10 +1026,15 @@ pub mod funcs {
|
||||
unsafe fn tolower(c: c_char) -> c_char;
|
||||
unsafe fn toupper(c: c_char) -> c_char;
|
||||
}
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod stdio {
|
||||
pub mod stdio {
|
||||
use libc::types::common::c95::{FILE, c_void, fpos_t};
|
||||
use libc::types::os::arch::c95::{c_char, c_int, c_long, size_t};
|
||||
|
||||
pub extern {
|
||||
unsafe fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
|
||||
unsafe fn freopen(filename: *c_char, mode: *c_char,
|
||||
file: *FILE) -> *FILE;
|
||||
@ -1070,11 +1074,17 @@ pub mod funcs {
|
||||
unsafe fn ferror(stream: *FILE) -> c_int;
|
||||
unsafe fn perror(s: *c_char);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod stdlib {
|
||||
pub mod stdlib {
|
||||
use libc::types::common::c95::c_void;
|
||||
use libc::types::os::arch::c95::{c_char, c_double, c_int};
|
||||
use libc::types::os::arch::c95::{c_long, c_uint, c_ulong};
|
||||
use libc::types::os::arch::c95::{size_t};
|
||||
|
||||
pub extern {
|
||||
unsafe fn abs(i: c_int) -> c_int;
|
||||
unsafe fn labs(i: c_long) -> c_long;
|
||||
// Omitted: div, ldiv (return pub type incomplete).
|
||||
@ -1098,17 +1108,24 @@ pub mod funcs {
|
||||
unsafe fn rand() -> c_int;
|
||||
unsafe fn srand(seed: c_uint);
|
||||
}
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod string {
|
||||
pub mod string {
|
||||
use libc::types::common::c95::c_void;
|
||||
use libc::types::os::arch::c95::{c_char, c_int, size_t};
|
||||
|
||||
pub extern {
|
||||
unsafe fn strcpy(dst: *c_char, src: *c_char) -> *c_char;
|
||||
unsafe fn strncpy(dst: *c_char, src: *c_char, n: size_t)
|
||||
-> *c_char;
|
||||
unsafe fn strcat(s: *c_char, ct: *c_char) -> *c_char;
|
||||
unsafe fn strncat(s: *c_char, ct: *c_char, n: size_t) -> *c_char;
|
||||
unsafe fn strncat(s: *c_char, ct: *c_char, n: size_t)
|
||||
-> *c_char;
|
||||
unsafe fn strcmp(cs: *c_char, ct: *c_char) -> c_int;
|
||||
unsafe fn strncmp(cs: *c_char, ct: *c_char, n: size_t) -> c_int;
|
||||
unsafe fn strncmp(cs: *c_char, ct: *c_char, n: size_t)
|
||||
-> c_int;
|
||||
unsafe fn strcoll(cs: *c_char, ct: *c_char) -> c_int;
|
||||
unsafe fn strchr(cs: *c_char, c: c_int) -> *c_char;
|
||||
unsafe fn strrchr(cs: *c_char, c: c_int) -> *c_char;
|
||||
@ -1119,19 +1136,23 @@ pub mod funcs {
|
||||
unsafe fn strlen(cs: *c_char) -> size_t;
|
||||
unsafe fn strerror(n: c_int) -> *c_char;
|
||||
unsafe fn strtok(s: *c_char, t: *c_char) -> *c_char;
|
||||
unsafe fn strxfrm(s: *c_char, ct: *c_char, n: size_t) -> size_t;
|
||||
unsafe fn strxfrm(s: *c_char, ct: *c_char, n: size_t)
|
||||
-> size_t;
|
||||
|
||||
// These are fine to execute on the Rust stack. They must be, in
|
||||
// fact, because LLVM generates calls to them!
|
||||
// These are fine to execute on the Rust stack. They must be,
|
||||
// in fact, because LLVM generates calls to them!
|
||||
#[rust_stack]
|
||||
#[inline(always)]
|
||||
unsafe fn memcpy(s: *c_void, ct: *c_void, n: size_t) -> *c_void;
|
||||
unsafe fn memcpy(s: *c_void, ct: *c_void, n: size_t)
|
||||
-> *c_void;
|
||||
#[rust_stack]
|
||||
#[inline(always)]
|
||||
unsafe fn memmove(s: *c_void, ct: *c_void, n: size_t) -> *c_void;
|
||||
unsafe fn memmove(s: *c_void, ct: *c_void, n: size_t)
|
||||
-> *c_void;
|
||||
#[rust_stack]
|
||||
#[inline(always)]
|
||||
unsafe fn memcmp(cx: *c_void, ct: *c_void, n: size_t) -> c_int;
|
||||
unsafe fn memcmp(cx: *c_void, ct: *c_void, n: size_t)
|
||||
-> c_int;
|
||||
#[rust_stack]
|
||||
#[inline(always)]
|
||||
unsafe fn memchr(cx: *c_void, c: c_int, n: size_t) -> *c_void;
|
||||
@ -1140,6 +1161,7 @@ pub mod funcs {
|
||||
unsafe fn memset(s: *c_void, c: c_int, n: size_t) -> *c_void;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Microsoft helpfully underscore-qualifies all of its POSIX-like symbols
|
||||
// to make sure you don't use them accidentally. It also randomly deviates
|
||||
@ -1151,10 +1173,11 @@ pub mod funcs {
|
||||
pub mod posix88 {
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod stat_ {
|
||||
pub mod stat_ {
|
||||
use libc::types::os::common::posix01::stat;
|
||||
use libc::types::os::arch::c95::{c_int, c_char};
|
||||
|
||||
pub extern {
|
||||
#[link_name = "_chmod"]
|
||||
unsafe fn chmod(path: *c_char, mode: c_int) -> c_int;
|
||||
|
||||
@ -1167,13 +1190,15 @@ pub mod funcs {
|
||||
#[link_name = "_stat64"]
|
||||
unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod stdio {
|
||||
pub mod stdio {
|
||||
use libc::types::common::c95::FILE;
|
||||
use libc::types::os::arch::c95::{c_int, c_char};
|
||||
|
||||
pub extern {
|
||||
#[link_name = "_popen"]
|
||||
unsafe fn popen(command: *c_char, mode: *c_char) -> *FILE;
|
||||
|
||||
@ -1186,33 +1211,38 @@ pub mod funcs {
|
||||
#[link_name = "_fileno"]
|
||||
unsafe fn fileno(stream: *FILE) -> c_int;
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod fcntl {
|
||||
use libc::types::os::arch::c95::{c_int, c_char};
|
||||
|
||||
#[link_name = "_open"]
|
||||
unsafe fn open(path: *c_char, oflag: c_int, mode: c_int) -> c_int;
|
||||
|
||||
#[link_name = "_creat"]
|
||||
unsafe fn creat(path: *c_char, mode: c_int) -> c_int;
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod dirent {
|
||||
pub mod fcntl {
|
||||
pub extern {
|
||||
use libc::types::os::arch::c95::{c_int, c_char};
|
||||
|
||||
#[link_name = "_open"]
|
||||
unsafe fn open(path: *c_char, oflag: c_int, mode: c_int)
|
||||
-> c_int;
|
||||
|
||||
#[link_name = "_creat"]
|
||||
unsafe fn creat(path: *c_char, mode: c_int) -> c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub mod dirent {
|
||||
// Not supplied at all.
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod unistd {
|
||||
pub mod unistd {
|
||||
use libc::types::common::c95::c_void;
|
||||
use libc::types::os::arch::c95::{c_int, c_uint, c_char,
|
||||
c_long, size_t};
|
||||
use libc::types::os::arch::c99::intptr_t;
|
||||
|
||||
pub extern {
|
||||
#[link_name = "_access"]
|
||||
unsafe fn access(path: *c_char, amode: c_int) -> c_int;
|
||||
|
||||
@ -1270,8 +1300,9 @@ pub mod funcs {
|
||||
unsafe fn unlink(c: *c_char) -> c_int;
|
||||
|
||||
#[link_name = "_write"]
|
||||
unsafe fn write(fd: c_int, buf: *c_void, count: c_uint) -> c_int;
|
||||
|
||||
unsafe fn write(fd: c_int, buf: *c_void, count: c_uint)
|
||||
-> c_int;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1281,17 +1312,14 @@ pub mod funcs {
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(target_os = "freebsd")]
|
||||
pub mod posix88 {
|
||||
use libc::types::common::c95::{FILE, c_void};
|
||||
use libc::types::common::posix88::{DIR, dirent_t};
|
||||
use libc::types::os::arch::c95::{c_char, c_int, c_long, c_uint};
|
||||
use libc::types::os::arch::c95::{size_t};
|
||||
pub mod stat_ {
|
||||
use libc::types::os::arch::c95::{c_char, c_int};
|
||||
use libc::types::os::arch::posix01::stat;
|
||||
use libc::types::os::arch::posix88::{gid_t, mode_t, off_t, pid_t};
|
||||
use libc::types::os::arch::posix88::{ssize_t, uid_t};
|
||||
use libc::types::os::arch::posix88::mode_t;
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod stat_ {
|
||||
pub extern {
|
||||
unsafe fn chmod(path: *c_char, mode: mode_t) -> c_int;
|
||||
unsafe fn fchmod(fd: c_int, mode: mode_t) -> c_int;
|
||||
|
||||
@ -1316,27 +1344,43 @@ pub mod funcs {
|
||||
#[link_name = "stat64"]
|
||||
unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod stdio {
|
||||
pub mod stdio {
|
||||
use libc::types::common::c95::FILE;
|
||||
use libc::types::os::arch::c95::{c_char, c_int};
|
||||
|
||||
pub extern {
|
||||
unsafe fn popen(command: *c_char, mode: *c_char) -> *FILE;
|
||||
unsafe fn pclose(stream: *FILE) -> c_int;
|
||||
unsafe fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
|
||||
unsafe fn fileno(stream: *FILE) -> c_int;
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod fcntl {
|
||||
unsafe fn open(path: *c_char, oflag: c_int, mode: c_int) -> c_int;
|
||||
unsafe fn creat(path: *c_char, mode: mode_t) -> c_int;
|
||||
unsafe fn fcntl(fd: c_int, cmd: c_int) -> c_int;
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod dirent {
|
||||
pub mod fcntl {
|
||||
use libc::types::os::arch::c95::{c_char, c_int};
|
||||
use libc::types::os::arch::posix88::mode_t;
|
||||
|
||||
pub extern {
|
||||
unsafe fn open(path: *c_char, oflag: c_int, mode: c_int)
|
||||
-> c_int;
|
||||
unsafe fn creat(path: *c_char, mode: mode_t) -> c_int;
|
||||
unsafe fn fcntl(fd: c_int, cmd: c_int) -> c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub mod dirent {
|
||||
use libc::types::common::posix88::{DIR, dirent_t};
|
||||
use libc::types::os::arch::c95::{c_char, c_int, c_long};
|
||||
|
||||
pub extern {
|
||||
unsafe fn opendir(dirname: *c_char) -> *DIR;
|
||||
unsafe fn closedir(dirp: *DIR) -> c_int;
|
||||
unsafe fn readdir(dirp: *DIR) -> *dirent_t;
|
||||
@ -1344,19 +1388,30 @@ pub mod funcs {
|
||||
unsafe fn seekdir(dirp: *DIR, loc: c_long);
|
||||
unsafe fn telldir(dirp: *DIR) -> c_long;
|
||||
}
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod unistd {
|
||||
pub mod unistd {
|
||||
use libc::types::common::c95::c_void;
|
||||
use libc::types::os::arch::c95::{c_char, c_int, c_long, c_uint};
|
||||
use libc::types::os::arch::c95::{size_t};
|
||||
use libc::types::os::arch::posix88::{gid_t, off_t, pid_t};
|
||||
use libc::types::os::arch::posix88::{ssize_t, uid_t};
|
||||
|
||||
pub extern {
|
||||
unsafe fn access(path: *c_char, amode: c_int) -> c_int;
|
||||
unsafe fn alarm(seconds: c_uint) -> c_uint;
|
||||
unsafe fn chdir(dir: *c_char) -> c_int;
|
||||
unsafe fn chown(path: *c_char, uid: uid_t, gid: gid_t) -> c_int;
|
||||
unsafe fn chown(path: *c_char, uid: uid_t, gid: gid_t)
|
||||
-> c_int;
|
||||
unsafe fn close(fd: c_int) -> c_int;
|
||||
unsafe fn dup(fd: c_int) -> c_int;
|
||||
unsafe fn dup2(src: c_int, dst: c_int) -> c_int;
|
||||
unsafe fn execv(prog: *c_char, argv: **c_char) -> c_int;
|
||||
unsafe fn execve(prog: *c_char, argv: **c_char, envp: **c_char)
|
||||
unsafe fn execve(prog: *c_char,
|
||||
argv: **c_char,
|
||||
envp: **c_char)
|
||||
-> c_int;
|
||||
unsafe fn execvp(c: *c_char, argv: **c_char) -> c_int;
|
||||
unsafe fn fork() -> pid_t;
|
||||
@ -1376,7 +1431,8 @@ pub mod funcs {
|
||||
unsafe fn getuid() -> uid_t;
|
||||
unsafe fn isatty(fd: c_int) -> c_int;
|
||||
unsafe fn link(src: *c_char, dst: *c_char) -> c_int;
|
||||
unsafe fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t;
|
||||
unsafe fn lseek(fd: c_int, offset: off_t, whence: c_int)
|
||||
-> off_t;
|
||||
unsafe fn pathconf(path: *c_char, name: c_int) -> c_long;
|
||||
unsafe fn pause() -> c_int;
|
||||
unsafe fn pipe(fds: *mut c_int) -> c_int;
|
||||
@ -1396,19 +1452,20 @@ pub mod funcs {
|
||||
-> ssize_t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "android")]
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(target_os = "freebsd")]
|
||||
pub mod posix01 {
|
||||
use libc::types::os::arch::c95::{c_char, c_int, size_t};
|
||||
use libc::types::os::arch::posix01::stat;
|
||||
use libc::types::os::arch::posix88::{pid_t, ssize_t};
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod stat_ {
|
||||
pub mod stat_ {
|
||||
use libc::types::os::arch::c95::{c_char, c_int};
|
||||
use libc::types::os::arch::posix01::stat;
|
||||
|
||||
pub extern {
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(target_os = "freebsd")]
|
||||
#[cfg(target_os = "android")]
|
||||
@ -1418,10 +1475,15 @@ pub mod funcs {
|
||||
#[link_name = "lstat64"]
|
||||
unsafe fn lstat(path: *c_char, buf: *mut stat) -> c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod unistd {
|
||||
pub mod unistd {
|
||||
use libc::types::os::arch::c95::{c_char, c_int, size_t};
|
||||
use libc::types::os::arch::posix88::{ssize_t};
|
||||
|
||||
pub extern {
|
||||
unsafe fn readlink(path: *c_char, buf: *mut c_char,
|
||||
bufsz: size_t) -> ssize_t;
|
||||
|
||||
@ -1438,23 +1500,29 @@ pub mod funcs {
|
||||
|
||||
unsafe fn symlink(path1: *c_char, path2: *c_char) -> c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod wait {
|
||||
unsafe fn waitpid(pid: pid_t, status: *mut c_int,
|
||||
options: c_int) -> pid_t;
|
||||
pub mod wait {
|
||||
use libc::types::os::arch::c95::{c_int};
|
||||
use libc::types::os::arch::posix88::{pid_t};
|
||||
|
||||
pub extern {
|
||||
unsafe fn waitpid(pid: pid_t,
|
||||
status: *mut c_int,
|
||||
options: c_int)
|
||||
-> pid_t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
pub mod posix01 {
|
||||
#[nolink]
|
||||
pub extern mod stat_ {
|
||||
pub mod stat_ {
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
pub extern mod unistd {
|
||||
pub mod unistd {
|
||||
}
|
||||
}
|
||||
|
||||
@ -1465,17 +1533,16 @@ pub mod funcs {
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(target_os = "freebsd")]
|
||||
pub mod posix08 {
|
||||
#[nolink]
|
||||
pub extern mod unistd {
|
||||
pub mod unistd {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(target_os = "freebsd")]
|
||||
#[nolink]
|
||||
pub mod bsd44 {
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod bsd44 {
|
||||
pub extern {
|
||||
use libc::types::common::c95::{c_void};
|
||||
use libc::types::os::arch::c95::{c_char, c_int, c_uint, size_t};
|
||||
|
||||
@ -1490,6 +1557,7 @@ pub mod funcs {
|
||||
unsafe fn sysctlnametomib(name: *c_char, mibp: *mut c_int,
|
||||
sizep: *mut size_t) -> c_int;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
@ -1500,12 +1568,15 @@ pub mod funcs {
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod extra {
|
||||
pub mod extra {
|
||||
use libc::types::os::arch::c95::{c_char, c_int};
|
||||
|
||||
#[abi = "cdecl"]
|
||||
pub extern {
|
||||
unsafe fn _NSGetExecutablePath(buf: *mut c_char,
|
||||
bufsize: *mut u32) -> c_int;
|
||||
bufsize: *mut u32)
|
||||
-> c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
@ -1520,40 +1591,52 @@ pub mod funcs {
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
pub mod extra {
|
||||
use libc::types::os::arch::c95::c_int;
|
||||
use libc::types::os::arch::extra::{DWORD, HMODULE, LPCWSTR, LPWSTR};
|
||||
use libc::types::os::arch::extra::{BOOL, LPSECURITY_ATTRIBUTES};
|
||||
|
||||
pub mod kernel32 {
|
||||
use libc::types::os::arch::extra::{BOOL, DWORD, HMODULE};
|
||||
use libc::types::os::arch::extra::{LPCWSTR, LPWSTR};
|
||||
use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES};
|
||||
|
||||
#[abi = "stdcall"]
|
||||
pub extern mod kernel32 {
|
||||
pub extern {
|
||||
unsafe fn GetEnvironmentVariableW(n: LPCWSTR,
|
||||
v: LPWSTR,
|
||||
nsize: DWORD) -> DWORD;
|
||||
unsafe fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL;
|
||||
nsize: DWORD)
|
||||
-> DWORD;
|
||||
unsafe fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR)
|
||||
-> BOOL;
|
||||
|
||||
unsafe fn GetModuleFileNameW(hModule: HMODULE,
|
||||
lpFilename: LPWSTR,
|
||||
nSize: DWORD) -> DWORD;
|
||||
nSize: DWORD)
|
||||
-> DWORD;
|
||||
unsafe fn CreateDirectoryW(lpPathName: LPCWSTR,
|
||||
lpSecurityAttributes:
|
||||
LPSECURITY_ATTRIBUTES) -> BOOL;
|
||||
LPSECURITY_ATTRIBUTES)
|
||||
-> BOOL;
|
||||
unsafe fn CopyFileW(lpExistingFileName: LPCWSTR,
|
||||
lpNewFileName: LPCWSTR,
|
||||
bFailIfExists: BOOL) -> BOOL;
|
||||
bFailIfExists: BOOL)
|
||||
-> BOOL;
|
||||
unsafe fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
|
||||
unsafe fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
|
||||
unsafe fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
|
||||
|
||||
unsafe fn GetLastError() -> DWORD;
|
||||
}
|
||||
}
|
||||
|
||||
pub mod msvcrt {
|
||||
use libc::types::os::arch::c95::c_int;
|
||||
|
||||
#[abi = "cdecl"]
|
||||
#[nolink]
|
||||
pub extern mod msvcrt {
|
||||
pub extern {
|
||||
#[link_name = "_commit"]
|
||||
unsafe fn commit(fd: c_int) -> c_int;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,13 +12,16 @@
|
||||
|
||||
use libc;
|
||||
|
||||
#[nolink]
|
||||
extern mod rustrt {
|
||||
pub mod rustrt {
|
||||
use libc;
|
||||
|
||||
pub extern {
|
||||
unsafe fn rust_log_console_on();
|
||||
unsafe fn rust_log_console_off();
|
||||
unsafe fn rust_log_str(level: u32,
|
||||
string: *libc::c_char,
|
||||
size: libc::size_t);
|
||||
}
|
||||
}
|
||||
|
||||
/// Turns on logging to stdout globally
|
||||
|
@ -72,8 +72,8 @@ impl<T:Ord> Ord for @const T {
|
||||
fn test() {
|
||||
let x = @3;
|
||||
let y = @3;
|
||||
assert (ptr_eq::<int>(x, x));
|
||||
assert (ptr_eq::<int>(y, y));
|
||||
assert (!ptr_eq::<int>(x, y));
|
||||
assert (!ptr_eq::<int>(y, x));
|
||||
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)));
|
||||
}
|
||||
|
@ -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.
|
||||
assert (m.mode as uint) == (ReadOnly as uint);
|
||||
fail_unless!((m.mode as uint) == (ReadOnly as uint));
|
||||
let Data {value: value, mode: _} = m;
|
||||
value
|
||||
}
|
||||
@ -105,9 +105,9 @@ pub fn test_const_in_mut() {
|
||||
let m = @Mut(1);
|
||||
do m.borrow_mut |p| {
|
||||
do m.borrow_const |q| {
|
||||
assert *p == *q;
|
||||
fail_unless!(*p == *q);
|
||||
*p += 1;
|
||||
assert *p == *q;
|
||||
fail_unless!(*p == *q);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -117,9 +117,9 @@ pub fn test_mut_in_const() {
|
||||
let m = @Mut(1);
|
||||
do m.borrow_const |p| {
|
||||
do m.borrow_mut |q| {
|
||||
assert *p == *q;
|
||||
fail_unless!(*p == *q);
|
||||
*q += 1;
|
||||
assert *p == *q;
|
||||
fail_unless!(*p == *q);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -129,7 +129,7 @@ pub fn test_imm_in_const() {
|
||||
let m = @Mut(1);
|
||||
do m.borrow_const |p| {
|
||||
do m.borrow_imm |q| {
|
||||
assert *p == *q;
|
||||
fail_unless!(*p == *q);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -139,7 +139,7 @@ pub fn test_const_in_imm() {
|
||||
let m = @Mut(1);
|
||||
do m.borrow_imm |p| {
|
||||
do m.borrow_const |q| {
|
||||
assert *p == *q;
|
||||
fail_unless!(*p == *q);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,12 @@ use libc::c_double;
|
||||
// function names are almost identical to C's libmath, a few have been
|
||||
// renamed, grep for "rename:"
|
||||
|
||||
#[link_name = "m"]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod c_double_utils {
|
||||
pub mod c_double_utils {
|
||||
use libc::{c_double, c_int};
|
||||
|
||||
#[link_name = "m"]
|
||||
#[abi = "cdecl"]
|
||||
pub extern {
|
||||
// Alpabetically sorted by link_name
|
||||
|
||||
unsafe fn acos(n: c_double) -> c_double;
|
||||
@ -43,20 +45,22 @@ pub extern mod c_double_utils {
|
||||
unsafe fn abs_sub(a: c_double, b: c_double) -> c_double;
|
||||
unsafe fn floor(n: c_double) -> c_double;
|
||||
// rename: for clarity and consistency with add/sub/mul/div
|
||||
#[link_name="fma"] unsafe fn mul_add(a: c_double, b: c_double,
|
||||
c: c_double) -> c_double;
|
||||
#[link_name="fmax"] unsafe fn fmax(a: c_double, b: c_double) -> c_double;
|
||||
#[link_name="fmin"] unsafe fn fmin(a: c_double, b: c_double) -> c_double;
|
||||
#[link_name="fma"]
|
||||
unsafe fn mul_add(a: c_double, b: c_double, c: c_double) -> c_double;
|
||||
#[link_name="fmax"]
|
||||
unsafe fn fmax(a: c_double, b: c_double) -> c_double;
|
||||
#[link_name="fmin"]
|
||||
unsafe fn fmin(a: c_double, b: c_double) -> c_double;
|
||||
unsafe fn nextafter(x: c_double, y: c_double) -> c_double;
|
||||
unsafe fn frexp(n: c_double, value: &mut c_int) -> c_double;
|
||||
unsafe fn hypot(x: c_double, y: c_double) -> c_double;
|
||||
unsafe fn ldexp(x: c_double, n: c_int) -> c_double;
|
||||
#[cfg(unix)]
|
||||
#[link_name="lgamma_r"] unsafe fn lgamma(n: c_double,
|
||||
sign: &mut c_int) -> c_double;
|
||||
#[link_name="lgamma_r"]
|
||||
unsafe fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
|
||||
#[cfg(windows)]
|
||||
#[link_name="__lgamma_r"] unsafe fn lgamma(n: c_double,
|
||||
sign: &mut c_int) -> c_double;
|
||||
#[link_name="__lgamma_r"]
|
||||
unsafe fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
|
||||
// renamed: log is a reserved keyword; ln seems more natural, too
|
||||
#[link_name="log"] unsafe fn ln(n: c_double) -> c_double;
|
||||
// renamed: "logb" /often/ is confused for log2 by beginners
|
||||
@ -68,8 +72,8 @@ pub extern mod c_double_utils {
|
||||
#[link_name="ilogb"] unsafe fn ilog_radix(n: c_double) -> c_int;
|
||||
unsafe fn modf(n: c_double, iptr: &mut c_double) -> c_double;
|
||||
unsafe fn pow(n: c_double, e: c_double) -> c_double;
|
||||
// FIXME (#1379): enable when rounding modes become available
|
||||
// unsafe fn rint(n: c_double) -> c_double;
|
||||
// FIXME (#1379): enable when rounding modes become available
|
||||
// unsafe fn rint(n: c_double) -> c_double;
|
||||
unsafe fn round(n: c_double) -> c_double;
|
||||
// rename: for consistency with logradix
|
||||
#[link_name="scalbn"] unsafe fn ldexp_radix(n: c_double, i: c_int) ->
|
||||
@ -91,18 +95,22 @@ pub extern mod c_double_utils {
|
||||
unsafe fn y0(n: c_double) -> c_double;
|
||||
unsafe fn y1(n: c_double) -> c_double;
|
||||
unsafe fn yn(i: c_int, n: c_double) -> c_double;
|
||||
}
|
||||
}
|
||||
|
||||
#[link_name = "m"]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod c_float_utils {
|
||||
pub mod c_float_utils {
|
||||
use libc::{c_float, c_int};
|
||||
|
||||
#[link_name = "m"]
|
||||
#[abi = "cdecl"]
|
||||
pub extern {
|
||||
// Alpabetically sorted by link_name
|
||||
|
||||
#[link_name="acosf"] unsafe fn acos(n: c_float) -> c_float;
|
||||
#[link_name="asinf"] unsafe fn asin(n: c_float) -> c_float;
|
||||
#[link_name="atanf"] unsafe fn atan(n: c_float) -> c_float;
|
||||
#[link_name="atan2f"] unsafe fn atan2(a: c_float, b: c_float) -> c_float;
|
||||
#[link_name="atan2f"]
|
||||
unsafe fn atan2(a: c_float, b: c_float) -> c_float;
|
||||
#[link_name="cbrtf"] unsafe fn cbrt(n: c_float) -> c_float;
|
||||
#[link_name="ceilf"] unsafe fn ceil(n: c_float) -> c_float;
|
||||
#[link_name="copysignf"] unsafe fn copysign(x: c_float,
|
||||
@ -115,26 +123,31 @@ pub extern mod c_float_utils {
|
||||
#[link_name="expm1f"]unsafe fn expm1(n: c_float) -> c_float;
|
||||
#[link_name="exp2f"] unsafe fn exp2(n: c_float) -> c_float;
|
||||
#[link_name="fabsf"] unsafe fn abs(n: c_float) -> c_float;
|
||||
#[link_name="fdimf"] unsafe fn abs_sub(a: c_float, b: c_float) -> c_float;
|
||||
#[link_name="fdimf"]
|
||||
unsafe fn abs_sub(a: c_float, b: c_float) -> c_float;
|
||||
#[link_name="floorf"] unsafe fn floor(n: c_float) -> c_float;
|
||||
#[link_name="frexpf"] unsafe fn frexp(n: c_float,
|
||||
value: &mut c_int) -> c_float;
|
||||
#[link_name="fmaf"] unsafe fn mul_add(a: c_float,
|
||||
b: c_float, c: c_float) -> c_float;
|
||||
#[link_name="fmaxf"] unsafe fn fmax(a: c_float, b: c_float) -> c_float;
|
||||
#[link_name="fminf"] unsafe fn fmin(a: c_float, b: c_float) -> c_float;
|
||||
#[link_name="nextafterf"] unsafe fn nextafter(x: c_float,
|
||||
y: c_float) -> c_float;
|
||||
#[link_name="hypotf"] unsafe fn hypot(x: c_float, y: c_float) -> c_float;
|
||||
#[link_name="ldexpf"] unsafe fn ldexp(x: c_float, n: c_int) -> c_float;
|
||||
#[link_name="fmaf"]
|
||||
unsafe fn mul_add(a: c_float, b: c_float, c: c_float) -> c_float;
|
||||
#[link_name="fmaxf"]
|
||||
unsafe fn fmax(a: c_float, b: c_float) -> c_float;
|
||||
#[link_name="fminf"]
|
||||
unsafe fn fmin(a: c_float, b: c_float) -> c_float;
|
||||
#[link_name="nextafterf"]
|
||||
unsafe fn nextafter(x: c_float, y: c_float) -> c_float;
|
||||
#[link_name="hypotf"]
|
||||
unsafe fn hypot(x: c_float, y: c_float) -> c_float;
|
||||
#[link_name="ldexpf"]
|
||||
unsafe fn ldexp(x: c_float, n: c_int) -> c_float;
|
||||
|
||||
#[cfg(unix)]
|
||||
#[link_name="lgammaf_r"] unsafe fn lgamma(n: c_float,
|
||||
sign: &mut c_int) -> c_float;
|
||||
|
||||
#[cfg(windows)]
|
||||
#[link_name="__lgammaf_r"] unsafe fn lgamma(n: c_float,
|
||||
sign: &mut c_int) -> c_float;
|
||||
#[link_name="__lgammaf_r"]
|
||||
unsafe fn lgamma(n: c_float, sign: &mut c_int) -> c_float;
|
||||
|
||||
#[link_name="logf"] unsafe fn ln(n: c_float) -> c_float;
|
||||
#[link_name="logbf"] unsafe fn log_radix(n: c_float) -> c_float;
|
||||
@ -145,8 +158,8 @@ pub extern mod c_float_utils {
|
||||
#[link_name="modff"] unsafe fn modf(n: c_float,
|
||||
iptr: &mut c_float) -> c_float;
|
||||
#[link_name="powf"] unsafe fn pow(n: c_float, e: c_float) -> c_float;
|
||||
// FIXME (#1379): enable when rounding modes become available
|
||||
// #[link_name="rintf"] unsafe fn rint(n: c_float) -> c_float;
|
||||
// FIXME (#1379): enable when rounding modes become available
|
||||
// #[link_name="rintf"] unsafe fn rint(n: c_float) -> c_float;
|
||||
#[link_name="roundf"] unsafe fn round(n: c_float) -> c_float;
|
||||
#[link_name="scalbnf"] unsafe fn ldexp_radix(n: c_float, i: c_int)
|
||||
-> c_float;
|
||||
@ -157,6 +170,7 @@ pub extern mod c_float_utils {
|
||||
#[link_name="tanhf"] unsafe fn tanh(n: c_float) -> c_float;
|
||||
#[link_name="tgammaf"] unsafe fn tgamma(n: c_float) -> c_float;
|
||||
#[link_name="truncf"] unsafe fn trunc(n: c_float) -> c_float;
|
||||
}
|
||||
}
|
||||
|
||||
// PORT check these by running src/etc/machconsts.c for your architecture
|
||||
|
@ -583,56 +583,56 @@ pub fn test_num() {
|
||||
let ten: f32 = num::cast(10);
|
||||
let two: f32 = num::cast(2);
|
||||
|
||||
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));
|
||||
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)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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!((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 (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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -607,56 +607,56 @@ pub fn test_num() {
|
||||
let ten: f64 = num::cast(10);
|
||||
let two: f64 = num::cast(2);
|
||||
|
||||
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));
|
||||
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)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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!((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 (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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -180,7 +180,7 @@ pub pure 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);
|
||||
assert s == ~"5.0000";
|
||||
fail_unless!(s == ~"5.0000");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -500,191 +500,191 @@ impl ops::Neg<float> for float {
|
||||
|
||||
#[test]
|
||||
pub fn test_from_str() {
|
||||
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);
|
||||
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));
|
||||
// note: NaN != NaN, hence this slightly complex test
|
||||
match from_str(~"NaN") {
|
||||
Some(f) => assert is_NaN(f),
|
||||
Some(f) => fail_unless!(is_NaN(f)),
|
||||
None => fail!()
|
||||
}
|
||||
// note: -0 == 0, hence these slightly more complex tests
|
||||
match from_str(~"-0") {
|
||||
Some(v) if is_zero(v) => assert is_negative(v),
|
||||
Some(v) if is_zero(v) => fail_unless!(is_negative(v)),
|
||||
_ => fail!()
|
||||
}
|
||||
match from_str(~"0") {
|
||||
Some(v) if is_zero(v) => assert is_positive(v),
|
||||
Some(v) if is_zero(v) => fail_unless!(is_positive(v)),
|
||||
_ => fail!()
|
||||
}
|
||||
|
||||
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();
|
||||
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());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_from_str_hex() {
|
||||
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);
|
||||
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));
|
||||
// note: NaN != NaN, hence this slightly complex test
|
||||
match from_str_hex(~"NaN") {
|
||||
Some(f) => assert is_NaN(f),
|
||||
Some(f) => fail_unless!(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) => assert is_negative(v),
|
||||
Some(v) if is_zero(v) => fail_unless!(is_negative(v)),
|
||||
_ => fail!()
|
||||
}
|
||||
match from_str_hex(~"0") {
|
||||
Some(v) if is_zero(v) => assert is_positive(v),
|
||||
Some(v) if is_zero(v) => fail_unless!(is_positive(v)),
|
||||
_ => fail!()
|
||||
}
|
||||
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(~"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(~"").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();
|
||||
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());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_to_str_hex() {
|
||||
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";
|
||||
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");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_to_str_radix() {
|
||||
assert to_str_radix(36., 36u) == ~"10";
|
||||
assert to_str_radix(8.125, 2u) == ~"1000.001";
|
||||
fail_unless!(to_str_radix(36., 36u) == ~"10");
|
||||
fail_unless!(to_str_radix(8.125, 2u) == ~"1000.001");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_from_str_radix() {
|
||||
assert from_str_radix(~"10", 36u) == Some(36.);
|
||||
assert from_str_radix(~"1000.001", 2u) == Some(8.125);
|
||||
fail_unless!(from_str_radix(~"10", 36u) == Some(36.));
|
||||
fail_unless!(from_str_radix(~"1000.001", 2u) == Some(8.125));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_positive() {
|
||||
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));
|
||||
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)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_negative() {
|
||||
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));
|
||||
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)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_nonpositive() {
|
||||
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));
|
||||
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)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_nonnegative() {
|
||||
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));
|
||||
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)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_to_str_inf() {
|
||||
assert to_str_digits(infinity, 10u) == ~"inf";
|
||||
assert to_str_digits(-infinity, 10u) == ~"-inf";
|
||||
fail_unless!(to_str_digits(infinity, 10u) == ~"inf");
|
||||
fail_unless!(to_str_digits(-infinity, 10u) == ~"-inf");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_round() {
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -692,56 +692,56 @@ pub fn test_num() {
|
||||
let ten: float = num::cast(10);
|
||||
let two: float = num::cast(2);
|
||||
|
||||
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));
|
||||
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)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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!((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 (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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,18 +41,18 @@ pub pure fn div(x: T, y: T) -> T { x / y }
|
||||
*
|
||||
* # Examples
|
||||
* ~~~
|
||||
* assert int::rem(5 / 2) == 1;
|
||||
* fail_unless!(int::rem(5 / 2) == 1);
|
||||
* ~~~
|
||||
*
|
||||
* When faced with negative numbers, the result copies the sign of the
|
||||
* dividend.
|
||||
*
|
||||
* ~~~
|
||||
* assert int::rem(2 / -3) == 2;
|
||||
* fail_unless!(int::rem(2 / -3) == 2);
|
||||
* ~~~
|
||||
*
|
||||
* ~~~
|
||||
* assert int::rem(-2 / 3) == -2;
|
||||
* fail_unless!(int::rem(-2 / 3) == -2);
|
||||
* ~~~
|
||||
*
|
||||
*/
|
||||
@ -95,7 +95,7 @@ pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
|
||||
* for int::range(1, 5) |i| {
|
||||
* sum += i;
|
||||
* }
|
||||
* assert sum == 10;
|
||||
* fail_unless!(sum == 10);
|
||||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
@ -275,117 +275,122 @@ impl ToStrRadix for T {
|
||||
|
||||
#[test]
|
||||
fn test_from_str() {
|
||||
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(~"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(~"-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(~"-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(~" ").is_none();
|
||||
assert from_str(~"x").is_none();
|
||||
fail_unless!(from_str(~" ").is_none());
|
||||
fail_unless!(from_str(~"x").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_bytes() {
|
||||
use str::to_bytes;
|
||||
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);
|
||||
assert i32::parse_bytes(to_bytes(~"FFFF"), 16u) == Some(65535 as i32);
|
||||
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) == Some(291 as i32));
|
||||
fail_unless!(i32::parse_bytes(to_bytes(~"ffff"), 16u) ==
|
||||
Some(65535 as i32));
|
||||
fail_unless!(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(~"-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);
|
||||
assert i32::parse_bytes(to_bytes(~"-FFFF"), 16u) == Some(-65535 as i32);
|
||||
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) ==
|
||||
Some(-291 as i32));
|
||||
fail_unless!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) ==
|
||||
Some(-65535 as i32));
|
||||
fail_unless!(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"), 35u).is_none();
|
||||
assert parse_bytes(to_bytes(~"-9"), 2u).is_none();
|
||||
fail_unless!(parse_bytes(to_bytes(~"Z"), 35u).is_none());
|
||||
fail_unless!(parse_bytes(to_bytes(~"-9"), 2u).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
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");
|
||||
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"));
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_int_to_str_overflow() {
|
||||
let mut i8_val: i8 = 127_i8;
|
||||
assert (i8::to_str(i8_val) == ~"127");
|
||||
fail_unless!((i8::to_str(i8_val) == ~"127"));
|
||||
|
||||
i8_val += 1 as i8;
|
||||
assert (i8::to_str(i8_val) == ~"-128");
|
||||
fail_unless!((i8::to_str(i8_val) == ~"-128"));
|
||||
|
||||
let mut i16_val: i16 = 32_767_i16;
|
||||
assert (i16::to_str(i16_val) == ~"32767");
|
||||
fail_unless!((i16::to_str(i16_val) == ~"32767"));
|
||||
|
||||
i16_val += 1 as i16;
|
||||
assert (i16::to_str(i16_val) == ~"-32768");
|
||||
fail_unless!((i16::to_str(i16_val) == ~"-32768"));
|
||||
|
||||
let mut i32_val: i32 = 2_147_483_647_i32;
|
||||
assert (i32::to_str(i32_val) == ~"2147483647");
|
||||
fail_unless!((i32::to_str(i32_val) == ~"2147483647"));
|
||||
|
||||
i32_val += 1 as i32;
|
||||
assert (i32::to_str(i32_val) == ~"-2147483648");
|
||||
fail_unless!((i32::to_str(i32_val) == ~"-2147483648"));
|
||||
|
||||
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
|
||||
assert (i64::to_str(i64_val) == ~"9223372036854775807");
|
||||
fail_unless!((i64::to_str(i64_val) == ~"9223372036854775807"));
|
||||
|
||||
i64_val += 1 as i64;
|
||||
assert (i64::to_str(i64_val) == ~"-9223372036854775808");
|
||||
fail_unless!((i64::to_str(i64_val) == ~"-9223372036854775808"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_int_from_str_overflow() {
|
||||
let mut i8_val: i8 = 127_i8;
|
||||
assert (i8::from_str(~"127") == Some(i8_val));
|
||||
assert (i8::from_str(~"128").is_none());
|
||||
fail_unless!((i8::from_str(~"127") == Some(i8_val)));
|
||||
fail_unless!((i8::from_str(~"128").is_none()));
|
||||
|
||||
i8_val += 1 as i8;
|
||||
assert (i8::from_str(~"-128") == Some(i8_val));
|
||||
assert (i8::from_str(~"-129").is_none());
|
||||
fail_unless!((i8::from_str(~"-128") == Some(i8_val)));
|
||||
fail_unless!((i8::from_str(~"-129").is_none()));
|
||||
|
||||
let mut i16_val: i16 = 32_767_i16;
|
||||
assert (i16::from_str(~"32767") == Some(i16_val));
|
||||
assert (i16::from_str(~"32768").is_none());
|
||||
fail_unless!((i16::from_str(~"32767") == Some(i16_val)));
|
||||
fail_unless!((i16::from_str(~"32768").is_none()));
|
||||
|
||||
i16_val += 1 as i16;
|
||||
assert (i16::from_str(~"-32768") == Some(i16_val));
|
||||
assert (i16::from_str(~"-32769").is_none());
|
||||
fail_unless!((i16::from_str(~"-32768") == Some(i16_val)));
|
||||
fail_unless!((i16::from_str(~"-32769").is_none()));
|
||||
|
||||
let mut i32_val: i32 = 2_147_483_647_i32;
|
||||
assert (i32::from_str(~"2147483647") == Some(i32_val));
|
||||
assert (i32::from_str(~"2147483648").is_none());
|
||||
fail_unless!((i32::from_str(~"2147483647") == Some(i32_val)));
|
||||
fail_unless!((i32::from_str(~"2147483648").is_none()));
|
||||
|
||||
i32_val += 1 as i32;
|
||||
assert (i32::from_str(~"-2147483648") == Some(i32_val));
|
||||
assert (i32::from_str(~"-2147483649").is_none());
|
||||
fail_unless!((i32::from_str(~"-2147483648") == Some(i32_val)));
|
||||
fail_unless!((i32::from_str(~"-2147483649").is_none()));
|
||||
|
||||
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
|
||||
assert (i64::from_str(~"9223372036854775807") == Some(i64_val));
|
||||
assert (i64::from_str(~"9223372036854775808").is_none());
|
||||
fail_unless!((i64::from_str(~"9223372036854775807") == Some(i64_val)));
|
||||
fail_unless!((i64::from_str(~"9223372036854775808").is_none()));
|
||||
|
||||
i64_val += 1 as i64;
|
||||
assert (i64::from_str(~"-9223372036854775808") == Some(i64_val));
|
||||
assert (i64::from_str(~"-9223372036854775809").is_none());
|
||||
fail_unless!((i64::from_str(~"-9223372036854775808") == Some(i64_val)));
|
||||
fail_unless!((i64::from_str(~"-9223372036854775809").is_none()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -393,11 +398,11 @@ pub fn test_num() {
|
||||
let ten: T = num::cast(10);
|
||||
let two: T = num::cast(2);
|
||||
|
||||
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));
|
||||
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)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -416,10 +421,10 @@ pub fn test_ranges() {
|
||||
for range_step(36,30,-2) |i| {
|
||||
l.push(i);
|
||||
}
|
||||
assert l == ~[0,1,2,
|
||||
fail_unless!(l == ~[0,1,2,
|
||||
13,12,11,
|
||||
20,22,24,
|
||||
36,34,32];
|
||||
36,34,32]);
|
||||
|
||||
// None of the `fail`s should execute.
|
||||
for range(10,0) |_i| {
|
||||
|
@ -43,45 +43,45 @@ impl NumCast for i16 {
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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!((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 (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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
@ -43,45 +43,45 @@ impl NumCast for i32 {
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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!((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 (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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
@ -43,45 +43,45 @@ impl NumCast for i64 {
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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!((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 (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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
@ -43,45 +43,45 @@ impl NumCast for i8 {
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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!((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 (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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
@ -40,21 +40,21 @@ mod inst {
|
||||
|
||||
#[test]
|
||||
fn test_pow() {
|
||||
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);
|
||||
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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_overflows() {
|
||||
assert (::int::max_value > 0);
|
||||
assert (::int::min_value <= 0);
|
||||
assert (::int::min_value + ::int::max_value + 1 == 0);
|
||||
fail_unless!((::int::max_value > 0));
|
||||
fail_unless!((::int::min_value <= 0));
|
||||
fail_unless!((::int::min_value + ::int::max_value + 1 == 0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,45 +84,45 @@ impl NumCast for int {
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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!((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 (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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ pub enum RoundMode {
|
||||
*
|
||||
* ~~~
|
||||
* let twenty: f32 = num::cast(0x14);
|
||||
* assert twenty == 20f32;
|
||||
* fail_unless!(twenty == 20f32);
|
||||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
|
@ -238,102 +238,104 @@ impl ToStrRadix for T {
|
||||
|
||||
#[test]
|
||||
pub fn test_to_str() {
|
||||
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";
|
||||
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");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_from_str() {
|
||||
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(~"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(~"").is_none();
|
||||
assert from_str(~" ").is_none();
|
||||
assert from_str(~"x").is_none();
|
||||
fail_unless!(from_str(~"").is_none());
|
||||
fail_unless!(from_str(~" ").is_none());
|
||||
fail_unless!(from_str(~"x").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_parse_bytes() {
|
||||
use str::to_bytes;
|
||||
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);
|
||||
assert u16::parse_bytes(to_bytes(~"ffff"), 16u) == Some(65535u as u16);
|
||||
assert parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T);
|
||||
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) ==
|
||||
Some(291u as u16));
|
||||
fail_unless!(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"), 10u).is_none();
|
||||
assert parse_bytes(to_bytes(~"_"), 2u).is_none();
|
||||
fail_unless!(parse_bytes(to_bytes(~"Z"), 10u).is_none());
|
||||
fail_unless!(parse_bytes(to_bytes(~"_"), 2u).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint_to_str_overflow() {
|
||||
let mut u8_val: u8 = 255_u8;
|
||||
assert (u8::to_str(u8_val) == ~"255");
|
||||
fail_unless!((u8::to_str(u8_val) == ~"255"));
|
||||
|
||||
u8_val += 1 as u8;
|
||||
assert (u8::to_str(u8_val) == ~"0");
|
||||
fail_unless!((u8::to_str(u8_val) == ~"0"));
|
||||
|
||||
let mut u16_val: u16 = 65_535_u16;
|
||||
assert (u16::to_str(u16_val) == ~"65535");
|
||||
fail_unless!((u16::to_str(u16_val) == ~"65535"));
|
||||
|
||||
u16_val += 1 as u16;
|
||||
assert (u16::to_str(u16_val) == ~"0");
|
||||
fail_unless!((u16::to_str(u16_val) == ~"0"));
|
||||
|
||||
let mut u32_val: u32 = 4_294_967_295_u32;
|
||||
assert (u32::to_str(u32_val) == ~"4294967295");
|
||||
fail_unless!((u32::to_str(u32_val) == ~"4294967295"));
|
||||
|
||||
u32_val += 1 as u32;
|
||||
assert (u32::to_str(u32_val) == ~"0");
|
||||
fail_unless!((u32::to_str(u32_val) == ~"0"));
|
||||
|
||||
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
|
||||
assert (u64::to_str(u64_val) == ~"18446744073709551615");
|
||||
fail_unless!((u64::to_str(u64_val) == ~"18446744073709551615"));
|
||||
|
||||
u64_val += 1 as u64;
|
||||
assert (u64::to_str(u64_val) == ~"0");
|
||||
fail_unless!((u64::to_str(u64_val) == ~"0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uint_from_str_overflow() {
|
||||
let mut u8_val: u8 = 255_u8;
|
||||
assert (u8::from_str(~"255") == Some(u8_val));
|
||||
assert (u8::from_str(~"256").is_none());
|
||||
fail_unless!((u8::from_str(~"255") == Some(u8_val)));
|
||||
fail_unless!((u8::from_str(~"256").is_none()));
|
||||
|
||||
u8_val += 1 as u8;
|
||||
assert (u8::from_str(~"0") == Some(u8_val));
|
||||
assert (u8::from_str(~"-1").is_none());
|
||||
fail_unless!((u8::from_str(~"0") == Some(u8_val)));
|
||||
fail_unless!((u8::from_str(~"-1").is_none()));
|
||||
|
||||
let mut u16_val: u16 = 65_535_u16;
|
||||
assert (u16::from_str(~"65535") == Some(u16_val));
|
||||
assert (u16::from_str(~"65536").is_none());
|
||||
fail_unless!((u16::from_str(~"65535") == Some(u16_val)));
|
||||
fail_unless!((u16::from_str(~"65536").is_none()));
|
||||
|
||||
u16_val += 1 as u16;
|
||||
assert (u16::from_str(~"0") == Some(u16_val));
|
||||
assert (u16::from_str(~"-1").is_none());
|
||||
fail_unless!((u16::from_str(~"0") == Some(u16_val)));
|
||||
fail_unless!((u16::from_str(~"-1").is_none()));
|
||||
|
||||
let mut u32_val: u32 = 4_294_967_295_u32;
|
||||
assert (u32::from_str(~"4294967295") == Some(u32_val));
|
||||
assert (u32::from_str(~"4294967296").is_none());
|
||||
fail_unless!((u32::from_str(~"4294967295") == Some(u32_val)));
|
||||
fail_unless!((u32::from_str(~"4294967296").is_none()));
|
||||
|
||||
u32_val += 1 as u32;
|
||||
assert (u32::from_str(~"0") == Some(u32_val));
|
||||
assert (u32::from_str(~"-1").is_none());
|
||||
fail_unless!((u32::from_str(~"0") == Some(u32_val)));
|
||||
fail_unless!((u32::from_str(~"-1").is_none()));
|
||||
|
||||
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
|
||||
assert (u64::from_str(~"18446744073709551615") == Some(u64_val));
|
||||
assert (u64::from_str(~"18446744073709551616").is_none());
|
||||
fail_unless!((u64::from_str(~"18446744073709551615") == Some(u64_val)));
|
||||
fail_unless!((u64::from_str(~"18446744073709551616").is_none()));
|
||||
|
||||
u64_val += 1 as u64;
|
||||
assert (u64::from_str(~"0") == Some(u64_val));
|
||||
assert (u64::from_str(~"-1").is_none());
|
||||
fail_unless!((u64::from_str(~"0") == Some(u64_val)));
|
||||
fail_unless!((u64::from_str(~"-1").is_none()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -367,10 +369,10 @@ pub fn test_ranges() {
|
||||
l.push(i);
|
||||
}
|
||||
|
||||
assert l == ~[0,1,2,
|
||||
fail_unless!(l == ~[0,1,2,
|
||||
13,12,11,
|
||||
20,22,24,
|
||||
36,34,32];
|
||||
36,34,32]);
|
||||
|
||||
// None of the `fail`s should execute.
|
||||
for range(0,0) |_i| {
|
||||
@ -392,11 +394,11 @@ pub fn test_num() {
|
||||
let ten: T = num::cast(10);
|
||||
let two: T = num::cast(2);
|
||||
|
||||
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));
|
||||
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)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -45,45 +45,45 @@ impl NumCast for u16 {
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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!((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 (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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
@ -45,45 +45,45 @@ impl NumCast for u32 {
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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!((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 (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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
@ -45,45 +45,45 @@ impl NumCast for u64 {
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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!((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 (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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
@ -52,45 +52,45 @@ impl NumCast for u8 {
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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!((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 (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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
@ -143,61 +143,61 @@ pub mod inst {
|
||||
|
||||
#[test]
|
||||
fn test_next_power_of_two() {
|
||||
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);
|
||||
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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_overflows() {
|
||||
use uint;
|
||||
assert (uint::max_value > 0u);
|
||||
assert (uint::min_value <= 0u);
|
||||
assert (uint::min_value + uint::max_value + 1u == 0u);
|
||||
fail_unless!((uint::max_value > 0u));
|
||||
fail_unless!((uint::min_value <= 0u));
|
||||
fail_unless!((uint::min_value + uint::max_value + 1u == 0u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_div() {
|
||||
assert(div_floor(3u, 4u) == 0u);
|
||||
assert(div_ceil(3u, 4u) == 1u);
|
||||
assert(div_round(3u, 4u) == 1u);
|
||||
fail_unless!((div_floor(3u, 4u) == 0u));
|
||||
fail_unless!((div_ceil(3u, 4u) == 1u));
|
||||
fail_unless!((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; }
|
||||
assert (accum == 10);
|
||||
fail_unless!((accum == 10));
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,45 +236,45 @@ impl NumCast for uint {
|
||||
|
||||
#[test]
|
||||
fn test_numcast() {
|
||||
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 == 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 == 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 == 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 == 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));
|
||||
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)));
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ fn test_unwrap_ptr() {
|
||||
let opt = Some(x);
|
||||
let y = unwrap(opt);
|
||||
let addr_y = ptr::addr_of(&(*y));
|
||||
assert addr_x == addr_y;
|
||||
fail_unless!(addr_x == addr_y);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -447,7 +447,7 @@ fn test_unwrap_str() {
|
||||
let opt = Some(x);
|
||||
let y = unwrap(opt);
|
||||
let addr_y = str::as_buf(y, |buf, _len| buf);
|
||||
assert addr_x == addr_y;
|
||||
fail_unless!(addr_x == addr_y);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -472,7 +472,7 @@ fn test_unwrap_resource() {
|
||||
let opt = Some(x);
|
||||
let _y = unwrap(opt);
|
||||
}
|
||||
assert *i == 1;
|
||||
fail_unless!(*i == 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -483,8 +483,8 @@ fn test_option_dance() {
|
||||
for x.each |_x| {
|
||||
y2 = swap_unwrap(&mut y);
|
||||
}
|
||||
assert y2 == 5;
|
||||
assert y.is_none();
|
||||
fail_unless!(y2 == 5);
|
||||
fail_unless!(y.is_none());
|
||||
}
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
fn test_option_too_much_dance() {
|
||||
@ -504,15 +504,15 @@ fn test_option_while_some() {
|
||||
None
|
||||
}
|
||||
}
|
||||
assert i == 11;
|
||||
fail_unless!(i == 11);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_or_zero() {
|
||||
let some_stuff = Some(42);
|
||||
assert some_stuff.get_or_zero() == 42;
|
||||
fail_unless!(some_stuff.get_or_zero() == 42);
|
||||
let no_stuff: Option<int> = None;
|
||||
assert no_stuff.get_or_zero() == 0;
|
||||
fail_unless!(no_stuff.get_or_zero() == 0);
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
@ -51,7 +51,11 @@ pub fn close(fd: c_int) -> c_int {
|
||||
}
|
||||
}
|
||||
|
||||
extern mod rustrt {
|
||||
pub mod rustrt {
|
||||
use libc::{c_char, c_int};
|
||||
use libc;
|
||||
|
||||
pub extern {
|
||||
unsafe fn rust_get_argc() -> c_int;
|
||||
unsafe fn rust_get_argv() -> **c_char;
|
||||
unsafe fn rust_getcwd() -> ~str;
|
||||
@ -60,6 +64,7 @@ extern mod rustrt {
|
||||
unsafe fn rust_list_files2(&&path: ~str) -> ~[~str];
|
||||
unsafe fn rust_process_wait(handle: c_int) -> c_int;
|
||||
unsafe fn rust_set_exit_status(code: libc::intptr_t);
|
||||
}
|
||||
}
|
||||
|
||||
pub const TMPBUF_SZ : uint = 1000u;
|
||||
@ -159,16 +164,16 @@ fn with_env_lock<T>(f: &fn() -> T) -> T {
|
||||
}
|
||||
|
||||
pub fn env() -> ~[(~str,~str)] {
|
||||
extern mod rustrt {
|
||||
extern {
|
||||
unsafe fn rust_env_pairs() -> ~[~str];
|
||||
}
|
||||
|
||||
unsafe {
|
||||
do with_env_lock {
|
||||
let mut pairs = ~[];
|
||||
for vec::each(rustrt::rust_env_pairs()) |p| {
|
||||
for vec::each(rust_env_pairs()) |p| {
|
||||
let vs = str::splitn_char(*p, '=', 1u);
|
||||
assert vec::len(vs) == 2u;
|
||||
fail_unless!(vec::len(vs) == 2u);
|
||||
pairs.push((copy vs[0], copy vs[1]));
|
||||
}
|
||||
pairs
|
||||
@ -308,7 +313,8 @@ pub fn waitpid(pid: pid_t) -> c_int {
|
||||
use libc::funcs::posix01::wait::*;
|
||||
let mut status = 0 as c_int;
|
||||
|
||||
assert (waitpid(pid, &mut status, 0 as c_int) != (-1 as c_int));
|
||||
fail_unless!((waitpid(pid, &mut status, 0 as c_int) !=
|
||||
(-1 as c_int)));
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@ -321,7 +327,7 @@ pub fn pipe() -> Pipe {
|
||||
unsafe {
|
||||
let mut fds = Pipe {in: 0 as c_int,
|
||||
out: 0 as c_int };
|
||||
assert (libc::pipe(&mut fds.in) == (0 as c_int));
|
||||
fail_unless!((libc::pipe(&mut fds.in) == (0 as c_int)));
|
||||
return Pipe {in: fds.in, out: fds.out};
|
||||
}
|
||||
}
|
||||
@ -340,9 +346,9 @@ pub fn pipe() -> Pipe {
|
||||
out: 0 as c_int };
|
||||
let res = libc::pipe(&mut fds.in, 1024 as c_uint,
|
||||
(libc::O_BINARY | libc::O_NOINHERIT) 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);
|
||||
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));
|
||||
return Pipe {in: fds.in, out: fds.out};
|
||||
}
|
||||
}
|
||||
@ -1137,13 +1143,13 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_args() {
|
||||
let a = real_args();
|
||||
assert a.len() >= 1;
|
||||
fail_unless!(a.len() >= 1);
|
||||
}
|
||||
|
||||
fn make_rand_name() -> ~str {
|
||||
let rng: rand::Rng = rand::Rng();
|
||||
let n = ~"TEST" + rng.gen_str(10u);
|
||||
assert getenv(n).is_none();
|
||||
fail_unless!(getenv(n).is_none());
|
||||
n
|
||||
}
|
||||
|
||||
@ -1151,7 +1157,7 @@ mod tests {
|
||||
fn test_setenv() {
|
||||
let n = make_rand_name();
|
||||
setenv(n, ~"VALUE");
|
||||
assert getenv(n) == option::Some(~"VALUE");
|
||||
fail_unless!(getenv(n) == option::Some(~"VALUE"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1161,9 +1167,9 @@ mod tests {
|
||||
let n = make_rand_name();
|
||||
setenv(n, ~"1");
|
||||
setenv(n, ~"2");
|
||||
assert getenv(n) == option::Some(~"2");
|
||||
fail_unless!(getenv(n) == option::Some(~"2"));
|
||||
setenv(n, ~"");
|
||||
assert getenv(n) == option::Some(~"");
|
||||
fail_unless!(getenv(n) == option::Some(~""));
|
||||
}
|
||||
|
||||
// Windows GetEnvironmentVariable requires some extra work to make sure
|
||||
@ -1178,25 +1184,25 @@ mod tests {
|
||||
let n = make_rand_name();
|
||||
setenv(n, s);
|
||||
log(debug, copy s);
|
||||
assert getenv(n) == option::Some(s);
|
||||
fail_unless!(getenv(n) == option::Some(s));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_self_exe_path() {
|
||||
let path = os::self_exe_path();
|
||||
assert path.is_some();
|
||||
fail_unless!(path.is_some());
|
||||
let path = path.get();
|
||||
log(debug, copy path);
|
||||
|
||||
// Hard to test this function
|
||||
assert path.is_absolute;
|
||||
fail_unless!(path.is_absolute);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_env_getenv() {
|
||||
let e = env();
|
||||
assert vec::len(e) > 0u;
|
||||
fail_unless!(vec::len(e) > 0u);
|
||||
for vec::each(e) |p| {
|
||||
let (n, v) = copy *p;
|
||||
log(debug, copy n);
|
||||
@ -1204,7 +1210,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().
|
||||
assert v2.is_none() || v2 == option::Some(v);
|
||||
fail_unless!(v2.is_none() || v2 == option::Some(v));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1214,15 +1220,15 @@ mod tests {
|
||||
|
||||
let mut e = env();
|
||||
setenv(n, ~"VALUE");
|
||||
assert !vec::contains(e, &(copy n, ~"VALUE"));
|
||||
fail_unless!(!vec::contains(e, &(copy n, ~"VALUE")));
|
||||
|
||||
e = env();
|
||||
assert vec::contains(e, &(n, ~"VALUE"));
|
||||
fail_unless!(vec::contains(e, &(n, ~"VALUE")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
assert (!Path("test-path").is_absolute);
|
||||
fail_unless!((!Path("test-path").is_absolute));
|
||||
|
||||
log(debug, ~"Current working directory: " + getcwd().to_str());
|
||||
|
||||
@ -1236,10 +1242,10 @@ mod tests {
|
||||
let oldhome = getenv(~"HOME");
|
||||
|
||||
setenv(~"HOME", ~"/home/MountainView");
|
||||
assert os::homedir() == Some(Path("/home/MountainView"));
|
||||
fail_unless!(os::homedir() == Some(Path("/home/MountainView")));
|
||||
|
||||
setenv(~"HOME", ~"");
|
||||
assert os::homedir().is_none();
|
||||
fail_unless!(os::homedir().is_none());
|
||||
|
||||
for oldhome.each |s| { setenv(~"HOME", *s) }
|
||||
}
|
||||
@ -1254,19 +1260,19 @@ mod tests {
|
||||
setenv(~"HOME", ~"");
|
||||
setenv(~"USERPROFILE", ~"");
|
||||
|
||||
assert os::homedir().is_none();
|
||||
fail_unless!(os::homedir().is_none());
|
||||
|
||||
setenv(~"HOME", ~"/home/MountainView");
|
||||
assert os::homedir() == Some(Path("/home/MountainView"));
|
||||
fail_unless!(os::homedir() == Some(Path("/home/MountainView")));
|
||||
|
||||
setenv(~"HOME", ~"");
|
||||
|
||||
setenv(~"USERPROFILE", ~"/home/MountainView");
|
||||
assert os::homedir() == Some(Path("/home/MountainView"));
|
||||
fail_unless!(os::homedir() == Some(Path("/home/MountainView")));
|
||||
|
||||
setenv(~"HOME", ~"/home/MountainView");
|
||||
setenv(~"USERPROFILE", ~"/home/PaloAlto");
|
||||
assert os::homedir() == Some(Path("/home/MountainView"));
|
||||
fail_unless!(os::homedir() == Some(Path("/home/MountainView")));
|
||||
|
||||
option::iter(&oldhome, |s| setenv(~"HOME", *s));
|
||||
option::iter(&olduserprofile,
|
||||
@ -1275,7 +1281,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn tmpdir() {
|
||||
assert !str::is_empty(os::tmpdir().to_str());
|
||||
fail_unless!(!str::is_empty(os::tmpdir().to_str()));
|
||||
}
|
||||
|
||||
// Issue #712
|
||||
@ -1288,7 +1294,7 @@ mod tests {
|
||||
fn list_dir() {
|
||||
let dirs = os::list_dir(&Path("."));
|
||||
// Just assuming that we've got some contents in the current directory
|
||||
assert (vec::len(dirs) > 0u);
|
||||
fail_unless!((vec::len(dirs) > 0u));
|
||||
|
||||
for vec::each(dirs) |dir| {
|
||||
log(debug, copy *dir);
|
||||
@ -1297,21 +1303,22 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn path_is_dir() {
|
||||
assert (os::path_is_dir(&Path(".")));
|
||||
assert (!os::path_is_dir(&Path("test/stdtest/fs.rs")));
|
||||
fail_unless!((os::path_is_dir(&Path("."))));
|
||||
fail_unless!((!os::path_is_dir(&Path("test/stdtest/fs.rs"))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn path_exists() {
|
||||
assert (os::path_exists(&Path(".")));
|
||||
assert (!os::path_exists(&Path("test/nonexistent-bogus-path")));
|
||||
fail_unless!((os::path_exists(&Path("."))));
|
||||
fail_unless!((!os::path_exists(&Path(
|
||||
"test/nonexistent-bogus-path"))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copy_file_does_not_exist() {
|
||||
assert !os::copy_file(&Path("test/nonexistent-bogus-path"),
|
||||
&Path("test/other-bogus-path"));
|
||||
assert !os::path_exists(&Path("test/other-bogus-path"));
|
||||
fail_unless!(!os::copy_file(&Path("test/nonexistent-bogus-path"),
|
||||
&Path("test/other-bogus-path")));
|
||||
fail_unless!(!os::path_exists(&Path("test/other-bogus-path")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1319,7 +1326,7 @@ mod tests {
|
||||
unsafe {
|
||||
let tempdir = getcwd(); // would like to use $TMPDIR,
|
||||
// doesn't seem to work on Linux
|
||||
assert (str::len(tempdir.to_str()) > 0u);
|
||||
fail_unless!((str::len(tempdir.to_str()) > 0u));
|
||||
let in = tempdir.push("in.txt");
|
||||
let out = tempdir.push("out.txt");
|
||||
|
||||
@ -1329,23 +1336,24 @@ mod tests {
|
||||
libc::fopen(fromp, modebuf)
|
||||
}
|
||||
};
|
||||
assert (ostream as uint != 0u);
|
||||
fail_unless!((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| {
|
||||
assert (libc::fwrite(b as *c_void, 1u as size_t,
|
||||
fail_unless!((libc::fwrite(b as *c_void, 1u as size_t,
|
||||
(str::len(s) + 1u) as size_t, ostream)
|
||||
== buf.len() as size_t)};
|
||||
assert (libc::fclose(ostream) == (0u as c_int));
|
||||
== buf.len() as size_t))
|
||||
}
|
||||
fail_unless!((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()));
|
||||
}
|
||||
assert(rs);
|
||||
fail_unless!((rs));
|
||||
let rslt = run::run_program(~"diff", ~[in.to_str(), out.to_str()]);
|
||||
assert (rslt == 0);
|
||||
assert (remove_file(&in));
|
||||
assert (remove_file(&out));
|
||||
fail_unless!((rslt == 0));
|
||||
fail_unless!((remove_file(&in)));
|
||||
fail_unless!((remove_file(&out)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -439,7 +439,7 @@ impl GenericPath for PosixPath {
|
||||
|
||||
pure fn with_filename(&self, f: &str) -> PosixPath {
|
||||
unsafe {
|
||||
assert ! str::any(f, |c| windows::is_sep(c as u8));
|
||||
fail_unless!(! str::any(f, |c| windows::is_sep(c as u8)));
|
||||
self.dir_path().push(f)
|
||||
}
|
||||
}
|
||||
@ -484,7 +484,7 @@ impl GenericPath for PosixPath {
|
||||
}
|
||||
|
||||
pure fn push_rel(&self, other: &PosixPath) -> PosixPath {
|
||||
assert !other.is_absolute;
|
||||
fail_unless!(!other.is_absolute);
|
||||
self.push_many(other.components)
|
||||
}
|
||||
|
||||
@ -650,7 +650,7 @@ impl GenericPath for WindowsPath {
|
||||
}
|
||||
|
||||
pure fn with_filename(&self, f: &str) -> WindowsPath {
|
||||
assert ! str::any(f, |c| windows::is_sep(c as u8));
|
||||
fail_unless!(! str::any(f, |c| windows::is_sep(c as u8)));
|
||||
self.dir_path().push(f)
|
||||
}
|
||||
|
||||
@ -697,7 +697,7 @@ impl GenericPath for WindowsPath {
|
||||
}
|
||||
|
||||
pure fn push_rel(&self, other: &WindowsPath) -> WindowsPath {
|
||||
assert !other.is_absolute;
|
||||
fail_unless!(!other.is_absolute);
|
||||
self.push_many(other.components)
|
||||
}
|
||||
|
||||
@ -880,30 +880,30 @@ mod tests {
|
||||
let path = PosixPath("tmp/");
|
||||
let path = path.push("/hmm");
|
||||
let path = path.normalize();
|
||||
assert ~"tmp/hmm" == path.to_str();
|
||||
fail_unless!(~"tmp/hmm" == path.to_str());
|
||||
|
||||
let path = WindowsPath("tmp/");
|
||||
let path = path.push("/hmm");
|
||||
let path = path.normalize();
|
||||
assert ~"tmp\\hmm" == path.to_str();
|
||||
fail_unless!(~"tmp\\hmm" == path.to_str());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filetype_foo_bar() {
|
||||
let wp = PosixPath("foo.bar");
|
||||
assert wp.filetype() == Some(~".bar");
|
||||
fail_unless!(wp.filetype() == Some(~".bar"));
|
||||
|
||||
let wp = WindowsPath("foo.bar");
|
||||
assert wp.filetype() == Some(~".bar");
|
||||
fail_unless!(wp.filetype() == Some(~".bar"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filetype_foo() {
|
||||
let wp = PosixPath("foo");
|
||||
assert wp.filetype() == None;
|
||||
fail_unless!(wp.filetype() == None);
|
||||
|
||||
let wp = WindowsPath("foo");
|
||||
assert wp.filetype() == None;
|
||||
fail_unless!(wp.filetype() == None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -914,7 +914,7 @@ mod tests {
|
||||
if (ss != sss) {
|
||||
debug!("got %s", ss);
|
||||
debug!("expected %s", sss);
|
||||
assert ss == sss;
|
||||
fail_unless!(ss == sss);
|
||||
}
|
||||
}
|
||||
|
||||
@ -972,7 +972,7 @@ mod tests {
|
||||
if (ss != sss) {
|
||||
debug!("got %s", ss);
|
||||
debug!("expected %s", sss);
|
||||
assert ss == sss;
|
||||
fail_unless!(ss == sss);
|
||||
}
|
||||
}
|
||||
|
||||
@ -988,37 +988,43 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_extract_unc_prefixes() {
|
||||
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", ~"\\"));
|
||||
assert windows::extract_unc_prefix("//hi\\") ==
|
||||
Some((~"hi", ~"\\"));
|
||||
assert windows::extract_unc_prefix("\\\\hi\\there") ==
|
||||
Some((~"hi", ~"\\there"));
|
||||
assert windows::extract_unc_prefix("//hi/there") ==
|
||||
Some((~"hi", ~"/there"));
|
||||
assert windows::extract_unc_prefix("\\\\hi\\there\\friends.txt") ==
|
||||
Some((~"hi", ~"\\there\\friends.txt"));
|
||||
assert windows::extract_unc_prefix("//hi\\there\\friends.txt") ==
|
||||
Some((~"hi", ~"\\there\\friends.txt"));
|
||||
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\\") ==
|
||||
Some((~"hi", ~"\\")));
|
||||
fail_unless!(windows::extract_unc_prefix("//hi\\") ==
|
||||
Some((~"hi", ~"\\")));
|
||||
fail_unless!(windows::extract_unc_prefix("\\\\hi\\there") ==
|
||||
Some((~"hi", ~"\\there")));
|
||||
fail_unless!(windows::extract_unc_prefix("//hi/there") ==
|
||||
Some((~"hi", ~"/there")));
|
||||
fail_unless!(windows::extract_unc_prefix(
|
||||
"\\\\hi\\there\\friends.txt") ==
|
||||
Some((~"hi", ~"\\there\\friends.txt")));
|
||||
fail_unless!(windows::extract_unc_prefix(
|
||||
"//hi\\there\\friends.txt") ==
|
||||
Some((~"hi", ~"\\there\\friends.txt")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_drive_prefixes() {
|
||||
assert windows::extract_drive_prefix("c").is_none();
|
||||
assert windows::extract_drive_prefix("c:") == Some((~"c", ~""));
|
||||
assert windows::extract_drive_prefix("d:") == Some((~"d", ~""));
|
||||
assert windows::extract_drive_prefix("z:") == Some((~"z", ~""));
|
||||
assert windows::extract_drive_prefix("c:\\hi") ==
|
||||
Some((~"c", ~"\\hi"));
|
||||
assert windows::extract_drive_prefix("d:hi") == Some((~"d", ~"hi"));
|
||||
assert windows::extract_drive_prefix("c:hi\\there.txt") ==
|
||||
Some((~"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").is_none());
|
||||
fail_unless!(windows::extract_drive_prefix("c:") ==
|
||||
Some((~"c", ~"")));
|
||||
fail_unless!(windows::extract_drive_prefix("d:") ==
|
||||
Some((~"d", ~"")));
|
||||
fail_unless!(windows::extract_drive_prefix("z:") ==
|
||||
Some((~"z", ~"")));
|
||||
fail_unless!(windows::extract_drive_prefix("c:\\hi") ==
|
||||
Some((~"c", ~"\\hi")));
|
||||
fail_unless!(windows::extract_drive_prefix("d:hi") ==
|
||||
Some((~"d", ~"hi")));
|
||||
fail_unless!(windows::extract_drive_prefix("c:hi\\there.txt") ==
|
||||
Some((~"c", ~"hi\\there.txt")));
|
||||
fail_unless!(windows::extract_drive_prefix("c:\\hi\\there.txt") ==
|
||||
Some((~"c", ~"\\hi\\there.txt")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1029,7 +1035,7 @@ mod tests {
|
||||
if (ss != sss) {
|
||||
debug!("got %s", ss);
|
||||
debug!("expected %s", sss);
|
||||
assert ss == sss;
|
||||
fail_unless!(ss == sss);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1114,9 +1120,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_windows_path_restrictions() {
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,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);
|
||||
assert old_task.is_null();
|
||||
fail_unless!(old_task.is_null());
|
||||
swap_state_acq(&mut self.state, Blocked)
|
||||
}
|
||||
|
||||
@ -183,7 +183,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 {
|
||||
assert self.buffer.is_not_null();
|
||||
fail_unless!(self.buffer.is_not_null());
|
||||
reinterpret_cast(&self.buffer)
|
||||
}
|
||||
|
||||
@ -288,10 +288,14 @@ pub fn swap_task(dst: &mut *rust_task, src: *rust_task) -> *rust_task {
|
||||
|
||||
#[doc(hidden)]
|
||||
#[allow(non_camel_case_types)]
|
||||
type rust_task = libc::c_void;
|
||||
pub type rust_task = libc::c_void;
|
||||
|
||||
#[doc(hidden)]
|
||||
extern mod rustrt {
|
||||
pub mod rustrt {
|
||||
use libc;
|
||||
use super::rust_task;
|
||||
|
||||
pub extern {
|
||||
#[rust_stack]
|
||||
unsafe fn rust_get_task() -> *rust_task;
|
||||
#[rust_stack]
|
||||
@ -301,9 +305,11 @@ extern mod rustrt {
|
||||
#[rust_stack]
|
||||
unsafe fn task_clear_event_reject(task: *rust_task);
|
||||
|
||||
unsafe fn task_wait_event(this: *rust_task, killed: &mut *libc::c_void)
|
||||
unsafe fn task_wait_event(this: *rust_task,
|
||||
killed: &mut *libc::c_void)
|
||||
-> bool;
|
||||
unsafe fn task_signal_event(target: *rust_task, event: *libc::c_void);
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
@ -380,8 +386,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_ };
|
||||
assert ptr::addr_of(&(p.header)) == header;
|
||||
assert p.payload.is_none();
|
||||
fail_unless!(ptr::addr_of(&(p.header)) == header);
|
||||
fail_unless!(p.payload.is_none());
|
||||
p.payload = Some(payload);
|
||||
let old_state = swap_state_rel(&mut p.header.state, Full);
|
||||
match old_state {
|
||||
@ -482,7 +488,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);
|
||||
assert old_task.is_null();
|
||||
fail_unless!(old_task.is_null());
|
||||
let mut first = true;
|
||||
let mut count = SPIN_COUNT;
|
||||
loop {
|
||||
@ -527,7 +533,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.
|
||||
assert old_state == Terminated;
|
||||
fail_unless!(old_state == Terminated);
|
||||
|
||||
let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
|
||||
if !old_task.is_null() {
|
||||
@ -576,7 +582,7 @@ fn sender_terminate<T:Owned>(p: *Packet<T>) {
|
||||
fail!(~"you dun goofed")
|
||||
}
|
||||
Terminated => {
|
||||
assert p.header.blocked_task.is_null();
|
||||
fail_unless!(p.header.blocked_task.is_null());
|
||||
// I have to clean up, use drop_glue
|
||||
}
|
||||
}
|
||||
@ -587,7 +593,7 @@ fn receiver_terminate<T:Owned>(p: *Packet<T>) {
|
||||
let p = unsafe { &*p };
|
||||
match swap_state_rel(&mut p.header.state, Terminated) {
|
||||
Empty => {
|
||||
assert p.header.blocked_task.is_null();
|
||||
fail_unless!(p.header.blocked_task.is_null());
|
||||
// the sender will clean up
|
||||
}
|
||||
Blocked => {
|
||||
@ -595,12 +601,12 @@ fn receiver_terminate<T:Owned>(p: *Packet<T>) {
|
||||
if !old_task.is_null() {
|
||||
unsafe {
|
||||
rustrt::rust_task_deref(old_task);
|
||||
assert old_task == rustrt::rust_get_task();
|
||||
fail_unless!(old_task == rustrt::rust_get_task());
|
||||
}
|
||||
}
|
||||
}
|
||||
Terminated | Full => {
|
||||
assert p.header.blocked_task.is_null();
|
||||
fail_unless!(p.header.blocked_task.is_null());
|
||||
// I have to clean up, use drop_glue
|
||||
}
|
||||
}
|
||||
@ -663,8 +669,8 @@ pub fn wait_many<T: Selectable>(pkts: &[T]) -> uint {
|
||||
debug!("%?, %?", ready_packet, pkts[ready_packet]);
|
||||
|
||||
unsafe {
|
||||
assert (*pkts[ready_packet].header()).state == Full
|
||||
|| (*pkts[ready_packet].header()).state == Terminated;
|
||||
fail_unless!((*pkts[ready_packet].header()).state == Full
|
||||
|| (*pkts[ready_packet].header()).state == Terminated);
|
||||
}
|
||||
|
||||
ready_packet
|
||||
@ -993,6 +999,6 @@ pub mod test {
|
||||
let _chan = chan;
|
||||
}
|
||||
|
||||
assert !port.peek();
|
||||
fail_unless!(!port.peek());
|
||||
}
|
||||
}
|
||||
|
@ -20,9 +20,13 @@ use sys;
|
||||
#[cfg(test)] use str;
|
||||
#[cfg(notest)] use cmp::{Eq, Ord};
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
extern mod libc_ {
|
||||
pub mod libc_ {
|
||||
use libc::c_void;
|
||||
use libc;
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
pub extern {
|
||||
#[rust_stack]
|
||||
unsafe fn memmove(dest: *mut c_void,
|
||||
src: *const c_void,
|
||||
@ -34,11 +38,14 @@ extern mod libc_ {
|
||||
c: libc::c_int,
|
||||
len: libc::size_t)
|
||||
-> *c_void;
|
||||
}
|
||||
}
|
||||
|
||||
#[abi = "rust-intrinsic"]
|
||||
extern mod rusti {
|
||||
pub mod rusti {
|
||||
#[abi = "rust-intrinsic"]
|
||||
pub extern {
|
||||
fn addr_of<T>(&&val: T) -> *T;
|
||||
}
|
||||
}
|
||||
|
||||
/// Get an unsafe pointer to a value
|
||||
@ -303,28 +310,30 @@ 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);
|
||||
assert (*iptr == 10);;
|
||||
fail_unless!((*iptr == 10));;
|
||||
*iptr = 30;
|
||||
assert (*iptr == 30);
|
||||
assert (p.fst == 30);;
|
||||
fail_unless!((*iptr == 30));
|
||||
fail_unless!((p.fst == 30));;
|
||||
|
||||
*pptr = Pair {fst: 50, snd: 60};
|
||||
assert (*iptr == 50);
|
||||
assert (p.fst == 50);
|
||||
assert (p.snd == 60);
|
||||
fail_unless!((*iptr == 50));
|
||||
fail_unless!((p.fst == 50));
|
||||
fail_unless!((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);
|
||||
assert (v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16);
|
||||
fail_unless!((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);
|
||||
assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16);
|
||||
fail_unless!((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);
|
||||
assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16);
|
||||
fail_unless!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
|
||||
v1[2] == 32000u16));
|
||||
}
|
||||
}
|
||||
|
||||
@ -335,9 +344,12 @@ pub fn test_position() {
|
||||
|
||||
let s = ~"hello";
|
||||
unsafe {
|
||||
assert 2u == as_c_str(s, |p| position(p, |c| *c == 'l' as c_char));
|
||||
assert 4u == as_c_str(s, |p| position(p, |c| *c == 'o' as c_char));
|
||||
assert 5u == as_c_str(s, |p| position(p, |c| *c == 0 as c_char));
|
||||
fail_unless!(2u == as_c_str(s, |p| position(p,
|
||||
|c| *c == 'l' as c_char)));
|
||||
fail_unless!(4u == as_c_str(s, |p| position(p,
|
||||
|c| *c == 'o' as c_char)));
|
||||
fail_unless!(5u == as_c_str(s, |p| position(p,
|
||||
|c| *c == 0 as c_char)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -351,8 +363,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| {
|
||||
assert unsafe { buf_len(vp) } == 3u;
|
||||
assert len == 4u;
|
||||
fail_unless!(unsafe { buf_len(vp) } == 3u);
|
||||
fail_unless!(len == 4u);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -362,18 +374,18 @@ pub fn test_buf_len() {
|
||||
#[test]
|
||||
pub fn test_is_null() {
|
||||
let p: *int = null();
|
||||
assert p.is_null();
|
||||
assert !p.is_not_null();
|
||||
fail_unless!(p.is_null());
|
||||
fail_unless!(!p.is_not_null());
|
||||
|
||||
let q = offset(p, 1u);
|
||||
assert !q.is_null();
|
||||
assert q.is_not_null();
|
||||
fail_unless!(!q.is_null());
|
||||
fail_unless!(q.is_not_null());
|
||||
|
||||
let mp: *mut int = mut_null();
|
||||
assert mp.is_null();
|
||||
assert !mp.is_not_null();
|
||||
fail_unless!(mp.is_null());
|
||||
fail_unless!(!mp.is_not_null());
|
||||
|
||||
let mq = mp.offset(1u);
|
||||
assert !mq.is_null();
|
||||
assert mq.is_not_null();
|
||||
fail_unless!(!mq.is_null());
|
||||
fail_unless!(mq.is_not_null());
|
||||
}
|
||||
|
@ -117,15 +117,20 @@ impl<T:Rand> Rand for Option<T> {
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)] // runtime type
|
||||
enum rust_rng {}
|
||||
pub enum rust_rng {}
|
||||
|
||||
#[abi = "cdecl"]
|
||||
extern mod rustrt {
|
||||
pub mod rustrt {
|
||||
use libc::size_t;
|
||||
use rand::rust_rng;
|
||||
|
||||
pub extern {
|
||||
unsafe fn rand_seed_size() -> size_t;
|
||||
unsafe fn rand_gen_seed(buf: *mut u8, sz: size_t);
|
||||
unsafe fn rand_new_seeded(buf: *u8, sz: size_t) -> *rust_rng;
|
||||
unsafe fn rand_next(rng: *rust_rng) -> u32;
|
||||
unsafe fn rand_free(rng: *rust_rng);
|
||||
}
|
||||
}
|
||||
|
||||
/// A random number generator
|
||||
@ -157,7 +162,7 @@ pub impl Rng {
|
||||
* failing if start >= end
|
||||
*/
|
||||
fn gen_int_range(&self, start: int, end: int) -> int {
|
||||
assert start < end;
|
||||
fail_unless!(start < end);
|
||||
start + int::abs(self.gen_int() % (end - start))
|
||||
}
|
||||
|
||||
@ -191,7 +196,7 @@ pub impl Rng {
|
||||
* failing if start >= end
|
||||
*/
|
||||
fn gen_uint_range(&self, start: uint, end: uint) -> uint {
|
||||
assert start < end;
|
||||
fail_unless!(start < end);
|
||||
start + (self.gen_uint() % (end - start))
|
||||
}
|
||||
|
||||
@ -243,7 +248,7 @@ pub impl Rng {
|
||||
* Return a char randomly chosen from chars, failing if chars is empty
|
||||
*/
|
||||
fn gen_char_from(&self, chars: &str) -> char {
|
||||
assert !chars.is_empty();
|
||||
fail_unless!(!chars.is_empty());
|
||||
self.choose(str::chars(chars))
|
||||
}
|
||||
|
||||
@ -498,7 +503,7 @@ pub mod tests {
|
||||
let seed = rand::seed();
|
||||
let ra = rand::seeded_rng(seed);
|
||||
let rb = rand::seeded_rng(seed);
|
||||
assert ra.gen_str(100u) == rb.gen_str(100u);
|
||||
fail_unless!(ra.gen_str(100u) == rb.gen_str(100u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -507,7 +512,7 @@ pub mod tests {
|
||||
let seed = [2u8, 32u8, 4u8, 32u8, 51u8];
|
||||
let ra = rand::seeded_rng(seed);
|
||||
let rb = rand::seeded_rng(seed);
|
||||
assert ra.gen_str(100u) == rb.gen_str(100u);
|
||||
fail_unless!(ra.gen_str(100u) == rb.gen_str(100u));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -517,17 +522,17 @@ pub mod tests {
|
||||
// Regression test that isaac is actually using the above vector
|
||||
let r = ra.next();
|
||||
error!("%?", r);
|
||||
assert r == 890007737u32 // on x86_64
|
||||
|| r == 2935188040u32; // on x86
|
||||
fail_unless!(r == 890007737u32 // on x86_64
|
||||
|| r == 2935188040u32); // on x86
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn gen_int_range() {
|
||||
let r = rand::Rng();
|
||||
let a = r.gen_int_range(-3, 42);
|
||||
assert a >= -3 && a < 42;
|
||||
assert r.gen_int_range(0, 1) == 0;
|
||||
assert r.gen_int_range(-12, -11) == -12;
|
||||
fail_unless!(a >= -3 && a < 42);
|
||||
fail_unless!(r.gen_int_range(0, 1) == 0);
|
||||
fail_unless!(r.gen_int_range(-12, -11) == -12);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -541,9 +546,9 @@ pub mod tests {
|
||||
pub fn gen_uint_range() {
|
||||
let r = rand::Rng();
|
||||
let a = r.gen_uint_range(3u, 42u);
|
||||
assert a >= 3u && a < 42u;
|
||||
assert r.gen_uint_range(0u, 1u) == 0u;
|
||||
assert r.gen_uint_range(12u, 13u) == 12u;
|
||||
fail_unless!(a >= 3u && a < 42u);
|
||||
fail_unless!(r.gen_uint_range(0u, 1u) == 0u);
|
||||
fail_unless!(r.gen_uint_range(12u, 13u) == 12u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -564,8 +569,8 @@ pub mod tests {
|
||||
#[test]
|
||||
pub fn gen_weighted_bool() {
|
||||
let r = rand::Rng();
|
||||
assert r.gen_weighted_bool(0u) == true;
|
||||
assert r.gen_weighted_bool(1u) == true;
|
||||
fail_unless!(r.gen_weighted_bool(0u) == true);
|
||||
fail_unless!(r.gen_weighted_bool(1u) == true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -574,85 +579,85 @@ pub mod tests {
|
||||
log(debug, r.gen_str(10u));
|
||||
log(debug, r.gen_str(10u));
|
||||
log(debug, r.gen_str(10u));
|
||||
assert r.gen_str(0u).len() == 0u;
|
||||
assert r.gen_str(10u).len() == 10u;
|
||||
assert r.gen_str(16u).len() == 16u;
|
||||
fail_unless!(r.gen_str(0u).len() == 0u);
|
||||
fail_unless!(r.gen_str(10u).len() == 10u);
|
||||
fail_unless!(r.gen_str(16u).len() == 16u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn gen_bytes() {
|
||||
let r = rand::Rng();
|
||||
assert r.gen_bytes(0u).len() == 0u;
|
||||
assert r.gen_bytes(10u).len() == 10u;
|
||||
assert r.gen_bytes(16u).len() == 16u;
|
||||
fail_unless!(r.gen_bytes(0u).len() == 0u);
|
||||
fail_unless!(r.gen_bytes(10u).len() == 10u);
|
||||
fail_unless!(r.gen_bytes(16u).len() == 16u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn choose() {
|
||||
let r = rand::Rng();
|
||||
assert r.choose([1, 1, 1]) == 1;
|
||||
fail_unless!(r.choose([1, 1, 1]) == 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn choose_option() {
|
||||
let r = rand::Rng();
|
||||
let x: Option<int> = r.choose_option([]);
|
||||
assert x.is_none();
|
||||
assert r.choose_option([1, 1, 1]) == Some(1);
|
||||
fail_unless!(x.is_none());
|
||||
fail_unless!(r.choose_option([1, 1, 1]) == Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn choose_weighted() {
|
||||
let r = rand::Rng();
|
||||
assert r.choose_weighted(~[
|
||||
fail_unless!(r.choose_weighted(~[
|
||||
rand::Weighted { weight: 1u, item: 42 },
|
||||
]) == 42;
|
||||
assert r.choose_weighted(~[
|
||||
]) == 42);
|
||||
fail_unless!(r.choose_weighted(~[
|
||||
rand::Weighted { weight: 0u, item: 42 },
|
||||
rand::Weighted { weight: 1u, item: 43 },
|
||||
]) == 43;
|
||||
]) == 43);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn choose_weighted_option() {
|
||||
let r = rand::Rng();
|
||||
assert r.choose_weighted_option(~[
|
||||
fail_unless!(r.choose_weighted_option(~[
|
||||
rand::Weighted { weight: 1u, item: 42 },
|
||||
]) == Some(42);
|
||||
assert r.choose_weighted_option(~[
|
||||
]) == Some(42));
|
||||
fail_unless!(r.choose_weighted_option(~[
|
||||
rand::Weighted { weight: 0u, item: 42 },
|
||||
rand::Weighted { weight: 1u, item: 43 },
|
||||
]) == Some(43);
|
||||
]) == Some(43));
|
||||
let v: Option<int> = r.choose_weighted_option([]);
|
||||
assert v.is_none();
|
||||
fail_unless!(v.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn weighted_vec() {
|
||||
let r = rand::Rng();
|
||||
let empty: ~[int] = ~[];
|
||||
assert r.weighted_vec(~[]) == empty;
|
||||
assert r.weighted_vec(~[
|
||||
fail_unless!(r.weighted_vec(~[]) == empty);
|
||||
fail_unless!(r.weighted_vec(~[
|
||||
rand::Weighted { weight: 0u, item: 3u },
|
||||
rand::Weighted { weight: 1u, item: 2u },
|
||||
rand::Weighted { weight: 2u, item: 1u },
|
||||
]) == ~[2u, 1u, 1u];
|
||||
]) == ~[2u, 1u, 1u]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn shuffle() {
|
||||
let r = rand::Rng();
|
||||
let empty: ~[int] = ~[];
|
||||
assert r.shuffle(~[]) == empty;
|
||||
assert r.shuffle(~[1, 1, 1]) == ~[1, 1, 1];
|
||||
fail_unless!(r.shuffle(~[]) == empty);
|
||||
fail_unless!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn task_rng() {
|
||||
let r = rand::task_rng();
|
||||
r.gen_int();
|
||||
assert r.shuffle(~[1, 1, 1]) == ~[1, 1, 1];
|
||||
assert r.gen_uint_range(0u, 1u) == 0u;
|
||||
fail_unless!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]);
|
||||
fail_unless!(r.gen_uint_range(0u, 1u) == 0u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -231,7 +231,7 @@ pub impl ReprVisitor {
|
||||
} else if mtbl == 1 {
|
||||
// skip, this is ast::m_imm
|
||||
} else {
|
||||
assert mtbl == 2;
|
||||
fail_unless!(mtbl == 2);
|
||||
self.writer.write_str("const ");
|
||||
}
|
||||
}
|
||||
@ -590,7 +590,7 @@ fn test_repr() {
|
||||
error!("expected '%s', got '%s'",
|
||||
e, s);
|
||||
}
|
||||
assert s == e;
|
||||
fail_unless!(s == e);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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|
|
||||
* assert incd == ~[2u, 3u, 4u];
|
||||
* fail_unless!(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> {
|
||||
|
||||
assert vec::same_length(ss, ts);
|
||||
fail_unless!(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> {
|
||||
|
||||
assert vec::same_length(ss, ts);
|
||||
fail_unless!(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() {
|
||||
assert get(&chain(op1(), op2)) == 667u;
|
||||
fail_unless!(get(&chain(op1(), op2)) == 667u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn chain_failure() {
|
||||
assert get_err(&chain(op3(), op2)) == ~"sadface";
|
||||
fail_unless!(get_err(&chain(op3(), op2)) == ~"sadface");
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_impl_iter() {
|
||||
let mut valid = false;
|
||||
Ok::<~str, ~str>(~"a").iter(|_x| valid = true);
|
||||
assert valid;
|
||||
fail_unless!(valid);
|
||||
|
||||
Err::<~str, ~str>(~"b").iter(|_x| valid = false);
|
||||
assert valid;
|
||||
fail_unless!(valid);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_impl_iter_err() {
|
||||
let mut valid = true;
|
||||
Ok::<~str, ~str>(~"a").iter_err(|_x| valid = false);
|
||||
assert valid;
|
||||
fail_unless!(valid);
|
||||
|
||||
valid = false;
|
||||
Err::<~str, ~str>(~"b").iter_err(|_x| valid = true);
|
||||
assert valid;
|
||||
fail_unless!(valid);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_impl_map() {
|
||||
assert Ok::<~str, ~str>(~"a").map(|_x| ~"b") == Ok(~"b");
|
||||
assert Err::<~str, ~str>(~"a").map(|_x| ~"b") == Err(~"a");
|
||||
fail_unless!(Ok::<~str, ~str>(~"a").map(|_x| ~"b") == Ok(~"b"));
|
||||
fail_unless!(Err::<~str, ~str>(~"a").map(|_x| ~"b") == Err(~"a"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_impl_map_err() {
|
||||
assert Ok::<~str, ~str>(~"a").map_err(|_x| ~"b") == Ok(~"a");
|
||||
assert Err::<~str, ~str>(~"a").map_err(|_x| ~"b") == Err(~"b");
|
||||
fail_unless!(Ok::<~str, ~str>(~"a").map_err(|_x| ~"b") == Ok(~"a"));
|
||||
fail_unless!(Err::<~str, ~str>(~"a").map_err(|_x| ~"b") == Err(~"b"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_get_ref_method() {
|
||||
let foo: Result<int, ()> = Ok(100);
|
||||
assert *foo.get_ref() == 100;
|
||||
fail_unless!(*foo.get_ref() == 100);
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +23,20 @@ use str;
|
||||
use task;
|
||||
use vec;
|
||||
|
||||
#[abi = "cdecl"]
|
||||
extern mod rustrt {
|
||||
unsafe fn rust_run_program(argv: **libc::c_char, envp: *c_void,
|
||||
pub mod rustrt {
|
||||
use libc::{c_int, c_void, pid_t};
|
||||
use libc;
|
||||
|
||||
#[abi = "cdecl"]
|
||||
pub extern {
|
||||
unsafe fn rust_run_program(argv: **libc::c_char,
|
||||
envp: *c_void,
|
||||
dir: *libc::c_char,
|
||||
in_fd: c_int, out_fd: c_int, err_fd: c_int)
|
||||
in_fd: c_int,
|
||||
out_fd: c_int,
|
||||
err_fd: c_int)
|
||||
-> pid_t;
|
||||
}
|
||||
}
|
||||
|
||||
/// A value representing a child process
|
||||
@ -488,7 +496,7 @@ mod tests {
|
||||
|
||||
log(debug, copy expected);
|
||||
log(debug, copy actual);
|
||||
assert (expected == actual);
|
||||
fail_unless!((expected == actual));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -497,7 +505,7 @@ mod tests {
|
||||
&None, &None,
|
||||
0i32, 0i32, 0i32);
|
||||
let status = run::waitpid(pid);
|
||||
assert status == 1;
|
||||
fail_unless!(status == 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -86,11 +86,16 @@ fn frame_address(f: fn(++x: *u8)) {
|
||||
}
|
||||
}
|
||||
|
||||
extern mod rustrt {
|
||||
pub mod rustrt {
|
||||
pub extern {
|
||||
pub unsafe fn rust_dbg_breakpoint();
|
||||
}
|
||||
}
|
||||
|
||||
#[abi = "rust-intrinsic"]
|
||||
extern mod rusti {
|
||||
pub mod rusti {
|
||||
#[abi = "rust-intrinsic"]
|
||||
pub extern {
|
||||
pub fn frame_address(f: &once fn(++x: *u8));
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -22,14 +22,14 @@ use str;
|
||||
pub type FreeGlue = &self/fn(*TypeDesc, *c_void);
|
||||
|
||||
// Corresponds to runtime type_desc type
|
||||
pub enum TypeDesc = {
|
||||
pub struct TypeDesc {
|
||||
size: uint,
|
||||
align: uint,
|
||||
take_glue: uint,
|
||||
drop_glue: uint,
|
||||
free_glue: uint
|
||||
// Remaining fields not listed
|
||||
};
|
||||
}
|
||||
|
||||
/// The representation of a Rust closure
|
||||
pub struct Closure {
|
||||
@ -37,17 +37,25 @@ pub struct Closure {
|
||||
env: *(),
|
||||
}
|
||||
|
||||
#[abi = "rust-intrinsic"]
|
||||
extern mod rusti {
|
||||
pub mod rusti {
|
||||
#[abi = "rust-intrinsic"]
|
||||
pub extern {
|
||||
fn get_tydesc<T>() -> *();
|
||||
fn size_of<T>() -> uint;
|
||||
fn pref_align_of<T>() -> uint;
|
||||
fn min_align_of<T>() -> uint;
|
||||
}
|
||||
}
|
||||
|
||||
extern mod rustrt {
|
||||
pub mod rustrt {
|
||||
use libc::{c_char, size_t};
|
||||
|
||||
pub extern {
|
||||
#[rust_stack]
|
||||
unsafe fn rust_upcall_fail(expr: *c_char, file: *c_char, line: size_t);
|
||||
unsafe fn rust_upcall_fail(expr: *c_char,
|
||||
file: *c_char,
|
||||
line: size_t);
|
||||
}
|
||||
}
|
||||
|
||||
/// Compares contents of two pointers using the default method.
|
||||
@ -148,6 +156,13 @@ pub pure fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
pub pure fn fail_assert(msg: &str, file: &str, line: uint) -> ! {
|
||||
unsafe {
|
||||
let (msg, file) = (msg.to_owned(), file.to_owned());
|
||||
begin_unwind(~"assertion failed: " + msg, file, line)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use cast;
|
||||
@ -155,10 +170,10 @@ pub mod tests {
|
||||
|
||||
#[test]
|
||||
pub fn size_of_basic() {
|
||||
assert size_of::<u8>() == 1u;
|
||||
assert size_of::<u16>() == 2u;
|
||||
assert size_of::<u32>() == 4u;
|
||||
assert size_of::<u64>() == 8u;
|
||||
fail_unless!(size_of::<u8>() == 1u);
|
||||
fail_unless!(size_of::<u16>() == 2u);
|
||||
fail_unless!(size_of::<u32>() == 4u);
|
||||
fail_unless!(size_of::<u64>() == 8u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -166,30 +181,30 @@ pub mod tests {
|
||||
#[cfg(target_arch = "arm")]
|
||||
#[cfg(target_arch = "mips")]
|
||||
pub fn size_of_32() {
|
||||
assert size_of::<uint>() == 4u;
|
||||
assert size_of::<*uint>() == 4u;
|
||||
fail_unless!(size_of::<uint>() == 4u);
|
||||
fail_unless!(size_of::<*uint>() == 4u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub fn size_of_64() {
|
||||
assert size_of::<uint>() == 8u;
|
||||
assert size_of::<*uint>() == 8u;
|
||||
fail_unless!(size_of::<uint>() == 8u);
|
||||
fail_unless!(size_of::<*uint>() == 8u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn nonzero_size_of_basic() {
|
||||
type Z = [i8 * 0];
|
||||
assert size_of::<Z>() == 0u;
|
||||
assert nonzero_size_of::<Z>() == 1u;
|
||||
assert nonzero_size_of::<uint>() == size_of::<uint>();
|
||||
fail_unless!(size_of::<Z>() == 0u);
|
||||
fail_unless!(nonzero_size_of::<Z>() == 1u);
|
||||
fail_unless!(nonzero_size_of::<uint>() == size_of::<uint>());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn align_of_basic() {
|
||||
assert pref_align_of::<u8>() == 1u;
|
||||
assert pref_align_of::<u16>() == 2u;
|
||||
assert pref_align_of::<u32>() == 4u;
|
||||
fail_unless!(pref_align_of::<u8>() == 1u);
|
||||
fail_unless!(pref_align_of::<u16>() == 2u);
|
||||
fail_unless!(pref_align_of::<u32>() == 4u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -197,15 +212,15 @@ pub mod tests {
|
||||
#[cfg(target_arch = "arm")]
|
||||
#[cfg(target_arch = "mips")]
|
||||
pub fn align_of_32() {
|
||||
assert pref_align_of::<uint>() == 4u;
|
||||
assert pref_align_of::<*uint>() == 4u;
|
||||
fail_unless!(pref_align_of::<uint>() == 4u);
|
||||
fail_unless!(pref_align_of::<*uint>() == 4u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub fn align_of_64() {
|
||||
assert pref_align_of::<uint>() == 8u;
|
||||
assert pref_align_of::<*uint>() == 8u;
|
||||
fail_unless!(pref_align_of::<uint>() == 8u);
|
||||
fail_unless!(pref_align_of::<*uint>() == 8u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -214,7 +229,7 @@ pub mod tests {
|
||||
let x = 10;
|
||||
let f: fn(int) -> int = |y| x + y;
|
||||
|
||||
assert f(20) == 30;
|
||||
fail_unless!(f(20) == 30);
|
||||
|
||||
let original_closure: Closure = cast::transmute(f);
|
||||
|
||||
@ -227,7 +242,7 @@ pub mod tests {
|
||||
};
|
||||
|
||||
let new_f: fn(int) -> int = cast::transmute(new_closure);
|
||||
assert new_f(20) == 30;
|
||||
fail_unless!(new_f(20) == 30);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,16 +92,17 @@ fn test_tls_multitask() {
|
||||
do task::spawn {
|
||||
unsafe {
|
||||
// TLS shouldn't carry over.
|
||||
assert local_data_get(my_key).is_none();
|
||||
fail_unless!(local_data_get(my_key).is_none());
|
||||
local_data_set(my_key, @~"child data");
|
||||
assert *(local_data_get(my_key).get()) == ~"child data";
|
||||
fail_unless!(*(local_data_get(my_key).get()) ==
|
||||
~"child data");
|
||||
// should be cleaned up for us
|
||||
}
|
||||
}
|
||||
// Must work multiple times
|
||||
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";
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,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.
|
||||
assert *(local_data_get(my_key).get()) == ~"next data";
|
||||
fail_unless!(*(local_data_get(my_key).get()) == ~"next data");
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,9 +121,9 @@ fn test_tls_pop() {
|
||||
unsafe {
|
||||
fn my_key(_x: @~str) { }
|
||||
local_data_set(my_key, @~"weasel");
|
||||
assert *(local_data_pop(my_key).get()) == ~"weasel";
|
||||
fail_unless!(*(local_data_pop(my_key).get()) == ~"weasel");
|
||||
// Pop must remove the data from the map.
|
||||
assert local_data_pop(my_key).is_none();
|
||||
fail_unless!(local_data_pop(my_key).is_none());
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +144,7 @@ fn test_tls_modify() {
|
||||
None => fail!(~"missing value")
|
||||
}
|
||||
});
|
||||
assert *(local_data_pop(my_key).get()) == ~"next data";
|
||||
fail_unless!(*(local_data_pop(my_key).get()) == ~"next data");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ type TaskLocalMap = @dvec::DVec<Option<TaskLocalElement>>;
|
||||
|
||||
extern fn cleanup_task_local_map(map_ptr: *libc::c_void) {
|
||||
unsafe {
|
||||
assert !map_ptr.is_null();
|
||||
fail_unless!(!map_ptr.is_null());
|
||||
// Get and keep the single reference that was created at the
|
||||
// beginning.
|
||||
let _map: TaskLocalMap = cast::reinterpret_cast(&map_ptr);
|
||||
|
@ -848,14 +848,14 @@ fn test_add_wrapper() {
|
||||
fn test_future_result() {
|
||||
let mut result = None;
|
||||
do task().future_result(|+r| { result = Some(r); }).spawn { }
|
||||
assert option::unwrap(result).recv() == Success;
|
||||
fail_unless!(option::unwrap(result).recv() == Success);
|
||||
|
||||
result = None;
|
||||
do task().future_result(|+r|
|
||||
{ result = Some(r); }).unlinked().spawn {
|
||||
fail!();
|
||||
}
|
||||
assert option::unwrap(result).recv() == Failure;
|
||||
fail_unless!(option::unwrap(result).recv() == Failure);
|
||||
}
|
||||
|
||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||
@ -901,7 +901,7 @@ fn test_spawn_sched() {
|
||||
|
||||
do spawn_sched(SingleThreaded) {
|
||||
let child_sched_id = unsafe { rt::rust_get_sched_id() };
|
||||
assert parent_sched_id != child_sched_id;
|
||||
fail_unless!(parent_sched_id != child_sched_id);
|
||||
|
||||
if (i == 0) {
|
||||
ch.send(());
|
||||
@ -929,8 +929,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() };
|
||||
assert parent_sched_id != child_sched_id;
|
||||
assert child_sched_id == default_id;
|
||||
fail_unless!(parent_sched_id != child_sched_id);
|
||||
fail_unless!(child_sched_id == default_id);
|
||||
ch.send(());
|
||||
};
|
||||
};
|
||||
@ -938,15 +938,19 @@ fn test_spawn_sched_childs_on_default_sched() {
|
||||
po.recv();
|
||||
}
|
||||
|
||||
#[nolink]
|
||||
#[cfg(test)]
|
||||
extern mod testrt {
|
||||
pub mod testrt {
|
||||
use libc;
|
||||
|
||||
#[nolink]
|
||||
pub extern {
|
||||
unsafe fn rust_dbg_lock_create() -> *libc::c_void;
|
||||
unsafe fn rust_dbg_lock_destroy(lock: *libc::c_void);
|
||||
unsafe fn rust_dbg_lock_lock(lock: *libc::c_void);
|
||||
unsafe fn rust_dbg_lock_unlock(lock: *libc::c_void);
|
||||
unsafe fn rust_dbg_lock_wait(lock: *libc::c_void);
|
||||
unsafe fn rust_dbg_lock_signal(lock: *libc::c_void);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1020,7 +1024,7 @@ fn avoid_copying_the_body(spawnfn: &fn(v: ~fn())) {
|
||||
}
|
||||
|
||||
let x_in_child = p.recv();
|
||||
assert x_in_parent == x_in_child;
|
||||
fail_unless!(x_in_parent == x_in_child);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1175,7 +1179,7 @@ fn test_sched_thread_per_core() {
|
||||
unsafe {
|
||||
let cores = rt::rust_num_threads();
|
||||
let reported_threads = rt::rust_sched_threads();
|
||||
assert(cores as uint == reported_threads as uint);
|
||||
fail_unless!((cores as uint == reported_threads as uint));
|
||||
chan.send(());
|
||||
}
|
||||
}
|
||||
@ -1190,9 +1194,9 @@ fn test_spawn_thread_on_demand() {
|
||||
do spawn_sched(ManualThreads(2)) || {
|
||||
unsafe {
|
||||
let max_threads = rt::rust_sched_threads();
|
||||
assert(max_threads as int == 2);
|
||||
fail_unless!((max_threads as int == 2));
|
||||
let running_threads = rt::rust_sched_current_nonlazy_threads();
|
||||
assert(running_threads as int == 1);
|
||||
fail_unless!((running_threads as int == 1));
|
||||
|
||||
let (port2, chan2) = comm::stream();
|
||||
|
||||
@ -1201,7 +1205,7 @@ fn test_spawn_thread_on_demand() {
|
||||
}
|
||||
|
||||
let running_threads2 = rt::rust_sched_current_nonlazy_threads();
|
||||
assert(running_threads2 as int == 2);
|
||||
fail_unless!((running_threads2 as int == 2));
|
||||
|
||||
port2.recv();
|
||||
chan.send(());
|
||||
|
@ -102,11 +102,11 @@ fn new_taskset() -> TaskSet {
|
||||
}
|
||||
fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) {
|
||||
let didnt_overwrite = tasks.insert(task);
|
||||
assert didnt_overwrite;
|
||||
fail_unless!(didnt_overwrite);
|
||||
}
|
||||
fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) {
|
||||
let was_present = tasks.remove(&task);
|
||||
assert was_present;
|
||||
fail_unless!(was_present);
|
||||
}
|
||||
pub fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) {
|
||||
tasks.each(|k| blk(*k))
|
||||
@ -230,7 +230,7 @@ fn each_ancestor(list: &mut AncestorList,
|
||||
// NB: Takes a lock! (this ancestor node)
|
||||
do access_ancestors(ancestor_arc) |nobe| {
|
||||
// Check monotonicity
|
||||
assert last_generation > nobe.generation;
|
||||
fail_unless!(last_generation > nobe.generation);
|
||||
/*##########################################################*
|
||||
* Step 1: Look at this ancestor group (call iterator block).
|
||||
*##########################################################*/
|
||||
@ -422,7 +422,7 @@ fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) {
|
||||
}
|
||||
}
|
||||
for taskset_each(&group.descendants) |child| {
|
||||
assert child != me;
|
||||
fail_unless!(child != me);
|
||||
rt::rust_task_kill_other(child);
|
||||
}
|
||||
// Only one task should ever do this.
|
||||
@ -497,7 +497,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
||||
}
|
||||
None => 0 // the actual value doesn't really matter.
|
||||
};
|
||||
assert new_generation < uint::max_value;
|
||||
fail_unless!(new_generation < uint::max_value);
|
||||
// Build a new node in the ancestor list.
|
||||
AncestorList(Some(unstable::exclusive(AncestorNode {
|
||||
generation: new_generation,
|
||||
@ -544,7 +544,7 @@ pub fn spawn_raw(opts: TaskOpts, f: ~fn()) {
|
||||
DefaultScheduler => rt::new_task(),
|
||||
_ => new_task_in_sched(opts.sched)
|
||||
};
|
||||
assert !new_task.is_null();
|
||||
fail_unless!(!new_task.is_null());
|
||||
// Getting killed after here would leak the task.
|
||||
let mut notify_chan = if opts.notify_chan.is_none() {
|
||||
None
|
||||
@ -716,7 +716,7 @@ fn test_spawn_raw_notify_success() {
|
||||
};
|
||||
do spawn_raw(opts) {
|
||||
}
|
||||
assert notify_po.recv() == Success;
|
||||
fail_unless!(notify_po.recv() == Success);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -733,5 +733,5 @@ fn test_spawn_raw_notify_failure() {
|
||||
do spawn_raw(opts) {
|
||||
fail!();
|
||||
}
|
||||
assert notify_po.recv() == Failure;
|
||||
fail_unless!(notify_po.recv() == Failure);
|
||||
}
|
||||
|
@ -140,31 +140,31 @@ impl<A:ToStr> ToStr for @[A] {
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_simple_types() {
|
||||
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";
|
||||
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");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tuple_types() {
|
||||
assert (1, 2).to_str() == ~"(1, 2)";
|
||||
assert (~"a", ~"b", false).to_str() == ~"(a, b, false)";
|
||||
assert ((), ((), 100)).to_str() == ~"((), ((), 100))";
|
||||
fail_unless!((1, 2).to_str() == ~"(1, 2)");
|
||||
fail_unless!((~"a", ~"b", false).to_str() == ~"(a, b, false)");
|
||||
fail_unless!(((), ((), 100)).to_str() == ~"((), ((), 100))");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vectors() {
|
||||
let x: ~[int] = ~[];
|
||||
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]]";
|
||||
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() ==
|
||||
~"[[], [1], [1, 1]]");
|
||||
}
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ fn remove<T>(count: &mut uint, child: &mut Child<T>, key: uint,
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn check_integrity<T>(trie: &TrieNode<T>) {
|
||||
assert trie.count != 0;
|
||||
fail_unless!(trie.count != 0);
|
||||
|
||||
let mut sum = 0;
|
||||
|
||||
@ -342,7 +342,7 @@ pub fn check_integrity<T>(trie: &TrieNode<T>) {
|
||||
}
|
||||
}
|
||||
|
||||
assert sum == trie.count;
|
||||
fail_unless!(sum == trie.count);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -356,32 +356,32 @@ mod tests {
|
||||
let n = 300;
|
||||
|
||||
for uint::range_step(1, n, 2) |x| {
|
||||
assert trie.insert(x, x + 1);
|
||||
assert trie.contains_key(&x);
|
||||
fail_unless!(trie.insert(x, x + 1));
|
||||
fail_unless!(trie.contains_key(&x));
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
|
||||
for uint::range_step(0, n, 2) |x| {
|
||||
assert !trie.contains_key(&x);
|
||||
assert trie.insert(x, x + 1);
|
||||
fail_unless!(!trie.contains_key(&x));
|
||||
fail_unless!(trie.insert(x, x + 1));
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
|
||||
for uint::range(0, n) |x| {
|
||||
assert trie.contains_key(&x);
|
||||
assert !trie.insert(x, x + 1);
|
||||
fail_unless!(trie.contains_key(&x));
|
||||
fail_unless!(!trie.insert(x, x + 1));
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
|
||||
for uint::range_step(1, n, 2) |x| {
|
||||
assert trie.remove(&x);
|
||||
assert !trie.contains_key(&x);
|
||||
fail_unless!(trie.remove(&x));
|
||||
fail_unless!(!trie.contains_key(&x));
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
|
||||
for uint::range_step(0, n, 2) |x| {
|
||||
assert trie.contains_key(&x);
|
||||
assert !trie.insert(x, x + 1);
|
||||
fail_unless!(trie.contains_key(&x));
|
||||
fail_unless!(!trie.insert(x, x + 1));
|
||||
check_integrity(&trie.root);
|
||||
}
|
||||
}
|
||||
@ -390,16 +390,16 @@ mod tests {
|
||||
fn test_each() {
|
||||
let mut m = TrieMap::new();
|
||||
|
||||
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);
|
||||
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));
|
||||
|
||||
let mut n = 0;
|
||||
for m.each |&(k, v)| {
|
||||
assert k == n;
|
||||
assert *v == n * 2;
|
||||
fail_unless!(k == n);
|
||||
fail_unless!(*v == n * 2);
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
@ -415,10 +415,10 @@ mod tests {
|
||||
let mut n = uint::max_value - 9999;
|
||||
for m.each |&(k, v)| {
|
||||
if n == uint::max_value - 5000 { break }
|
||||
assert n < uint::max_value - 5000;
|
||||
fail_unless!(n < uint::max_value - 5000);
|
||||
|
||||
assert k == n;
|
||||
assert *v == n / 2;
|
||||
fail_unless!(k == n);
|
||||
fail_unless!(*v == n / 2);
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
@ -427,16 +427,16 @@ mod tests {
|
||||
fn test_each_reverse() {
|
||||
let mut m = TrieMap::new();
|
||||
|
||||
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);
|
||||
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));
|
||||
|
||||
let mut n = 4;
|
||||
for m.each_reverse |&(k, v)| {
|
||||
assert k == n;
|
||||
assert *v == n * 2;
|
||||
fail_unless!(k == n);
|
||||
fail_unless!(*v == n * 2);
|
||||
n -= 1;
|
||||
}
|
||||
}
|
||||
@ -452,10 +452,10 @@ mod tests {
|
||||
let mut n = uint::max_value;
|
||||
for m.each_reverse |&(k, v)| {
|
||||
if n == uint::max_value - 5000 { break }
|
||||
assert n > uint::max_value - 5000;
|
||||
fail_unless!(n > uint::max_value - 5000);
|
||||
|
||||
assert k == n;
|
||||
assert *v == n / 2;
|
||||
fail_unless!(k == n);
|
||||
fail_unless!(*v == n / 2);
|
||||
n -= 1;
|
||||
}
|
||||
}
|
||||
|
@ -202,15 +202,15 @@ impl<A:Ord,B:Ord,C:Ord> Ord for (A, B, C) {
|
||||
#[test]
|
||||
fn test_tuple_ref() {
|
||||
let x = (~"foo", ~"bar");
|
||||
assert x.first_ref() == &~"foo";
|
||||
assert x.second_ref() == &~"bar";
|
||||
fail_unless!(x.first_ref() == &~"foo");
|
||||
fail_unless!(x.second_ref() == &~"bar");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(non_implicitly_copyable_typarams)]
|
||||
fn test_tuple() {
|
||||
assert (948, 4039.48).first() == 948;
|
||||
assert (34.5, ~"foo").second() == ~"foo";
|
||||
assert ('a', 2).swap() == (2, 'a');
|
||||
fail_unless!((948, 4039.48).first() == 948);
|
||||
fail_unless!((34.5, ~"foo").second() == ~"foo");
|
||||
fail_unless!(('a', 2).swap() == (2, 'a'));
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,10 @@ pub mod extfmt;
|
||||
#[cfg(notest)]
|
||||
pub mod lang;
|
||||
|
||||
extern mod rustrt {
|
||||
mod rustrt {
|
||||
use unstable::{raw_thread, rust_little_lock};
|
||||
|
||||
pub extern {
|
||||
pub unsafe fn rust_create_little_lock() -> rust_little_lock;
|
||||
pub unsafe fn rust_destroy_little_lock(lock: rust_little_lock);
|
||||
pub unsafe fn rust_lock_little_lock(lock: rust_little_lock);
|
||||
@ -44,10 +47,11 @@ extern mod rustrt {
|
||||
|
||||
pub unsafe fn rust_raw_thread_start(f: &fn()) -> *raw_thread;
|
||||
pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)] // runtime type
|
||||
type raw_thread = libc::c_void;
|
||||
pub type raw_thread = libc::c_void;
|
||||
|
||||
/**
|
||||
|
||||
@ -79,7 +83,7 @@ fn test_run_in_bare_thread() {
|
||||
unsafe {
|
||||
let i = 100;
|
||||
do run_in_bare_thread {
|
||||
assert i == 100;
|
||||
fail_unless!(i == 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -90,7 +94,7 @@ fn test_run_in_bare_thread_exchange() {
|
||||
// Does the exchange heap work without the runtime?
|
||||
let i = ~100;
|
||||
do run_in_bare_thread {
|
||||
assert i == ~100;
|
||||
fail_unless!(i == ~100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -123,7 +127,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;
|
||||
assert new_count >= 0;
|
||||
fail_unless!(new_count >= 0);
|
||||
if new_count == 0 {
|
||||
// drop glue takes over.
|
||||
} else {
|
||||
@ -163,7 +167,7 @@ pub unsafe fn get_shared_mutable_state<T:Owned>(
|
||||
{
|
||||
unsafe {
|
||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
||||
assert ptr.count > 0;
|
||||
fail_unless!(ptr.count > 0);
|
||||
let r = cast::transmute(option::get_ref(&ptr.data));
|
||||
cast::forget(ptr);
|
||||
return r;
|
||||
@ -174,7 +178,7 @@ pub unsafe fn get_shared_immutable_state<T:Owned>(
|
||||
rc: &a/SharedMutableState<T>) -> &a/T {
|
||||
unsafe {
|
||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
||||
assert ptr.count > 0;
|
||||
fail_unless!(ptr.count > 0);
|
||||
// Cast us back into the correct region
|
||||
let r = cast::transmute_region(option::get_ref(&ptr.data));
|
||||
cast::forget(ptr);
|
||||
@ -187,7 +191,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;
|
||||
assert new_count >= 2;
|
||||
fail_unless!(new_count >= 2);
|
||||
cast::forget(ptr);
|
||||
}
|
||||
ArcDestruct((*rc).data)
|
||||
@ -204,7 +208,7 @@ impl<T:Owned> Clone for SharedMutableState<T> {
|
||||
/****************************************************************************/
|
||||
|
||||
#[allow(non_camel_case_types)] // runtime type
|
||||
type rust_little_lock = *libc::c_void;
|
||||
pub type rust_little_lock = *libc::c_void;
|
||||
|
||||
struct LittleLock {
|
||||
l: rust_little_lock,
|
||||
@ -338,7 +342,7 @@ pub mod tests {
|
||||
for futures.each |f| { f.recv() }
|
||||
|
||||
do total.with |total| {
|
||||
assert **total == num_tasks * count
|
||||
fail_unless!(**total == num_tasks * count)
|
||||
};
|
||||
}
|
||||
|
||||
@ -350,11 +354,11 @@ pub mod tests {
|
||||
let x2 = x.clone();
|
||||
do task::try || {
|
||||
do x2.with |one| {
|
||||
assert *one == 2;
|
||||
fail_unless!(*one == 2);
|
||||
}
|
||||
};
|
||||
do x.with |one| {
|
||||
assert *one == 1;
|
||||
fail_unless!(*one == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,12 @@ pub fn at_exit(f: ~fn()) {
|
||||
// NB: The double pointer indirection here is because ~fn() is a fat
|
||||
// pointer and due to FFI problems I am more comfortable making the
|
||||
// interface use a normal pointer
|
||||
extern mod rustrt {
|
||||
mod rustrt {
|
||||
use libc::c_void;
|
||||
|
||||
pub extern {
|
||||
fn rust_register_exit_function(runner: *c_void, f: ~~fn());
|
||||
}
|
||||
}
|
||||
|
||||
struct ExitFunctions {
|
||||
@ -75,7 +79,7 @@ fn test_at_exit() {
|
||||
let i = 10;
|
||||
do at_exit {
|
||||
debug!("at_exit1");
|
||||
assert i == 10;
|
||||
fail_unless!(i == 10);
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,8 +89,8 @@ fn test_at_exit_many() {
|
||||
for uint::range(20, 100) |j| {
|
||||
do at_exit {
|
||||
debug!("at_exit2");
|
||||
assert i == 10;
|
||||
assert j > i;
|
||||
fail_unless!(i == 10);
|
||||
fail_unless!(j > i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,11 +20,11 @@ use intrinsic::TyDesc;
|
||||
|
||||
pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
|
||||
unsafe {
|
||||
assert td.is_not_null();
|
||||
fail_unless!(td.is_not_null());
|
||||
|
||||
let total_size = get_box_size(size, (*td).align);
|
||||
let p = c_malloc(total_size as size_t);
|
||||
assert p.is_not_null();
|
||||
fail_unless!(p.is_not_null());
|
||||
|
||||
// FIXME #3475: Converting between our two different tydesc types
|
||||
let td: *TyDesc = transmute(td);
|
||||
@ -46,7 +46,7 @@ pub unsafe fn free(ptr: *c_void) {
|
||||
let exchange_count = &mut *rust_get_exchange_count_ptr();
|
||||
atomic_xsub(exchange_count, 1);
|
||||
|
||||
assert ptr.is_not_null();
|
||||
fail_unless!(ptr.is_not_null());
|
||||
c_free(ptr);
|
||||
}
|
||||
|
||||
@ -60,7 +60,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 {
|
||||
assert align != 0;
|
||||
fail_unless!(align != 0);
|
||||
(size + align - 1) & !(align - 1)
|
||||
}
|
||||
|
||||
|
@ -340,11 +340,11 @@ pub mod ct {
|
||||
parse_count(s, 0, s.len()) == Parsed::new(count, next)
|
||||
}
|
||||
|
||||
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);
|
||||
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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -355,8 +355,8 @@ pub mod ct {
|
||||
|
||||
fn test(s: &str, flags: &[Flag], next: uint) {
|
||||
let f = parse_flags(s, 0, s.len());
|
||||
assert pack(f.val) == pack(flags);
|
||||
assert f.next == next;
|
||||
fail_unless!(pack(f.val) == pack(flags));
|
||||
fail_unless!(f.next == next);
|
||||
}
|
||||
|
||||
test("", [], 0);
|
||||
@ -367,7 +367,7 @@ pub mod ct {
|
||||
|
||||
#[test]
|
||||
fn test_parse_fmt_string() {
|
||||
assert parse_fmt_string("foo %s bar", die) == ~[
|
||||
fail_unless!(parse_fmt_string("foo %s bar", die) == ~[
|
||||
PieceString(~"foo "),
|
||||
PieceConv(Conv {
|
||||
param: None,
|
||||
@ -376,19 +376,19 @@ pub mod ct {
|
||||
precision: CountImplied,
|
||||
ty: TyStr,
|
||||
}),
|
||||
PieceString(~" bar")];
|
||||
PieceString(~" bar")]);
|
||||
|
||||
assert parse_fmt_string("%s", die) == ~[
|
||||
fail_unless!(parse_fmt_string("%s", die) == ~[
|
||||
PieceConv(Conv {
|
||||
param: None,
|
||||
flags: ~[],
|
||||
width: CountImplied,
|
||||
precision: CountImplied,
|
||||
ty: TyStr,
|
||||
})];
|
||||
})]);
|
||||
|
||||
assert parse_fmt_string("%%%%", die) == ~[
|
||||
PieceString(~"%"), PieceString(~"%")];
|
||||
fail_unless!(parse_fmt_string("%%%%", die) == ~[
|
||||
PieceString(~"%"), PieceString(~"%")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -397,10 +397,10 @@ pub mod ct {
|
||||
parse_parameter(s, 0, s.len()) == Parsed::new(param, next)
|
||||
}
|
||||
|
||||
assert test("", None, 0);
|
||||
assert test("foo", None, 0);
|
||||
assert test("123", None, 0);
|
||||
assert test("123$", Some(123), 4);
|
||||
fail_unless!(test("", None, 0));
|
||||
fail_unless!(test("foo", None, 0));
|
||||
fail_unless!(test("123", None, 0));
|
||||
fail_unless!(test("123$", Some(123), 4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -409,12 +409,12 @@ pub mod ct {
|
||||
parse_precision(s, 0, s.len()) == Parsed::new(count, next)
|
||||
}
|
||||
|
||||
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);
|
||||
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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -423,17 +423,17 @@ pub mod ct {
|
||||
parse_type(s, 0, s.len(), die) == Parsed::new(ty, 1)
|
||||
}
|
||||
|
||||
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);
|
||||
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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -453,16 +453,16 @@ pub mod ct {
|
||||
#[test]
|
||||
fn test_peek_num() {
|
||||
let s1 = "";
|
||||
assert peek_num(s1, 0, s1.len()).is_none();
|
||||
fail_unless!(peek_num(s1, 0, s1.len()).is_none());
|
||||
|
||||
let s2 = "foo";
|
||||
assert peek_num(s2, 0, s2.len()).is_none();
|
||||
fail_unless!(peek_num(s2, 0, s2.len()).is_none());
|
||||
|
||||
let s3 = "123";
|
||||
assert peek_num(s3, 0, s3.len()) == Some(Parsed::new(123, 3));
|
||||
fail_unless!(peek_num(s3, 0, s3.len()) == Some(Parsed::new(123, 3)));
|
||||
|
||||
let s4 = "123foo";
|
||||
assert peek_num(s4, 0, s4.len()) == Some(Parsed::new(123, 3));
|
||||
fail_unless!(peek_num(s4, 0, s4.len()) == Some(Parsed::new(123, 3)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,11 +57,11 @@ fn test_success() {
|
||||
do (|| {
|
||||
i = 10;
|
||||
}).finally {
|
||||
assert !failing();
|
||||
assert i == 10;
|
||||
fail_unless!(!failing());
|
||||
fail_unless!(i == 10);
|
||||
i = 20;
|
||||
}
|
||||
assert i == 20;
|
||||
fail_unless!(i == 20);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -73,8 +73,8 @@ fn test_fail() {
|
||||
i = 10;
|
||||
fail!();
|
||||
}).finally {
|
||||
assert failing();
|
||||
assert i == 10;
|
||||
fail_unless!(failing());
|
||||
fail_unless!(i == 10);
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ fn test_fail() {
|
||||
fn test_retval() {
|
||||
let closure: &fn() -> int = || 10;
|
||||
let i = do closure.finally { };
|
||||
assert i == 10;
|
||||
fail_unless!(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
|
||||
assert prev_i != POISON;
|
||||
fail_unless!(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)
|
||||
};
|
||||
assert prev_i == state_i;
|
||||
fail_unless!(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)
|
||||
};
|
||||
|
||||
assert get_shared_immutable_state(&val) == &10;
|
||||
fail_unless!(get_shared_immutable_state(&val) == &10);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -273,7 +273,7 @@ fn test_modify() {
|
||||
match v {
|
||||
Some(sms) => {
|
||||
let v = get_shared_immutable_state(sms);
|
||||
assert *v == 10;
|
||||
fail_unless!(*v == 10);
|
||||
None
|
||||
},
|
||||
_ => fail!()
|
||||
|
@ -26,12 +26,16 @@ pub const FROZEN_BIT: uint = 0x80000000;
|
||||
#[cfg(target_word_size = "64")]
|
||||
pub const FROZEN_BIT: uint = 0x8000000000000000;
|
||||
|
||||
pub extern mod rustrt {
|
||||
pub mod rustrt {
|
||||
use libc::{c_char, uintptr_t};
|
||||
|
||||
pub extern {
|
||||
#[rust_stack]
|
||||
unsafe fn rust_upcall_malloc(td: *c_char, size: uintptr_t) -> *c_char;
|
||||
|
||||
#[rust_stack]
|
||||
unsafe fn rust_upcall_free(ptr: *c_char);
|
||||
}
|
||||
}
|
||||
|
||||
#[lang="fail_"]
|
||||
|
@ -40,7 +40,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
|
||||
assert service.try_send(RegisterWeakTask(task, shutdown_chan));
|
||||
fail_unless!(service.try_send(RegisterWeakTask(task, shutdown_chan)));
|
||||
unsafe { rust_dec_kernel_live_count(); }
|
||||
do (|| {
|
||||
f(shutdown_port.take())
|
||||
@ -102,7 +102,7 @@ fn run_weak_task_service(port: Port<ServiceMsg>) {
|
||||
RegisterWeakTask(task, shutdown_chan) => {
|
||||
let previously_unregistered =
|
||||
shutdown_map.insert(task, shutdown_chan);
|
||||
assert previously_unregistered;
|
||||
fail_unless!(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 {
|
||||
assert !v.is_empty();
|
||||
fail_unless!(!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 assert x.eq(id(copy x));
|
||||
//FIXME #3387 fail_unless!(x.eq(id(copy x)));
|
||||
let y = copy x;
|
||||
assert x.eq(&id(y));
|
||||
fail_unless!(x.eq(&id(y)));
|
||||
}
|
||||
#[test]
|
||||
pub fn test_swap() {
|
||||
let mut x = 31337;
|
||||
let mut y = 42;
|
||||
swap(&mut x, &mut y);
|
||||
assert x == 42;
|
||||
assert y == 31337;
|
||||
fail_unless!(x == 42);
|
||||
fail_unless!(y == 31337);
|
||||
}
|
||||
#[test]
|
||||
pub fn test_replace() {
|
||||
let mut x = Some(NonCopyable());
|
||||
let y = replace(&mut x, None);
|
||||
assert x.is_none();
|
||||
assert y.is_some();
|
||||
fail_unless!(x.is_none());
|
||||
fail_unless!(y.is_some());
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -29,13 +29,13 @@ pure fn builtin_equal<T>(&&a: T, &&b: T) -> bool { return a == b; }
|
||||
pure fn builtin_equal_int(&&a: int, &&b: int) -> bool { return a == b; }
|
||||
|
||||
fn main() {
|
||||
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));
|
||||
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)));
|
||||
|
||||
error!("Pass");
|
||||
}
|
||||
|
@ -14,12 +14,12 @@ use uint::range;
|
||||
|
||||
// random uint less than n
|
||||
fn under(r : rand::rng, n : uint) -> uint {
|
||||
assert n != 0u; r.next() as uint % n
|
||||
fail_unless!(n != 0u); r.next() as uint % n
|
||||
}
|
||||
|
||||
// random choice from a vec
|
||||
fn choice<T:copy>(r : rand::rng, v : ~[const T]) -> T {
|
||||
assert vec::len(v) != 0u; v[under(r, vec::len(v))]
|
||||
fail_unless!(vec::len(v) != 0u); v[under(r, vec::len(v))]
|
||||
}
|
||||
|
||||
// k in n chance of being true
|
||||
|
@ -109,8 +109,7 @@ pub pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool {
|
||||
| ast::expr_match(*) | ast::expr_while(*) => { false }
|
||||
|
||||
// https://github.com/mozilla/rust/issues/929
|
||||
ast::expr_cast(*) | ast::expr_assert(*) |
|
||||
ast::expr_binary(*) | ast::expr_assign(*) |
|
||||
ast::expr_cast(*) | ast::expr_binary(*) | ast::expr_assign(*) |
|
||||
ast::expr_assign_op(*) => { false }
|
||||
|
||||
ast::expr_ret(option::None) => { false }
|
||||
@ -371,13 +370,13 @@ pub fn check_whole_compiler(code: ~str, suggested_filename_prefix: &Path,
|
||||
|
||||
pub fn removeIfExists(filename: &Path) {
|
||||
// So sketchy!
|
||||
assert !contains(filename.to_str(), ~" ");
|
||||
fail_unless!(!contains(filename.to_str(), ~" "));
|
||||
run::program_output(~"bash", ~[~"-c", ~"rm " + filename.to_str()]);
|
||||
}
|
||||
|
||||
pub fn removeDirIfExists(filename: &Path) {
|
||||
// So sketchy!
|
||||
assert !contains(filename.to_str(), ~" ");
|
||||
fail_unless!(!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 {
|
||||
assert n != 0u; r.next() as uint % n
|
||||
fail_unless!(n != 0u); r.next() as uint % n
|
||||
}
|
||||
|
||||
// random choice from a vec
|
||||
fn choice<T:copy>(r : rand::rng, v : ~[T]) -> T {
|
||||
assert vec::len(v) != 0u; v[under(r, vec::len(v))]
|
||||
fail_unless!(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 {
|
||||
assert vec::len(v) != 0u;
|
||||
fail_unless!(vec::len(v) != 0u);
|
||||
let total = 0u;
|
||||
for {weight: weight, item: _} in v {
|
||||
total += weight;
|
||||
}
|
||||
assert total >= 0u;
|
||||
fail_unless!(total >= 0u);
|
||||
let chosen = under(r, total);
|
||||
let so_far = 0u;
|
||||
for {weight: weight, item: item} in v {
|
||||
|
@ -17,7 +17,7 @@ use lib::llvm::llvm;
|
||||
use lib::llvm::{ModuleRef, mk_pass_manager, mk_target_data, True, False};
|
||||
use lib;
|
||||
use metadata::common::LinkMeta;
|
||||
use metadata::{encoder, cstore};
|
||||
use metadata::{encoder, csearch, cstore};
|
||||
use middle::trans::common::CrateContext;
|
||||
use middle::ty;
|
||||
use util::ppaux;
|
||||
@ -94,11 +94,13 @@ pub mod jit {
|
||||
use core::ptr;
|
||||
use core::str;
|
||||
|
||||
pub mod rusti {
|
||||
#[nolink]
|
||||
#[abi = "rust-intrinsic"]
|
||||
pub extern mod rusti {
|
||||
pub extern {
|
||||
pub fn morestack_addr() -> *();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Closure {
|
||||
code: *(),
|
||||
@ -812,6 +814,14 @@ pub fn link_binary(sess: Session,
|
||||
let ula = cstore::get_used_link_args(cstore);
|
||||
for ula.each |arg| { cc_args.push(/*bad*/copy *arg); }
|
||||
|
||||
// Add all the link args for external crates.
|
||||
do cstore::iter_crate_data(cstore) |crate_num, _| {
|
||||
let link_args = csearch::get_link_args_for_crate(cstore, crate_num);
|
||||
do vec::consume(link_args) |_, link_arg| {
|
||||
cc_args.push(link_arg);
|
||||
}
|
||||
}
|
||||
|
||||
// # Extern library linking
|
||||
|
||||
// User-supplied library search paths (-L on the cammand line) These are
|
||||
|
@ -118,7 +118,7 @@ pub fn get_rpath_relative_to_output(os: session::os,
|
||||
-> Path {
|
||||
use core::os;
|
||||
|
||||
assert not_win32(os);
|
||||
fail_unless!(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 {
|
||||
assert abs1.is_absolute;
|
||||
assert abs2.is_absolute;
|
||||
fail_unless!(abs1.is_absolute);
|
||||
fail_unless!(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 = /*bad*/copy abs2.components;
|
||||
let len1 = vec::len(split1);
|
||||
let len2 = vec::len(split2);
|
||||
assert len1 > 0;
|
||||
assert len2 > 0;
|
||||
fail_unless!(len1 > 0);
|
||||
fail_unless!(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")]);
|
||||
assert flags == ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"];
|
||||
fail_unless!(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());
|
||||
assert str::ends_with(res.to_str(), d.to_str());
|
||||
fail_unless!(str::ends_with(res.to_str(), d.to_str()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_prefix_rpath_abs() {
|
||||
let res = get_install_prefix_rpath("triple");
|
||||
assert res.is_absolute;
|
||||
fail_unless!(res.is_absolute);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -240,7 +240,7 @@ mod test {
|
||||
let res = minimize_rpaths([Path("rpath1"),
|
||||
Path("rpath2"),
|
||||
Path("rpath1")]);
|
||||
assert res == ~[Path("rpath1"), Path("rpath2")];
|
||||
fail_unless!(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")]);
|
||||
assert res == ~[Path("1a"), Path("2"), Path("4a"), Path("3")];
|
||||
fail_unless!(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);
|
||||
assert res == Path("../lib");
|
||||
fail_unless!(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);
|
||||
assert res == Path("../lib");
|
||||
fail_unless!(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);
|
||||
assert res == Path("../../lib/whatever");
|
||||
fail_unless!(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);
|
||||
assert res == Path("../lib/whatever");
|
||||
fail_unless!(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);
|
||||
assert res == Path("../lib");
|
||||
fail_unless!(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);
|
||||
assert res == Path("2");
|
||||
fail_unless!(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);
|
||||
assert res == Path("..");
|
||||
fail_unless!(res == Path(".."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -318,7 +318,7 @@ mod test {
|
||||
debug!("test_relative_tu8: %s vs. %s",
|
||||
res.to_str(),
|
||||
Path(".").to_str());
|
||||
assert res == Path(".");
|
||||
fail_unless!(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"));
|
||||
assert res.to_str() == ~"$ORIGIN/../lib";
|
||||
fail_unless!(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"));
|
||||
assert res.to_str() == ~"$ORIGIN/../lib";
|
||||
fail_unless!(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"));
|
||||
assert res.to_str() == ~"@executable_path/../lib";
|
||||
fail_unless!(res.to_str() == ~"@executable_path/../lib");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -358,6 +358,6 @@ mod test {
|
||||
res.to_str(),
|
||||
os::make_absolute(&Path("lib")).to_str());
|
||||
|
||||
assert res == os::make_absolute(&Path("lib"));
|
||||
fail_unless!(res == os::make_absolute(&Path("lib")));
|
||||
}
|
||||
}
|
||||
|
@ -902,7 +902,7 @@ pub mod test {
|
||||
~"rustc", matches, diagnostic::emit);
|
||||
let sess = build_session(sessopts, diagnostic::emit);
|
||||
let cfg = build_configuration(sess, ~"whatever", str_input(~""));
|
||||
assert (attr::contains_name(cfg, ~"test"));
|
||||
fail_unless!((attr::contains_name(cfg, ~"test")));
|
||||
}
|
||||
|
||||
// When the user supplies --test and --cfg test, don't implicitly add
|
||||
@ -922,7 +922,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");
|
||||
assert (vec::len(test_items) == 1u);
|
||||
fail_unless!((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);
|
||||
assert !building_library(unknown_crate, crate, false);
|
||||
fail_unless!(!building_library(unknown_crate, crate, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn lib_crate_type_attr_results_in_lib_output() {
|
||||
let crate = make_crate(false, true);
|
||||
assert building_library(unknown_crate, crate, false);
|
||||
fail_unless!(building_library(unknown_crate, crate, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn bin_option_overrides_lib_crate_type() {
|
||||
let crate = make_crate(false, true);
|
||||
assert !building_library(bin_crate, crate, false);
|
||||
fail_unless!(!building_library(bin_crate, crate, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn lib_option_overrides_bin_crate_type() {
|
||||
let crate = make_crate(true, false);
|
||||
assert building_library(lib_crate, crate, false);
|
||||
fail_unless!(building_library(lib_crate, crate, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn bin_crate_type_is_default() {
|
||||
let crate = make_crate(false, false);
|
||||
assert !building_library(unknown_crate, crate, false);
|
||||
fail_unless!(!building_library(unknown_crate, crate, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_option_overrides_lib_crate_type() {
|
||||
let crate = make_crate(false, true);
|
||||
assert !building_library(unknown_crate, crate, true);
|
||||
fail_unless!(!building_library(unknown_crate, crate, true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_option_does_not_override_requested_lib_type() {
|
||||
let crate = make_crate(false, false);
|
||||
assert building_library(lib_crate, crate, true);
|
||||
fail_unless!(building_library(lib_crate, crate, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,11 +22,11 @@ pub mod intrinsic {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum TyDesc = {
|
||||
pub struct TyDesc {
|
||||
size: uint,
|
||||
align: uint
|
||||
// Remaining fields not listed
|
||||
};
|
||||
}
|
||||
|
||||
pub trait TyVisitor {
|
||||
fn visit_bot(&self) -> bool;
|
||||
@ -122,9 +122,13 @@ pub mod intrinsic {
|
||||
fn visit_closure_ptr(&self, ck: uint) -> bool;
|
||||
}
|
||||
|
||||
pub mod rusti {
|
||||
use super::{TyDesc, TyVisitor};
|
||||
|
||||
#[abi = "rust-intrinsic"]
|
||||
pub extern mod rusti {
|
||||
pub extern {
|
||||
pub fn get_tydesc<T>() -> *();
|
||||
pub fn visit_tydesc(++td: *TyDesc, &&tv: TyVisitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,10 +216,19 @@ pub type ObjectFileRef = *ObjectFile_opaque;
|
||||
pub enum SectionIterator_opaque {}
|
||||
pub type SectionIteratorRef = *SectionIterator_opaque;
|
||||
|
||||
#[link_args = "-Lrustllvm"]
|
||||
#[link_name = "rustllvm"]
|
||||
#[abi = "cdecl"]
|
||||
pub extern mod llvm {
|
||||
pub mod llvm {
|
||||
use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, Bool, BuilderRef};
|
||||
use super::{ContextRef, MemoryBufferRef, ModuleRef, ObjectFileRef};
|
||||
use super::{Opcode, PassManagerRef, PassManagerBuilderRef};
|
||||
use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
|
||||
use super::{ValueRef};
|
||||
|
||||
use core::libc::{c_char, c_int, c_longlong, c_uint, c_ulonglong};
|
||||
|
||||
#[link_args = "-Lrustllvm -lrustllvm"]
|
||||
#[link_name = "rustllvm"]
|
||||
#[abi = "cdecl"]
|
||||
pub extern {
|
||||
/* Create and destroy contexts. */
|
||||
pub unsafe fn LLVMContextCreate() -> ContextRef;
|
||||
pub unsafe fn LLVMGetGlobalContext() -> ContextRef;
|
||||
@ -287,8 +296,11 @@ pub extern mod llvm {
|
||||
pub unsafe fn LLVMPPCFP128Type() -> TypeRef;
|
||||
|
||||
/* Operations on function types */
|
||||
pub unsafe fn LLVMFunctionType(ReturnType: TypeRef, ParamTypes: *TypeRef,
|
||||
ParamCount: c_uint, IsVarArg: Bool) -> TypeRef;
|
||||
pub unsafe fn LLVMFunctionType(ReturnType: TypeRef,
|
||||
ParamTypes: *TypeRef,
|
||||
ParamCount: c_uint,
|
||||
IsVarArg: Bool)
|
||||
-> TypeRef;
|
||||
pub unsafe fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
|
||||
pub unsafe fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
|
||||
pub unsafe fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
|
||||
@ -299,9 +311,12 @@ pub extern mod llvm {
|
||||
ElementTypes: *TypeRef,
|
||||
ElementCount: c_uint,
|
||||
Packed: Bool) -> TypeRef;
|
||||
pub unsafe fn LLVMStructType(ElementTypes: *TypeRef, ElementCount: c_uint,
|
||||
Packed: Bool) -> TypeRef;
|
||||
pub unsafe fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
|
||||
pub unsafe fn LLVMStructType(ElementTypes: *TypeRef,
|
||||
ElementCount: c_uint,
|
||||
Packed: Bool)
|
||||
-> TypeRef;
|
||||
pub unsafe fn LLVMCountStructElementTypes(StructTy: TypeRef)
|
||||
-> c_uint;
|
||||
pub unsafe fn LLVMGetStructElementTypes(StructTy: TypeRef,
|
||||
Dest: *mut TypeRef);
|
||||
pub unsafe fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
|
||||
@ -316,7 +331,8 @@ pub extern mod llvm {
|
||||
|
||||
pub unsafe fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
|
||||
pub unsafe fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
|
||||
pub unsafe fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
|
||||
pub unsafe fn LLVMGetPointerAddressSpace(PointerTy: TypeRef)
|
||||
-> c_uint;
|
||||
pub unsafe fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
|
||||
|
||||
/* Operations on other types */
|
||||
@ -333,9 +349,11 @@ pub extern mod llvm {
|
||||
pub unsafe fn LLVMGetValueName(Val: ValueRef) -> *c_char;
|
||||
pub unsafe fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
|
||||
pub unsafe fn LLVMDumpValue(Val: ValueRef);
|
||||
pub unsafe fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
|
||||
pub unsafe fn LLVMReplaceAllUsesWith(OldVal: ValueRef,
|
||||
NewVal: ValueRef);
|
||||
pub unsafe fn LLVMHasMetadata(Val: ValueRef) -> c_int;
|
||||
pub unsafe fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
|
||||
pub unsafe fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMSetMetadata(Val: ValueRef,
|
||||
KindID: c_uint,
|
||||
Node: ValueRef);
|
||||
@ -348,8 +366,11 @@ pub extern mod llvm {
|
||||
|
||||
/* Operations on Users */
|
||||
pub unsafe fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
|
||||
pub unsafe fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
|
||||
pub unsafe fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
|
||||
pub unsafe fn LLVMGetOperand(Val: ValueRef, Index: c_uint)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMSetOperand(Val: ValueRef,
|
||||
Index: c_uint,
|
||||
Op: ValueRef);
|
||||
|
||||
/* Operations on constants of any type */
|
||||
pub unsafe fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
|
||||
@ -385,15 +406,19 @@ pub extern mod llvm {
|
||||
Text: *c_char,
|
||||
Radix: u8)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMConstIntOfStringAndSize(IntTy: TypeRef, Text: *c_char,
|
||||
pub unsafe fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
|
||||
Text: *c_char,
|
||||
SLen: c_uint,
|
||||
Radix: u8) -> ValueRef;
|
||||
Radix: u8)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
|
||||
pub unsafe fn LLVMConstRealOfString(RealTy: TypeRef,
|
||||
Text: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMConstRealOfStringAndSize(RealTy: TypeRef, Text: *c_char,
|
||||
SLen: c_uint) -> ValueRef;
|
||||
pub unsafe fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
|
||||
Text: *c_char,
|
||||
SLen: c_uint)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef)
|
||||
-> c_ulonglong;
|
||||
pub unsafe fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef)
|
||||
@ -561,8 +586,10 @@ pub extern mod llvm {
|
||||
pub unsafe fn LLVMConstPointerCast(ConstantVal: ValueRef,
|
||||
ToType: TypeRef)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMConstIntCast(ConstantVal: ValueRef, ToType: TypeRef,
|
||||
isSigned: Bool) -> ValueRef;
|
||||
pub unsafe fn LLVMConstIntCast(ConstantVal: ValueRef,
|
||||
ToType: TypeRef,
|
||||
isSigned: Bool)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMConstFPCast(ConstantVal: ValueRef,
|
||||
ToType: TypeRef)
|
||||
-> ValueRef;
|
||||
@ -582,8 +609,10 @@ pub extern mod llvm {
|
||||
IdxList: *c_uint,
|
||||
NumIdx: c_uint) -> ValueRef;
|
||||
pub unsafe fn LLVMConstInsertValue(AggConstant: ValueRef,
|
||||
ElementValueConstant: ValueRef, IdxList: *c_uint,
|
||||
NumIdx: c_uint) -> ValueRef;
|
||||
ElementValueConstant: ValueRef,
|
||||
IdxList: *c_uint,
|
||||
NumIdx: c_uint)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: *c_char,
|
||||
Constraints: *c_char, HasSideEffects: Bool,
|
||||
IsAlignStack: Bool) -> ValueRef;
|
||||
@ -615,7 +644,8 @@ pub extern mod llvm {
|
||||
Name: *c_char,
|
||||
AddressSpace: c_uint)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
|
||||
pub unsafe fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
|
||||
pub unsafe fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
|
||||
@ -632,8 +662,11 @@ pub extern mod llvm {
|
||||
IsConstant: Bool);
|
||||
|
||||
/* Operations on aliases */
|
||||
pub unsafe fn LLVMAddAlias(M: ModuleRef, Ty: TypeRef, Aliasee: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMAddAlias(M: ModuleRef,
|
||||
Ty: TypeRef,
|
||||
Aliasee: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
|
||||
/* Operations on functions */
|
||||
pub unsafe fn LLVMAddFunction(M: ModuleRef,
|
||||
@ -654,8 +687,9 @@ pub extern mod llvm {
|
||||
pub unsafe fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
|
||||
pub unsafe fn LLVMGetGC(Fn: ValueRef) -> *c_char;
|
||||
pub unsafe fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
|
||||
pub unsafe fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_ulonglong, HighPA:
|
||||
c_ulonglong);
|
||||
pub unsafe fn LLVMAddFunctionAttr(Fn: ValueRef,
|
||||
PA: c_ulonglong,
|
||||
HighPA: c_ulonglong);
|
||||
pub unsafe fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
|
||||
pub unsafe fn LLVMRemoveFunctionAttr(Fn: ValueRef,
|
||||
PA: c_ulonglong,
|
||||
@ -681,16 +715,20 @@ pub extern mod llvm {
|
||||
pub unsafe fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
|
||||
pub unsafe fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
|
||||
pub unsafe fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
|
||||
pub unsafe fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
|
||||
pub unsafe fn LLVMGetBasicBlocks(Fn: ValueRef,
|
||||
BasicBlocks: *ValueRef);
|
||||
pub unsafe fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
|
||||
pub unsafe fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
|
||||
pub unsafe fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
|
||||
pub unsafe fn LLVMGetNextBasicBlock(BB: BasicBlockRef)
|
||||
-> BasicBlockRef;
|
||||
pub unsafe fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef)
|
||||
-> BasicBlockRef;
|
||||
pub unsafe fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
|
||||
|
||||
pub unsafe fn LLVMAppendBasicBlockInContext(C: ContextRef, Fn: ValueRef,
|
||||
Name: *c_char) -> BasicBlockRef;
|
||||
pub unsafe fn LLVMAppendBasicBlockInContext(C: ContextRef,
|
||||
Fn: ValueRef,
|
||||
Name: *c_char)
|
||||
-> BasicBlockRef;
|
||||
pub unsafe fn LLVMInsertBasicBlockInContext(C: ContextRef,
|
||||
BB: BasicBlockRef,
|
||||
Name: *c_char)
|
||||
@ -705,7 +743,8 @@ pub extern mod llvm {
|
||||
pub unsafe fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
|
||||
|
||||
/* Operations on instructions */
|
||||
pub unsafe fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
|
||||
pub unsafe fn LLVMGetInstructionParent(Inst: ValueRef)
|
||||
-> BasicBlockRef;
|
||||
pub unsafe fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
|
||||
pub unsafe fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
|
||||
pub unsafe fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
|
||||
@ -717,9 +756,11 @@ pub extern mod llvm {
|
||||
pub unsafe fn LLVMAddInstrAttribute(Instr: ValueRef,
|
||||
index: c_uint,
|
||||
IA: c_uint);
|
||||
pub unsafe fn LLVMRemoveInstrAttribute(Instr: ValueRef, index: c_uint,
|
||||
pub unsafe fn LLVMRemoveInstrAttribute(Instr: ValueRef,
|
||||
index: c_uint,
|
||||
IA: c_uint);
|
||||
pub unsafe fn LLVMSetInstrParamAlignment(Instr: ValueRef, index: c_uint,
|
||||
pub unsafe fn LLVMSetInstrParamAlignment(Instr: ValueRef,
|
||||
index: c_uint,
|
||||
align: c_uint);
|
||||
|
||||
/* Operations on call instructions (only) */
|
||||
@ -748,9 +789,11 @@ pub extern mod llvm {
|
||||
Instr: ValueRef);
|
||||
pub unsafe fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
|
||||
Block: BasicBlockRef);
|
||||
pub unsafe fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
|
||||
pub unsafe fn LLVMGetInsertBlock(Builder: BuilderRef)
|
||||
-> BasicBlockRef;
|
||||
pub unsafe fn LLVMClearInsertionPosition(Builder: BuilderRef);
|
||||
pub unsafe fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
|
||||
pub unsafe fn LLVMInsertIntoBuilder(Builder: BuilderRef,
|
||||
Instr: ValueRef);
|
||||
pub unsafe fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
|
||||
Instr: ValueRef,
|
||||
Name: *c_char);
|
||||
@ -769,7 +812,8 @@ pub extern mod llvm {
|
||||
pub unsafe fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildAggregateRet(B: BuilderRef, RetVals: *ValueRef,
|
||||
N: c_uint) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildCondBr(B: BuilderRef,
|
||||
If: ValueRef,
|
||||
Then: BasicBlockRef,
|
||||
@ -793,7 +837,8 @@ pub extern mod llvm {
|
||||
NumClauses: c_uint,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
|
||||
|
||||
/* Add a case to the switch instruction */
|
||||
@ -806,63 +851,138 @@ pub extern mod llvm {
|
||||
Dest: BasicBlockRef);
|
||||
|
||||
/* Add a clause to the landing pad instruction */
|
||||
pub unsafe fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
|
||||
pub unsafe fn LLVMAddClause(LandingPad: ValueRef,
|
||||
ClauseVal: ValueRef);
|
||||
|
||||
/* Set the cleanup on a landing pad instruction */
|
||||
pub unsafe fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
|
||||
|
||||
/* Arithmetic */
|
||||
pub unsafe fn LLVMBuildAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildNSWAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildNUWAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildFAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildNSWSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildNUWSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildFSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildNSWMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildNUWMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildFMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildUDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildSDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildExactSDiv(B: BuilderRef, LHS: ValueRef,
|
||||
RHS: ValueRef, Name: *c_char)
|
||||
pub unsafe fn LLVMBuildAdd(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildNSWAdd(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildNUWAdd(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildFAdd(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildSub(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildNSWSub(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildNUWSub(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildFSub(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildMul(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildNSWMul(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildNUWMul(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildFMul(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildUDiv(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildSDiv(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildExactSDiv(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildFDiv(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildURem(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildSRem(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildFRem(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildShl(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildLShr(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildAShr(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildAnd(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildOr(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildXor(B: BuilderRef,
|
||||
LHS: ValueRef,
|
||||
RHS: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildFDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildURem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildSRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildFRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildShl(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildLShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildAShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildAnd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildOr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildXor(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildBinOp(B: BuilderRef,
|
||||
Op: Opcode,
|
||||
LHS: ValueRef,
|
||||
@ -945,10 +1065,16 @@ pub extern mod llvm {
|
||||
Val: ValueRef,
|
||||
DestTy: TypeRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildZExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildSExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
|
||||
Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildZExt(B: BuilderRef,
|
||||
Val: ValueRef,
|
||||
DestTy: TypeRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildSExt(B: BuilderRef,
|
||||
Val: ValueRef,
|
||||
DestTy: TypeRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildFPToUI(B: BuilderRef,
|
||||
Val: ValueRef,
|
||||
DestTy: TypeRef,
|
||||
@ -1027,11 +1153,21 @@ pub extern mod llvm {
|
||||
Ty: TypeRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildCall(B: BuilderRef, Fn: ValueRef, Args: *ValueRef,
|
||||
NumArgs: c_uint, Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildSelect(B: BuilderRef, If: ValueRef, Then: ValueRef,
|
||||
Else: ValueRef, Name: *c_char) -> ValueRef;
|
||||
pub unsafe fn LLVMBuildVAArg(B: BuilderRef, list: ValueRef, Ty: TypeRef,
|
||||
pub unsafe fn LLVMBuildCall(B: BuilderRef,
|
||||
Fn: ValueRef,
|
||||
Args: *ValueRef,
|
||||
NumArgs: c_uint,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildSelect(B: BuilderRef,
|
||||
If: ValueRef,
|
||||
Then: ValueRef,
|
||||
Else: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildVAArg(B: BuilderRef,
|
||||
list: ValueRef,
|
||||
Ty: TypeRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildExtractElement(B: BuilderRef,
|
||||
@ -1063,7 +1199,9 @@ pub extern mod llvm {
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
|
||||
pub unsafe fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
|
||||
pub unsafe fn LLVMBuildIsNull(B: BuilderRef,
|
||||
Val: ValueRef,
|
||||
Name: *c_char)
|
||||
-> ValueRef;
|
||||
pub unsafe fn LLVMBuildIsNotNull(B: BuilderRef,
|
||||
Val: ValueRef,
|
||||
@ -1090,10 +1228,12 @@ pub extern mod llvm {
|
||||
Path: *c_char) -> c_int;
|
||||
|
||||
/** Creates target data from a target layout string. */
|
||||
pub unsafe fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
|
||||
pub unsafe fn LLVMCreateTargetData(StringRep: *c_char)
|
||||
-> TargetDataRef;
|
||||
/** Adds the target data to the given pass manager. The pass manager
|
||||
references the target data only weakly. */
|
||||
pub unsafe fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
|
||||
pub unsafe fn LLVMAddTargetData(TD: TargetDataRef,
|
||||
PM: PassManagerRef);
|
||||
/** Number of bytes clobbered when doing a Store to *T. */
|
||||
pub unsafe fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
|
||||
-> c_ulonglong;
|
||||
@ -1104,7 +1244,8 @@ pub extern mod llvm {
|
||||
|
||||
/** Distance between successive elements in an array of T.
|
||||
Includes ABI padding. */
|
||||
pub unsafe fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
|
||||
pub unsafe fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef)
|
||||
-> c_uint;
|
||||
|
||||
/** Returns the preferred alignment of a type. */
|
||||
pub unsafe fn LLVMPreferredAlignmentOfType(TD: TargetDataRef,
|
||||
@ -1112,9 +1253,12 @@ pub extern mod llvm {
|
||||
/** Returns the minimum alignment of a type. */
|
||||
pub unsafe fn LLVMABIAlignmentOfType(TD: TargetDataRef,
|
||||
Ty: TypeRef) -> c_uint;
|
||||
/** Returns the minimum alignment of a type when part of a call frame. */
|
||||
/**
|
||||
* Returns the minimum alignment of a type when part of a call frame.
|
||||
*/
|
||||
pub unsafe fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef,
|
||||
Ty: TypeRef) -> c_uint;
|
||||
Ty: TypeRef)
|
||||
-> c_uint;
|
||||
|
||||
/** Disposes target data. */
|
||||
pub unsafe fn LLVMDisposeTargetData(TD: TargetDataRef);
|
||||
@ -1158,7 +1302,8 @@ pub extern mod llvm {
|
||||
pub unsafe fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
|
||||
pub unsafe fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
|
||||
pub unsafe fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
|
||||
pub unsafe fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
|
||||
pub unsafe fn LLVMAddCorrelatedValuePropagationPass(PM:
|
||||
PassManagerRef);
|
||||
pub unsafe fn LLVMAddPruneEHPass(PM: PassManagerRef);
|
||||
pub unsafe fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
|
||||
pub unsafe fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
|
||||
@ -1167,7 +1312,8 @@ pub extern mod llvm {
|
||||
pub unsafe fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
|
||||
|
||||
pub unsafe fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
|
||||
pub unsafe fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
|
||||
pub unsafe fn LLVMPassManagerBuilderDispose(PMB:
|
||||
PassManagerBuilderRef);
|
||||
pub unsafe fn LLVMPassManagerBuilderSetOptLevel(
|
||||
PMB: PassManagerBuilderRef, OptimizationLevel: c_uint);
|
||||
pub unsafe fn LLVMPassManagerBuilderSetSizeLevel(
|
||||
@ -1212,22 +1358,28 @@ pub extern mod llvm {
|
||||
/** Returns the current section name. */
|
||||
pub unsafe fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
|
||||
/** Returns the current section size. */
|
||||
pub unsafe fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
|
||||
pub unsafe fn LLVMGetSectionSize(SI: SectionIteratorRef)
|
||||
-> c_ulonglong;
|
||||
/** Returns the current section contents as a string buffer. */
|
||||
pub unsafe fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
|
||||
pub unsafe fn LLVMGetSectionContents(SI: SectionIteratorRef)
|
||||
-> *c_char;
|
||||
|
||||
/** Reads the given file and returns it as a memory buffer. Use
|
||||
LLVMDisposeMemoryBuffer() to get rid of it. */
|
||||
pub unsafe fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char)
|
||||
pub unsafe fn LLVMRustCreateMemoryBufferWithContentsOfFile(
|
||||
Path: *c_char)
|
||||
-> MemoryBufferRef;
|
||||
|
||||
pub unsafe fn LLVMRustWriteOutputFile(PM: PassManagerRef, M: ModuleRef,
|
||||
pub unsafe fn LLVMRustWriteOutputFile(PM: PassManagerRef,
|
||||
M: ModuleRef,
|
||||
Triple: *c_char,
|
||||
// FIXME: When #2334 is fixed, change
|
||||
// c_uint to FileType
|
||||
Output: *c_char, FileType: c_uint,
|
||||
// FIXME: When #2334 is fixed,
|
||||
// change c_uint to FileType
|
||||
Output: *c_char,
|
||||
FileType: c_uint,
|
||||
OptLevel: c_int,
|
||||
EnableSegmentedStacks: bool) -> bool;
|
||||
EnableSegmentedStacks: bool)
|
||||
-> bool;
|
||||
|
||||
/** Returns a string describing the last error caused by an LLVMRust*
|
||||
call. */
|
||||
@ -1238,7 +1390,8 @@ pub extern mod llvm {
|
||||
|
||||
/** Load a crate into the memory manager. */
|
||||
pub unsafe fn LLVMRustLoadCrate(MM: *(),
|
||||
Filename: *c_char) -> bool;
|
||||
Filename: *c_char)
|
||||
-> bool;
|
||||
|
||||
/** Execute the JIT engine. */
|
||||
pub unsafe fn LLVMRustExecuteJIT(MM: *(),
|
||||
@ -1248,31 +1401,39 @@ pub extern mod llvm {
|
||||
EnableSegmentedStacks: bool) -> *();
|
||||
|
||||
/** Parses the bitcode in the given memory buffer. */
|
||||
pub unsafe fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;
|
||||
pub unsafe fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef)
|
||||
-> ModuleRef;
|
||||
|
||||
/** Parses LLVM asm in the given file */
|
||||
pub unsafe fn LLVMRustParseAssemblyFile(Filename: *c_char) -> ModuleRef;
|
||||
pub unsafe fn LLVMRustParseAssemblyFile(Filename: *c_char)
|
||||
-> ModuleRef;
|
||||
|
||||
pub unsafe fn LLVMRustAddPrintModulePass(PM: PassManagerRef, M: ModuleRef,
|
||||
pub unsafe fn LLVMRustAddPrintModulePass(PM: PassManagerRef,
|
||||
M: ModuleRef,
|
||||
Output: *c_char);
|
||||
|
||||
/** Turn on LLVM pass-timing. */
|
||||
pub unsafe fn LLVMRustEnableTimePasses();
|
||||
|
||||
/** Print the pass timings since static dtors aren't picking them up. */
|
||||
/// Print the pass timings since static dtors aren't picking them up.
|
||||
pub unsafe fn LLVMRustPrintPassTimings();
|
||||
|
||||
pub unsafe fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char)
|
||||
-> TypeRef;
|
||||
|
||||
pub unsafe fn LLVMStructSetBody(StructTy: TypeRef, ElementTypes: *TypeRef,
|
||||
ElementCount: c_uint, Packed: Bool);
|
||||
pub unsafe fn LLVMStructSetBody(StructTy: TypeRef,
|
||||
ElementTypes: *TypeRef,
|
||||
ElementCount: c_uint,
|
||||
Packed: Bool);
|
||||
|
||||
pub unsafe fn LLVMConstNamedStruct(S: TypeRef, ConstantVals: *ValueRef,
|
||||
Count: c_uint) -> ValueRef;
|
||||
pub unsafe fn LLVMConstNamedStruct(S: TypeRef,
|
||||
ConstantVals: *ValueRef,
|
||||
Count: c_uint)
|
||||
-> ValueRef;
|
||||
|
||||
/** Enables LLVM debug output. */
|
||||
pub unsafe fn LLVMSetDebug(Enabled: c_int);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
|
||||
@ -1299,8 +1460,8 @@ pub struct TypeNames {
|
||||
}
|
||||
|
||||
pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) {
|
||||
assert tn.type_names.insert(t, s);
|
||||
assert tn.named_types.insert(s, t);
|
||||
fail_unless!(tn.type_names.insert(t, s));
|
||||
fail_unless!(tn.named_types.insert(s, t));
|
||||
}
|
||||
|
||||
pub fn type_has_name(tn: @TypeNames, t: TypeRef) -> Option<@str> {
|
||||
|
@ -156,6 +156,9 @@ pub const tag_item_unnamed_field: uint = 0x76;
|
||||
pub const tag_items_data_item_struct_ctor: uint = 0x77;
|
||||
pub const tag_items_data_item_visibility: uint = 0x78;
|
||||
|
||||
pub const tag_link_args: uint = 0x79;
|
||||
pub const tag_link_args_arg: uint = 0x7a;
|
||||
|
||||
pub struct LinkMeta {
|
||||
name: @str,
|
||||
vers: @str,
|
||||
|
@ -95,7 +95,7 @@ fn warn_if_multiple_versions(e: @mut Env,
|
||||
}
|
||||
}));
|
||||
|
||||
assert !matches.is_empty();
|
||||
fail_unless!(!matches.is_empty());
|
||||
|
||||
if matches.len() != 1u {
|
||||
diag.handler().warn(
|
||||
|
@ -237,6 +237,13 @@ pub fn get_method_visibility(cstore: @mut cstore::CStore,
|
||||
decoder::get_method_visibility(cdata, def_id.node)
|
||||
}
|
||||
|
||||
pub fn get_link_args_for_crate(cstore: @mut cstore::CStore,
|
||||
crate_num: ast::crate_num)
|
||||
-> ~[~str] {
|
||||
let cdata = cstore::get_crate_data(cstore, crate_num);
|
||||
decoder::get_link_args_for_crate(cdata)
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
// mode: rust
|
||||
// fill-column: 78;
|
||||
|
@ -106,7 +106,7 @@ pub fn get_used_crate_files(cstore: @mut CStore) -> ~[Path] {
|
||||
}
|
||||
|
||||
pub fn add_used_library(cstore: @mut CStore, lib: @~str) -> bool {
|
||||
assert *lib != ~"";
|
||||
fail_unless!(*lib != ~"");
|
||||
|
||||
if cstore.used_libraries.contains(&*lib) { return false; }
|
||||
cstore.used_libraries.push(/*bad*/ copy *lib);
|
||||
|
@ -1000,7 +1000,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
|
||||
assert (vec::len(meta_items) == 1u);
|
||||
fail_unless!((vec::len(meta_items) == 1u));
|
||||
let meta_item = meta_items[0];
|
||||
attrs.push(
|
||||
codemap::spanned {
|
||||
@ -1131,6 +1131,15 @@ pub fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_link_args_for_crate(cdata: cmd) -> ~[~str] {
|
||||
let link_args = reader::get_doc(reader::Doc(cdata.data), tag_link_args);
|
||||
let mut result = ~[];
|
||||
for reader::tagged_docs(link_args, tag_link_args_arg) |arg_doc| {
|
||||
result.push(reader::doc_as_str(arg_doc));
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
// mode: rust
|
||||
// fill-column: 78;
|
||||
|
@ -74,6 +74,7 @@ struct Stats {
|
||||
attr_bytes: uint,
|
||||
dep_bytes: uint,
|
||||
lang_item_bytes: uint,
|
||||
link_args_bytes: uint,
|
||||
item_bytes: uint,
|
||||
index_bytes: uint,
|
||||
zero_bytes: uint,
|
||||
@ -1064,7 +1065,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);
|
||||
assert elt.pos < 0xffff_ffff;
|
||||
fail_unless!(elt.pos < 0xffff_ffff);
|
||||
writer.write_be_u32(elt.pos as u32);
|
||||
write_fn(writer, elt.val);
|
||||
ebml_w.end_tag();
|
||||
@ -1074,7 +1075,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| {
|
||||
assert *pos < 0xffff_ffff;
|
||||
fail_unless!(*pos < 0xffff_ffff);
|
||||
writer.write_be_u32(*pos as u32);
|
||||
}
|
||||
ebml_w.end_tag();
|
||||
@ -1084,7 +1085,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) {
|
||||
assert n < 0x7fff_ffff;
|
||||
fail_unless!(n < 0x7fff_ffff);
|
||||
writer.write_be_u32(n as u32);
|
||||
}
|
||||
|
||||
@ -1145,8 +1146,8 @@ fn synthesize_crate_attrs(ecx: @EncodeContext,
|
||||
fn synthesize_link_attr(ecx: @EncodeContext, +items: ~[@meta_item]) ->
|
||||
attribute {
|
||||
|
||||
assert !ecx.link_meta.name.is_empty();
|
||||
assert !ecx.link_meta.vers.is_empty();
|
||||
fail_unless!(!ecx.link_meta.name.is_empty());
|
||||
fail_unless!(!ecx.link_meta.vers.is_empty());
|
||||
|
||||
let name_item =
|
||||
attr::mk_name_value_item_str(@~"name",
|
||||
@ -1212,7 +1213,7 @@ fn encode_crate_deps(ecx: @EncodeContext,
|
||||
// Sanity-check the crate numbers
|
||||
let mut expected_cnum = 1;
|
||||
for deps.each |n| {
|
||||
assert (n.cnum == expected_cnum);
|
||||
fail_unless!((n.cnum == expected_cnum));
|
||||
expected_cnum += 1;
|
||||
}
|
||||
|
||||
@ -1255,6 +1256,20 @@ fn encode_lang_items(ecx: @EncodeContext, ebml_w: writer::Encoder) {
|
||||
ebml_w.end_tag(); // tag_lang_items
|
||||
}
|
||||
|
||||
fn encode_link_args(ecx: @EncodeContext,
|
||||
ebml_w: writer::Encoder) {
|
||||
ebml_w.start_tag(tag_link_args);
|
||||
|
||||
let link_args = cstore::get_used_link_args(ecx.cstore);
|
||||
for link_args.each |link_arg| {
|
||||
ebml_w.start_tag(tag_link_args_arg);
|
||||
ebml_w.writer.write_str(link_arg.to_str());
|
||||
ebml_w.end_tag();
|
||||
}
|
||||
|
||||
ebml_w.end_tag();
|
||||
}
|
||||
|
||||
fn encode_crate_dep(ecx: @EncodeContext, ebml_w: writer::Encoder,
|
||||
dep: decoder::crate_dep) {
|
||||
ebml_w.start_tag(tag_crate_dep);
|
||||
@ -1291,6 +1306,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
|
||||
attr_bytes: 0,
|
||||
dep_bytes: 0,
|
||||
lang_item_bytes: 0,
|
||||
link_args_bytes: 0,
|
||||
item_bytes: 0,
|
||||
index_bytes: 0,
|
||||
zero_bytes: 0,
|
||||
@ -1329,6 +1345,11 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
|
||||
encode_lang_items(ecx, ebml_w);
|
||||
ecx.stats.lang_item_bytes = wr.pos - i;
|
||||
|
||||
// Encode the link args.
|
||||
i = wr.pos;
|
||||
encode_link_args(ecx, ebml_w);
|
||||
ecx.stats.link_args_bytes = wr.pos - i;
|
||||
|
||||
// Encode and index the items.
|
||||
ebml_w.start_tag(tag_items);
|
||||
i = wr.pos;
|
||||
@ -1359,6 +1380,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
|
||||
io::println(fmt!(" attribute bytes: %u", ecx.stats.attr_bytes));
|
||||
io::println(fmt!(" dep bytes: %u", ecx.stats.dep_bytes));
|
||||
io::println(fmt!(" lang item bytes: %u", ecx.stats.lang_item_bytes));
|
||||
io::println(fmt!(" link args bytes: %u", ecx.stats.link_args_bytes));
|
||||
io::println(fmt!(" item bytes: %u", ecx.stats.item_bytes));
|
||||
io::println(fmt!(" index bytes: %u", ecx.stats.index_bytes));
|
||||
io::println(fmt!(" zero bytes: %u", ecx.stats.zero_bytes));
|
||||
|
@ -140,12 +140,12 @@ fn parse_sigil(st: @mut PState) -> ast::Sigil {
|
||||
}
|
||||
|
||||
fn parse_vstore(st: @mut PState) -> ty::vstore {
|
||||
assert next(st) == '/';
|
||||
fail_unless!(next(st) == '/');
|
||||
|
||||
let c = peek(st);
|
||||
if '0' <= c && c <= '9' {
|
||||
let n = parse_int(st) as uint;
|
||||
assert next(st) == '|';
|
||||
fail_unless!(next(st) == '|');
|
||||
return ty::vstore_fixed(n);
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ fn parse_substs(st: @mut PState, conv: conv_did) -> ty::substs {
|
||||
|
||||
let self_ty = parse_opt(st, || parse_ty(st, conv) );
|
||||
|
||||
assert next(st) == '[';
|
||||
fail_unless!(next(st) == '[');
|
||||
let mut params: ~[ty::t] = ~[];
|
||||
while peek(st) != ']' { params.push(parse_ty(st, conv)); }
|
||||
st.pos = st.pos + 1u;
|
||||
@ -179,13 +179,13 @@ fn parse_bound_region(st: @mut PState) -> ty::bound_region {
|
||||
's' => ty::br_self,
|
||||
'a' => {
|
||||
let id = parse_int(st) as uint;
|
||||
assert next(st) == '|';
|
||||
fail_unless!(next(st) == '|');
|
||||
ty::br_anon(id)
|
||||
}
|
||||
'[' => ty::br_named(st.tcx.sess.ident_of(parse_str(st, ']'))),
|
||||
'c' => {
|
||||
let id = parse_int(st);
|
||||
assert next(st) == '|';
|
||||
fail_unless!(next(st) == '|');
|
||||
ty::br_cap_avoid(id, @parse_bound_region(st))
|
||||
},
|
||||
_ => fail!(~"parse_bound_region: bad input")
|
||||
@ -198,16 +198,16 @@ fn parse_region(st: @mut PState) -> ty::Region {
|
||||
ty::re_bound(parse_bound_region(st))
|
||||
}
|
||||
'f' => {
|
||||
assert next(st) == '[';
|
||||
fail_unless!(next(st) == '[');
|
||||
let id = parse_int(st);
|
||||
assert next(st) == '|';
|
||||
fail_unless!(next(st) == '|');
|
||||
let br = parse_bound_region(st);
|
||||
assert next(st) == ']';
|
||||
fail_unless!(next(st) == ']');
|
||||
ty::re_free(id, br)
|
||||
}
|
||||
's' => {
|
||||
let id = parse_int(st);
|
||||
assert next(st) == '|';
|
||||
fail_unless!(next(st) == '|');
|
||||
ty::re_scope(id)
|
||||
}
|
||||
't' => {
|
||||
@ -259,18 +259,18 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
|
||||
}
|
||||
'c' => return ty::mk_char(st.tcx),
|
||||
't' => {
|
||||
assert (next(st) == '[');
|
||||
fail_unless!((next(st) == '['));
|
||||
let def = parse_def(st, NominalType, conv);
|
||||
let substs = parse_substs(st, conv);
|
||||
assert next(st) == ']';
|
||||
fail_unless!(next(st) == ']');
|
||||
return ty::mk_enum(st.tcx, def, substs);
|
||||
}
|
||||
'x' => {
|
||||
assert next(st) == '[';
|
||||
fail_unless!(next(st) == '[');
|
||||
let def = parse_def(st, NominalType, conv);
|
||||
let substs = parse_substs(st, conv);
|
||||
let vstore = parse_vstore(st);
|
||||
assert next(st) == ']';
|
||||
fail_unless!(next(st) == ']');
|
||||
return ty::mk_trait(st.tcx, def, substs, vstore);
|
||||
}
|
||||
'p' => {
|
||||
@ -299,18 +299,8 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
|
||||
let v = parse_vstore(st);
|
||||
return ty::mk_estr(st.tcx, v);
|
||||
}
|
||||
'R' => {
|
||||
assert (next(st) == '[');
|
||||
let mut fields: ~[ty::field] = ~[];
|
||||
while peek(st) != ']' {
|
||||
let name = st.tcx.sess.ident_of(parse_str(st, '='));
|
||||
fields.push(ty::field { ident: name, mt: parse_mt(st, conv) });
|
||||
}
|
||||
st.pos = st.pos + 1u;
|
||||
return ty::mk_rec(st.tcx, fields);
|
||||
}
|
||||
'T' => {
|
||||
assert (next(st) == '[');
|
||||
fail_unless!((next(st) == '['));
|
||||
let mut params = ~[];
|
||||
while peek(st) != ']' { params.push(parse_ty(st, conv)); }
|
||||
st.pos = st.pos + 1u;
|
||||
@ -329,9 +319,9 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
|
||||
}
|
||||
'#' => {
|
||||
let pos = parse_hex(st);
|
||||
assert (next(st) == ':');
|
||||
fail_unless!((next(st) == ':'));
|
||||
let len = parse_hex(st);
|
||||
assert (next(st) == '#');
|
||||
fail_unless!((next(st) == '#'));
|
||||
let key = ty::creader_cache_key {cnum: st.crate,
|
||||
pos: pos,
|
||||
len: len };
|
||||
@ -352,10 +342,10 @@ fn parse_ty(st: @mut PState, conv: conv_did) -> ty::t {
|
||||
}
|
||||
'B' => ty::mk_opaque_box(st.tcx),
|
||||
'a' => {
|
||||
assert (next(st) == '[');
|
||||
fail_unless!((next(st) == '['));
|
||||
let did = parse_def(st, NominalType, conv);
|
||||
let substs = parse_substs(st, conv);
|
||||
assert (next(st) == ']');
|
||||
fail_unless!((next(st) == ']'));
|
||||
return ty::mk_struct(st.tcx, did, substs);
|
||||
}
|
||||
c => { error!("unexpected char in type string: %c", c); fail!();}
|
||||
@ -470,7 +460,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 {
|
||||
assert (next(st) == '[');
|
||||
fail_unless!((next(st) == '['));
|
||||
let mut inputs: ~[ty::arg] = ~[];
|
||||
while peek(st) != ']' {
|
||||
let mode = parse_mode(st);
|
||||
|
@ -283,15 +283,6 @@ fn enc_sty(w: io::Writer, cx: @ctxt, +st: ty::sty) {
|
||||
enc_vstore(w, cx, v);
|
||||
}
|
||||
ty::ty_unboxed_vec(mt) => { w.write_char('U'); enc_mt(w, cx, mt); }
|
||||
ty::ty_rec(fields) => {
|
||||
w.write_str(&"R[");
|
||||
for fields.each |field| {
|
||||
w.write_str(*cx.tcx.sess.str_of(field.ident));
|
||||
w.write_char('=');
|
||||
enc_mt(w, cx, field.mt);
|
||||
}
|
||||
w.write_char(']');
|
||||
}
|
||||
ty::ty_closure(ref f) => {
|
||||
w.write_char('f');
|
||||
enc_closure_ty(w, cx, f);
|
||||
|
@ -176,7 +176,7 @@ pub impl ExtendedDecodeContext {
|
||||
*/
|
||||
|
||||
// from_id_range should be non-empty
|
||||
assert !ast_util::empty(self.from_id_range);
|
||||
fail_unless!(!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 {
|
||||
@ -213,7 +213,7 @@ pub impl ExtendedDecodeContext {
|
||||
* refer to the current crate and to the new, inlined node-id.
|
||||
*/
|
||||
|
||||
assert did.crate == ast::local_crate;
|
||||
fail_unless!(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 {
|
||||
@ -1231,7 +1231,7 @@ fn roundtrip(in_item: Option<@ast::item>) {
|
||||
debug!("expected string: %s", exp_str);
|
||||
debug!("actual string : %s", out_str);
|
||||
|
||||
assert exp_str == out_str;
|
||||
fail_unless!(exp_str == out_str);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1278,8 +1278,10 @@ fn test_simplification() {
|
||||
).get());
|
||||
match (item_out, item_exp) {
|
||||
(ast::ii_item(item_out), ast::ii_item(item_exp)) => {
|
||||
assert pprust::item_to_str(item_out, ext_cx.parse_sess().interner)
|
||||
== pprust::item_to_str(item_exp, ext_cx.parse_sess().interner);
|
||||
fail_unless!(pprust::item_to_str(item_out,
|
||||
ext_cx.parse_sess().interner)
|
||||
== pprust::item_to_str(item_exp,
|
||||
ext_cx.parse_sess().interner));
|
||||
}
|
||||
_ => fail!()
|
||||
}
|
||||
|
@ -162,8 +162,7 @@ pub fn check_expr(sess: Session,
|
||||
expr_field(*) |
|
||||
expr_index(*) |
|
||||
expr_tup(*) |
|
||||
expr_struct(_, _, None) |
|
||||
expr_rec(_, None) => { }
|
||||
expr_struct(_, _, None) => { }
|
||||
expr_addr_of(*) => {
|
||||
sess.span_err(
|
||||
e.span,
|
||||
|
@ -132,7 +132,7 @@ pub fn raw_pat(p: @pat) -> @pat {
|
||||
}
|
||||
|
||||
pub fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) {
|
||||
assert(!pats.is_empty());
|
||||
fail_unless!((!pats.is_empty()));
|
||||
let ext = match is_useful(cx, &pats.map(|p| ~[*p]), ~[wild()]) {
|
||||
not_useful => {
|
||||
// This is good, wildcard pattern isn't reachable
|
||||
@ -319,8 +319,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
|
||||
_ => Some(single)
|
||||
}
|
||||
}
|
||||
pat_box(_) | pat_uniq(_) | pat_rec(_, _) | pat_tup(_) |
|
||||
pat_region(*) => {
|
||||
pat_box(_) | pat_uniq(_) | pat_tup(_) | pat_region(*) => {
|
||||
Some(single)
|
||||
}
|
||||
pat_vec(elems, tail) => {
|
||||
@ -352,7 +351,7 @@ pub fn missing_ctor(cx: @MatchCheckCtxt,
|
||||
-> Option<ctor> {
|
||||
match ty::get(left_ty).sty {
|
||||
ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_rptr(*) | ty::ty_tup(_) |
|
||||
ty::ty_rec(_) | ty::ty_struct(*) => {
|
||||
ty::ty_struct(*) => {
|
||||
for m.each |r| {
|
||||
if !is_wild(cx, r[0]) { return None; }
|
||||
}
|
||||
@ -449,7 +448,6 @@ pub fn missing_ctor(cx: @MatchCheckCtxt,
|
||||
pub fn ctor_arity(cx: @MatchCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
|
||||
match /*bad*/copy ty::get(ty).sty {
|
||||
ty::ty_tup(fs) => fs.len(),
|
||||
ty::ty_rec(fs) => fs.len(),
|
||||
ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_rptr(*) => 1u,
|
||||
ty::ty_enum(eid, _) => {
|
||||
let id = match ctor { variant(id) => id,
|
||||
@ -548,19 +546,6 @@ pub fn specialize(cx: @MatchCheckCtxt,
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
pat_rec(ref flds, _) => {
|
||||
let ty_flds = match /*bad*/copy ty::get(left_ty).sty {
|
||||
ty::ty_rec(flds) => flds,
|
||||
_ => fail!(~"bad type for pat_rec")
|
||||
};
|
||||
let args = vec::map(ty_flds, |ty_fld| {
|
||||
match flds.find(|f| f.ident == ty_fld.ident) {
|
||||
Some(f) => f.pat,
|
||||
_ => wild()
|
||||
}
|
||||
});
|
||||
Some(vec::append(args, vec::from_slice(r.tail())))
|
||||
}
|
||||
pat_struct(_, ref flds, _) => {
|
||||
// Is this a struct or an enum variant?
|
||||
match cx.tcx.def_map.get(&pat_id) {
|
||||
@ -722,9 +707,6 @@ pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
|
||||
false
|
||||
}
|
||||
pat_lit(_) | pat_range(_, _) => { true }
|
||||
pat_rec(fields, _) => {
|
||||
fields.any(|f| is_refutable(cx, f.pat))
|
||||
}
|
||||
pat_struct(_, fields, _) => {
|
||||
fields.any(|f| is_refutable(cx, f.pat))
|
||||
}
|
||||
|
@ -117,8 +117,7 @@ pub fn classify(e: @expr,
|
||||
}
|
||||
}
|
||||
|
||||
ast::expr_struct(_, ref fs, None) |
|
||||
ast::expr_rec(ref fs, None) => {
|
||||
ast::expr_struct(_, ref fs, None) => {
|
||||
let cs = do vec::map((*fs)) |f| {
|
||||
if f.node.mutbl == ast::m_imm {
|
||||
classify(f.node.expr, def_map, tcx)
|
||||
|
@ -73,7 +73,6 @@ pub enum lint {
|
||||
deprecated_mode,
|
||||
deprecated_pattern,
|
||||
non_camel_case_types,
|
||||
structural_records,
|
||||
type_limits,
|
||||
default_methods,
|
||||
deprecated_self,
|
||||
@ -217,13 +216,6 @@ pub fn get_lint_dict() -> LintDict {
|
||||
default: allow
|
||||
}),
|
||||
|
||||
(@~"structural_records",
|
||||
@LintSpec {
|
||||
lint: structural_records,
|
||||
desc: "use of any structural records",
|
||||
default: deny
|
||||
}),
|
||||
|
||||
(@~"legacy modes",
|
||||
@LintSpec {
|
||||
lint: legacy_modes,
|
||||
@ -486,7 +478,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
|
||||
check_item_path_statement(cx, i);
|
||||
check_item_non_camel_case_types(cx, i);
|
||||
check_item_heap(cx, i);
|
||||
check_item_structural_records(cx, i);
|
||||
check_item_deprecated_modes(cx, i);
|
||||
check_item_type_limits(cx, i);
|
||||
check_item_default_methods(cx, i);
|
||||
@ -729,24 +720,6 @@ fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_item_structural_records(cx: ty::ctxt, it: @ast::item) {
|
||||
let visit = item_stopping_visitor(
|
||||
visit::mk_simple_visitor(@visit::SimpleVisitor {
|
||||
visit_expr: |e: @ast::expr| {
|
||||
match e.node {
|
||||
ast::expr_rec(*) =>
|
||||
cx.sess.span_lint(
|
||||
structural_records, e.id, it.id,
|
||||
e.span,
|
||||
~"structural records are deprecated"),
|
||||
_ => ()
|
||||
}
|
||||
},
|
||||
.. *visit::default_simple_visitor()
|
||||
}));
|
||||
visit::visit_item(it, (), visit);
|
||||
}
|
||||
|
||||
fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
|
||||
|
||||
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,
|
||||
@ -899,7 +872,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);
|
||||
assert !ident.is_empty();
|
||||
fail_unless!(!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)) &&
|
||||
|
@ -615,16 +615,13 @@ fn visit_expr(expr: @expr, &&self: @mut IrMaps, vt: vt<@mut IrMaps>) {
|
||||
}
|
||||
|
||||
// otherwise, live nodes are not required:
|
||||
expr_index(*) | expr_field(*) | expr_vstore(*) |
|
||||
expr_vec(*) | expr_rec(*) | expr_call(*) | expr_method_call(*) |
|
||||
expr_tup(*) | expr_log(*) | expr_binary(*) |
|
||||
expr_assert(*) | expr_addr_of(*) | expr_copy(*) |
|
||||
expr_loop_body(*) | expr_do_body(*) | expr_cast(*) |
|
||||
expr_unary(*) |
|
||||
expr_break(_) | expr_again(_) | expr_lit(_) | expr_ret(*) |
|
||||
expr_block(*) | expr_assign(*) |
|
||||
expr_swap(*) | expr_assign_op(*) | expr_mac(*) | expr_struct(*) |
|
||||
expr_repeat(*) | expr_paren(*) => {
|
||||
expr_index(*) | expr_field(*) | expr_vstore(*) | expr_vec(*) |
|
||||
expr_call(*) | expr_method_call(*) | expr_tup(*) | expr_log(*) |
|
||||
expr_binary(*) | expr_addr_of(*) | expr_copy(*) | expr_loop_body(*) |
|
||||
expr_do_body(*) | expr_cast(*) | expr_unary(*) | expr_break(_) |
|
||||
expr_again(_) | expr_lit(_) | expr_ret(*) | expr_block(*) |
|
||||
expr_assign(*) | expr_swap(*) | expr_assign_op(*) | expr_mac(*) |
|
||||
expr_struct(*) | expr_repeat(*) | expr_paren(*) => {
|
||||
visit::visit_expr(expr, self, vt);
|
||||
}
|
||||
}
|
||||
@ -780,7 +777,7 @@ pub impl Liveness {
|
||||
fn live_on_entry(&self, ln: LiveNode, var: Variable)
|
||||
-> Option<LiveNodeKind> {
|
||||
|
||||
assert ln.is_valid();
|
||||
fail_unless!(ln.is_valid());
|
||||
let reader = self.users[self.idx(ln, var)].reader;
|
||||
if reader.is_valid() {Some(self.ir.lnk(reader))} else {None}
|
||||
}
|
||||
@ -795,14 +792,14 @@ pub impl Liveness {
|
||||
}
|
||||
|
||||
fn used_on_entry(&self, ln: LiveNode, var: Variable) -> bool {
|
||||
assert ln.is_valid();
|
||||
fail_unless!(ln.is_valid());
|
||||
self.users[self.idx(ln, var)].used
|
||||
}
|
||||
|
||||
fn assigned_on_entry(&self, ln: LiveNode, var: Variable)
|
||||
-> Option<LiveNodeKind> {
|
||||
|
||||
assert ln.is_valid();
|
||||
fail_unless!(ln.is_valid());
|
||||
let writer = self.users[self.idx(ln, var)].writer;
|
||||
if writer.is_valid() {Some(self.ir.lnk(writer))} else {None}
|
||||
}
|
||||
@ -1287,13 +1284,6 @@ pub impl Liveness {
|
||||
self.propagate_through_expr(element, succ)
|
||||
}
|
||||
|
||||
expr_rec(ref fields, with_expr) => {
|
||||
let succ = self.propagate_through_opt_expr(with_expr, succ);
|
||||
do (*fields).foldr(succ) |field, succ| {
|
||||
self.propagate_through_expr(field.node.expr, succ)
|
||||
}
|
||||
}
|
||||
|
||||
expr_struct(_, ref fields, with_expr) => {
|
||||
let succ = self.propagate_through_opt_expr(with_expr, succ);
|
||||
do (*fields).foldr(succ) |field, succ| {
|
||||
@ -1342,7 +1332,6 @@ pub impl Liveness {
|
||||
self.propagate_through_exprs(~[l, r], succ)
|
||||
}
|
||||
|
||||
expr_assert(e) |
|
||||
expr_addr_of(_, e) |
|
||||
expr_copy(e) |
|
||||
expr_loop_body(e) |
|
||||
@ -1503,11 +1492,12 @@ pub impl Liveness {
|
||||
// repeat until fixed point is reached:
|
||||
while self.merge_from_succ(ln, body_ln, first_merge) {
|
||||
first_merge = false;
|
||||
assert cond_ln == self.propagate_through_opt_expr(cond, ln);
|
||||
assert body_ln == self.with_loop_nodes(expr.id, succ, ln,
|
||||
fail_unless!(cond_ln == self.propagate_through_opt_expr(cond,
|
||||
ln));
|
||||
fail_unless!(body_ln == self.with_loop_nodes(expr.id, succ, ln,
|
||||
|| {
|
||||
self.propagate_through_block(body, cond_ln)
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
cond_ln
|
||||
@ -1618,18 +1608,14 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) {
|
||||
}
|
||||
|
||||
// no correctness conditions related to liveness
|
||||
expr_call(*) | expr_method_call(*) |
|
||||
expr_if(*) | expr_match(*) |
|
||||
expr_while(*) | expr_loop(*) |
|
||||
expr_index(*) | expr_field(*) | expr_vstore(*) |
|
||||
expr_vec(*) | expr_rec(*) | expr_tup(*) |
|
||||
expr_log(*) | expr_binary(*) |
|
||||
expr_assert(*) | expr_copy(*) |
|
||||
expr_loop_body(*) | expr_do_body(*) |
|
||||
expr_cast(*) | expr_unary(*) |
|
||||
expr_ret(*) | expr_break(*) | expr_again(*) | expr_lit(_) |
|
||||
expr_block(*) | expr_swap(*) | expr_mac(*) | expr_addr_of(*) |
|
||||
expr_struct(*) | expr_repeat(*) | expr_paren(*) => {
|
||||
expr_call(*) | expr_method_call(*) | expr_if(*) | expr_match(*) |
|
||||
expr_while(*) | expr_loop(*) | expr_index(*) | expr_field(*) |
|
||||
expr_vstore(*) | expr_vec(*) | expr_tup(*) | expr_log(*) |
|
||||
expr_binary(*) | expr_copy(*) | expr_loop_body(*) | expr_do_body(*) |
|
||||
expr_cast(*) | expr_unary(*) | expr_ret(*) | expr_break(*) |
|
||||
expr_again(*) | expr_lit(_) | expr_block(*) | expr_swap(*) |
|
||||
expr_mac(*) | expr_addr_of(*) | expr_struct(*) | expr_repeat(*) |
|
||||
expr_paren(*) => {
|
||||
visit::visit_expr(expr, self, vt);
|
||||
}
|
||||
}
|
||||
|
@ -437,19 +437,16 @@ pub impl mem_categorization_ctxt {
|
||||
|
||||
ast::expr_paren(e) => self.cat_expr_unadjusted(e),
|
||||
|
||||
ast::expr_addr_of(*) | ast::expr_call(*) |
|
||||
ast::expr_swap(*) | ast::expr_assign(*) |
|
||||
ast::expr_assign_op(*) | ast::expr_fn_block(*) |
|
||||
ast::expr_assert(*) | ast::expr_ret(*) |
|
||||
ast::expr_loop_body(*) | ast::expr_do_body(*) |
|
||||
ast::expr_unary(*) | ast::expr_method_call(*) |
|
||||
ast::expr_copy(*) | ast::expr_cast(*) |
|
||||
ast::expr_addr_of(*) | ast::expr_call(*) | ast::expr_swap(*) |
|
||||
ast::expr_assign(*) | ast::expr_assign_op(*) |
|
||||
ast::expr_fn_block(*) | ast::expr_ret(*) | ast::expr_loop_body(*) |
|
||||
ast::expr_do_body(*) | ast::expr_unary(*) |
|
||||
ast::expr_method_call(*) | ast::expr_copy(*) | ast::expr_cast(*) |
|
||||
ast::expr_vstore(*) | ast::expr_vec(*) | ast::expr_tup(*) |
|
||||
ast::expr_if(*) | ast::expr_log(*) |
|
||||
ast::expr_binary(*) | ast::expr_while(*) |
|
||||
ast::expr_block(*) | ast::expr_loop(*) | ast::expr_match(*) |
|
||||
ast::expr_lit(*) | ast::expr_break(*) | ast::expr_mac(*) |
|
||||
ast::expr_again(*) | ast::expr_rec(*) | ast::expr_struct(*) |
|
||||
ast::expr_if(*) | ast::expr_log(*) | ast::expr_binary(*) |
|
||||
ast::expr_while(*) | ast::expr_block(*) | ast::expr_loop(*) |
|
||||
ast::expr_match(*) | ast::expr_lit(*) | ast::expr_break(*) |
|
||||
ast::expr_mac(*) | ast::expr_again(*) | ast::expr_struct(*) |
|
||||
ast::expr_repeat(*) => {
|
||||
return self.cat_rvalue(expr, expr_ty);
|
||||
}
|
||||
@ -943,7 +940,6 @@ pub impl mem_categorization_ctxt {
|
||||
// nullary variant or identifier: ignore
|
||||
}
|
||||
|
||||
ast::pat_rec(ref field_pats, _) |
|
||||
ast::pat_struct(_, ref field_pats, _) => {
|
||||
// {f1: p1, ..., fN: pN}
|
||||
for field_pats.each |fp| {
|
||||
@ -1114,15 +1110,8 @@ pub fn field_mutbl(tcx: ty::ctxt,
|
||||
f_name: ast::ident,
|
||||
node_id: ast::node_id)
|
||||
-> Option<ast::mutability> {
|
||||
// Need to refactor so that records/class fields can be treated uniformly.
|
||||
// Need to refactor so that struct/enum fields can be treated uniformly.
|
||||
match /*bad*/copy ty::get(base_ty).sty {
|
||||
ty::ty_rec(fields) => {
|
||||
for fields.each |f| {
|
||||
if f.ident == f_name {
|
||||
return Some(f.mt.mutbl);
|
||||
}
|
||||
}
|
||||
}
|
||||
ty::ty_struct(did, _) => {
|
||||
for ty::lookup_struct_fields(tcx, did).each |fld| {
|
||||
if fld.ident == f_name {
|
||||
|
@ -469,7 +469,6 @@ pub impl VisitContext {
|
||||
self.use_fn_args(expr.callee_id, *args, visitor);
|
||||
}
|
||||
|
||||
expr_rec(ref fields, opt_with) |
|
||||
expr_struct(_, ref fields, opt_with) => {
|
||||
for fields.each |field| {
|
||||
self.consume_expr(field.node.expr, visitor);
|
||||
@ -480,7 +479,6 @@ pub impl VisitContext {
|
||||
// then `with` is consumed, otherwise it is only read
|
||||
let with_ty = ty::expr_ty(self.tcx, *with_expr);
|
||||
let with_fields = match ty::get(with_ty).sty {
|
||||
ty::ty_rec(ref f) => copy *f,
|
||||
ty::ty_struct(did, ref substs) => {
|
||||
ty::struct_fields(self.tcx, did, substs)
|
||||
}
|
||||
@ -573,10 +571,6 @@ pub impl VisitContext {
|
||||
self.use_expr(b_expr, Read, visitor);
|
||||
}
|
||||
|
||||
expr_assert(cond_expr) => {
|
||||
self.consume_expr(cond_expr, visitor);
|
||||
}
|
||||
|
||||
expr_while(cond_expr, ref blk) => {
|
||||
self.consume_expr(cond_expr, visitor);
|
||||
self.consume_block(blk, visitor);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user