aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-03-07 21:21:01 -0500
committerBrian Anderson <[email protected]>2011-03-07 21:21:01 -0500
commit9fc4db6b89213afdf45c02fc2bd2be62b0ddc40c (patch)
tree6c84574116273f91cbe89abd256b9f809adf97de /src/test
parentAllow the else part of an expr_if to be either expr_if or expr_block (diff)
parentrustc: Cast the LLVM representations of tag types when constructing boxes. Un... (diff)
downloadrust-9fc4db6b89213afdf45c02fc2bd2be62b0ddc40c.tar.xz
rust-9fc4db6b89213afdf45c02fc2bd2be62b0ddc40c.zip
Merge branch 'master' into recursive-elseif
Conflicts: src/Makefile src/comp/front/ast.rs src/comp/front/parser.rs src/comp/middle/fold.rs src/comp/middle/trans.rs
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/reserved-dec.rs5
-rw-r--r--src/test/compile-fail/reserved-f128.rs5
-rw-r--r--src/test/compile-fail/reserved-f16.rs5
-rw-r--r--src/test/compile-fail/reserved-f80.rs5
-rw-r--r--src/test/compile-fail/reserved-m128.rs5
-rw-r--r--src/test/compile-fail/reserved-m32.rs5
-rw-r--r--src/test/compile-fail/reserved-m64.rs5
-rw-r--r--src/test/compile-fail/tail-non-call.rs10
-rw-r--r--src/test/compile-fail/tail-typeck.rs13
-rw-r--r--src/test/run-pass/alt-pattern-lit.rs17
-rw-r--r--src/test/run-pass/arith-unsigned.rs24
-rw-r--r--src/test/run-pass/generic-box.rs8
-rw-r--r--src/test/run-pass/generic-fn-box.rs9
-rw-r--r--src/test/run-pass/generic-recursive-tag.rs7
-rw-r--r--src/test/run-pass/generic-tag.rs2
-rw-r--r--src/test/run-pass/generic-type-synonym.rs2
-rw-r--r--src/test/run-pass/lib-io.rs6
-rw-r--r--src/test/run-pass/lib-sha1.rs115
-rw-r--r--src/test/run-pass/native2.rs20
-rw-r--r--src/test/run-pass/path.rs8
-rw-r--r--src/test/run-pass/syntax-extension-fmt.rs15
-rw-r--r--src/test/run-pass/typestate-cfg-nesting.rs26
22 files changed, 307 insertions, 10 deletions
diff --git a/src/test/compile-fail/reserved-dec.rs b/src/test/compile-fail/reserved-dec.rs
new file mode 100644
index 00000000..d8c204d9
--- /dev/null
+++ b/src/test/compile-fail/reserved-dec.rs
@@ -0,0 +1,5 @@
+// error-pattern:reserved keyword
+
+fn main() {
+ let int dec = 0;
+}
diff --git a/src/test/compile-fail/reserved-f128.rs b/src/test/compile-fail/reserved-f128.rs
new file mode 100644
index 00000000..63d00f70
--- /dev/null
+++ b/src/test/compile-fail/reserved-f128.rs
@@ -0,0 +1,5 @@
+// error-pattern:reserved keyword
+
+fn main() {
+ let int f128 = 0;
+}
diff --git a/src/test/compile-fail/reserved-f16.rs b/src/test/compile-fail/reserved-f16.rs
new file mode 100644
index 00000000..bfb14cd8
--- /dev/null
+++ b/src/test/compile-fail/reserved-f16.rs
@@ -0,0 +1,5 @@
+// error-pattern:reserved keyword
+
+fn main() {
+ let int f16 = 0;
+}
diff --git a/src/test/compile-fail/reserved-f80.rs b/src/test/compile-fail/reserved-f80.rs
new file mode 100644
index 00000000..33e8bd5e
--- /dev/null
+++ b/src/test/compile-fail/reserved-f80.rs
@@ -0,0 +1,5 @@
+// error-pattern:reserved keyword
+
+fn main() {
+ let int f80 = 0;
+}
diff --git a/src/test/compile-fail/reserved-m128.rs b/src/test/compile-fail/reserved-m128.rs
new file mode 100644
index 00000000..c4d36bf7
--- /dev/null
+++ b/src/test/compile-fail/reserved-m128.rs
@@ -0,0 +1,5 @@
+// error-pattern:reserved keyword
+
+fn main() {
+ let int m128 = 0;
+}
diff --git a/src/test/compile-fail/reserved-m32.rs b/src/test/compile-fail/reserved-m32.rs
new file mode 100644
index 00000000..bdb3a427
--- /dev/null
+++ b/src/test/compile-fail/reserved-m32.rs
@@ -0,0 +1,5 @@
+// error-pattern:reserved keyword
+
+fn main() {
+ let int m32 = 0;
+}
diff --git a/src/test/compile-fail/reserved-m64.rs b/src/test/compile-fail/reserved-m64.rs
new file mode 100644
index 00000000..034884a6
--- /dev/null
+++ b/src/test/compile-fail/reserved-m64.rs
@@ -0,0 +1,5 @@
+// error-pattern:reserved keyword
+
+fn main() {
+ let int m64 = 0;
+}
diff --git a/src/test/compile-fail/tail-non-call.rs b/src/test/compile-fail/tail-non-call.rs
new file mode 100644
index 00000000..00a451f6
--- /dev/null
+++ b/src/test/compile-fail/tail-non-call.rs
@@ -0,0 +1,10 @@
+// error-pattern: Non-call expression in tail call
+
+fn f() -> int {
+ auto x = 1;
+ be x;
+}
+
+fn main() {
+ auto y = f();
+}
diff --git a/src/test/compile-fail/tail-typeck.rs b/src/test/compile-fail/tail-typeck.rs
new file mode 100644
index 00000000..64beedb9
--- /dev/null
+++ b/src/test/compile-fail/tail-typeck.rs
@@ -0,0 +1,13 @@
+// error-pattern: mismatched types
+
+fn f() -> int {
+ be g();
+}
+
+fn g() -> uint {
+ ret 0u;
+}
+
+fn main() {
+ auto y = f();
+}
diff --git a/src/test/run-pass/alt-pattern-lit.rs b/src/test/run-pass/alt-pattern-lit.rs
new file mode 100644
index 00000000..91190260
--- /dev/null
+++ b/src/test/run-pass/alt-pattern-lit.rs
@@ -0,0 +1,17 @@
+fn altlit(int f) -> int {
+ alt (f) {
+ case (10) {
+ log "case 10";
+ ret 20;
+ }
+ case (11) {
+ log "case 11";
+ ret 22;
+ }
+ }
+}
+
+fn main() {
+ check (altlit(10) == 20);
+ check (altlit(11) == 22);
+}
diff --git a/src/test/run-pass/arith-unsigned.rs b/src/test/run-pass/arith-unsigned.rs
new file mode 100644
index 00000000..3fac3714
--- /dev/null
+++ b/src/test/run-pass/arith-unsigned.rs
@@ -0,0 +1,24 @@
+// Unsigned integer operations
+
+fn main() {
+ check (0u8 < 255u8);
+ check (0u8 <= 255u8);
+ check (255u8 > 0u8);
+ check (255u8 >= 0u8);
+ check (250u8 / 10u8 == 25u8);
+ check (255u8 % 10u8 == 5u8);
+ check (0u16 < 60000u16);
+ check (0u16 <= 60000u16);
+ check (60000u16 > 0u16);
+ check (60000u16 >= 0u16);
+ check (60000u16 / 10u16 == 6000u16);
+ check (60005u16 % 10u16 == 5u16);
+ check (0u32 < 4000000000u32);
+ check (0u32 <= 4000000000u32);
+ check (4000000000u32 > 0u32);
+ check (4000000000u32 >= 0u32);
+ check (4000000000u32 / 10u32 == 400000000u32);
+ check (4000000005u32 % 10u32 == 5u32);
+
+ // 64-bit numbers have some flakiness yet. Not tested
+}
diff --git a/src/test/run-pass/generic-box.rs b/src/test/run-pass/generic-box.rs
new file mode 100644
index 00000000..856f3aff
--- /dev/null
+++ b/src/test/run-pass/generic-box.rs
@@ -0,0 +1,8 @@
+fn box[T](&tup(T,T,T) x) -> @tup(T,T,T) {
+ ret @x;
+}
+
+fn main() {
+ let @tup(int,int,int) x = box[int](tup(1,2,3));
+ check (x._1 == 2);
+} \ No newline at end of file
diff --git a/src/test/run-pass/generic-fn-box.rs b/src/test/run-pass/generic-fn-box.rs
new file mode 100644
index 00000000..e821a784
--- /dev/null
+++ b/src/test/run-pass/generic-fn-box.rs
@@ -0,0 +1,9 @@
+fn f[T](@T x) -> @T {
+ ret x;
+}
+
+fn main() {
+ auto x = f(@3);
+ log *x;
+}
+
diff --git a/src/test/run-pass/generic-recursive-tag.rs b/src/test/run-pass/generic-recursive-tag.rs
index ad06345b..b9596b0d 100644
--- a/src/test/run-pass/generic-recursive-tag.rs
+++ b/src/test/run-pass/generic-recursive-tag.rs
@@ -1,8 +1,9 @@
tag list[T] {
cons(@T, @list[T]);
- nil();
+ nil;
}
fn main() {
- let list[int] a = cons[int](10, cons[int](12, cons[int](13, nil[int]())));
-} \ No newline at end of file
+ let list[int] a = cons[int](@10, @cons[int](@12, @cons[int](@13,
+ @nil[int])));
+}
diff --git a/src/test/run-pass/generic-tag.rs b/src/test/run-pass/generic-tag.rs
index 1fd88255..68d7c18f 100644
--- a/src/test/run-pass/generic-tag.rs
+++ b/src/test/run-pass/generic-tag.rs
@@ -6,4 +6,4 @@ tag option[T] {
fn main() {
let option[int] a = some[int](@10);
a = none[int];
-} \ No newline at end of file
+}
diff --git a/src/test/run-pass/generic-type-synonym.rs b/src/test/run-pass/generic-type-synonym.rs
index 4ddc8946..c3d2a9d5 100644
--- a/src/test/run-pass/generic-type-synonym.rs
+++ b/src/test/run-pass/generic-type-synonym.rs
@@ -1,4 +1,4 @@
type foo[T] = tup(T);
type bar[T] = foo[T];
-fn takebar[T](bar[T] b) {}
+fn takebar[T](&bar[T] b) {}
fn main() {} \ No newline at end of file
diff --git a/src/test/run-pass/lib-io.rs b/src/test/run-pass/lib-io.rs
index 66394435..0c0bcdcd 100644
--- a/src/test/run-pass/lib-io.rs
+++ b/src/test/run-pass/lib-io.rs
@@ -1,7 +1,7 @@
// -*- rust -*-
use std;
-import std._io;
+import std.io;
import std._str;
fn test_simple(str tmpfilebase) {
@@ -11,11 +11,11 @@ fn test_simple(str tmpfilebase) {
log frood;
{
- let _io.buf_writer out = _io.new_buf_writer(tmpfile, vec(_io.create()));
+ let io.buf_writer out = io.new_buf_writer(tmpfile, vec(io.create));
out.write(_str.bytes(frood));
}
- let _io.buf_reader inp = _io.new_buf_reader(tmpfile);
+ let io.buf_reader inp = io.new_buf_reader(tmpfile);
let str frood2 = _str.from_bytes(inp.read());
log frood2;
check (_str.eq(frood, frood2));
diff --git a/src/test/run-pass/lib-sha1.rs b/src/test/run-pass/lib-sha1.rs
new file mode 100644
index 00000000..57e3cdc8
--- /dev/null
+++ b/src/test/run-pass/lib-sha1.rs
@@ -0,0 +1,115 @@
+// -*- rust -*-
+
+use std;
+
+import std.sha1;
+import std._vec;
+import std._str;
+
+fn main() {
+
+ type test = rec(str input, vec[u8] output);
+
+ fn a_million_letter_a() -> str {
+ auto i = 0;
+ auto res = "";
+ while (i < 100000) {
+ res += "aaaaaaaaaa";
+ i += 1;
+ }
+ ret res;
+ }
+
+ // Test messages from FIPS 180-1
+ let vec[test] fips_180_1_tests =
+ vec(
+ rec(input = "abc",
+ output = vec(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 = vec(0x84u8, 0x98u8, 0x3Eu8, 0x44u8, 0x1Cu8,
+ 0x3Bu8, 0xD2u8, 0x6Eu8, 0xBAu8, 0xAEu8,
+ 0x4Au8, 0xA1u8, 0xF9u8, 0x51u8, 0x29u8,
+ 0xE5u8, 0xE5u8, 0x46u8, 0x70u8, 0xF1u8)
+ )
+ // FIXME: This test is disabled because it takes some
+ // minutes to run under rustboot+valgrind. It may be
+ // possible to reenable once things are more optimized.
+ /*,
+ rec(input = a_million_letter_a(),
+ output = vec(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 =
+ vec(
+ rec(input = "The quick brown fox jumps over the lazy dog",
+ output = vec(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 = vec(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) {
+ check (_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);
+ check (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) {
+ sh.input_str(t.input);
+ auto 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;
+ sh.input_str(_str.substr(t.input, len - left, take));
+ left = left - take;
+ }
+ auto out = sh.result();
+ check_vec_eq(t.output, out);
+ sh.reset();
+ }
+}
+
+
+// Local Variables:
+// mode: rust;
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
diff --git a/src/test/run-pass/native2.rs b/src/test/run-pass/native2.rs
new file mode 100644
index 00000000..4815345a
--- /dev/null
+++ b/src/test/run-pass/native2.rs
@@ -0,0 +1,20 @@
+native "rust" mod rustrt {
+ type vbuf;
+ fn vec_buf[T](vec[T] v, uint offset) -> vbuf;
+}
+
+native "rust" mod bar = "foo" {
+}
+
+native mod zed {
+}
+
+native mod libc = "libc.dylib" {
+ fn write(int fd, rustrt.vbuf buf, uint count) -> int;
+}
+
+native "cdecl" mod baz {
+}
+
+fn main(vec[str] args) {
+}
diff --git a/src/test/run-pass/path.rs b/src/test/run-pass/path.rs
new file mode 100644
index 00000000..e94d32eb
--- /dev/null
+++ b/src/test/run-pass/path.rs
@@ -0,0 +1,8 @@
+mod foo {
+ fn bar(uint offset) {
+ }
+}
+
+fn main(vec[str] args) {
+ foo.bar(0u);
+}
diff --git a/src/test/run-pass/syntax-extension-fmt.rs b/src/test/run-pass/syntax-extension-fmt.rs
index 65e7647e..ebb09f96 100644
--- a/src/test/run-pass/syntax-extension-fmt.rs
+++ b/src/test/run-pass/syntax-extension-fmt.rs
@@ -1,5 +1,16 @@
use std;
+import std._str;
+
+fn test(str actual, str expected) {
+ log actual;
+ log expected;
+ check (_str.eq(actual, expected));
+}
+
fn main() {
- auto s = #fmt("hello %d friends and %s things", 10, "formatted");
- log s;
+ test(#fmt("hello %d friends and %s things", 10, "formatted"),
+ "hello 10 friends and formatted things");
+ test(#fmt("d: %d", 1), "d: 1");
+ test(#fmt("i: %i", 2), "i: 2");
+ test(#fmt("s: %s", "test"), "s: test");
}
diff --git a/src/test/run-pass/typestate-cfg-nesting.rs b/src/test/run-pass/typestate-cfg-nesting.rs
new file mode 100644
index 00000000..8f050646
--- /dev/null
+++ b/src/test/run-pass/typestate-cfg-nesting.rs
@@ -0,0 +1,26 @@
+
+fn f() {
+
+ auto x = 10;
+ auto y = 11;
+ if (true) {
+ alt (x) {
+ case (_) {
+ y = x;
+ }
+ }
+ } else {
+ }
+}
+
+fn main() {
+
+ auto x = 10;
+ auto y = 11;
+ if (true) {
+ while (false) {
+ y = x;
+ }
+ } else {
+ }
+}