diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-07-27 14:19:39 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-07-27 15:54:33 +0200 |
| commit | df7f21db093b0f206048b18e977161f91b7c28f1 (patch) | |
| tree | 36c56d12572266bd0b8d2b3379e52d04bf0e9152 /src/test/stdtest | |
| parent | 0e3ee39c41462652f41993a5610265abea6daa96 (diff) | |
| download | rust-df7f21db093b0f206048b18e977161f91b7c28f1.tar.gz rust-df7f21db093b0f206048b18e977161f91b7c28f1.zip | |
Reformat for new syntax
Diffstat (limited to 'src/test/stdtest')
28 files changed, 819 insertions, 876 deletions
diff --git a/src/test/stdtest/bitv.rs b/src/test/stdtest/bitv.rs index a550136ec2c..2cf8a79edb4 100644 --- a/src/test/stdtest/bitv.rs +++ b/src/test/stdtest/bitv.rs @@ -5,8 +5,8 @@ import std::bitv; #[test] fn test_0_elements() { - auto act; - auto exp; + let act; + let exp; act = bitv::create(0u, false); exp = vec::init_elt[uint](0u, 0u); // FIXME: why can't I write vec[uint]()? @@ -16,7 +16,7 @@ fn test_0_elements() { #[test] fn test_1_element() { - auto act; + let act; act = bitv::create(1u, false); assert (bitv::eq_vec(act, [0u])); act = bitv::create(1u, true); @@ -25,7 +25,7 @@ fn test_1_element() { #[test] fn test_10_elements() { - auto act; + let act; // all 0 act = bitv::create(10u, false); @@ -64,7 +64,7 @@ fn test_10_elements() { #[test] fn test_31_elements() { - auto act; + let act; // all 0 act = bitv::create(31u, false); @@ -137,7 +137,7 @@ fn test_31_elements() { #[test] fn test_32_elements() { - auto act; + let act; // all 0 act = bitv::create(32u, false); @@ -212,7 +212,7 @@ fn test_32_elements() { #[test] fn test_33_elements() { - auto act; + let act; // all 0 act = bitv::create(33u, false); diff --git a/src/test/stdtest/box.rs b/src/test/stdtest/box.rs index 6b2d199ca6f..6212ec63965 100644 --- a/src/test/stdtest/box.rs +++ b/src/test/stdtest/box.rs @@ -4,8 +4,8 @@ import std::box; #[test] fn test() { - auto x = @3; - auto y = @3; + let x = @3; + let y = @3; assert (box::ptr_eq[int](x, x)); assert (box::ptr_eq[int](y, y)); assert (!box::ptr_eq[int](x, y)); diff --git a/src/test/stdtest/deque.rs b/src/test/stdtest/deque.rs index 0a66ab39daa..d43d4b7b603 100644 --- a/src/test/stdtest/deque.rs +++ b/src/test/stdtest/deque.rs @@ -6,7 +6,7 @@ import std::deque; #[test] fn test_simple() { - let deque::t[int] d = deque::create[int](); + let d: deque::t[int] = deque::create[int](); assert (d.size() == 0u); d.add_front(17); d.add_front(42); @@ -18,7 +18,7 @@ fn test_simple() { assert (d.peek_front() == 42); log d.peek_back(); assert (d.peek_back() == 137); - let int i = d.pop_front(); + let i: int = d.pop_front(); log i; assert (i == 42); i = d.pop_back(); @@ -49,8 +49,8 @@ fn test_simple() { assert (d.get(3) == 4); } -fn test_boxes(@int a, @int b, @int c, @int d) { - let deque::t[@int] deq = deque::create[@int](); +fn test_boxes(a: @int, b: @int, c: @int, d: @int) { + let deq: deque::t[@int] = deque::create[@int](); assert (deq.size() == 0u); deq.add_front(a); deq.add_front(b); @@ -81,8 +81,8 @@ fn test_boxes(@int a, @int b, @int c, @int d) { type eqfn[T] = fn(&T, &T) -> bool ; -fn test_parameterized[T](eqfn[T] e, &T a, &T b, &T c, &T d) { - let deque::t[T] deq = deque::create[T](); +fn test_parameterized[T](e: eqfn[T], a: &T, b: &T, c: &T, d: &T) { + let deq: deque::t[T] = deque::create[T](); assert (deq.size() == 0u); deq.add_front(a); deq.add_front(b); @@ -115,80 +115,70 @@ tag taggy { one(int); two(int, int); three(int, int, int); } tag taggypar[T] { onepar(int); twopar(int, int); threepar(int, int, int); } -type reccy = rec(int x, int y, taggy t); +type reccy = {x: int, y: int, t: taggy}; #[test] fn test() { - fn inteq(&int a, &int b) -> bool { ret a == b; } - fn intboxeq(&@int a, &@int b) -> bool { ret a == b; } - fn taggyeq(&taggy a, &taggy b) -> bool { - alt (a) { - case (one(?a1)) { - alt (b) { - case (one(?b1)) { ret a1 == b1; } - case (_) { ret false; } - } + fn inteq(a: &int, b: &int) -> bool { ret a == b; } + fn intboxeq(a: &@int, b: &@int) -> bool { ret a == b; } + fn taggyeq(a: &taggy, b: &taggy) -> bool { + alt a { + one(a1) { alt b { one(b1) { ret a1 == b1; } _ { ret false; } } } + two(a1, a2) { + alt b { + two(b1, b2) { ret a1 == b1 && a2 == b2; } + _ { ret false; } } - case (two(?a1, ?a2)) { - alt (b) { - case (two(?b1, ?b2)) { ret a1 == b1 && a2 == b2; } - case (_) { ret false; } - } - } - case (three(?a1, ?a2, ?a3)) { - alt (b) { - case (three(?b1, ?b2, ?b3)) { - ret a1 == b1 && a2 == b2 && a3 == b3; - } - case (_) { ret false; } - } + } + three(a1, a2, a3) { + alt b { + three(b1, b2, b3) { ret a1 == b1 && a2 == b2 && a3 == b3; } + _ { ret false; } } + } } } - fn taggypareq[T](&taggypar[T] a, &taggypar[T] b) -> bool { - alt (a) { - case (onepar[T](?a1)) { - alt (b) { - case (onepar[T](?b1)) { ret a1 == b1; } - case (_) { ret false; } - } - } - case (twopar[T](?a1, ?a2)) { - alt (b) { - case (twopar[T](?b1, ?b2)) { ret a1 == b1 && a2 == b2; } - case (_) { ret false; } - } + fn taggypareq[T](a: &taggypar[T], b: &taggypar[T]) -> bool { + alt a { + onepar[T](a1) { + alt b { onepar[T](b1) { ret a1 == b1; } _ { ret false; } } + } + twopar[T](a1, a2) { + alt b { + twopar[T](b1, b2) { ret a1 == b1 && a2 == b2; } + _ { ret false; } } - case (threepar[T](?a1, ?a2, ?a3)) { - alt (b) { - case (threepar[T](?b1, ?b2, ?b3)) { - ret a1 == b1 && a2 == b2 && a3 == b3; - } - case (_) { ret false; } - } + } + threepar[T](a1, a2, a3) { + alt b { + threepar[T](b1, b2, b3) { + ret a1 == b1 && a2 == b2 && a3 == b3; + } + _ { ret false; } } + } } } - fn reccyeq(&reccy a, &reccy b) -> bool { + fn reccyeq(a: &reccy, b: &reccy) -> bool { ret a.x == b.x && a.y == b.y && taggyeq(a.t, b.t); } log "*** test boxes"; test_boxes(@5, @72, @64, @175); log "*** end test boxes"; log "test parameterized: int"; - let eqfn[int] eq1 = inteq; + let eq1: eqfn[int] = inteq; test_parameterized[int](eq1, 5, 72, 64, 175); log "*** test parameterized: @int"; - let eqfn[@int] eq2 = intboxeq; + let eq2: eqfn[@int] = intboxeq; test_parameterized[@int](eq2, @5, @72, @64, @175); log "*** end test parameterized @int"; log "test parameterized: taggy"; - let eqfn[taggy] eq3 = taggyeq; + let eq3: eqfn[taggy] = taggyeq; test_parameterized[taggy](eq3, one(1), two(1, 2), three(1, 2, 3), two(17, 42)); /* * FIXME: Segfault. Also appears to be caused only after upcall_grow_task - + log "*** test parameterized: taggypar[int]"; let eqfn[taggypar[int]] eq4 = taggypareq[int]; test_parameterized[taggypar[int]](eq4, @@ -197,15 +187,15 @@ fn test() { threepar[int](1, 2, 3), twopar[int](17, 42)); log "*** end test parameterized: taggypar[int]"; - + */ log "*** test parameterized: reccy"; - let reccy reccy1 = rec(x=1, y=2, t=one(1)); - let reccy reccy2 = rec(x=345, y=2, t=two(1, 2)); - let reccy reccy3 = rec(x=1, y=777, t=three(1, 2, 3)); - let reccy reccy4 = rec(x=19, y=252, t=two(17, 42)); - let eqfn[reccy] eq5 = reccyeq; + let reccy1: reccy = {x: 1, y: 2, t: one(1)}; + let reccy2: reccy = {x: 345, y: 2, t: two(1, 2)}; + let reccy3: reccy = {x: 1, y: 777, t: three(1, 2, 3)}; + let reccy4: reccy = {x: 19, y: 252, t: two(17, 42)}; + let eq5: eqfn[reccy] = reccyeq; test_parameterized[reccy](eq5, reccy1, reccy2, reccy3, reccy4); log "*** end test parameterized: reccy"; log "*** done"; diff --git a/src/test/stdtest/either.rs b/src/test/stdtest/either.rs index 3096bd1ba82..97ed9ef1000 100644 --- a/src/test/stdtest/either.rs +++ b/src/test/stdtest/either.rs @@ -4,109 +4,93 @@ import std::ivec::len; #[test] fn test_either_left() { - auto val = left(10); - fn f_left(&int x) -> bool { x == 10 } - fn f_right(&uint x) -> bool { false } - assert (either(f_left, f_right, val)); + let val = left(10); + fn f_left(x: &int) -> bool { x == 10 } + fn f_right(x: &uint) -> bool { false } + assert (either(f_left, f_right, val)); } #[test] fn test_either_right() { - auto val = right(10u); - fn f_left(&int x) -> bool { false } - fn f_right(&uint x) -> bool { x == 10u } - assert (either(f_left, f_right, val)); + let val = right(10u); + fn f_left(x: &int) -> bool { false } + fn f_right(x: &uint) -> bool { x == 10u } + assert (either(f_left, f_right, val)); } #[test] fn test_lefts() { - auto input = ~[left(10), - right(11), - left(12), - right(13), - left(14)]; - auto result = lefts(input); - assert (result == ~[10, 12, 14]); + let input = ~[left(10), right(11), left(12), right(13), left(14)]; + let result = lefts(input); + assert (result == ~[10, 12, 14]); } #[test] fn test_lefts_none() { - let (t[int, int])[] input = ~[right(10), - right(10)]; - auto result = lefts(input); - assert (len(result) == 0u); + let input: (t[int, int])[] = ~[right(10), right(10)]; + let result = lefts(input); + assert (len(result) == 0u); } #[test] fn test_lefts_empty() { - let (t[int, int])[] input = ~[]; - auto result = lefts(input); - assert (len(result) == 0u); + let input: (t[int, int])[] = ~[]; + let result = lefts(input); + assert (len(result) == 0u); } #[test] fn test_rights() { - auto input = ~[left(10), - right(11), - left(12), - right(13), - left(14)]; - auto result = rights(input); - assert (result == ~[11, 13]); + let input = ~[left(10), right(11), left(12), right(13), left(14)]; + let result = rights(input); + assert (result == ~[11, 13]); } #[test] fn test_rights_none() { - let (t[int, int])[] input = ~[left(10), - left(10)]; - auto result = rights(input); - assert (len(result) == 0u); + let input: (t[int, int])[] = ~[left(10), left(10)]; + let result = rights(input); + assert (len(result) == 0u); } #[test] fn test_rights_empty() { - let (t[int, int])[] input = ~[]; - auto result = rights(input); + let input: (t[int, int])[] = ~[]; + let result = rights(input); assert (len(result) == 0u); } #[test] fn test_partition() { - auto input = ~[left(10), - right(11), - left(12), - right(13), - left(14)]; - auto result = partition(input); - 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); + let input = ~[left(10), right(11), left(12), right(13), left(14)]; + let result = partition(input); + 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] fn test_partition_no_lefts() { - let (t[int, int])[] input = ~[right(10), - right(11)]; - auto result = partition(input); - assert (len(result.lefts) == 0u); - assert (len(result.rights) == 2u); + let input: (t[int, int])[] = ~[right(10), right(11)]; + let result = partition(input); + assert (len(result.lefts) == 0u); + assert (len(result.rights) == 2u); } #[test] fn test_partition_no_rights() { - let (t[int, int])[] input = ~[left(10), - left(11)]; - auto result = partition(input); - assert (len(result.lefts) == 2u); - assert (len(result.rights) == 0u); + let input: (t[int, int])[] = ~[left(10), left(11)]; + let result = partition(input); + 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.lefts) == 0u); - assert (len(result.rights) == 0u); -} + let input: (t[int, int])[] = ~[]; + let result = partition(input); + assert (len(result.lefts) == 0u); + assert (len(result.rights) == 0u); +} \ No newline at end of file diff --git a/src/test/stdtest/fs.rs b/src/test/stdtest/fs.rs index 76321fbb436..7c33b37e4ef 100644 --- a/src/test/stdtest/fs.rs +++ b/src/test/stdtest/fs.rs @@ -4,7 +4,7 @@ import std::fs; #[test] fn test_connect() { - auto slash = fs::path_sep(); + let slash = fs::path_sep(); log_err fs::connect("a", "b"); assert (fs::connect("a", "b") == "a" + slash + "b"); assert (fs::connect("a" + slash, "b") == "a" + slash + "b"); @@ -12,7 +12,5 @@ fn test_connect() { // Issue #712 #[test] -fn test_list_dir_no_invalid_memory_access() { - fs::list_dir("."); -} +fn test_list_dir_no_invalid_memory_access() { fs::list_dir("."); } diff --git a/src/test/stdtest/getopts.rs b/src/test/stdtest/getopts.rs index 233e3a546fc..7515c43271e 100644 --- a/src/test/stdtest/getopts.rs +++ b/src/test/stdtest/getopts.rs @@ -12,18 +12,14 @@ tag fail_type { unexpected_argument; } -fn check_fail_type(opt::fail_ f, fail_type ft) { - alt (f) { - case (opt::argument_missing(_)) { assert (ft == argument_missing); } - case (opt::unrecognized_option(_)) { - assert (ft == unrecognized_option); - } - case (opt::option_missing(_)) { assert (ft == option_missing); } - case (opt::option_duplicated(_)) { assert (ft == option_duplicated); } - case (opt::unexpected_argument(_)) { - assert (ft == unexpected_argument); - } - case (_) { fail; } +fn check_fail_type(f: opt::fail_, ft: fail_type) { + alt f { + opt::argument_missing(_) { assert (ft == argument_missing); } + opt::unrecognized_option(_) { assert (ft == unrecognized_option); } + opt::option_missing(_) { assert (ft == option_missing); } + opt::option_duplicated(_) { assert (ft == option_duplicated); } + opt::unexpected_argument(_) { assert (ft == unexpected_argument); } + _ { fail; } } } @@ -31,95 +27,95 @@ fn check_fail_type(opt::fail_ f, fail_type ft) { // Tests for reqopt #[test] fn test_reqopt_long() { - auto args = ["--test=20"]; - auto opts = [opt::reqopt("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { - assert (opt::opt_present(m, "test")); - assert (opt::opt_str(m, "test") == "20"); - } - case (_) { fail; } + let args = ["--test=20"]; + let opts = [opt::reqopt("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { + assert (opt::opt_present(m, "test")); + assert (opt::opt_str(m, "test") == "20"); + } + _ { fail; } } } #[test] fn test_reqopt_long_missing() { - auto args = ["blah"]; - auto opts = [opt::reqopt("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, option_missing); } - case (_) { fail; } + let args = ["blah"]; + let opts = [opt::reqopt("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, option_missing); } + _ { fail; } } } #[test] fn test_reqopt_long_no_arg() { - auto args = ["--test"]; - auto opts = [opt::reqopt("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, argument_missing); } - case (_) { fail; } + let args = ["--test"]; + let opts = [opt::reqopt("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, argument_missing); } + _ { fail; } } } #[test] fn test_reqopt_long_multi() { - auto args = ["--test=20", "--test=30"]; - auto opts = [opt::reqopt("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, option_duplicated); } - case (_) { fail; } + let args = ["--test=20", "--test=30"]; + let opts = [opt::reqopt("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, option_duplicated); } + _ { fail; } } } #[test] fn test_reqopt_short() { - auto args = ["-t", "20"]; - auto opts = [opt::reqopt("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { - assert (opt::opt_present(m, "t")); - assert (opt::opt_str(m, "t") == "20"); - } - case (_) { fail; } + let args = ["-t", "20"]; + let opts = [opt::reqopt("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { + assert (opt::opt_present(m, "t")); + assert (opt::opt_str(m, "t") == "20"); + } + _ { fail; } } } #[test] fn test_reqopt_short_missing() { - auto args = ["blah"]; - auto opts = [opt::reqopt("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, option_missing); } - case (_) { fail; } + let args = ["blah"]; + let opts = [opt::reqopt("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, option_missing); } + _ { fail; } } } #[test] fn test_reqopt_short_no_arg() { - auto args = ["-t"]; - auto opts = [opt::reqopt("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, argument_missing); } - case (_) { fail; } + let args = ["-t"]; + let opts = [opt::reqopt("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, argument_missing); } + _ { fail; } } } #[test] fn test_reqopt_short_multi() { - auto args = ["-t", "20", "-t", "30"]; - auto opts = [opt::reqopt("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, option_duplicated); } - case (_) { fail; } + let args = ["-t", "20", "-t", "30"]; + let opts = [opt::reqopt("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, option_duplicated); } + _ { fail; } } } @@ -127,95 +123,95 @@ fn test_reqopt_short_multi() { // Tests for optopt #[test] fn test_optopt_long() { - auto args = ["--test=20"]; - auto opts = [opt::optopt("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { - assert (opt::opt_present(m, "test")); - assert (opt::opt_str(m, "test") == "20"); - } - case (_) { fail; } + let args = ["--test=20"]; + let opts = [opt::optopt("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { + assert (opt::opt_present(m, "test")); + assert (opt::opt_str(m, "test") == "20"); + } + _ { fail; } } } #[test] fn test_optopt_long_missing() { - auto args = ["blah"]; - auto opts = [opt::optopt("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { assert (!opt::opt_present(m, "test")); } - case (_) { fail; } + let args = ["blah"]; + let opts = [opt::optopt("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { assert (!opt::opt_present(m, "test")); } + _ { fail; } } } #[test] fn test_optopt_long_no_arg() { - auto args = ["--test"]; - auto opts = [opt::optopt("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, argument_missing); } - case (_) { fail; } + let args = ["--test"]; + let opts = [opt::optopt("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, argument_missing); } + _ { fail; } } } #[test] fn test_optopt_long_multi() { - auto args = ["--test=20", "--test=30"]; - auto opts = [opt::optopt("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, option_duplicated); } - case (_) { fail; } + let args = ["--test=20", "--test=30"]; + let opts = [opt::optopt("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, option_duplicated); } + _ { fail; } } } #[test] fn test_optopt_short() { - auto args = ["-t", "20"]; - auto opts = [opt::optopt("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { - assert (opt::opt_present(m, "t")); - assert (opt::opt_str(m, "t") == "20"); - } - case (_) { fail; } + let args = ["-t", "20"]; + let opts = [opt::optopt("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { + assert (opt::opt_present(m, "t")); + assert (opt::opt_str(m, "t") == "20"); + } + _ { fail; } } } #[test] fn test_optopt_short_missing() { - auto args = ["blah"]; - auto opts = [opt::optopt("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { assert (!opt::opt_present(m, "t")); } - case (_) { fail; } + let args = ["blah"]; + let opts = [opt::optopt("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { assert (!opt::opt_present(m, "t")); } + _ { fail; } } } #[test] fn test_optopt_short_no_arg() { - auto args = ["-t"]; - auto opts = [opt::optopt("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, argument_missing); } - case (_) { fail; } + let args = ["-t"]; + let opts = [opt::optopt("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, argument_missing); } + _ { fail; } } } #[test] fn test_optopt_short_multi() { - auto args = ["-t", "20", "-t", "30"]; - auto opts = [opt::optopt("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, option_duplicated); } - case (_) { fail; } + let args = ["-t", "20", "-t", "30"]; + let opts = [opt::optopt("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, option_duplicated); } + _ { fail; } } } @@ -223,96 +219,96 @@ fn test_optopt_short_multi() { // Tests for optflag #[test] fn test_optflag_long() { - auto args = ["--test"]; - auto opts = [opt::optflag("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { assert (opt::opt_present(m, "test")); } - case (_) { fail; } + let args = ["--test"]; + let opts = [opt::optflag("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { assert (opt::opt_present(m, "test")); } + _ { fail; } } } #[test] fn test_optflag_long_missing() { - auto args = ["blah"]; - auto opts = [opt::optflag("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { assert (!opt::opt_present(m, "test")); } - case (_) { fail; } + let args = ["blah"]; + let opts = [opt::optflag("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { assert (!opt::opt_present(m, "test")); } + _ { fail; } } } #[test] fn test_optflag_long_arg() { - auto args = ["--test=20"]; - auto opts = [opt::optflag("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { - log_err opt::fail_str(f); - check_fail_type(f, unexpected_argument); - } - case (_) { fail; } + let args = ["--test=20"]; + let opts = [opt::optflag("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { + log_err opt::fail_str(f); + check_fail_type(f, unexpected_argument); + } + _ { fail; } } } #[test] fn test_optflag_long_multi() { - auto args = ["--test", "--test"]; - auto opts = [opt::optflag("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, option_duplicated); } - case (_) { fail; } + let args = ["--test", "--test"]; + let opts = [opt::optflag("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, option_duplicated); } + _ { fail; } } } #[test] fn test_optflag_short() { - auto args = ["-t"]; - auto opts = [opt::optflag("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { assert (opt::opt_present(m, "t")); } - case (_) { fail; } + let args = ["-t"]; + let opts = [opt::optflag("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { assert (opt::opt_present(m, "t")); } + _ { fail; } } } #[test] fn test_optflag_short_missing() { - auto args = ["blah"]; - auto opts = [opt::optflag("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { assert (!opt::opt_present(m, "t")); } - case (_) { fail; } + let args = ["blah"]; + let opts = [opt::optflag("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { assert (!opt::opt_present(m, "t")); } + _ { fail; } } } #[test] fn test_optflag_short_arg() { - auto args = ["-t", "20"]; - auto opts = [opt::optflag("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { - // The next variable after the flag is just a free argument + let args = ["-t", "20"]; + let opts = [opt::optflag("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { + // The next variable after the flag is just a free argument - assert (m.free.(0) == "20"); - } - case (_) { fail; } + assert (m.free.(0) == "20"); + } + _ { fail; } } } #[test] fn test_optflag_short_multi() { - auto args = ["-t", "-t"]; - auto opts = [opt::optflag("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, option_duplicated); } - case (_) { fail; } + let args = ["-t", "-t"]; + let opts = [opt::optflag("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, option_duplicated); } + _ { fail; } } } @@ -320,153 +316,153 @@ fn test_optflag_short_multi() { // Tests for optmulti #[test] fn test_optmulti_long() { - auto args = ["--test=20"]; - auto opts = [opt::optmulti("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { - assert (opt::opt_present(m, "test")); - assert (opt::opt_str(m, "test") == "20"); - } - case (_) { fail; } + let args = ["--test=20"]; + let opts = [opt::optmulti("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { + assert (opt::opt_present(m, "test")); + assert (opt::opt_str(m, "test") == "20"); + } + _ { fail; } } } #[test] fn test_optmulti_long_missing() { - auto args = ["blah"]; - auto opts = [opt::optmulti("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { assert (!opt::opt_present(m, "test")); } - case (_) { fail; } + let args = ["blah"]; + let opts = [opt::optmulti("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { assert (!opt::opt_present(m, "test")); } + _ { fail; } } } #[test] fn test_optmulti_long_no_arg() { - auto args = ["--test"]; - auto opts = [opt::optmulti("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, argument_missing); } - case (_) { fail; } + let args = ["--test"]; + let opts = [opt::optmulti("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, argument_missing); } + _ { fail; } } } #[test] fn test_optmulti_long_multi() { - auto args = ["--test=20", "--test=30"]; - auto opts = [opt::optmulti("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { - assert (opt::opt_present(m, "test")); - assert (opt::opt_str(m, "test") == "20"); - assert (opt::opt_strs(m, "test").(0) == "20"); - assert (opt::opt_strs(m, "test").(1) == "30"); - } - case (_) { fail; } + let args = ["--test=20", "--test=30"]; + let opts = [opt::optmulti("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { + assert (opt::opt_present(m, "test")); + assert (opt::opt_str(m, "test") == "20"); + assert (opt::opt_strs(m, "test").(0) == "20"); + assert (opt::opt_strs(m, "test").(1) == "30"); + } + _ { fail; } } } #[test] fn test_optmulti_short() { - auto args = ["-t", "20"]; - auto opts = [opt::optmulti("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { - assert (opt::opt_present(m, "t")); - assert (opt::opt_str(m, "t") == "20"); - } - case (_) { fail; } + let args = ["-t", "20"]; + let opts = [opt::optmulti("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { + assert (opt::opt_present(m, "t")); + assert (opt::opt_str(m, "t") == "20"); + } + _ { fail; } } } #[test] fn test_optmulti_short_missing() { - auto args = ["blah"]; - auto opts = [opt::optmulti("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { assert (!opt::opt_present(m, "t")); } - case (_) { fail; } + let args = ["blah"]; + let opts = [opt::optmulti("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { assert (!opt::opt_present(m, "t")); } + _ { fail; } } } #[test] fn test_optmulti_short_no_arg() { - auto args = ["-t"]; - auto opts = [opt::optmulti("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, argument_missing); } - case (_) { fail; } + let args = ["-t"]; + let opts = [opt::optmulti("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, argument_missing); } + _ { fail; } } } #[test] fn test_optmulti_short_multi() { - auto args = ["-t", "20", "-t", "30"]; - auto opts = [opt::optmulti("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { - assert (opt::opt_present(m, "t")); - assert (opt::opt_str(m, "t") == "20"); - assert (opt::opt_strs(m, "t").(0) == "20"); - assert (opt::opt_strs(m, "t").(1) == "30"); - } - case (_) { fail; } + let args = ["-t", "20", "-t", "30"]; + let opts = [opt::optmulti("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { + assert (opt::opt_present(m, "t")); + assert (opt::opt_str(m, "t") == "20"); + assert (opt::opt_strs(m, "t").(0) == "20"); + assert (opt::opt_strs(m, "t").(1) == "30"); + } + _ { fail; } } } #[test] fn test_unrecognized_option_long() { - auto args = ["--untest"]; - auto opts = [opt::optmulti("t")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, unrecognized_option); } - case (_) { fail; } + let args = ["--untest"]; + let opts = [opt::optmulti("t")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, unrecognized_option); } + _ { fail; } } } #[test] fn test_unrecognized_option_short() { - auto args = ["-t"]; - auto opts = [opt::optmulti("test")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::failure(?f)) { check_fail_type(f, unrecognized_option); } - case (_) { fail; } + let args = ["-t"]; + let opts = [opt::optmulti("test")]; + let rs = opt::getopts(args, opts); + alt rs { + opt::failure(f) { check_fail_type(f, unrecognized_option); } + _ { fail; } } } #[test] fn test_combined() { - auto args = + let args = ["prog", "free1", "-s", "20", "free2", "--flag", "--long=30", "-f", "-m", "40", "-m", "50"]; - auto opts = + let opts = [opt::optopt("s"), opt::optflag("flag"), opt::reqopt("long"), opt::optflag("f"), opt::optmulti("m"), opt::optopt("notpresent")]; - auto rs = opt::getopts(args, opts); - alt (rs) { - case (opt::success(?m)) { - assert (m.free.(0) == "prog"); - assert (m.free.(1) == "free1"); - assert (opt::opt_str(m, "s") == "20"); - assert (m.free.(2) == "free2"); - assert (opt::opt_present(m, "flag")); - assert (opt::opt_str(m, "long") == "30"); - assert (opt::opt_present(m, "f")); - assert (opt::opt_strs(m, "m").(0) == "40"); - assert (opt::opt_strs(m, "m").(1) == "50"); - assert (!opt::opt_present(m, "notpresent")); - } - case (_) { fail; } + let rs = opt::getopts(args, opts); + alt rs { + opt::success(m) { + assert (m.free.(0) == "prog"); + assert (m.free.(1) == "free1"); + assert (opt::opt_str(m, "s") == "20"); + assert (m.free.(2) == "free2"); + assert (opt::opt_present(m, "flag")); + assert (opt::opt_str(m, "long") == "30"); + assert (opt::opt_present(m, "f")); + assert (opt::opt_strs(m, "m").(0) == "40"); + assert (opt::opt_strs(m, "m").(1) == "50"); + assert (!opt::opt_present(m, "notpresent")); + } + _ { fail; } } } diff --git a/src/test/stdtest/int.rs b/src/test/stdtest/int.rs index 61d3448a175..936b1fa91d3 100644 --- a/src/test/stdtest/int.rs +++ b/src/test/stdtest/int.rs @@ -22,4 +22,4 @@ fn test_pow() { assert (int::pow(-3, 2u) == 9); assert (int::pow(-3, 3u) == -27); assert (int::pow(4, 9u) == 262144); -} +} \ No newline at end of file diff --git a/src/test/stdtest/io.rs b/src/test/stdtest/io.rs index 460d68b7569..08330c619fc 100644 --- a/src/test/stdtest/io.rs +++ b/src/test/stdtest/io.rs @@ -7,17 +7,17 @@ import std::str; #[cfg(target_os = "win32")] #[test] fn test_simple() { - let str tmpfile = "test/run-pass/lib-io-test-simple.tmp"; + let tmpfile: str = "test/run-pass/lib-io-test-simple.tmp"; log tmpfile; - let str frood = "A hoopy frood who really knows where his towel is."; + let frood: str = "A hoopy frood who really knows where his towel is."; log frood; { - let io::writer out = io::file_writer(tmpfile, [io::create, - io::truncate]); + let out: io::writer = + io::file_writer(tmpfile, [io::create, io::truncate]); out.write_str(frood); } - let io::reader inp = io::file_reader(tmpfile); - let str frood2 = inp.read_c_str(); + let inp: io::reader = io::file_reader(tmpfile); + let frood2: str = inp.read_c_str(); log frood2; assert (str::eq(frood, frood2)); } @@ -26,5 +26,5 @@ fn test_simple() { #[cfg(target_os = "macos")] #[test] #[ignore] -fn test_simple() {} +fn test_simple() { } diff --git a/src/test/stdtest/ivec.rs b/src/test/stdtest/ivec.rs index 95e1271f76f..ab486b46e0b 100644 --- a/src/test/stdtest/ivec.rs +++ b/src/test/stdtest/ivec.rs @@ -5,21 +5,21 @@ import std::option; import std::option::none; import std::option::some; -fn square(uint n) -> uint { ret n * n; } +fn square(n: uint) -> uint { ret n * n; } -fn square_alias(&uint n) -> uint { ret n * n; } +fn square_alias(n: &uint) -> uint { ret n * n; } -pred is_three(&uint n) -> bool { ret n == 3u; } +pred is_three(n: &uint) -> bool { ret n == 3u; } -fn square_if_odd(&uint n) -> option::t[uint] { - ret if (n % 2u == 1u) { some(n * n) } else { none }; +fn square_if_odd(n: &uint) -> option::t[uint] { + ret if n % 2u == 1u { some(n * n) } else { none }; } -fn add(&uint x, &uint y) -> uint { ret x + y; } +fn add(x: &uint, y: &uint) -> uint { ret x + y; } #[test] fn test_reserve_and_on_heap() { - let int[] v = ~[ 1, 2 ]; + let v: int[] = ~[1, 2]; assert (!ivec::on_heap(v)); ivec::reserve(v, 8u); assert (ivec::on_heap(v)); @@ -28,9 +28,9 @@ fn test_reserve_and_on_heap() { #[test] fn test_unsafe_ptrs() { // Test on-stack copy-from-buf. - auto a = ~[ 1, 2, 3 ]; - auto ptr = ivec::to_ptr(a); - auto b = ~[]; + let a = ~[1, 2, 3]; + let ptr = ivec::to_ptr(a); + let b = ~[]; ivec::unsafe::copy_from_buf(b, ptr, 3u); assert (ivec::len(b) == 3u); assert (b.(0) == 1); @@ -38,9 +38,9 @@ fn test_unsafe_ptrs() { assert (b.(2) == 3); // Test on-heap copy-from-buf. - auto c = ~[ 1, 2, 3, 4, 5 ]; + let c = ~[1, 2, 3, 4, 5]; ptr = ivec::to_ptr(c); - auto d = ~[]; + let d = ~[]; ivec::unsafe::copy_from_buf(d, ptr, 5u); assert (ivec::len(d) == 5u); assert (d.(0) == 1); @@ -53,7 +53,7 @@ fn test_unsafe_ptrs() { #[test] fn test_init_fn() { // Test on-stack init_fn. - auto v = ivec::init_fn(square, 3u); + let v = ivec::init_fn(square, 3u); assert (ivec::len(v) == 3u); assert (v.(0) == 0u); assert (v.(1) == 1u); @@ -72,7 +72,7 @@ fn test_init_fn() { #[test] fn test_init_elt() { // Test on-stack init_elt. - auto v = ivec::init_elt(10u, 2u); + let v = ivec::init_elt(10u, 2u); assert (ivec::len(v) == 2u); assert (v.(0) == 10u); assert (v.(1) == 10u); @@ -89,61 +89,61 @@ fn test_init_elt() { #[test] fn test_is_empty() { - assert ivec::is_empty[int](~[]); - assert !ivec::is_empty(~[0]); + assert (ivec::is_empty[int](~[])); + assert (!ivec::is_empty(~[0])); } #[test] fn test_is_not_empty() { - assert ivec::is_not_empty(~[0]); - assert !ivec::is_not_empty[int](~[]); + assert (ivec::is_not_empty(~[0])); + assert (!ivec::is_not_empty[int](~[])); } #[test] fn test_head() { - auto a = ~[11, 12]; - check ivec::is_not_empty(a); - assert ivec::head(a) == 11; + let a = ~[11, 12]; + check (ivec::is_not_empty(a)); + assert (ivec::head(a) == 11); } #[test] fn test_tail() { - auto a = ~[11]; - check ivec::is_not_empty(a); - assert ivec::tail(a) == ~[]; + let a = ~[11]; + check (ivec::is_not_empty(a)); + assert (ivec::tail(a) == ~[]); a = ~[11, 12]; - check ivec::is_not_empty(a); - assert ivec::tail(a) == ~[12]; + check (ivec::is_not_empty(a)); + assert (ivec::tail(a) == ~[12]); } #[test] fn test_last() { - auto n = ivec::last(~[]); + let n = ivec::last(~[]); assert (n == none); - n = ivec::last(~[ 1, 2, 3 ]); + n = ivec::last(~[1, 2, 3]); assert (n == some(3)); - n = ivec::last(~[ 1, 2, 3, 4, 5 ]); + n = ivec::last(~[1, 2, 3, 4, 5]); assert (n == some(5)); } #[test] fn test_slice() { // Test on-stack -> on-stack slice. - auto v = ivec::slice(~[ 1, 2, 3 ], 1u, 3u); + let v = ivec::slice(~[1, 2, 3], 1u, 3u); assert (ivec::len(v) == 2u); assert (v.(0) == 2); assert (v.(1) == 3); // Test on-heap -> on-stack slice. - v = ivec::slice(~[ 1, 2, 3, 4, 5 ], 0u, 3u); + v = ivec::slice(~[1, 2, 3, 4, 5], 0u, 3u); assert (ivec::len(v) == 3u); assert (v.(0) == 1); assert (v.(1) == 2); assert (v.(2) == 3); // Test on-heap -> on-heap slice. - v = ivec::slice(~[ 1, 2, 3, 4, 5, 6 ], 1u, 6u); + v = ivec::slice(~[1, 2, 3, 4, 5, 6], 1u, 6u); assert (ivec::len(v) == 5u); assert (v.(0) == 2); assert (v.(1) == 3); @@ -155,15 +155,15 @@ fn test_slice() { #[test] fn test_pop() { // Test on-stack pop. - auto v = ~[ 1, 2, 3 ]; - auto e = ivec::pop(v); + let v = ~[1, 2, 3]; + let e = ivec::pop(v); assert (ivec::len(v) == 2u); assert (v.(0) == 1); assert (v.(1) == 2); assert (e == 3); // Test on-heap pop. - v = ~[ 1, 2, 3, 4, 5 ]; + v = ~[1, 2, 3, 4, 5]; e = ivec::pop(v); assert (ivec::len(v) == 4u); assert (v.(0) == 1); @@ -176,7 +176,7 @@ fn test_pop() { #[test] fn test_grow() { // Test on-stack grow(). - auto v = ~[]; + let v = ~[]; ivec::grow(v, 2u, 1); assert (ivec::len(v) == 2u); assert (v.(0) == 1); @@ -194,7 +194,7 @@ fn test_grow() { #[test] fn test_grow_fn() { - auto v = ~[]; + let v = ~[]; ivec::grow_fn(v, 3u, square); assert (ivec::len(v) == 3u); assert (v.(0) == 0u); @@ -204,7 +204,7 @@ fn test_grow_fn() { #[test] fn test_grow_set() { - auto v = ~[ mutable 1, 2, 3 ]; + let v = ~[mutable 1, 2, 3]; ivec::grow_set(v, 4u, 4, 5); assert (ivec::len(v) == 5u); assert (v.(0) == 1); @@ -217,15 +217,15 @@ fn test_grow_set() { #[test] fn test_map() { // Test on-stack map. - auto v = ~[ 1u, 2u, 3u ]; - auto w = ivec::map(square_alias, v); + let v = ~[1u, 2u, 3u]; + let w = ivec::map(square_alias, v); assert (ivec::len(w) == 3u); assert (w.(0) == 1u); assert (w.(1) == 4u); assert (w.(2) == 9u); // Test on-heap map. - v = ~[ 1u, 2u, 3u, 4u, 5u ]; + v = ~[1u, 2u, 3u, 4u, 5u]; w = ivec::map(square_alias, v); assert (ivec::len(w) == 5u); assert (w.(0) == 1u); @@ -238,14 +238,14 @@ fn test_map() { #[test] fn test_filter_map() { // Test on-stack filter-map. - auto v = ~[ 1u, 2u, 3u ]; - auto w = ivec::filter_map(square_if_odd, v); + let v = ~[1u, 2u, 3u]; + let w = ivec::filter_map(square_if_odd, v); assert (ivec::len(w) == 2u); assert (w.(0) == 1u); assert (w.(1) == 9u); // Test on-heap filter-map. - v = ~[ 1u, 2u, 3u, 4u, 5u ]; + v = ~[1u, 2u, 3u, 4u, 5u]; w = ivec::filter_map(square_if_odd, v); assert (ivec::len(w) == 3u); assert (w.(0) == 1u); @@ -256,44 +256,44 @@ fn test_filter_map() { #[test] fn test_foldl() { // Test on-stack fold. - auto v = ~[ 1u, 2u, 3u ]; - auto sum = ivec::foldl(add, 0u, v); + let v = ~[1u, 2u, 3u]; + let sum = ivec::foldl(add, 0u, v); assert (sum == 6u); // Test on-heap fold. - v = ~[ 1u, 2u, 3u, 4u, 5u ]; + v = ~[1u, 2u, 3u, 4u, 5u]; sum = ivec::foldl(add, 0u, v); assert (sum == 15u); } #[test] fn test_any_and_all() { - assert (ivec::any(is_three, ~[ 1u, 2u, 3u ])); - assert (!ivec::any(is_three, ~[ 0u, 1u, 2u ])); - assert (ivec::any(is_three, ~[ 1u, 2u, 3u, 4u, 5u ])); - assert (!ivec::any(is_three, ~[ 1u, 2u, 4u, 5u, 6u ])); - - assert (ivec::all(is_three, ~[ 3u, 3u, 3u ])); - assert (!ivec::all(is_three, ~[ 3u, 3u, 2u ])); - assert (ivec::all(is_three, ~[ 3u, 3u, 3u, 3u, 3u ])); - assert (!ivec::all(is_three, ~[ 3u, 3u, 0u, 1u, 2u ])); + assert (ivec::any(is_three, ~[1u, 2u, 3u])); + assert (!ivec::any(is_three, ~[0u, 1u, 2u])); + assert (ivec::any(is_three, ~[1u, 2u, 3u, 4u, 5u])); + assert (!ivec::any(is_three, ~[1u, 2u, 4u, 5u, 6u])); + + assert (ivec::all(is_three, ~[3u, 3u, 3u])); + assert (!ivec::all(is_three, ~[3u, 3u, 2u])); + assert (ivec::all(is_three, ~[3u, 3u, 3u, 3u, 3u])); + assert (!ivec::all(is_three, ~[3u, 3u, 0u, 1u, 2u])); } #[test] fn test_zip_unzip() { - auto v1 = ~[1, 2, 3]; - auto v2 = ~[4, 5, 6]; - auto z1 = ivec::zip(v1, v2); + let v1 = ~[1, 2, 3]; + let v2 = ~[4, 5, 6]; + let z1 = ivec::zip(v1, v2); - assert rec(_0=1, _1=4) == z1.(0); - assert rec(_0=2, _1=5) == z1.(1); - assert rec(_0=3, _1=6) == z1.(2); + assert ({_0: 1, _1: 4} == z1.(0)); + assert ({_0: 2, _1: 5} == z1.(1)); + assert ({_0: 3, _1: 6} == z1.(2)); - auto u1 = ivec::unzip(z1); + let u1 = ivec::unzip(z1); - 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)); + assert ({_0: 1, _1: 4} == {_0: u1._0.(0), _1: u1._1.(0)}); + assert ({_0: 2, _1: 5} == {_0: u1._0.(1), _1: u1._1.(1)}); + assert ({_0: 3, _1: 6} == {_0: u1._0.(2), _1: u1._1.(2)}); } // Local Variables: diff --git a/src/test/stdtest/list.rs b/src/test/stdtest/list.rs index 3d937016b1f..f96fc7cb75c 100644 --- a/src/test/stdtest/list.rs +++ b/src/test/stdtest/list.rs @@ -8,7 +8,7 @@ import std::option; #[test] fn test_from_vec() { - auto l = from_vec([0, 1, 2]); + let l = from_vec([0, 1, 2]); assert (car(l) == 0); assert (car(cdr(l)) == 1); assert (car(cdr(cdr(l))) == 2); @@ -16,34 +16,34 @@ fn test_from_vec() { #[test] fn test_foldl() { - auto l = from_vec([0, 1, 2, 3, 4]); - fn add(&int a, &uint b) -> uint { ret (a as uint) + b; } - auto rs = list::foldl(l, 0u, add); + let l = from_vec([0, 1, 2, 3, 4]); + fn add(a: &int, b: &uint) -> uint { ret (a as uint) + b; } + let rs = list::foldl(l, 0u, add); assert (rs == 10u); } #[test] fn test_find_success() { - auto l = from_vec([0, 1, 2]); - fn match(&int i) -> option::t[int] { - ret if (i == 2) { option::some(i) } else { option::none[int] }; + let l = from_vec([0, 1, 2]); + fn match(i: &int) -> option::t[int] { + ret if i == 2 { option::some(i) } else { option::none[int] }; } - auto rs = list::find(l, match); + let rs = list::find(l, match); assert (rs == option::some(2)); } #[test] fn test_find_fail() { - auto l = from_vec([0, 1, 2]); - fn match(&int i) -> option::t[int] { ret option::none[int]; } - auto rs = list::find(l, match); + let l = from_vec([0, 1, 2]); + fn match(i: &int) -> option::t[int] { ret option::none[int]; } + let rs = list::find(l, match); assert (rs == option::none[int]); } #[test] fn test_has() { - auto l = from_vec([5, 8, 6]); - auto empty = list::nil[int]; + let l = from_vec([5, 8, 6]); + let empty = list::nil[int]; assert (list::has(l, 5)); assert (!list::has(l, 7)); assert (list::has(l, 8)); @@ -52,7 +52,7 @@ fn test_has() { #[test] fn test_length() { - auto l = from_vec([0, 1, 2]); + let l = from_vec([0, 1, 2]); assert (list::length(l) == 3u); } diff --git a/src/test/stdtest/map.rs b/src/test/stdtest/map.rs index da6d0630116..44edb3f9111 100644 --- a/src/test/stdtest/map.rs +++ b/src/test/stdtest/map.rs @@ -10,19 +10,19 @@ import std::util; #[test] fn test_simple() { log "*** starting test_simple"; - fn eq_uint(&uint x, &uint y) -> bool { ret x == y; } - fn hash_uint(&uint u) -> uint { + fn eq_uint(x: &uint, y: &uint) -> bool { ret x == y; } + fn hash_uint(u: &uint) -> uint { // FIXME: can't use std::util::id since we'd be capturing a type // param, and presently we can't close items over type params. ret u; } - let map::hashfn[uint] hasher_uint = hash_uint; - let map::eqfn[uint] eqer_uint = eq_uint; - let map::hashfn[str] hasher_str = str::hash; - let map::eqfn[str] eqer_str = str::eq; + let hasher_uint: map::hashfn[uint] = hash_uint; + let eqer_uint: map::eqfn[uint] = eq_uint; + let hasher_str: map::hashfn[str] = str::hash; + let eqer_str: map::eqfn[str] = str::eq; log "uint -> uint"; - let map::hashmap[uint, uint] hm_uu = + let hm_uu: map::hashmap[uint, uint] = map::mk_hashmap[uint, uint](hasher_uint, eqer_uint); assert (hm_uu.insert(10u, 12u)); assert (hm_uu.insert(11u, 13u)); @@ -34,11 +34,11 @@ fn test_simple() { assert (hm_uu.get(12u) == 14u); assert (!hm_uu.insert(12u, 12u)); assert (hm_uu.get(12u) == 12u); - let str ten = "ten"; - let str eleven = "eleven"; - let str twelve = "twelve"; + let ten: str = "ten"; + let eleven: str = "eleven"; + let twelve: str = "twelve"; log "str -> uint"; - let map::hashmap[str, uint] hm_su = + let hm_su: map::hashmap[str, uint] = map::mk_hashmap[str, uint](hasher_str, eqer_str); assert (hm_su.insert("ten", 12u)); assert (hm_su.insert(eleven, 13u)); @@ -52,7 +52,7 @@ fn test_simple() { assert (!hm_su.insert("twelve", 12u)); assert (hm_su.get("twelve") == 12u); log "uint -> str"; - let map::hashmap[uint, str] hm_us = + let hm_us: map::hashmap[uint, str] = map::mk_hashmap[uint, str](hasher_uint, eqer_uint); assert (hm_us.insert(10u, "twelve")); assert (hm_us.insert(11u, "thirteen")); @@ -65,7 +65,7 @@ fn test_simple() { assert (!hm_us.insert(12u, "twelve")); assert (str::eq(hm_us.get(12u), "twelve")); log "str -> str"; - let map::hashmap[str, str] hm_ss = + let hm_ss: map::hashmap[str, str] = map::mk_hashmap[str, str](hasher_str, eqer_str); assert (hm_ss.insert(ten, "twelve")); assert (hm_ss.insert(eleven, "thirteen")); @@ -87,21 +87,21 @@ fn test_simple() { #[test] fn test_growth() { log "*** starting test_growth"; - let uint num_to_insert = 64u; - fn eq_uint(&uint x, &uint y) -> bool { ret x == y; } - fn hash_uint(&uint u) -> uint { + let num_to_insert: uint = 64u; + fn eq_uint(x: &uint, y: &uint) -> bool { ret x == y; } + fn hash_uint(u: &uint) -> uint { // FIXME: can't use std::util::id since we'd be capturing a type // param, and presently we can't close items over type params. ret u; } log "uint -> uint"; - let map::hashfn[uint] hasher_uint = hash_uint; - let map::eqfn[uint] eqer_uint = eq_uint; - let map::hashmap[uint, uint] hm_uu = + let hasher_uint: map::hashfn[uint] = hash_uint; + let eqer_uint: map::eqfn[uint] = eq_uint; + let hm_uu: map::hashmap[uint, uint] = map::mk_hashmap[uint, uint](hasher_uint, eqer_uint); - let uint i = 0u; - while (i < num_to_insert) { + let i: uint = 0u; + while i < num_to_insert { assert (hm_uu.insert(i, i * i)); log "inserting " + uint::to_str(i, 10u) + " -> " + uint::to_str(i * i, 10u); @@ -109,7 +109,7 @@ fn test_growth() { } log "-----"; i = 0u; - while (i < num_to_insert) { + while i < num_to_insert { log "get(" + uint::to_str(i, 10u) + ") = " + uint::to_str(hm_uu.get(i), 10u); assert (hm_uu.get(i) == i * i); @@ -120,19 +120,19 @@ fn test_growth() { log "-----"; hm_uu.rehash(); i = 0u; - while (i < num_to_insert) { + while i < num_to_insert { log "get(" + uint::to_str(i, 10u) + ") = " + uint::to_str(hm_uu.get(i), 10u); assert (hm_uu.get(i) == i * i); i += 1u; } log "str -> str"; - let map::hashfn[str] hasher_str = str::hash; - let map::eqfn[str] eqer_str = str::eq; - let map::hashmap[str, str] hm_ss = + let hasher_str: map::hashfn[str] = str::hash; + let eqer_str: map::eqfn[str] = str::eq; + let hm_ss: map::hashmap[str, str] = map::mk_hashmap[str, str](hasher_str, eqer_str); i = 0u; - while (i < num_to_insert) { + while i < num_to_insert { assert (hm_ss.insert(uint::to_str(i, 2u), uint::to_str(i * i, 2u))); log "inserting \"" + uint::to_str(i, 2u) + "\" -> \"" + uint::to_str(i * i, 2u) + "\""; @@ -140,7 +140,7 @@ fn test_growth() { } log "-----"; i = 0u; - while (i < num_to_insert) { + while i < num_to_insert { log "get(\"" + uint::to_str(i, 2u) + "\") = \"" + hm_ss.get(uint::to_str(i, 2u)) + "\""; assert (str::eq(hm_ss.get(uint::to_str(i, 2u)), @@ -154,7 +154,7 @@ fn test_growth() { log "-----"; hm_ss.rehash(); i = 0u; - while (i < num_to_insert) { + while i < num_to_insert { log "get(\"" + uint::to_str(i, 2u) + "\") = \"" + hm_ss.get(uint::to_str(i, 2u)) + "\""; assert (str::eq(hm_ss.get(uint::to_str(i, 2u)), @@ -167,9 +167,9 @@ fn test_growth() { #[test] fn test_removal() { log "*** starting test_removal"; - let uint num_to_insert = 64u; - fn eq(&uint x, &uint y) -> bool { ret x == y; } - fn hash(&uint u) -> uint { + let num_to_insert: uint = 64u; + fn eq(x: &uint, y: &uint) -> bool { ret x == y; } + fn hash(u: &uint) -> uint { // This hash function intentionally causes collisions between // consecutive integer pairs. @@ -178,12 +178,12 @@ fn test_removal() { assert (hash(0u) == hash(1u)); assert (hash(2u) == hash(3u)); assert (hash(0u) != hash(2u)); - let map::hashfn[uint] hasher = hash; - let map::eqfn[uint] eqer = eq; - let map::hashmap[uint, uint] hm = + let hasher: map::hashfn[uint] = hash; + let eqer: map::eqfn[uint] = eq; + let hm: map::hashmap[uint, uint] = map::mk_hashmap[uint, uint](hasher, eqer); - let uint i = 0u; - while (i < num_to_insert) { + let i: uint = 0u; + while i < num_to_insert { assert (hm.insert(i, i * i)); log "inserting " + uint::to_str(i, 10u) + " -> " + uint::to_str(i * i, 10u); @@ -193,11 +193,11 @@ fn test_removal() { log "-----"; log "removing evens"; i = 0u; - while (i < num_to_insert) { + while i < num_to_insert { /** * FIXME (issue #150): we want to check the removed value as in the * following: - + let util.option[uint] v = hm.remove(i); alt (v) { case (util.some[uint](u)) { @@ -205,7 +205,7 @@ fn test_removal() { } case (util.none[uint]()) { fail; } } - + * but we util.option is a tag type so util.some and util.none are * off limits until we parse the dwarf for tag types. */ @@ -216,7 +216,7 @@ fn test_removal() { assert (hm.size() == num_to_insert / 2u); log "-----"; i = 1u; - while (i < num_to_insert) { + while i < num_to_insert { log "get(" + uint::to_str(i, 10u) + ") = " + uint::to_str(hm.get(i), 10u); assert (hm.get(i) == i * i); @@ -227,7 +227,7 @@ fn test_removal() { hm.rehash(); log "-----"; i = 1u; - while (i < num_to_insert) { + while i < num_to_insert { log "get(" + uint::to_str(i, 10u) + ") = " + uint::to_str(hm.get(i), 10u); assert (hm.get(i) == i * i); @@ -235,7 +235,7 @@ fn test_removal() { } log "-----"; i = 0u; - while (i < num_to_insert) { + while i < num_to_insert { assert (hm.insert(i, i * i)); log "inserting " + uint::to_str(i, 10u) + " -> " + uint::to_str(i * i, 10u); @@ -244,7 +244,7 @@ fn test_removal() { assert (hm.size() == num_to_insert); log "-----"; i = 0u; - while (i < num_to_insert) { + while i < num_to_insert { log "get(" + uint::to_str(i, 10u) + ") = " + uint::to_str(hm.get(i), 10u); assert (hm.get(i) == i * i); @@ -256,7 +256,7 @@ fn test_removal() { log "-----"; assert (hm.size() == num_to_insert); i = 0u; - while (i < num_to_insert) { + while i < num_to_insert { log "get(" + uint::to_str(i, 10u) + ") = " + uint::to_str(hm.get(i), 10u); assert (hm.get(i) == i * i); @@ -267,8 +267,8 @@ fn test_removal() { #[test] fn test_contains_key() { - auto key = "k"; - auto map = map::mk_hashmap[str, str](str::hash, str::eq); + let key = "k"; + let map = map::mk_hashmap[str, str](str::hash, str::eq); assert (!map.contains_key(key)); map.insert(key, "val"); assert (map.contains_key(key)); @@ -276,9 +276,9 @@ fn test_contains_key() { #[test] fn test_find() { - auto key = "k"; - auto map = map::mk_hashmap[str, str](str::hash, str::eq); + let key = "k"; + let map = map::mk_hashmap[str, str](str::hash, str::eq); assert (std::option::is_none(map.find(key))); map.insert(key, "val"); assert (std::option::get(map.find(key)) == "val"); -} +} \ No newline at end of file diff --git a/src/test/stdtest/option.rs b/src/test/stdtest/option.rs index a22effc524a..6426c96ffb6 100644 --- a/src/test/stdtest/option.rs +++ b/src/test/stdtest/option.rs @@ -2,4 +2,4 @@ use std; #[test] -fn test() { auto x = std::option::some[int](10); } \ No newline at end of file +fn test() { let x = std::option::some[int](10); } \ No newline at end of file diff --git a/src/test/stdtest/os.rs b/src/test/stdtest/os.rs index 8fcfd35b85c..49ebb217dbf 100644 --- a/src/test/stdtest/os.rs +++ b/src/test/stdtest/os.rs @@ -7,28 +7,25 @@ fn test_setenv() { // NB: Each test of setenv needs to use different variable names or the // tests will not be threadsafe setenv("NAME1", "VALUE"); - assert getenv("NAME1") == option::some("VALUE"); + assert (getenv("NAME1") == option::some("VALUE")); } #[test] fn test_setenv_overwrite() { setenv("NAME2", "1"); setenv("NAME2", "2"); - assert getenv("NAME2") == option::some("2"); + assert (getenv("NAME2") == option::some("2")); } // Windows GetEnvironmentVariable requires some extra work to make sure // the buffer the variable is copied into is the right size #[test] fn test_getenv_big() { - auto s = ""; - auto i = 0; - while (i < 100) { - s += "aaaaaaaaaa"; - i += 1; - } + let s = ""; + let i = 0; + while i < 100 { s += "aaaaaaaaaa"; i += 1; } setenv("NAME3", s); - assert getenv("NAME3") == option::some(s); + assert (getenv("NAME3") == option::some(s)); } // Local Variables: diff --git a/src/test/stdtest/path.rs b/src/test/stdtest/path.rs index 81fd74208f8..5f7c34c5e05 100644 --- a/src/test/stdtest/path.rs +++ b/src/test/stdtest/path.rs @@ -8,10 +8,10 @@ import std::os; #[test] fn test() { - assert(!fs::path_is_absolute("test-path")); + assert (!fs::path_is_absolute("test-path")); - log "Current working directory: " + os::getcwd(); + log "Current working directory: " + os::getcwd(); - log fs::make_absolute("test-path"); - log fs::make_absolute("/usr/bin"); + log fs::make_absolute("test-path"); + log fs::make_absolute("/usr/bin"); } \ No newline at end of file diff --git a/src/test/stdtest/ptr.rs b/src/test/stdtest/ptr.rs index bf9633e0686..269febfc6b7 100644 --- a/src/test/stdtest/ptr.rs +++ b/src/test/stdtest/ptr.rs @@ -2,19 +2,19 @@ use std; import std::ptr; import std::unsafe; -type pair = rec(mutable int fst, mutable int snd); +type pair = {mutable fst: int, mutable snd: int}; #[test] fn test() { - auto p = rec(mutable fst=10, mutable snd=20); - let *mutable pair pptr = ptr::addr_of(p); - let *mutable int iptr = unsafe::reinterpret_cast(pptr); + let p = {mutable fst: 10, mutable snd: 20}; + let pptr: *mutable pair = ptr::addr_of(p); + let iptr: *mutable int = unsafe::reinterpret_cast(pptr); assert (*iptr == 10); *iptr = 30; assert (*iptr == 30); assert (p.fst == 30); - *pptr = rec(mutable fst=50, mutable snd=60); + *pptr = {mutable fst: 50, mutable snd: 60}; assert (*iptr == 50); assert (p.fst == 50); assert (p.snd == 60); diff --git a/src/test/stdtest/qsort.rs b/src/test/stdtest/qsort.rs index c05daeca0c0..c8f19e373b3 100644 --- a/src/test/stdtest/qsort.rs +++ b/src/test/stdtest/qsort.rs @@ -5,36 +5,36 @@ import std::sort; import std::ivec; import std::int; -fn check_sort(vec[mutable int] v1, vec[mutable int] v2) { - auto len = std::vec::len[int](v1); - fn ltequal(&int a, &int b) -> bool { ret a <= b; } - auto f = ltequal; +fn check_sort(v1: vec[mutable int], v2: vec[mutable int]) { + let len = std::vec::len[int](v1); + fn ltequal(a: &int, b: &int) -> bool { ret a <= b; } + let f = ltequal; std::sort::quick_sort[int](f, v1); - auto i = 0u; - while (i < len) { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; } + let i = 0u; + while i < len { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; } } #[test] fn test() { { - auto v1 = [mutable 3, 7, 4, 5, 2, 9, 5, 8]; - auto v2 = [mutable 2, 3, 4, 5, 5, 7, 8, 9]; + let v1 = [mutable 3, 7, 4, 5, 2, 9, 5, 8]; + let v2 = [mutable 2, 3, 4, 5, 5, 7, 8, 9]; check_sort(v1, v2); } { - auto v1 = [mutable 1, 1, 1]; - auto v2 = [mutable 1, 1, 1]; + let v1 = [mutable 1, 1, 1]; + let v2 = [mutable 1, 1, 1]; check_sort(v1, v2); } { - let vec[mutable int] v1 = [mutable ]; - let vec[mutable int] v2 = [mutable ]; + let v1: vec[mutable int] = [mutable ]; + let v2: vec[mutable int] = [mutable ]; check_sort(v1, v2); } - { auto v1 = [mutable 9]; auto v2 = [mutable 9]; check_sort(v1, v2); } + { let v1 = [mutable 9]; let v2 = [mutable 9]; check_sort(v1, v2); } { - auto v1 = [mutable 9, 3, 3, 3, 9]; - auto v2 = [mutable 3, 3, 3, 9, 9]; + let v1 = [mutable 9, 3, 3, 3, 9]; + let v2 = [mutable 3, 3, 3, 9, 9]; check_sort(v1, v2); } } @@ -42,17 +42,17 @@ fn test() { // Regression test for #705 #[test] fn test_simple() { - auto names = ~[mutable 2, 1, 3]; + let names = ~[mutable 2, 1, 3]; - auto expected = ~[1, 2, 3]; + let expected = ~[1, 2, 3]; - fn lteq(&int a, &int b) -> bool { int::le(a, b) } + fn lteq(a: &int, b: &int) -> bool { int::le(a, b) } sort::ivector::quick_sort(lteq, names); - auto pairs = ivec::zip(expected, ivec::from_mut(names)); - for (rec(int _0, int _1) p in pairs) { + let pairs = ivec::zip(expected, ivec::from_mut(names)); + for p: {_0: int, _1: int} in pairs { log #fmt("%d %d", p._0, p._1); - assert p._0 == p._1; + assert (p._0 == p._1); } } diff --git a/src/test/stdtest/qsort3.rs b/src/test/stdtest/qsort3.rs index 58abf1bc8fa..79e4c42c590 100644 --- a/src/test/stdtest/qsort3.rs +++ b/src/test/stdtest/qsort3.rs @@ -1,38 +1,38 @@ use std; -fn check_sort(vec[mutable int] v1, vec[mutable int] v2) { - auto len = std::vec::len[int](v1); - fn lt(&int a, &int b) -> bool { ret a < b; } - fn equal(&int a, &int b) -> bool { ret a == b; } - auto f1 = lt; - auto f2 = equal; +fn check_sort(v1: vec[mutable int], v2: vec[mutable int]) { + let len = std::vec::len[int](v1); + fn lt(a: &int, b: &int) -> bool { ret a < b; } + fn equal(a: &int, b: &int) -> bool { ret a == b; } + let f1 = lt; + let f2 = equal; std::sort::quick_sort3[int](f1, f2, v1); - auto i = 0u; - while (i < len) { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; } + let i = 0u; + while i < len { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; } } #[test] fn test() { { - auto v1 = [mutable 3, 7, 4, 5, 2, 9, 5, 8]; - auto v2 = [mutable 2, 3, 4, 5, 5, 7, 8, 9]; + let v1 = [mutable 3, 7, 4, 5, 2, 9, 5, 8]; + let v2 = [mutable 2, 3, 4, 5, 5, 7, 8, 9]; check_sort(v1, v2); } { - auto v1 = [mutable 1, 1, 1]; - auto v2 = [mutable 1, 1, 1]; + let v1 = [mutable 1, 1, 1]; + let v2 = [mutable 1, 1, 1]; check_sort(v1, v2); } { - let vec[mutable int] v1 = [mutable ]; - let vec[mutable int] v2 = [mutable ]; + let v1: vec[mutable int] = [mutable ]; + let v2: vec[mutable int] = [mutable ]; check_sort(v1, v2); } - { auto v1 = [mutable 9]; auto v2 = [mutable 9]; check_sort(v1, v2); } + { let v1 = [mutable 9]; let v2 = [mutable 9]; check_sort(v1, v2); } { - auto v1 = [mutable 9, 3, 3, 3, 9]; - auto v2 = [mutable 3, 3, 3, 9, 9]; + let v1 = [mutable 9, 3, 3, 3, 9]; + let v2 = [mutable 3, 3, 3, 9, 9]; check_sort(v1, v2); } } diff --git a/src/test/stdtest/rand.rs b/src/test/stdtest/rand.rs index 8d7b26df04b..bf394602fab 100644 --- a/src/test/stdtest/rand.rs +++ b/src/test/stdtest/rand.rs @@ -6,11 +6,11 @@ import std::rand; #[test] fn test() { - let rand::rng r1 = rand::mk_rng(); + let r1: rand::rng = rand::mk_rng(); log r1.next(); log r1.next(); { - auto r2 = rand::mk_rng(); + let r2 = rand::mk_rng(); log r1.next(); log r2.next(); log r1.next(); diff --git a/src/test/stdtest/run.rs b/src/test/stdtest/run.rs index c86182d36c9..8ba4c6a80ec 100644 --- a/src/test/stdtest/run.rs +++ b/src/test/stdtest/run.rs @@ -6,13 +6,13 @@ import std::run; #[cfg(target_os = "macos")] #[test] fn test_leaks() { - run::run_program("echo", []); - run::start_program("echo", []); - run::program_output("echo", []); + run::run_program("echo", []); + run::start_program("echo", []); + run::program_output("echo", []); } // FIXME #[cfg(target_os = "win32")] #[test] #[ignore] -fn test_leaks() {} +fn test_leaks() { } \ No newline at end of file diff --git a/src/test/stdtest/sha1.rs b/src/test/stdtest/sha1.rs index 038444552e0..a514d340750 100644 --- a/src/test/stdtest/sha1.rs +++ b/src/test/stdtest/sha1.rs @@ -9,73 +9,79 @@ import std::str; #[test] fn test() { - type test = rec(str input, vec[u8] output); + type test = {input: str, output: vec[u8]}; fn a_million_letter_a() -> str { - auto i = 0; - auto rs = ""; - while (i < 100000) { rs += "aaaaaaaaaa"; i += 1; } + let i = 0; + let rs = ""; + while i < 100000 { rs += "aaaaaaaaaa"; i += 1; } ret rs; } // Test messages from FIPS 180-1 - let vec[test] fips_180_1_tests = - [rec(input="abc", - output=[0xA9u8, 0x99u8, 0x3Eu8, 0x36u8, 0x47u8, 0x06u8, 0x81u8, - 0x6Au8, 0xBAu8, 0x3Eu8, 0x25u8, 0x71u8, 0x78u8, 0x50u8, - 0xC2u8, 0x6Cu8, 0x9Cu8, 0xD0u8, 0xD8u8, 0x9Du8]), - rec(input="abcdbcdecdefdefgefghfghighij" + - "hijkijkljklmklmnlmnomnopnopq", - output=[0x84u8, 0x98u8, 0x3Eu8, 0x44u8, 0x1Cu8, 0x3Bu8, 0xD2u8, - 0x6Eu8, 0xBAu8, 0xAEu8, 0x4Au8, 0xA1u8, 0xF9u8, 0x51u8, - 0x29u8, 0xE5u8, 0xE5u8, 0x46u8, 0x70u8, 0xF1u8]), - rec(input=a_million_letter_a(), - output=[0x34u8, 0xAAu8, 0x97u8, 0x3Cu8, 0xD4u8, 0xC4u8, 0xDAu8, - 0xA4u8, 0xF6u8, 0x1Eu8, 0xEBu8, 0x2Bu8, 0xDBu8, 0xADu8, - 0x27u8, 0x31u8, 0x65u8, 0x34u8, 0x01u8, 0x6Fu8])]; + let fips_180_1_tests: vec[test] = + [{input: "abc", + output: + [0xA9u8, 0x99u8, 0x3Eu8, 0x36u8, 0x47u8, 0x06u8, 0x81u8, 0x6Au8, + 0xBAu8, 0x3Eu8, 0x25u8, 0x71u8, 0x78u8, 0x50u8, 0xC2u8, 0x6Cu8, + 0x9Cu8, 0xD0u8, 0xD8u8, 0x9Du8]}, + {input: + "abcdbcdecdefdefgefghfghighij" + "hijkijkljklmklmnlmnomnopnopq", + output: + [0x84u8, 0x98u8, 0x3Eu8, 0x44u8, 0x1Cu8, 0x3Bu8, 0xD2u8, 0x6Eu8, + 0xBAu8, 0xAEu8, 0x4Au8, 0xA1u8, 0xF9u8, 0x51u8, 0x29u8, 0xE5u8, + 0xE5u8, 0x46u8, 0x70u8, 0xF1u8]}, + {input: a_million_letter_a(), + output: + [0x34u8, 0xAAu8, 0x97u8, 0x3Cu8, 0xD4u8, 0xC4u8, 0xDAu8, 0xA4u8, + 0xF6u8, 0x1Eu8, 0xEBu8, 0x2Bu8, 0xDBu8, 0xADu8, 0x27u8, 0x31u8, + 0x65u8, 0x34u8, 0x01u8, 0x6Fu8]}]; // Examples from wikipedia - let vec[test] wikipedia_tests = - [rec(input="The quick brown fox jumps over the lazy dog", - output=[0x2fu8, 0xd4u8, 0xe1u8, 0xc6u8, 0x7au8, 0x2du8, 0x28u8, - 0xfcu8, 0xedu8, 0x84u8, 0x9eu8, 0xe1u8, 0xbbu8, 0x76u8, - 0xe7u8, 0x39u8, 0x1bu8, 0x93u8, 0xebu8, 0x12u8]), - rec(input="The quick brown fox jumps over the lazy cog", - output=[0xdeu8, 0x9fu8, 0x2cu8, 0x7fu8, 0xd2u8, 0x5eu8, 0x1bu8, - 0x3au8, 0xfau8, 0xd3u8, 0xe8u8, 0x5au8, 0x0bu8, 0xd1u8, - 0x7du8, 0x9bu8, 0x10u8, 0x0du8, 0xb4u8, 0xb3u8])]; - auto tests = fips_180_1_tests + wikipedia_tests; - fn check_vec_eq(vec[u8] v0, vec[u8] v1) { + let wikipedia_tests: vec[test] = + [{input: "The quick brown fox jumps over the lazy dog", + output: + [0x2fu8, 0xd4u8, 0xe1u8, 0xc6u8, 0x7au8, 0x2du8, 0x28u8, 0xfcu8, + 0xedu8, 0x84u8, 0x9eu8, 0xe1u8, 0xbbu8, 0x76u8, 0xe7u8, 0x39u8, + 0x1bu8, 0x93u8, 0xebu8, 0x12u8]}, + {input: "The quick brown fox jumps over the lazy cog", + output: + [0xdeu8, 0x9fu8, 0x2cu8, 0x7fu8, 0xd2u8, 0x5eu8, 0x1bu8, 0x3au8, + 0xfau8, 0xd3u8, 0xe8u8, 0x5au8, 0x0bu8, 0xd1u8, 0x7du8, 0x9bu8, + 0x10u8, 0x0du8, 0xb4u8, 0xb3u8]}]; + let tests = fips_180_1_tests + wikipedia_tests; + fn check_vec_eq(v0: vec[u8], v1: vec[u8]) { assert (vec::len[u8](v0) == vec::len[u8](v1)); - auto len = vec::len[u8](v0); - auto i = 0u; - while (i < len) { - auto a = v0.(i); - auto b = v1.(i); + let len = vec::len[u8](v0); + let i = 0u; + while i < len { + let a = v0.(i); + let b = v1.(i); assert (a == b); i += 1u; } } // Test that it works when accepting the message all at once - auto sh = sha1::mk_sha1(); - for (test t in tests) { + let sh = sha1::mk_sha1(); + for t: test in tests { sh.input_str(t.input); - auto out = sh.result(); + let out = sh.result(); check_vec_eq(t.output, out); sh.reset(); } + // Test that it works when accepting the message in pieces - for (test t in tests) { - auto len = str::byte_len(t.input); - auto left = len; - while (left > 0u) { - auto take = (left + 1u) / 2u; + for t: test in tests { + let len = str::byte_len(t.input); + let left = len; + while left > 0u { + let take = (left + 1u) / 2u; sh.input_str(str::substr(t.input, len - left, take)); left = left - take; } - auto out = sh.result(); + let out = sh.result(); check_vec_eq(t.output, out); sh.reset(); } diff --git a/src/test/stdtest/sort.rs b/src/test/stdtest/sort.rs index aae679217bb..e2ce3f028fb 100644 --- a/src/test/stdtest/sort.rs +++ b/src/test/stdtest/sort.rs @@ -1,28 +1,28 @@ use std; -fn check_sort(vec[int] v1, vec[int] v2) { - auto len = std::vec::len[int](v1); - fn lteq(&int a, &int b) -> bool { ret a <= b; } - auto f = lteq; - auto v3 = std::sort::merge_sort[int](f, v1); - auto i = 0u; - while (i < len) { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; } +fn check_sort(v1: vec[int], v2: vec[int]) { + let len = std::vec::len[int](v1); + fn lteq(a: &int, b: &int) -> bool { ret a <= b; } + let f = lteq; + let v3 = std::sort::merge_sort[int](f, v1); + let i = 0u; + while i < len { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; } } #[test] fn test() { { - auto v1 = [3, 7, 4, 5, 2, 9, 5, 8]; - auto v2 = [2, 3, 4, 5, 5, 7, 8, 9]; + let v1 = [3, 7, 4, 5, 2, 9, 5, 8]; + let v2 = [2, 3, 4, 5, 5, 7, 8, 9]; check_sort(v1, v2); } - { auto v1 = [1, 1, 1]; auto v2 = [1, 1, 1]; check_sort(v1, v2); } - { let vec[int] v1 = []; let vec[int] v2 = []; check_sort(v1, v2); } - { auto v1 = [9]; auto v2 = [9]; check_sort(v1, v2); } + { let v1 = [1, 1, 1]; let v2 = [1, 1, 1]; check_sort(v1, v2); } + { let v1: vec[int] = []; let v2: vec[int] = []; check_sort(v1, v2); } + { let v1 = [9]; let v2 = [9]; check_sort(v1, v2); } { - auto v1 = [9, 3, 3, 3, 9]; - auto v2 = [3, 3, 3, 9, 9]; + let v1 = [9, 3, 3, 3, 9]; + let v2 = [3, 3, 3, 9, 9]; check_sort(v1, v2); } } \ No newline at end of file diff --git a/src/test/stdtest/sort_ivec.rs b/src/test/stdtest/sort_ivec.rs index dcc90a8edc9..14654a89ad9 100644 --- a/src/test/stdtest/sort_ivec.rs +++ b/src/test/stdtest/sort_ivec.rs @@ -1,28 +1,28 @@ use std; -fn check_sort(&int[] v1, &int[] v2) { - auto len = std::ivec::len[int](v1); - fn lteq(&int a, &int b) -> bool { ret a <= b; } - auto f = lteq; - auto v3 = std::sort::ivector::merge_sort[int](f, v1); - auto i = 0u; - while (i < len) { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; } +fn check_sort(v1: &int[], v2: &int[]) { + let len = std::ivec::len[int](v1); + fn lteq(a: &int, b: &int) -> bool { ret a <= b; } + let f = lteq; + let v3 = std::sort::ivector::merge_sort[int](f, v1); + let i = 0u; + while i < len { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; } } #[test] fn test() { { - auto v1 = ~[3, 7, 4, 5, 2, 9, 5, 8]; - auto v2 = ~[2, 3, 4, 5, 5, 7, 8, 9]; + let v1 = ~[3, 7, 4, 5, 2, 9, 5, 8]; + let v2 = ~[2, 3, 4, 5, 5, 7, 8, 9]; check_sort(v1, v2); } - { auto v1 = ~[1, 1, 1]; auto v2 = ~[1, 1, 1]; check_sort(v1, v2); } - { let int[] v1 = ~[]; let int[] v2 = ~[]; check_sort(v1, v2); } - { auto v1 = ~[9]; auto v2 = ~[9]; check_sort(v1, v2); } + { let v1 = ~[1, 1, 1]; let v2 = ~[1, 1, 1]; check_sort(v1, v2); } + { let v1: int[] = ~[]; let v2: int[] = ~[]; check_sort(v1, v2); } + { let v1 = ~[9]; let v2 = ~[9]; check_sort(v1, v2); } { - auto v1 = ~[9, 3, 3, 3, 9]; - auto v2 = ~[3, 3, 3, 9, 9]; + let v1 = ~[9, 3, 3, 3, 9]; + let v2 = ~[3, 3, 3, 9, 9]; check_sort(v1, v2); } -} +} \ No newline at end of file diff --git a/src/test/stdtest/str.rs b/src/test/stdtest/str.rs index 063a0d9783c..f2b6a6b46ec 100644 --- a/src/test/stdtest/str.rs +++ b/src/test/stdtest/str.rs @@ -24,12 +24,12 @@ fn test_index_and_rindex() { #[test] fn test_split() { - fn t(&str s, char c, int i, &str k) { + fn t(s: &str, c: char, i: int, k: &str) { log "splitting: " + s; log i; - auto v = str::split(s, c as u8); + let v = str::split(s, c as u8); log "split to: "; - for (str z in v) { log z; } + for z: str in v { log z; } log "comparing: " + v.(i) + " vs. " + k; assert (str::eq(v.(i), k)); } @@ -44,8 +44,8 @@ fn test_split() { #[test] fn test_find() { - fn t(&str haystack, &str needle, int i) { - let int j = str::find(haystack, needle); + fn t(haystack: &str, needle: &str, i: int) { + let j: int = str::find(haystack, needle); log "searched for " + needle; log j; assert (i == j); @@ -59,7 +59,7 @@ fn test_find() { #[test] fn test_substr() { - fn t(&str a, &str b, int start) { + fn t(a: &str, b: &str, start: int) { assert (str::eq(str::substr(a, start as uint, str::byte_len(b)), b)); } t("hello", "llo", 2); @@ -69,20 +69,20 @@ fn test_substr() { #[test] fn test_concat() { - fn t(&vec[str] v, &str s) { assert (str::eq(str::concat(v), s)); } + fn t(v: &vec[str], s: &str) { assert (str::eq(str::concat(v), s)); } t(["you", "know", "I'm", "no", "good"], "youknowI'mnogood"); - let vec[str] v = []; + let v: vec[str] = []; t(v, ""); t(["hi"], "hi"); } #[test] fn test_connect() { - fn t(&vec[str] v, &str sep, &str s) { + fn t(v: &vec[str], sep: &str, s: &str) { assert (str::eq(str::connect(v, sep), s)); } t(["you", "know", "I'm", "no", "good"], " ", "you know I'm no good"); - let vec[str] v = []; + let v: vec[str] = []; t(v, " ", ""); t(["hi"], " ", "hi"); } @@ -92,10 +92,10 @@ fn test_to_upper() { // to_upper doesn't understand unicode yet, // but we need to at least preserve it - auto unicode = "\u65e5\u672c"; - auto input = "abcDEF" + unicode + "xyz:.;"; - auto expected = "ABCDEF" + unicode + "XYZ:.;"; - auto actual = str::to_upper(input); + let unicode = "\u65e5\u672c"; + let input = "abcDEF" + unicode + "xyz:.;"; + let expected = "ABCDEF" + unicode + "XYZ:.;"; + let actual = str::to_upper(input); assert (str::eq(expected, actual)); } @@ -105,15 +105,15 @@ fn test_slice() { assert (str::eq("bc", str::slice("abc", 1u, 3u))); assert (str::eq("", str::slice("abc", 1u, 1u))); fn a_million_letter_a() -> str { - auto i = 0; - auto rs = ""; - while (i < 100000) { rs += "aaaaaaaaaa"; i += 1; } + let i = 0; + let rs = ""; + while i < 100000 { rs += "aaaaaaaaaa"; i += 1; } ret rs; } fn half_a_million_letter_a() -> str { - auto i = 0; - auto rs = ""; - while (i < 100000) { rs += "aaaaa"; i += 1; } + let i = 0; + let rs = ""; + while i < 100000 { rs += "aaaaa"; i += 1; } ret rs; } assert (str::eq(half_a_million_letter_a(), @@ -131,28 +131,27 @@ fn test_ends_with() { #[test] fn test_is_empty() { - assert str::is_empty(""); - assert !str::is_empty("a"); + assert (str::is_empty("")); + assert (!str::is_empty("a")); } #[test] fn test_is_not_empty() { - assert str::is_not_empty("a"); - assert !str::is_not_empty(""); + assert (str::is_not_empty("a")); + assert (!str::is_not_empty("")); } #[test] fn test_replace() { - auto a = "a"; - check str::is_not_empty(a); - assert str::replace("", a, "b") == ""; - assert str::replace("a", a, "b") == "b"; - assert str::replace("ab", a, "b") == "bb"; - auto test = "test"; - check str::is_not_empty(test); - assert str::replace(" test test ", test, "toast") - == " toast toast "; - assert str::replace(" test test ", test, "") == " "; + let a = "a"; + check (str::is_not_empty(a)); + assert (str::replace("", a, "b") == ""); + assert (str::replace("a", a, "b") == "b"); + assert (str::replace("ab", a, "b") == "bb"); + let test = "test"; + check (str::is_not_empty(test)); + assert (str::replace(" test test ", test, "toast") == " toast toast "); + assert (str::replace(" test test ", test, "") == " "); } diff --git a/src/test/stdtest/str_buf.rs b/src/test/stdtest/str_buf.rs index 0bc005224c2..6b013ed8db2 100644 --- a/src/test/stdtest/str_buf.rs +++ b/src/test/stdtest/str_buf.rs @@ -6,10 +6,10 @@ import std::str; #[test] fn test() { - auto s = "hello"; - auto sb = str::buf(s); - auto s_cstr = str::str_from_cstr(sb); + let s = "hello"; + let sb = str::buf(s); + let s_cstr = str::str_from_cstr(sb); assert (str::eq(s_cstr, s)); - auto s_buf = str::str_from_buf(sb, 5u); + let s_buf = str::str_from_buf(sb, 5u); assert (str::eq(s_buf, s)); } \ No newline at end of file diff --git a/src/test/stdtest/task.rs b/src/test/stdtest/task.rs index 62ed8b9638a..1324326c06d 100644 --- a/src/test/stdtest/task.rs +++ b/src/test/stdtest/task.rs @@ -7,59 +7,53 @@ fn test_sleep() { task::sleep(1000000u); } #[test] fn test_unsupervise() { - fn f() { - task::unsupervise(); - fail; - } + fn f() { task::unsupervise(); fail; } spawn f(); } #[test] fn test_join() { - fn winner() { - } + fn winner() { } - auto wintask = spawn winner(); + let wintask = spawn winner(); - assert task::join(wintask) == task::tr_success; + assert (task::join(wintask) == task::tr_success); - fn failer() { - task::unsupervise(); - fail; - } + fn failer() { task::unsupervise(); fail; } - auto failtask = spawn failer(); + let failtask = spawn failer(); - assert task::join(failtask) == task::tr_failure; + assert (task::join(failtask) == task::tr_failure); } #[test] fn test_send_recv() { - auto p = port[int](); - auto c = chan(p); + let p = port[int](); + let c = chan(p); task::send(c, 10); - assert task::recv(p) == 10; + assert (task::recv(p) == 10); } #[test] fn test_worker() { - task::worker(fn(port[int] p) { - auto x; p |> x; - assert x == 10; - }).chan <| 10; - - task::worker(fn(port[rec(int x, int y)] p) { - auto x; p |> x; - assert x.y == 20; - }).chan <| rec(x = 10, y = 20); - - task::worker(fn(port[rec(int x, int y, int z)] p) { - auto x; p |> x; - assert x.z == 30; - }).chan <| rec(x = 10, y = 20, z = 30); - - task::worker(fn(port[rec(int a, int b, int c, int d)] p) { - auto x; p |> x; - assert x.d == 40; - }).chan <| rec(a = 10, b = 20, c = 30, d = 40); -} + task::worker(fn (p: port[int]) { let x; p |> x; assert (x == 10); }).chan + <| 10; + + task::worker(fn (p: port[{x: int, y: int}]) { + let x; + p |> x; + assert (x.y == 20); + }).chan <| {x: 10, y: 20}; + + task::worker(fn (p: port[{x: int, y: int, z: int}]) { + let x; + p |> x; + assert (x.z == 30); + }).chan <| {x: 10, y: 20, z: 30}; + + task::worker(fn (p: port[{a: int, b: int, c: int, d: int}]) { + let x; + p |> x; + assert (x.d == 40); + }).chan <| {a: 10, b: 20, c: 30, d: 40}; +} \ No newline at end of file diff --git a/src/test/stdtest/test.rs b/src/test/stdtest/test.rs index 65c1a049f93..fd6f8831bf9 100644 --- a/src/test/stdtest/test.rs +++ b/src/test/stdtest/test.rs @@ -6,44 +6,38 @@ import std::ivec; #[test] fn do_not_run_ignored_tests() { - auto ran = @mutable false; - auto f = bind fn(@mutable bool ran) { - *ran = true; - } (ran); + let ran = @mutable false; + let f = bind fn (ran: @mutable bool) { *ran = true; }(ran); - auto desc = rec(name = "whatever", - fn = f, - ignore = true); + let desc = {name: "whatever", fn: f, ignore: true}; test::run_test(desc, test::default_test_to_task); - assert ran == false; + assert (ran == false); } #[test] fn ignored_tests_result_in_ignored() { fn f() { } - auto desc = rec(name = "whatever", - fn = f, - ignore = true); - auto res = test::run_test(desc, test::default_test_to_task).wait(); - assert res == test::tr_ignored; + let desc = {name: "whatever", fn: f, ignore: true}; + let res = test::run_test(desc, test::default_test_to_task).wait(); + assert (res == test::tr_ignored); } #[test] fn first_free_arg_should_be_a_filter() { - auto args = ~["progname", "filter"]; - check ivec::is_not_empty(args); - auto opts = alt test::parse_opts(args) { either::left(?o) { o } }; - assert str::eq("filter", option::get(opts.filter)); + let args = ~["progname", "filter"]; + check (ivec::is_not_empty(args)); + let opts = alt test::parse_opts(args) { either::left(o) { o } }; + assert (str::eq("filter", option::get(opts.filter))); } #[test] fn parse_ignored_flag() { - auto args = ~["progname", "filter", "--ignored"]; - check ivec::is_not_empty(args); - auto opts = alt test::parse_opts(args) { either::left(?o) { o } }; - assert opts.run_ignored; + let args = ~["progname", "filter", "--ignored"]; + check (ivec::is_not_empty(args)); + let opts = alt test::parse_opts(args) { either::left(o) { o } }; + assert (opts.run_ignored); } #[test] @@ -51,62 +45,52 @@ fn filter_for_ignored_option() { // When we run ignored tests the test filter should filter out all the // unignored tests and flip the ignore flag on the rest to false - auto opts = rec(filter = option::none, - run_ignored = true); - auto tests = ~[rec(name = "1", - fn = fn() {}, - ignore = true), - rec(name = "2", - fn = fn() {}, - ignore = false)]; - auto filtered = test::filter_tests(opts, tests); - - assert ivec::len(filtered) == 1u; - assert filtered.(0).name == "1"; - assert filtered.(0).ignore == false; + let opts = {filter: option::none, run_ignored: true}; + let tests = + ~[{name: "1", fn: fn () { }, ignore: true}, + {name: "2", fn: fn () { }, ignore: false}]; + let filtered = test::filter_tests(opts, tests); + + assert (ivec::len(filtered) == 1u); + assert (filtered.(0).name == "1"); + assert (filtered.(0).ignore == false); } #[test] fn sort_tests() { - auto opts = rec(filter = option::none, - run_ignored = false); - - auto names = ~["sha1::test", - "int::test_to_str", - "int::test_pow", - "test::do_not_run_ignored_tests", - "test::ignored_tests_result_in_ignored", - "test::first_free_arg_should_be_a_filter", - "test::parse_ignored_flag", - "test::filter_for_ignored_option", - "test::sort_tests"]; - auto tests = { - auto testfn = fn() {}; - auto tests = ~[]; - for (str name in names) { - auto test = rec(name = name, - fn = testfn, - ignore = false); - tests += ~[test]; - } - tests - }; - auto filtered = test::filter_tests(opts, tests); - - auto expected = ~["int::test_pow", - "int::test_to_str", - "sha1::test", - "test::do_not_run_ignored_tests", - "test::filter_for_ignored_option", - "test::first_free_arg_should_be_a_filter", - "test::ignored_tests_result_in_ignored", - "test::parse_ignored_flag", - "test::sort_tests"]; - - auto pairs = ivec::zip(expected, filtered); - - for (rec(str _0, test::test_desc _1) p in pairs) { - assert p._0 == p._1.name; + let opts = {filter: option::none, run_ignored: false}; + + let names = + ~["sha1::test", "int::test_to_str", "int::test_pow", + "test::do_not_run_ignored_tests", + "test::ignored_tests_result_in_ignored", + "test::first_free_arg_should_be_a_filter", + "test::parse_ignored_flag", "test::filter_for_ignored_option", + "test::sort_tests"]; + let tests = + { + let testfn = fn () { }; + let tests = ~[]; + for name: str in names { + let test = {name: name, fn: testfn, ignore: false}; + tests += ~[test]; + } + tests + }; + let filtered = test::filter_tests(opts, tests); + + let expected = + ~["int::test_pow", "int::test_to_str", "sha1::test", + "test::do_not_run_ignored_tests", "test::filter_for_ignored_option", + "test::first_free_arg_should_be_a_filter", + "test::ignored_tests_result_in_ignored", "test::parse_ignored_flag", + "test::sort_tests"]; + + let pairs = ivec::zip(expected, filtered); + + + for p: {_0: str, _1: test::test_desc} in pairs { + assert (p._0 == p._1.name); } } diff --git a/src/test/stdtest/vec.rs b/src/test/stdtest/vec.rs index 5e140a783cc..af346472f82 100644 --- a/src/test/stdtest/vec.rs +++ b/src/test/stdtest/vec.rs @@ -6,19 +6,19 @@ import std::option; #[test] fn test_init_elt() { - let vec[uint] v = init_elt[uint](5u, 3u); + let v: vec[uint] = init_elt[uint](5u, 3u); assert (len[uint](v) == 3u); assert (v.(0) == 5u); assert (v.(1) == 5u); assert (v.(2) == 5u); } -fn id(uint x) -> uint { ret x; } +fn id(x: uint) -> uint { ret x; } #[test] fn test_init_fn() { - let fn(uint) -> uint op = id; - let vec[uint] v = init_fn[uint](op, 5u); + let op: fn(uint) -> uint = id; + let v: vec[uint] = init_fn[uint](op, 5u); assert (len[uint](v) == 5u); assert (v.(0) == 0u); assert (v.(1) == 1u); @@ -29,8 +29,8 @@ fn test_init_fn() { #[test] fn test_slice() { - let vec[int] v = [1, 2, 3, 4, 5]; - auto v2 = slice[int](v, 2u, 4u); + let v: vec[int] = [1, 2, 3, 4, 5]; + let v2 = slice[int](v, 2u, 4u); assert (len[int](v2) == 2u); assert (v2.(0) == 3); assert (v2.(1) == 4); @@ -38,40 +38,39 @@ fn test_slice() { #[test] fn test_map() { - fn square(&int x) -> int { ret x * x; } - let option::operator[int, int] op = square; - let vec[int] v = [1, 2, 3, 4, 5]; - let vec[int] s = map[int, int](op, v); - let int i = 0; - while (i < 5) { assert (v.(i) * v.(i) == s.(i)); i += 1; } + fn square(x: &int) -> int { ret x * x; } + let op: option::operator[int, int] = square; + let v: vec[int] = [1, 2, 3, 4, 5]; + let s: vec[int] = map[int, int](op, v); + let i: int = 0; + while i < 5 { assert (v.(i) * v.(i) == s.(i)); i += 1; } } #[test] fn test_map2() { - fn times(&int x, &int y) -> int { ret x * y; } - auto f = times; - auto v0 = [1, 2, 3, 4, 5]; - auto v1 = [5, 4, 3, 2, 1]; - auto u = map2[int, int, int](f, v0, v1); - auto i = 0; - while (i < 5) { assert (v0.(i) * v1.(i) == u.(i)); i += 1; } + fn times(x: &int, y: &int) -> int { ret x * y; } + let f = times; + let v0 = [1, 2, 3, 4, 5]; + let v1 = [5, 4, 3, 2, 1]; + let u = map2[int, int, int](f, v0, v1); + let i = 0; + while i < 5 { assert (v0.(i) * v1.(i) == u.(i)); i += 1; } } #[test] fn test_filter_map() { - fn halve(&int i) -> option::t[int] { - if (i % 2 == 0) { + fn halve(i: &int) -> option::t[int] { + if i % 2 == 0 { ret option::some[int](i / 2); } else { ret option::none[int]; } } - fn halve_for_sure(&int i) -> int { ret i / 2; } - let vec[int] all_even = [0, 2, 8, 6]; - let vec[int] all_odd1 = [1, 7, 3]; - let vec[int] all_odd2 = []; - let vec[int] mix = [9, 2, 6, 7, 1, 0, 0, 3]; - let vec[int] mix_dest = [1, 3, 0, 0]; - assert (filter_map(halve, all_even) == - map(halve_for_sure, all_even)); + fn halve_for_sure(i: &int) -> int { ret i / 2; } + let all_even: vec[int] = [0, 2, 8, 6]; + let all_odd1: vec[int] = [1, 7, 3]; + let all_odd2: vec[int] = []; + let mix: vec[int] = [9, 2, 6, 7, 1, 0, 0, 3]; + let mix_dest: vec[int] = [1, 3, 0, 0]; + assert (filter_map(halve, all_even) == map(halve_for_sure, all_even)); assert (filter_map(halve, all_odd1) == empty[int]()); assert (filter_map(halve, all_odd2) == empty[int]()); assert (filter_map(halve, mix) == mix_dest); @@ -79,22 +78,18 @@ fn test_filter_map() { #[test] fn test_position() { - let vec[int] v1 = [1, 2, 3, 3, 2, 5]; - assert (position(1, v1) == option::some[uint](0u)); - assert (position(2, v1) == option::some[uint](1u)); - assert (position(5, v1) == option::some[uint](5u)); - assert (position(4, v1) == option::none[uint]); + let v1: vec[int] = [1, 2, 3, 3, 2, 5]; + assert (position(1, v1) == option::some[uint](0u)); + assert (position(2, v1) == option::some[uint](1u)); + assert (position(5, v1) == option::some[uint](5u)); + assert (position(4, v1) == option::none[uint]); } #[test] fn test_position_pred() { - fn less_than_three(&int i) -> bool { - ret i <3; - } - fn is_eighteen(&int i) -> bool { - ret i == 18; - } - let vec[int] v1 = [5, 4, 3, 2, 1]; - assert (position_pred(less_than_three, v1) == option::some[uint](3u)); - assert (position_pred(is_eighteen, v1) == option::none[uint]); -} + fn less_than_three(i: &int) -> bool { ret i < 3; } + fn is_eighteen(i: &int) -> bool { ret i == 18; } + let v1: vec[int] = [5, 4, 3, 2, 1]; + assert (position_pred(less_than_three, v1) == option::some[uint](3u)); + assert (position_pred(is_eighteen, v1) == option::none[uint]); +} \ No newline at end of file diff --git a/src/test/stdtest/vec_str_conversions.rs b/src/test/stdtest/vec_str_conversions.rs index dddbb5b21be..554fd694f7f 100644 --- a/src/test/stdtest/vec_str_conversions.rs +++ b/src/test/stdtest/vec_str_conversions.rs @@ -7,7 +7,7 @@ import std::vec; #[test] fn test_simple() { - let str s1 = "All mimsy were the borogoves"; + let s1: str = "All mimsy were the borogoves"; /* * FIXME from_bytes(vec[u8] v) has constraint is_utf(v), which is * unimplemented and thereby just fails. This doesn't stop us from @@ -15,15 +15,15 @@ fn test_simple() { * working, but we should implement is_utf8 before that happens. */ - let vec[u8] v = str::bytes(s1); - let str s2 = str::from_bytes(v); - let uint i = 0u; - let uint n1 = str::byte_len(s1); - let uint n2 = vec::len[u8](v); + let v: vec[u8] = str::bytes(s1); + let s2: str = str::from_bytes(v); + let i: uint = 0u; + let n1: uint = str::byte_len(s1); + let n2: uint = vec::len[u8](v); assert (n1 == n2); - while (i < n1) { - let u8 a = s1.(i); - let u8 b = s2.(i); + while i < n1 { + let a: u8 = s1.(i); + let b: u8 = s2.(i); log a; log b; assert (a == b); @@ -31,4 +31,4 @@ fn test_simple() { } log "refcnt is"; log str::refcount(s1); -} +} \ No newline at end of file |
