From 40f74341f3ba2cee2afedb31014ee14432d700cd Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 16 Jul 2013 17:42:28 -0700 Subject: [PATCH] test: new codegen tests, rename hello. --- src/test/codegen/iterate-over-array.cc | 17 +++++++++++++++++ src/test/codegen/iterate-over-array.rs | 10 ++++++++++ src/test/codegen/scalar-function-call.cc | 10 ++++++++++ src/test/codegen/scalar-function-call.rs | 8 ++++++++ src/test/codegen/small-dense-int-switch.cc | 11 +++++++++++ src/test/codegen/small-dense-int-switch.rs | 9 +++++++++ .../{hello.cc => stack-alloc-string-slice.cc} | 0 .../{hello.rs => stack-alloc-string-slice.rs} | 0 8 files changed, 65 insertions(+) create mode 100644 src/test/codegen/iterate-over-array.cc create mode 100644 src/test/codegen/iterate-over-array.rs create mode 100644 src/test/codegen/scalar-function-call.cc create mode 100644 src/test/codegen/scalar-function-call.rs create mode 100644 src/test/codegen/small-dense-int-switch.cc create mode 100644 src/test/codegen/small-dense-int-switch.rs rename src/test/codegen/{hello.cc => stack-alloc-string-slice.cc} (100%) rename src/test/codegen/{hello.rs => stack-alloc-string-slice.rs} (100%) diff --git a/src/test/codegen/iterate-over-array.cc b/src/test/codegen/iterate-over-array.cc new file mode 100644 index 0000000000000..7eca21b13d70b --- /dev/null +++ b/src/test/codegen/iterate-over-array.cc @@ -0,0 +1,17 @@ +#include +#include + +struct slice { + int const *p; + size_t len; +}; + +extern "C" +size_t test(slice s) { + size_t y = 0; + for (int i = 0; i < s.len; ++i) { + assert(i < s.len); + y += s.p[i]; + } + return y; +} diff --git a/src/test/codegen/iterate-over-array.rs b/src/test/codegen/iterate-over-array.rs new file mode 100644 index 0000000000000..cf54e6eafbaf1 --- /dev/null +++ b/src/test/codegen/iterate-over-array.rs @@ -0,0 +1,10 @@ +#[no_mangle] +fn test(x: &[int]) -> int { + let mut y = 0; + let mut i = 0; + while (i < x.len()) { + y += x[i]; + i += 1; + } + y +} diff --git a/src/test/codegen/scalar-function-call.cc b/src/test/codegen/scalar-function-call.cc new file mode 100644 index 0000000000000..91ed882f68a9f --- /dev/null +++ b/src/test/codegen/scalar-function-call.cc @@ -0,0 +1,10 @@ +#include + +size_t foo(size_t x) { + return x * x; +} + +extern "C" +void test() { + size_t x = foo(10); +} diff --git a/src/test/codegen/scalar-function-call.rs b/src/test/codegen/scalar-function-call.rs new file mode 100644 index 0000000000000..7e4a566749ba6 --- /dev/null +++ b/src/test/codegen/scalar-function-call.rs @@ -0,0 +1,8 @@ +fn foo(x: int) -> int { + x * x +} + +#[no_mangle] +fn test() { + let x = foo(10); +} diff --git a/src/test/codegen/small-dense-int-switch.cc b/src/test/codegen/small-dense-int-switch.cc new file mode 100644 index 0000000000000..87bc5bf852eb4 --- /dev/null +++ b/src/test/codegen/small-dense-int-switch.cc @@ -0,0 +1,11 @@ +#include + +extern "C" +size_t test(size_t x, size_t y) { + switch (x) { + case 1: return y; + case 2: return y*2; + case 4: return y*3; + default: return 11; + } +} diff --git a/src/test/codegen/small-dense-int-switch.rs b/src/test/codegen/small-dense-int-switch.rs new file mode 100644 index 0000000000000..6840dc7411b34 --- /dev/null +++ b/src/test/codegen/small-dense-int-switch.rs @@ -0,0 +1,9 @@ +#[no_mangle] +fn test(x: int, y: int) -> int { + match x { + 1 => y, + 2 => y*2, + 4 => y*3, + _ => 11 + } +} diff --git a/src/test/codegen/hello.cc b/src/test/codegen/stack-alloc-string-slice.cc similarity index 100% rename from src/test/codegen/hello.cc rename to src/test/codegen/stack-alloc-string-slice.cc diff --git a/src/test/codegen/hello.rs b/src/test/codegen/stack-alloc-string-slice.rs similarity index 100% rename from src/test/codegen/hello.rs rename to src/test/codegen/stack-alloc-string-slice.rs