Create a bunch of test cases for unique boxes by copying box tests

XFAIL the ones that don't work

Issue #409
This commit is contained in:
Brian Anderson 2011-09-23 14:58:06 -07:00
parent 2082f67765
commit 18b01d5cfe
23 changed files with 269 additions and 0 deletions

View file

@ -0,0 +1,10 @@
// error-pattern:fail
fn failfn() {
fail;
}
fn main() {
@0;
failfn();
}

View file

@ -0,0 +1,7 @@
// xfail-test
fn main() {
let x = ~{mutable a: ~10, b: ~20};
alt x {
~{a, b} { assert *a == 10; (*x).a = ~30; assert *a == 10; }
}
}

View file

@ -0,0 +1,18 @@
// xfail-test
// -*- rust -*-
type compare<T> = fn(~T, ~T) -> bool;
fn test_generic<T>(expected: ~T, eq: compare<T>) {
let actual: ~T = alt true { true { expected } };
assert (eq(expected, actual));
}
fn test_box() {
fn compare_box(b1: ~bool, b2: ~bool) -> bool { ret *b1 == *b2; }
let eq = bind compare_box(_, _);
test_generic::<bool>(~true, eq);
}
fn main() { test_box(); }

View file

@ -0,0 +1,18 @@
// -*- rust -*-
type compare<T> = fn(T, T) -> bool;
fn test_generic<T>(expected: T, eq: compare<T>) {
let actual: T = alt true { true { expected } };
assert (eq(expected, actual));
}
fn test_vec() {
fn compare_box(v1: ~int, v2: ~int) -> bool { ret v1 == v2; }
let eq = bind compare_box(_, _);
test_generic::<~int>(~1, eq);
}
fn main() { test_vec(); }

View file

@ -0,0 +1,9 @@
// -*- rust -*-
// Tests for alt as expressions resulting in boxed types
fn test_box() { let res = alt true { true { ~100 } }; assert (*res == 100); }
fn main() { test_box(); }

View file

@ -0,0 +1,22 @@
// xfail-test
// -*- rust -*-
type compare<T> = fn(~T, ~T) -> bool;
fn test_generic<T>(expected: ~T, eq: compare<T>) {
let actual: ~T = { expected };
assert (eq(expected, actual));
}
fn test_box() {
fn compare_box(b1: ~bool, b2: ~bool) -> bool {
log *b1;
log *b2;
ret *b1 == *b2;
}
let eq = bind compare_box(_, _);
test_generic::<bool>(~true, eq);
}
fn main() { test_box(); }

View file

@ -0,0 +1,18 @@
// -*- rust -*-
type compare<T> = fn(T, T) -> bool;
fn test_generic<T>(expected: T, eq: compare<T>) {
let actual: T = { expected };
assert (eq(expected, actual));
}
fn test_vec() {
fn compare_vec(v1: ~int, v2: ~int) -> bool { ret v1 == v2; }
let eq = bind compare_vec(_, _);
test_generic::<~int>(~1, eq);
}
fn main() { test_vec(); }

View file

@ -0,0 +1,5 @@
// -*- rust -*-
fn main() { let x = { ~100 }; assert (*x == 100); }

View file

@ -0,0 +1,12 @@
// -*- rust -*-
// Tests for if as expressions returning boxed types
fn test_box() {
let rs = if true { ~100 } else { ~101 };
assert (*rs == 100);
}
fn main() { test_box(); }

View file

@ -0,0 +1,18 @@
fn fix_help<A, ~B>(f: fn(fn(A) -> B, A) -> B, x: A) -> B {
ret f(bind fix_help(f, _), x);
}
fn fix<A, ~B>(f: fn(fn(A) -> B, A) -> B) -> fn(A) -> B {
ret bind fix_help(f, _);
}
fn fact_(f: fn(int) -> int, n: int) -> int {
// fun fact 0 = 1
ret if n == 0 { 1 } else { n * f(n - 1) };
}
fn main() {
let fact = fix(fact_);
assert (fact(5) == 120);
assert (fact(2) == 2);
}

