|
| 1 | +// xfail-boot |
| 2 | +// xfail-stage0 |
| 3 | +// -*- rust -*- |
| 4 | + |
| 5 | +// Tests for standalone blocks as expressions with dynamic type sizes |
| 6 | + |
| 7 | +type compare[T] = fn(&T t1, &T t2) -> bool; |
| 8 | + |
| 9 | +fn test_generic[T](&T expected, &compare[T] eq) { |
| 10 | + let T actual = { expected }; |
| 11 | + check (eq(expected, actual)); |
| 12 | +} |
| 13 | + |
| 14 | +fn test_bool() { |
| 15 | + fn compare_bool(&bool b1, &bool b2) -> bool { |
| 16 | + ret b1 == b2; |
| 17 | + } |
| 18 | + auto eq = bind compare_bool(_, _); |
| 19 | + test_generic[bool](true, eq); |
| 20 | +} |
| 21 | + |
| 22 | + |
| 23 | +fn test_tup() { |
| 24 | + type t = tup(int, int); |
| 25 | + fn compare_tup(&t t1, &t t2) -> bool { |
| 26 | + ret t1 == t2; |
| 27 | + } |
| 28 | + auto eq = bind compare_tup(_, _); |
| 29 | + test_generic[t](tup(1, 2), eq); |
| 30 | +} |
| 31 | + |
| 32 | +fn test_vec() { |
| 33 | + fn compare_vec(&vec[int] v1, &vec[int] v2) -> bool { |
| 34 | + ret v1 == v2; |
| 35 | + } |
| 36 | + auto eq = bind compare_vec(_, _); |
| 37 | + test_generic[vec[int]](vec(1, 2), eq); |
| 38 | +} |
| 39 | + |
| 40 | +fn test_box() { |
| 41 | + fn compare_box(&@bool b1, &@bool b2) -> bool { |
| 42 | + ret *b1 == *b2; |
| 43 | + } |
| 44 | + auto eq = bind compare_box(_, _); |
| 45 | + test_generic[@bool](@true, eq); |
| 46 | +} |
| 47 | + |
| 48 | +fn main() { |
| 49 | + test_bool(); |
| 50 | + test_tup(); |
| 51 | + // FIXME: These two don't pass yet |
| 52 | + test_vec(); |
| 53 | + test_box(); |
| 54 | +} |
| 55 | + |
| 56 | + |
0 commit comments