Skip to content

Commit

Permalink
auto merge of #7839 : graydon/rust/new-codegen-tests, r=pcwalton
Browse files Browse the repository at this point in the history
Add some codegen tests. Nothing too surprising.
  • Loading branch information
bors committed Jul 17, 2013
2 parents af54f63 + 40f7434 commit a93244d
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/test/codegen/iterate-over-array.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdlib.h>
#include <assert.h>

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;
}
10 changes: 10 additions & 0 deletions src/test/codegen/iterate-over-array.rs
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions src/test/codegen/scalar-function-call.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdlib.h>

size_t foo(size_t x) {
return x * x;
}

extern "C"
void test() {
size_t x = foo(10);
}
8 changes: 8 additions & 0 deletions src/test/codegen/scalar-function-call.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn foo(x: int) -> int {
x * x
}

#[no_mangle]
fn test() {
let x = foo(10);
}
11 changes: 11 additions & 0 deletions src/test/codegen/small-dense-int-switch.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdlib.h>

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;
}
}
9 changes: 9 additions & 0 deletions src/test/codegen/small-dense-int-switch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[no_mangle]
fn test(x: int, y: int) -> int {
match x {
1 => y,
2 => y*2,
4 => y*3,
_ => 11
}
}
File renamed without changes.
File renamed without changes.

0 comments on commit a93244d

Please sign in to comment.