Add tests for newtype-style tags
This commit is contained in:
parent
432e5e9f7f
commit
d863cdb98f
16
src/test/run-pass/newtype-polymorphic.rs
Normal file
16
src/test/run-pass/newtype-polymorphic.rs
Normal file
@ -0,0 +1,16 @@
|
||||
tag myvec[X] = vec[X];
|
||||
|
||||
fn myvec_deref[X](&myvec[X] mv) -> vec[X] {
|
||||
ret *mv;
|
||||
}
|
||||
|
||||
fn myvec_elt[X](&myvec[X] mv) -> X {
|
||||
ret mv.(0);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
auto mv = myvec([1, 2, 3]);
|
||||
assert(myvec_deref(mv).(1) == 2);
|
||||
assert(myvec_elt(mv) == 1);
|
||||
assert(mv.(2) == 3);
|
||||
}
|
10
src/test/run-pass/newtype.rs
Normal file
10
src/test/run-pass/newtype.rs
Normal file
@ -0,0 +1,10 @@
|
||||
tag mytype = rec(fn (&mytype i) -> int compute, int val);
|
||||
|
||||
fn compute(&mytype i) -> int {
|
||||
ret i.val + 20;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
auto myval = mytype(rec(compute=compute, val=30));
|
||||
assert(myval.compute(myval) == 50);
|
||||
}
|
Loading…
Reference in New Issue
Block a user