Add tests for newtype-style tags

This commit is contained in:
Marijn Haverbeke 2011-07-01 15:55:20 +02:00
parent 432e5e9f7f
commit d863cdb98f
2 changed files with 26 additions and 0 deletions

View 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);
}

View 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);
}