mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-23 20:34:06 +00:00
Remove uses of tuples from the test suite
This commit is contained in:
parent
aea537779e
commit
f8968d1e71
@ -21,24 +21,24 @@ obj myrandom(mutable u32 last) {
|
||||
}
|
||||
}
|
||||
|
||||
type aminoacids = tup(char, u32);
|
||||
type aminoacids = rec(char ch, u32 prob);
|
||||
|
||||
fn make_cumulative(vec[aminoacids] aa) -> vec[aminoacids] {
|
||||
let u32 cp = 0u32;
|
||||
let vec[aminoacids] ans = [];
|
||||
for (aminoacids a in aa) { cp += a._1; ans += [tup(a._0, cp)]; }
|
||||
for (aminoacids a in aa) { cp += a.prob; ans += [rec(ch=a.ch, prob=cp)]; }
|
||||
ret ans;
|
||||
}
|
||||
|
||||
fn select_random(u32 r, vec[aminoacids] genelist) -> char {
|
||||
if (r < genelist.(0)._1) { ret genelist.(0)._0; }
|
||||
if (r < genelist.(0).prob) { ret genelist.(0).ch; }
|
||||
fn bisect(vec[aminoacids] v, uint lo, uint hi, u32 target) -> char {
|
||||
if (hi > lo + 1u) {
|
||||
let uint mid = lo + (hi - lo) / 2u;
|
||||
if (target < v.(mid)._1) {
|
||||
if (target < v.(mid).prob) {
|
||||
be bisect(v, lo, mid, target);
|
||||
} else { be bisect(v, mid, hi, target); }
|
||||
} else { ret v.(hi)._0; }
|
||||
} else { ret v.(hi).ch; }
|
||||
}
|
||||
ret bisect(genelist, 0u, vec::len[aminoacids](genelist) - 1u, r);
|
||||
}
|
||||
@ -65,16 +65,18 @@ fn make_repeat_fasta(str id, str desc, str s, int n) {
|
||||
if (str::byte_len(op) > 0u) { log op; }
|
||||
}
|
||||
|
||||
fn acid(char ch, u32 prob) { ret rec(ch=ch, prob=prob); }
|
||||
|
||||
fn main(vec[str] args) {
|
||||
let vec[aminoacids] iub =
|
||||
make_cumulative([tup('a', 27u32), tup('c', 12u32), tup('g', 12u32),
|
||||
tup('t', 27u32), tup('B', 2u32), tup('D', 2u32),
|
||||
tup('H', 2u32), tup('K', 2u32), tup('M', 2u32),
|
||||
tup('N', 2u32), tup('R', 2u32), tup('S', 2u32),
|
||||
tup('V', 2u32), tup('W', 2u32), tup('Y', 2u32)]);
|
||||
make_cumulative([acid('a', 27u32), acid('c', 12u32), acid('g', 12u32),
|
||||
acid('t', 27u32), acid('B', 2u32), acid('D', 2u32),
|
||||
acid('H', 2u32), acid('K', 2u32), acid('M', 2u32),
|
||||
acid('N', 2u32), acid('R', 2u32), acid('S', 2u32),
|
||||
acid('V', 2u32), acid('W', 2u32), acid('Y', 2u32)]);
|
||||
let vec[aminoacids] homosapiens =
|
||||
make_cumulative([tup('a', 30u32), tup('c', 20u32), tup('g', 20u32),
|
||||
tup('t', 30u32)]);
|
||||
make_cumulative([acid('a', 30u32), acid('c', 20u32), acid('g', 20u32),
|
||||
acid('t', 30u32)]);
|
||||
let str alu =
|
||||
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
|
||||
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
|
||||
|
@ -134,9 +134,10 @@ mod map_reduce {
|
||||
|
||||
map(input, bind emit(intermediates, ctrl, _, _));
|
||||
|
||||
for each(@tup(str, chan[reduce_proto]) kv in intermediates.items()) {
|
||||
for each(@rec(str key, chan[reduce_proto] val) kv
|
||||
in intermediates.items()) {
|
||||
// log_err "sending done to reducer for " + kv._0;
|
||||
kv._1 <| release;
|
||||
kv.val <| release;
|
||||
}
|
||||
|
||||
ctrl <| mapper_done;
|
||||
@ -228,9 +229,10 @@ mod map_reduce {
|
||||
}
|
||||
}
|
||||
|
||||
for each(@tup(str, chan[reduce_proto]) kv in reducers.items()) {
|
||||
for each(@rec(str key, chan[reduce_proto] val) kv
|
||||
in reducers.items()) {
|
||||
// log_err "sending done to reducer for " + kv._0;
|
||||
kv._1 <| done;
|
||||
kv.val <| done;
|
||||
}
|
||||
|
||||
// log_err #fmt("joining %u tasks", ivec::len(tasks));
|
||||
|
@ -1,7 +1,7 @@
|
||||
// xfail-stage0
|
||||
// error-pattern:+ cannot be applied to type `tup(bool)`
|
||||
// error-pattern:+ cannot be applied to type `rec(bool x)`
|
||||
|
||||
fn main() {
|
||||
auto x = tup(true);
|
||||
x += tup(false);
|
||||
auto x = rec(x=true);
|
||||
x += rec(x=false);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// xfail-stage0
|
||||
// error-pattern:+ cannot be applied to type `tup(bool)`
|
||||
// error-pattern:+ cannot be applied to type `rec(bool x)`
|
||||
|
||||
fn main() {
|
||||
auto x = tup(true) + tup(false);
|
||||
auto x = rec(x=true) + rec(x=false);
|
||||
}
|
@ -9,9 +9,10 @@ type var_info = rec(uint a, uint b);
|
||||
fn bitv_to_str(fn_info enclosing, bitv::t v) -> str {
|
||||
auto s = "";
|
||||
|
||||
// error is that the value type in the hash map is var_info, not a tuple
|
||||
for each (@tup(uint, tup(uint, uint)) p in enclosing.vars.items()) {
|
||||
if (bitv::get(v, p._1._0)) {
|
||||
// error is that the value type in the hash map is var_info, not a box
|
||||
for each (@rec(uint key, @uint val) p
|
||||
in enclosing.vars.items()) {
|
||||
if (bitv::get(v, *p.val)) {
|
||||
s += "foo";
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
mod foo {
|
||||
fn bar[T](T f) -> int { ret 17; }
|
||||
type bar[U, T] = tup(int, U, T);
|
||||
type bar[U, T] = rec(int a, U b, T c);
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,5 +0,0 @@
|
||||
// error-pattern: assignment to immutable field
|
||||
fn main() {
|
||||
let tup(int) t = tup(1);
|
||||
t._0 = 5;
|
||||
}
|
@ -4,12 +4,11 @@
|
||||
// xfail-stage3
|
||||
// -*- rust -*-
|
||||
|
||||
fn f(chan[int] c)
|
||||
{
|
||||
type t = tup(int,int,int);
|
||||
fn f(chan[int] c) {
|
||||
type t = rec(int _0, int _1, int _2);
|
||||
|
||||
// Allocate a box.
|
||||
let @t x = @tup(1,2,3);
|
||||
let @t x = @rec(_0=1, _1=2, _2=3);
|
||||
|
||||
// Signal parent that we've allocated a box.
|
||||
c <| 1;
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
|
||||
// -*- rust -*-
|
||||
fn f[T, U](&T x, &U y) -> tup(T, U) { ret tup(x, y); }
|
||||
fn f[T, U](&T x, &U y) -> rec(T a, U b) { ret rec(a=x, b=y); }
|
||||
|
||||
fn main() { log f(tup(3, 4, 5), 4)._0._0; log f(5, 6)._0; }
|
||||
fn main() { log f(rec(x=3, y=4, z=5), 4).a.x; log f(5, 6).a; }
|
@ -4,7 +4,7 @@
|
||||
// -*- rust -*-
|
||||
type clam = rec(@int x, @int y);
|
||||
|
||||
type fish = tup(@int);
|
||||
type fish = rec(@int a);
|
||||
|
||||
fn main() {
|
||||
let clam a = rec(x=@1, y=@2);
|
||||
@ -12,9 +12,9 @@ fn main() {
|
||||
let int z = a.x + b.y;
|
||||
log z;
|
||||
assert (z == 21);
|
||||
let fish forty = tup(@40);
|
||||
let fish two = tup(@2);
|
||||
let int answer = forty._0 + two._0;
|
||||
let fish forty = rec(a=@40);
|
||||
let fish two = rec(a=@2);
|
||||
let int answer = forty.a + two.a;
|
||||
log answer;
|
||||
assert (answer == 42);
|
||||
}
|
@ -54,7 +54,7 @@ fn test_char() {
|
||||
fn test_box() {
|
||||
assert @10 == 10;
|
||||
assert 0xFF & @0xF0 == 0xF0;
|
||||
assert tup(1, 3) < @tup(1, 4);
|
||||
assert rec(a=1, b=3) < @rec(a=1, b=4);
|
||||
assert @rec(a = 'x') != @rec(a = 'y');
|
||||
}
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
|
||||
|
||||
fn main() { let tup(mutable @int) i = tup(mutable @10); i._0 = @11; }
|
@ -1,12 +1,12 @@
|
||||
|
||||
|
||||
type box[T] = tup(@T);
|
||||
type box[T] = rec(@T c);
|
||||
|
||||
fn unbox[T](&box[T] b) -> T { ret *b._0; }
|
||||
fn unbox[T](&box[T] b) -> T { ret *b.c; }
|
||||
|
||||
fn main() {
|
||||
let int foo = 17;
|
||||
let box[int] bfoo = tup(@foo);
|
||||
let box[int] bfoo = rec(c=@foo);
|
||||
log "see what's in our box";
|
||||
assert (unbox[int](bfoo) == foo);
|
||||
}
|
@ -15,12 +15,12 @@ fn test_bool() {
|
||||
test_generic[bool](true, eq);
|
||||
}
|
||||
|
||||
fn test_tup() {
|
||||
type t = tup(int, int);
|
||||
fn test_rec() {
|
||||
type t = rec(int a, int b);
|
||||
|
||||
fn compare_tup(&t t1, &t t2) -> bool { ret t1 == t2; }
|
||||
auto eq = bind compare_tup(_, _);
|
||||
test_generic[t](tup(1, 2), eq);
|
||||
fn compare_rec(&t t1, &t t2) -> bool { ret t1 == t2; }
|
||||
auto eq = bind compare_rec(_, _);
|
||||
test_generic[t](rec(a=1, b=2), eq);
|
||||
}
|
||||
|
||||
fn main() { test_bool(); test_tup(); }
|
||||
fn main() { test_bool(); test_rec(); }
|
@ -17,12 +17,12 @@ fn test_bool() {
|
||||
test_generic[bool](true, eq);
|
||||
}
|
||||
|
||||
fn test_tup() {
|
||||
type t = tup(int, int);
|
||||
fn test_rec() {
|
||||
type t = rec(int a, int b);
|
||||
|
||||
fn compare_tup(&t t1, &t t2) -> bool { ret t1 == t2; }
|
||||
auto eq = bind compare_tup(_, _);
|
||||
test_generic[t](tup(1, 2), eq);
|
||||
fn compare_rec(&t t1, &t t2) -> bool { ret t1 == t2; }
|
||||
auto eq = bind compare_rec(_, _);
|
||||
test_generic[t](rec(a=1, b=2), eq);
|
||||
}
|
||||
|
||||
fn main() { test_bool(); test_tup(); }
|
||||
fn main() { test_bool(); test_rec(); }
|
@ -5,8 +5,8 @@
|
||||
|
||||
// Regression test for issue #377
|
||||
fn main() {
|
||||
auto a = { auto b = tup(3); b };
|
||||
assert (a._0 == 3);
|
||||
auto a = { auto b = rec(a=3); b };
|
||||
assert (a.a == 3);
|
||||
auto c = { auto d = rec(v=3); d };
|
||||
assert (c.v == 3);
|
||||
}
|
@ -17,12 +17,12 @@ fn test_bool() {
|
||||
test_generic[bool](true, false, eq);
|
||||
}
|
||||
|
||||
fn test_tup() {
|
||||
type t = tup(int, int);
|
||||
fn test_rec() {
|
||||
type t = rec(int a, int b);
|
||||
|
||||
fn compare_tup(&t t1, &t t2) -> bool { ret t1 == t2; }
|
||||
auto eq = bind compare_tup(_, _);
|
||||
test_generic[t](tup(1, 2), tup(2, 3), eq);
|
||||
fn compare_rec(&t t1, &t t2) -> bool { ret t1 == t2; }
|
||||
auto eq = bind compare_rec(_, _);
|
||||
test_generic[t](rec(a=1, b=2), rec(a=2, b=3), eq);
|
||||
}
|
||||
|
||||
fn main() { test_bool(); test_tup(); }
|
||||
fn main() { test_bool(); test_rec(); }
|
@ -1,9 +1,9 @@
|
||||
|
||||
|
||||
obj ob[K](K k) {
|
||||
iter foo() -> @tup(K) { put @tup(k); }
|
||||
iter foo() -> @rec(K a) { put @rec(a=k); }
|
||||
}
|
||||
|
||||
fn x(&ob[str] o) { for each (@tup(str) i in o.foo()) { } }
|
||||
fn x(&ob[str] o) { for each (@rec(str a) i in o.foo()) { } }
|
||||
|
||||
fn main() { auto o = ob[str]("hi" + "there"); x(o); }
|
@ -1,15 +1,15 @@
|
||||
|
||||
|
||||
iter pairs() -> tup(int, int) {
|
||||
iter pairs() -> rec(int _0, int _1) {
|
||||
let int i = 0;
|
||||
let int j = 0;
|
||||
while (i < 10) { put tup(i, j); i += 1; j += i; }
|
||||
while (i < 10) { put rec(_0=i, _1=j); i += 1; j += i; }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let int i = 10;
|
||||
let int j = 0;
|
||||
for each (tup(int, int) p in pairs()) {
|
||||
for each (rec(int _0, int _1) p in pairs()) {
|
||||
log p._0;
|
||||
log p._1;
|
||||
assert (p._0 + 10 == i);
|
||||
|
@ -3,8 +3,8 @@
|
||||
fn id[T](&T t) -> T { ret t; }
|
||||
|
||||
fn main() {
|
||||
auto t = tup(1, 2, 3, 4, 5, 6, 7);
|
||||
assert (t._5 == 6);
|
||||
auto f0 = bind id[tup(int, int, int, int, int, int, int)](t);
|
||||
assert (f0()._5 == 6);
|
||||
auto t = rec(a=1, b=2, c=3, d=4, e=5, f=6, g=7);
|
||||
assert (t.f == 6);
|
||||
auto f0 = bind id(t);
|
||||
assert (f0().f == 6);
|
||||
}
|
@ -3,8 +3,9 @@
|
||||
fn id[T](&T t) -> T { ret t; }
|
||||
|
||||
fn main() {
|
||||
auto t = tup(1, 2, 3, 4, 5, 6, 7);
|
||||
auto t = rec(_0=1, _1=2, _2=3, _3=4, _4=5, _5=6, _6=7);
|
||||
assert (t._5 == 6);
|
||||
auto f1 = bind id[tup(int, int, int, int, int, int, int)](_);
|
||||
auto f1 = bind id[rec(int _0, int _1, int _2, int _3, int _4,
|
||||
int _5, int _6)](_);
|
||||
assert (f1(t)._5 == 6);
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
|
||||
|
||||
fn box[T](&tup(T, T, T) x) -> @tup(T, T, T) { ret @x; }
|
||||
fn box[T](&rec(T x, T y, T z) x) -> @rec(T x, T y, T z) { ret @x; }
|
||||
|
||||
fn main() {
|
||||
let @tup(int, int, int) x = box[int](tup(1, 2, 3));
|
||||
assert (x._1 == 2);
|
||||
let @rec(int x, int y, int z) x = box[int](rec(x=1, y=2, z=3));
|
||||
assert (x.y == 2);
|
||||
}
|
@ -2,17 +2,17 @@
|
||||
|
||||
fn g[X](&X x) -> X { ret x; }
|
||||
|
||||
fn f[T](&T t) -> tup(T, T) {
|
||||
type pair = tup(T, T);
|
||||
fn f[T](&T t) -> rec(T a, T b) {
|
||||
type pair = rec(T a, T b);
|
||||
|
||||
let pair x = tup(t, t);
|
||||
let pair x = rec(a=t, b=t);
|
||||
ret g[pair](x);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
auto b = f[int](10);
|
||||
log b._0;
|
||||
log b._1;
|
||||
assert (b._0 == 10);
|
||||
assert (b._1 == 10);
|
||||
log b.a;
|
||||
log b.b;
|
||||
assert (b.a == 10);
|
||||
assert (b.b == 10);
|
||||
}
|
@ -1,17 +1,11 @@
|
||||
|
||||
|
||||
type tupbox[T] = tup(@T);
|
||||
|
||||
type recbox[T] = rec(@T x);
|
||||
|
||||
fn tuplift[T](&T t) -> tupbox[T] { ret tup(@t); }
|
||||
|
||||
fn reclift[T](&T t) -> recbox[T] { ret rec(x=@t); }
|
||||
|
||||
fn main() {
|
||||
let int foo = 17;
|
||||
let tupbox[int] tbfoo = tuplift[int](foo);
|
||||
let recbox[int] rbfoo = reclift[int](foo);
|
||||
assert (tbfoo._0 == foo);
|
||||
assert (rbfoo.x == foo);
|
||||
}
|
@ -4,15 +4,15 @@
|
||||
// -*- rust -*-
|
||||
fn id[T](&T x) -> T { ret x; }
|
||||
|
||||
type triple = tup(int, int, int);
|
||||
type triple = rec(int x, int y, int z);
|
||||
|
||||
fn main() {
|
||||
auto x = 62;
|
||||
auto y = 63;
|
||||
auto a = 'a';
|
||||
auto b = 'b';
|
||||
let triple p = tup(65, 66, 67);
|
||||
let triple q = tup(68, 69, 70);
|
||||
let triple p = rec(x=65, y=66, z=67);
|
||||
let triple q = rec(x=68, y=69, z=70);
|
||||
y = id[int](x);
|
||||
log y;
|
||||
assert (x == y);
|
||||
@ -20,8 +20,8 @@ fn main() {
|
||||
log b;
|
||||
assert (a == b);
|
||||
q = id[triple](p);
|
||||
x = p._2;
|
||||
y = q._2;
|
||||
x = p.z;
|
||||
y = q.z;
|
||||
log y;
|
||||
assert (x == y);
|
||||
}
|
@ -5,14 +5,16 @@ obj handle[T](T data) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
type rgb = tup(u8, u8, u8);
|
||||
type rgb = rec(u8 x, u8 y, u8 z);
|
||||
|
||||
let handle[rgb] h = handle[rgb](tup(1 as u8, 2 as u8, 3 as u8));
|
||||
let handle[rgb] h = handle[rgb](rec(x=1 as u8,
|
||||
y=2 as u8,
|
||||
z=3 as u8));
|
||||
log "constructed object";
|
||||
log h.get()._0;
|
||||
log h.get()._1;
|
||||
log h.get()._2;
|
||||
assert (h.get()._0 == 1 as u8);
|
||||
assert (h.get()._1 == 2 as u8);
|
||||
assert (h.get()._2 == 3 as u8);
|
||||
log h.get().x;
|
||||
log h.get().y;
|
||||
log h.get().z;
|
||||
assert (h.get().x == 1 as u8);
|
||||
assert (h.get().y == 2 as u8);
|
||||
assert (h.get().z == 3 as u8);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
obj buf[T](tup(T, T, T) data) {
|
||||
obj buf[T](rec(T _0, T _1, T _2) data) {
|
||||
fn get(int i) -> T {
|
||||
if (i == 0) {
|
||||
ret data._0;
|
||||
@ -11,7 +11,7 @@ obj buf[T](tup(T, T, T) data) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let buf[int] b = buf[int](tup(1, 2, 3));
|
||||
let buf[int] b = buf[int](rec(_0=1, _1=2, _2=3));
|
||||
log "constructed object";
|
||||
log b.get(0);
|
||||
log b.get(1);
|
||||
|
@ -7,13 +7,13 @@ tag noption[T] { some(T); }
|
||||
fn main() {
|
||||
let noption[int] nop = some[int](5);
|
||||
alt (nop) { case (some[int](?n)) { log n; assert (n == 5); } }
|
||||
let noption[tup(int, int)] nop2 = some[tup(int, int)](tup(17, 42));
|
||||
let noption[rec(int x, int y)] nop2 = some(rec(x=17, y=42));
|
||||
alt (nop2) {
|
||||
case (some[tup(int, int)](?t)) {
|
||||
log t._0;
|
||||
log t._1;
|
||||
assert (t._0 == 17);
|
||||
assert (t._1 == 42);
|
||||
case (some(?t)) {
|
||||
log t.x;
|
||||
log t.y;
|
||||
assert (t.x == 17);
|
||||
assert (t.y == 42);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
|
||||
|
||||
fn get_third[T](&tup(T, T, T) t) -> T { ret t._2; }
|
||||
|
||||
fn main() {
|
||||
log get_third(tup(1, 2, 3));
|
||||
assert (get_third(tup(1, 2, 3)) == 3);
|
||||
assert (get_third(tup(5u8, 6u8, 7u8)) == 7u8);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
type foo[T] = tup(T);
|
||||
type foo[T] = rec(T a);
|
||||
|
||||
type bar[T] = foo[T];
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
|
||||
|
||||
type pair[T] = tup(T, T);
|
||||
type pair[T] = rec(T x, T y);
|
||||
|
||||
fn main() {
|
||||
let pair[int] x = tup(10, 12);
|
||||
assert (x._0 == 10);
|
||||
assert (x._1 == 12);
|
||||
let pair[int] x = rec(x=10, y=12);
|
||||
assert (x.x == 10);
|
||||
assert (x.y == 12);
|
||||
}
|
@ -7,14 +7,14 @@
|
||||
// -*- rust -*-
|
||||
use std;
|
||||
|
||||
type cell = tup(mutable @list);
|
||||
type cell = rec(mutable @list c);
|
||||
|
||||
tag list { link(@cell); nil; }
|
||||
|
||||
fn main() {
|
||||
let @cell first = @tup(mutable @nil());
|
||||
let @cell second = @tup(mutable @link(first));
|
||||
let @cell first = @rec(mutable c=@nil());
|
||||
let @cell second = @rec(mutable c=@link(first));
|
||||
first._0 = @link(second);
|
||||
std::sys.rustrt.gc();
|
||||
let @cell third = @tup(mutable @nil());
|
||||
let @cell third = @rec(mutable c=@nil());
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
fn test(bool x, @tup(int, int, int) foo) -> int {
|
||||
fn test(bool x, @rec(int x, int y, int z) foo) -> int {
|
||||
auto bar = foo;
|
||||
let @tup(int,int,int) y;
|
||||
let @rec(int x,int y, int z) y;
|
||||
if (x) {
|
||||
y <- bar;
|
||||
} else {
|
||||
y = @tup(4,5,6);
|
||||
y = @rec(x=4, y=5, z=6);
|
||||
}
|
||||
ret y._1;
|
||||
ret y.y;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
auto x = @tup(1,2,3);
|
||||
auto x = @rec(x=1, y=2, z=3);
|
||||
assert (test(true, x) == 2);
|
||||
assert (test(true, x) == 2);
|
||||
assert (test(true, x) == 2);
|
||||
|
@ -1,3 +1,7 @@
|
||||
|
||||
|
||||
fn main() { auto x = @tup(1, 2, 3); auto y <- x; assert (y._1 == 2); }
|
||||
fn main() {
|
||||
auto x = @rec(x=1, y=2, z=3);
|
||||
auto y <- x;
|
||||
assert (y.y == 2);
|
||||
}
|
@ -1,19 +1,19 @@
|
||||
use std;
|
||||
import std::uint;
|
||||
|
||||
fn test(bool x, @tup(int, int, int) foo) -> int {
|
||||
fn test(bool x, @rec(int x, int y, int z) foo) -> int {
|
||||
auto bar = foo;
|
||||
let @tup(int,int,int) y;
|
||||
let @rec(int x, int y, int z) y;
|
||||
if (x) {
|
||||
y <- bar;
|
||||
} else {
|
||||
y = @tup(4,5,6);
|
||||
y = @rec(x=4, y=5, z=6);
|
||||
}
|
||||
ret y._1;
|
||||
ret y.y;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
auto x = @tup(1,2,3);
|
||||
auto x = @rec(x=1, y=2, z=3);
|
||||
for each (uint i in uint::range(0u, 10000u)) {
|
||||
assert (test(true, x) == 2);
|
||||
}
|
||||
|
@ -2,11 +2,15 @@
|
||||
use std;
|
||||
import std::uint;
|
||||
|
||||
fn test(@tup(int, int, int) foo) -> @tup(int, int, int) {
|
||||
fn test(@rec(int a, int b, int c) foo) -> @rec(int a, int b, int c) {
|
||||
auto bar <- foo;
|
||||
auto baz <- bar;
|
||||
auto quux <- baz;
|
||||
ret quux;
|
||||
}
|
||||
|
||||
fn main() { auto x = @tup(1, 2, 3); auto y = test(x); assert (y._2 == 3); }
|
||||
fn main() {
|
||||
auto x = @rec(a=1, b=2, c=3);
|
||||
auto y = test(x);
|
||||
assert (y.c == 3);
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
|
||||
|
||||
fn main() {
|
||||
// This just tests whether the vec leaks its members.
|
||||
|
||||
let vec[mutable @tup(int, int)] pvec =
|
||||
[mutable @tup(1, 2), @tup(3, 4), @tup(5, 6)];
|
||||
let vec[mutable @rec(int a, int b)] pvec =
|
||||
[mutable @rec(a=1, b=2), @rec(a=3, b=4), @rec(a=5, b=6)];
|
||||
}
|
@ -4,21 +4,21 @@ fn ret_int_i() -> int { ret 10; }
|
||||
|
||||
fn ret_ext_i() -> @int { ret @10; }
|
||||
|
||||
fn ret_int_tup() -> tup(int, int) { ret tup(10, 10); }
|
||||
fn ret_int_rec() -> rec(int a, int b) { ret rec(a=10, b=10); }
|
||||
|
||||
fn ret_ext_tup() -> @tup(int, int) { ret @tup(10, 10); }
|
||||
fn ret_ext_rec() -> @rec(int a, int b) { ret @rec(a=10, b=10); }
|
||||
|
||||
fn ret_ext_mem() -> tup(@int, @int) { ret tup(@10, @10); }
|
||||
fn ret_ext_mem() -> rec(@int a, @int b) { ret rec(a=@10, b=@10); }
|
||||
|
||||
fn ret_ext_ext_mem() -> @tup(@int, @int) { ret @tup(@10, @10); }
|
||||
fn ret_ext_ext_mem() -> @rec(@int a, @int b) { ret @rec(a=@10, b=@10); }
|
||||
|
||||
fn main() {
|
||||
let int int_i;
|
||||
let @int ext_i;
|
||||
let tup(int, int) int_tup;
|
||||
let @tup(int, int) ext_tup;
|
||||
let tup(@int, @int) ext_mem;
|
||||
let @tup(@int, @int) ext_ext_mem;
|
||||
let rec(int a, int b) int_rec;
|
||||
let @rec(int a, int b) ext_rec;
|
||||
let rec(@int a, @int b) ext_mem;
|
||||
let @rec(@int a, @int b) ext_ext_mem;
|
||||
int_i = ret_int_i(); // initializing
|
||||
|
||||
int_i = ret_int_i(); // non-initializing
|
||||
@ -31,17 +31,17 @@ fn main() {
|
||||
|
||||
ext_i = ret_ext_i(); // non-initializing
|
||||
|
||||
int_tup = ret_int_tup(); // initializing
|
||||
int_rec = ret_int_rec(); // initializing
|
||||
|
||||
int_tup = ret_int_tup(); // non-initializing
|
||||
int_rec = ret_int_rec(); // non-initializing
|
||||
|
||||
int_tup = ret_int_tup(); // non-initializing
|
||||
int_rec = ret_int_rec(); // non-initializing
|
||||
|
||||
ext_tup = ret_ext_tup(); // initializing
|
||||
ext_rec = ret_ext_rec(); // initializing
|
||||
|
||||
ext_tup = ret_ext_tup(); // non-initializing
|
||||
ext_rec = ret_ext_rec(); // non-initializing
|
||||
|
||||
ext_tup = ret_ext_tup(); // non-initializing
|
||||
ext_rec = ret_ext_rec(); // non-initializing
|
||||
|
||||
ext_mem = ret_ext_mem(); // initializing
|
||||
|
||||
|
@ -1,27 +0,0 @@
|
||||
|
||||
|
||||
|
||||
// -*- rust -*-
|
||||
type point = rec(int x, int y);
|
||||
|
||||
type rect = tup(point, point);
|
||||
|
||||
fn f(rect r, int x1, int y1, int x2, int y2) {
|
||||
assert (r._0.x == x1);
|
||||
assert (r._0.y == y1);
|
||||
assert (r._1.x == x2);
|
||||
assert (r._1.y == y2);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let rect r = tup(rec(x=10, y=20), rec(x=11, y=22));
|
||||
assert (r._0.x == 10);
|
||||
assert (r._0.y == 20);
|
||||
assert (r._1.x == 11);
|
||||
assert (r._1.y == 22);
|
||||
let rect r2 = r;
|
||||
let int x = r2._0.x;
|
||||
assert (x == 10);
|
||||
f(r, 10, 20, 11, 22);
|
||||
f(r2, 10, 20, 11, 22);
|
||||
}
|
@ -14,7 +14,7 @@ fn test_qsort() {
|
||||
sort::ivector::quick_sort(lteq, names);
|
||||
|
||||
auto pairs = ivec::zip(expected, ivec::from_mut(names));
|
||||
for (tup(int, int) p in pairs) {
|
||||
for (rec(int _0, int _1) p in pairs) {
|
||||
log_err #fmt("%d %d", p._0, p._1);
|
||||
assert p._0 == p._1;
|
||||
}
|
||||
|
@ -3,14 +3,14 @@
|
||||
tag foo { large; small; }
|
||||
|
||||
fn main() {
|
||||
auto a = tup(1, 2, 3);
|
||||
auto b = tup(1, 2, 3);
|
||||
auto a = rec(x=1, y=2, z=3);
|
||||
auto b = rec(x=1, y=2, z=3);
|
||||
assert (a == b);
|
||||
assert (a != tup(1, 2, 4));
|
||||
assert (a < tup(1, 2, 4));
|
||||
assert (a <= tup(1, 2, 4));
|
||||
assert (tup(1, 2, 4) > a);
|
||||
assert (tup(1, 2, 4) >= a);
|
||||
assert (a != rec(x=1, y=2, z=4));
|
||||
assert (a < rec(x=1, y=2, z=4));
|
||||
assert (a <= rec(x=1, y=2, z=4));
|
||||
assert (rec(x=1, y=2, z=4) > a);
|
||||
assert (rec(x=1, y=2, z=4) >= a);
|
||||
auto x = large;
|
||||
auto y = small;
|
||||
assert (x != y);
|
||||
|
@ -40,20 +40,6 @@ fn test_str() {
|
||||
assert (s1.(3) as u8 == 't' as u8);
|
||||
}
|
||||
|
||||
fn test_tup() {
|
||||
type t = tup(int, u8, char);
|
||||
|
||||
let port[t] po = port();
|
||||
let chan[t] ch = chan(po);
|
||||
let t t0 = tup(0, 1u8, '2');
|
||||
ch <| t0;
|
||||
let t t1;
|
||||
po |> t1;
|
||||
assert (t0._0 == 0);
|
||||
assert (t0._1 == 1u8);
|
||||
assert (t0._2 == '2');
|
||||
}
|
||||
|
||||
fn test_tag() {
|
||||
tag t { tag1; tag2(int); tag3(int, u8, char); }
|
||||
let port[t] po = port();
|
||||
@ -90,7 +76,6 @@ fn main() {
|
||||
test_rec();
|
||||
test_vec();
|
||||
test_str();
|
||||
test_tup();
|
||||
test_tag();
|
||||
test_chan();
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
|
||||
|
||||
|
||||
// -*- rust -*-
|
||||
type point = tup(int, int);
|
||||
|
||||
fn f(point p, int x, int y) { assert (p._0 == x); assert (p._1 == y); }
|
||||
|
||||
fn main() {
|
||||
let point p = tup(10, 20);
|
||||
assert (p._0 == 10);
|
||||
assert (p._1 == 20);
|
||||
let point p2 = p;
|
||||
let int x = p2._0;
|
||||
assert (x == 10);
|
||||
f(p, 10, 20);
|
||||
f(p2, 10, 20);
|
||||
}
|
@ -5,7 +5,7 @@ iter range(uint lo, uint hi) -> uint {
|
||||
while (lo_ < hi) { put lo_; lo_ += 1u; }
|
||||
}
|
||||
|
||||
fn create_index[T](vec[tup(T, uint)] index, fn(&T) -> uint hash_fn) {
|
||||
fn create_index[T](vec[rec(T a, uint b)] index, fn(&T) -> uint hash_fn) {
|
||||
for each (uint i in range(0u, 256u)) { let vec[T] bucket = []; }
|
||||
}
|
||||
|
||||
|
@ -13,13 +13,14 @@ fn main() {
|
||||
assert (size_of[char]() == 4 as uint);
|
||||
assert (size_of[i8]() == 1 as uint);
|
||||
assert (size_of[i32]() == 4 as uint);
|
||||
assert (size_of[tup(u8, i8)]() == 2 as uint);
|
||||
assert (size_of[tup(u8, i8, u8)]() == 3 as uint);
|
||||
assert (size_of[rec(u8 a, i8 b)]() == 2 as uint);
|
||||
assert (size_of[rec(u8 a, i8 b, u8 c)]() == 3 as uint);
|
||||
// Alignment causes padding before the char and the u32.
|
||||
|
||||
assert (size_of[tup(u8, i8, tup(char, u8), u32)]() == 16 as uint);
|
||||
assert (size_of[rec(u8 a, i8 b, rec(char u, u8 v) c, u32 d)]()
|
||||
== 16 as uint);
|
||||
assert (size_of[int]() == size_of[uint]());
|
||||
assert (size_of[tup(int, ())]() == size_of[int]());
|
||||
assert (size_of[tup(int, (), ())]() == size_of[int]());
|
||||
assert (size_of[rec(int a, () b)]() == size_of[int]());
|
||||
assert (size_of[rec(int a, () b, () c)]() == size_of[int]());
|
||||
assert (size_of[int]() == size_of[rec(int x)]());
|
||||
}
|
@ -3,5 +3,7 @@
|
||||
fn main() {
|
||||
// This just tests whether the vec leaks its members.
|
||||
|
||||
let vec[@tup(int, int)] pvec = [@tup(1, 2), @tup(3, 4), @tup(5, 6)];
|
||||
let vec[@rec(int x, int y)] pvec = [@rec(x=1, y=2),
|
||||
@rec(x=3, y=4),
|
||||
@rec(x=5, y=6)];
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
|
||||
|
||||
fn main() {
|
||||
let tup(mutable vec[int]) i = tup(mutable [1, 2, 3]);
|
||||
i._0 = [4, 5, 6];
|
||||
}
|
@ -78,11 +78,11 @@ fn test_partition() {
|
||||
right(13),
|
||||
left(14)];
|
||||
auto result = partition(input);
|
||||
assert (result._0.(0) == 10);
|
||||
assert (result._0.(1) == 12);
|
||||
assert (result._0.(2) == 14);
|
||||
assert (result._1.(0) == 11);
|
||||
assert (result._1.(1) == 13);
|
||||
assert (result.lefts.(0) == 10);
|
||||
assert (result.lefts.(1) == 12);
|
||||
assert (result.lefts.(2) == 14);
|
||||
assert (result.rights.(0) == 11);
|
||||
assert (result.rights.(1) == 13);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -90,8 +90,8 @@ fn test_partition_no_lefts() {
|
||||
let (t[int, int])[] input = ~[right(10),
|
||||
right(11)];
|
||||
auto result = partition(input);
|
||||
assert (len(result._0) == 0u);
|
||||
assert (len(result._1) == 2u);
|
||||
assert (len(result.lefts) == 0u);
|
||||
assert (len(result.rights) == 2u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -99,14 +99,14 @@ fn test_partition_no_rights() {
|
||||
let (t[int, int])[] input = ~[left(10),
|
||||
left(11)];
|
||||
auto result = partition(input);
|
||||
assert (len(result._0) == 2u);
|
||||
assert (len(result._1) == 0u);
|
||||
assert (len(result.lefts) == 2u);
|
||||
assert (len(result.rights) == 0u);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_partition_empty() {
|
||||
let (t[int, int])[] input = ~[];
|
||||
auto result = partition(input);
|
||||
assert (len(result._0) == 0u);
|
||||
assert (len(result._1) == 0u);
|
||||
assert (len(result.lefts) == 0u);
|
||||
assert (len(result.rights) == 0u);
|
||||
}
|
||||
|
@ -285,15 +285,15 @@ fn test_zip_unzip() {
|
||||
auto v2 = ~[4, 5, 6];
|
||||
auto z1 = ivec::zip(v1, v2);
|
||||
|
||||
assert tup(1, 4) == z1.(0);
|
||||
assert tup(2, 5) == z1.(1);
|
||||
assert tup(3, 6) == z1.(2);
|
||||
assert rec(_0=1, _1=4) == z1.(0);
|
||||
assert rec(_0=2, _1=5) == z1.(1);
|
||||
assert rec(_0=3, _1=6) == z1.(2);
|
||||
|
||||
auto u1 = ivec::unzip(z1);
|
||||
|
||||
assert tup(1, 4) == tup(u1._0.(0), u1._1.(0));
|
||||
assert tup(2, 5) == tup(u1._0.(1), u1._1.(1));
|
||||
assert tup(3, 6) == tup(u1._0.(2), u1._1.(2));
|
||||
assert rec(_0=1, _1=4) == rec(_0=u1._0.(0), _1=u1._1.(0));
|
||||
assert rec(_0=2, _1=5) == rec(_0=u1._0.(1), _1=u1._1.(1));
|
||||
assert rec(_0=3, _1=6) == rec(_0=u1._0.(2), _1=u1._1.(2));
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
@ -50,7 +50,7 @@ fn test_simple() {
|
||||
sort::ivector::quick_sort(lteq, names);
|
||||
|
||||
auto pairs = ivec::zip(expected, ivec::from_mut(names));
|
||||
for (tup(int, int) p in pairs) {
|
||||
for (rec(int _0, int _1) p in pairs) {
|
||||
log #fmt("%d %d", p._0, p._1);
|
||||
assert p._0 == p._1;
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ fn sort_tests() {
|
||||
|
||||
auto pairs = ivec::zip(expected, filtered);
|
||||
|
||||
for (tup(str, test::test_desc) p in pairs) {
|
||||
for (rec(str _0, test::test_desc _1) p in pairs) {
|
||||
assert p._0 == p._1.name;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user