rust/src/fuzzer/ast_match.rs

31 lines
883 B
Rust
Raw Normal View History

2011-07-08 02:16:46 -07:00
use std;
import vec;
2011-07-08 02:16:46 -07:00
fn vec_equal<T>(v: ~[T], u: ~[T],
element_equality_test: fn@(&&T, &&T) -> bool) ->
bool {
2011-08-15 16:38:23 -07:00
let Lv = vec::len(v);
if Lv != vec::len(u) { ret false; }
2011-07-27 14:19:39 +02:00
let i = 0u;
while i < Lv {
if !element_equality_test(v[i], u[i]) { ret false; }
2011-07-08 02:16:46 -07:00
i += 1u;
}
ret true;
}
2012-01-06 22:06:32 -08:00
pure fn builtin_equal<T>(&&a: T, &&b: T) -> bool { ret a == b; }
pure fn builtin_equal_int(&&a: int, &&b: int) -> bool { ret a == b; }
2011-07-08 02:16:46 -07:00
fn main() {
2011-07-27 14:19:39 +02:00
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));
2011-07-08 02:16:46 -07:00
error!{"Pass"};
}