View file

@ -0,0 +1,9 @@
// xfail-test
obj ob<K>(k: K) {
iter foo() -> ~{a: K} { put ~{a: k}; }
}
fn x(o: ob<str>) { for each i: ~{a: str} in o.foo() { } }
fn main() { let o = ob::<str>("hi" + "there"); x(o); }

View file

@ -0,0 +1,10 @@
fn id<~T>(t: T) -> T { ret t; }
fn main() {
let expected = ~100;
let actual = id::<~int>(expected);
log *actual;
assert (*expected == *actual);
}

View file

@ -0,0 +1,11 @@
type recbox<T> = {x: ~T};
fn reclift<T>(t: T) -> recbox<T> { ret {x: ~t}; }
fn main() {
let foo: int = 17;
let rbfoo: recbox<int> = reclift::<int>(foo);
assert (*rbfoo.x == foo);
}

View file

@ -0,0 +1,5 @@
// xfail-test
fn f<T>(x: ~T) -> ~T { ret x; }
fn main() { let x = f(~3); log *x; }

View file

@ -0,0 +1,8 @@
// xfail-test
fn box<T>(x: {x: T, y: T, z: T}) -> ~{x: T, y: T, z: T} { ret ~x; }
fn main() {
let x: ~{x: int, y: int, z: int} = box::<int>({x: 1, y: 2, z: 3});
assert (x.y == 2);
}

View file

@ -0,0 +1,5 @@
fn leaky<T>(t: T) { }
fn main() { let x = ~10; leaky::<~int>(x); }

View file

@ -0,0 +1,16 @@
// xfail-test
fn test(x: bool, foo: ~{x: int, y: int, z: int}) -> int {
let bar = foo;
let y: ~{x: int, y: int, z: int};
if x { y <- bar; } else { y = ~{x: 4, y: 5, z: 6}; }
ret y.y;
}
fn main() {
let x = ~{x: 1, y: 2, z: 3};
assert (test(true, x) == 2);
assert (test(true, x) == 2);
assert (test(true, x) == 2);
assert (test(false, x) == 5);
}

View file

@ -0,0 +1,3 @@
fn main() { let x = ~{x: 1, y: 2, z: 3}; let y <- x; assert (y.y == 2); }

View file

@ -0,0 +1,18 @@
// xfail-test
use std;
import std::uint;
fn test(x: bool, foo: ~{x: int, y: int, z: int}) -> int {
let bar = foo;
let y: ~{x: int, y: int, z: int};
if x { y <- bar; } else { y = ~{x: 4, y: 5, z: 6}; }
ret y.y;
}
fn main() {
let x = ~{x: 1, y: 2, z: 3};
for each i: uint in uint::range(0u, 10000u) {
assert (test(true, x) == 2);
}
assert (test(false, x) == 5);
}

View file

@ -0,0 +1,12 @@
// xfail-test
use std;
import std::uint;
fn test(foo: ~{a: int, b: int, c: int}) -> ~{a: int, b: int, c: int} {
let bar <- foo;
let baz <- bar;
let quux <- baz;
ret quux;
}
fn main() { let x = ~{a: 1, b: 2, c: 3}; let y = test(x); assert (y.c == 3); }

View file

@ -0,0 +1,10 @@
fn test(-foo: ~[int]) { assert (foo[0] == 10); }
fn main() {
let x = ~[10];
// Test forgetting a local by move-in
test(x);
// Test forgetting a temporary by move-in.
test(~[10]);
}

View file

@ -0,0 +1,11 @@
// xfail-test
type foo = {a: int, b: uint};
tag bar { u(~foo); w(int); }
fn main() {
assert (alt u(~{a: 10, b: 40u}) {
u(~{a: a, b: b}) { a + (b as int) }
_ { 66 }
} == 50);
}

View file

@ -0,0 +1,14 @@
// xfail-win32
use std;
import std::task;
fn f() {
task::unsupervise();
let a = ~0;
fail;
}
fn main() {
let g = f;
task::spawn(g);
}