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:
parent
2082f67765
commit
18b01d5cfe
10
src/test/run-fail/unwind-unique.rs
Normal file
10
src/test/run-fail/unwind-unique.rs
Normal file
@ -0,0 +1,10 @@
|
||||
// error-pattern:fail
|
||||
|
||||
fn failfn() {
|
||||
fail;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@0;
|
||||
failfn();
|
||||
}
|
7
src/test/run-pass/alt-implicit-copy-unique.rs
Normal file
7
src/test/run-pass/alt-implicit-copy-unique.rs
Normal 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; }
|
||||
}
|
||||
}
|
18
src/test/run-pass/expr-alt-generic-unique1.rs
Normal file
18
src/test/run-pass/expr-alt-generic-unique1.rs
Normal 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(); }
|
18
src/test/run-pass/expr-alt-generic-unique2.rs
Normal file
18
src/test/run-pass/expr-alt-generic-unique2.rs
Normal 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(); }
|
9
src/test/run-pass/expr-alt-unique.rs
Normal file
9
src/test/run-pass/expr-alt-unique.rs
Normal 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(); }
|
22
src/test/run-pass/expr-block-generic-unique1.rs
Normal file
22
src/test/run-pass/expr-block-generic-unique1.rs
Normal 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(); }
|
18
src/test/run-pass/expr-block-generic-unique2.rs
Normal file
18
src/test/run-pass/expr-block-generic-unique2.rs
Normal 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(); }
|
5
src/test/run-pass/expr-block-unique.rs
Normal file
5
src/test/run-pass/expr-block-unique.rs
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
|
||||
// -*- rust -*-
|
||||
fn main() { let x = { ~100 }; assert (*x == 100); }
|
12
src/test/run-pass/expr-if-unique.rs
Normal file
12
src/test/run-pass/expr-if-unique.rs
Normal 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(); }
|
18
src/test/run-pass/fixed-point-bind-unique.rs
Normal file
18
src/test/run-pass/fixed-point-bind-unique.rs
Normal 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);
|
||||
}
|
9
src/test/run-pass/foreach-unique-drop.rs
Normal file
9
src/test/run-pass/foreach-unique-drop.rs
Normal 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); }
|
10
src/test/run-pass/generic-alias-unique.rs
Normal file
10
src/test/run-pass/generic-alias-unique.rs
Normal 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);
|
||||
}
|
11
src/test/run-pass/generic-exterior-unique.rs
Normal file
11
src/test/run-pass/generic-exterior-unique.rs
Normal 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);
|
||||
}
|
5
src/test/run-pass/generic-fn-unique.rs
Normal file
5
src/test/run-pass/generic-fn-unique.rs
Normal file
@ -0,0 +1,5 @@
|
||||
// xfail-test
|
||||
|
||||
fn f<T>(x: ~T) -> ~T { ret x; }
|
||||
|
||||
fn main() { let x = f(~3); log *x; }
|
8
src/test/run-pass/generic-unique.rs
Normal file
8
src/test/run-pass/generic-unique.rs
Normal 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);
|
||||
}
|
5
src/test/run-pass/leak-unique-as-tydesc.rs
Normal file
5
src/test/run-pass/leak-unique-as-tydesc.rs
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
fn leaky<T>(t: T) { }
|
||||
|
||||
fn main() { let x = ~10; leaky::<~int>(x); }
|
16
src/test/run-pass/move-1-unique.rs
Normal file
16
src/test/run-pass/move-1-unique.rs
Normal 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);
|
||||
}
|
3
src/test/run-pass/move-2-unique.rs
Normal file
3
src/test/run-pass/move-2-unique.rs
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
fn main() { let x = ~{x: 1, y: 2, z: 3}; let y <- x; assert (y.y == 2); }
|
18
src/test/run-pass/move-3-unique.rs
Normal file
18
src/test/run-pass/move-3-unique.rs
Normal 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);
|
||||
}
|
12
src/test/run-pass/move-4-unique.rs
Normal file
12
src/test/run-pass/move-4-unique.rs
Normal 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); }
|
10
src/test/run-pass/move-arg-2-unique.rs
Normal file
10
src/test/run-pass/move-arg-2-unique.rs
Normal 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]);
|
||||
}
|
11
src/test/run-pass/unique-pat-2.rs
Normal file
11
src/test/run-pass/unique-pat-2.rs
Normal 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);
|
||||
}
|
14
src/test/run-pass/unwind-unique.rs
Normal file
14
src/test/run-pass/unwind-unique.rs
Normal 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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user