passing all tests

This commit is contained in:
Andrew Kelley
2016-04-12 13:30:52 -07:00
parent aa89fd3b3e
commit be4df96e4b
5 changed files with 240 additions and 164 deletions

View File

@@ -218,6 +218,7 @@ pub fn bar_function() {
)SOURCE");
add_source_file(tc, "other.zig", R"SOURCE(
#static_eval_enable(false)
pub fn foo_function() -> bool {
// this one conflicts with the one from foo
return true;
@@ -406,20 +407,6 @@ pub fn main(args: [][]u8) -> %void {
}
)SOURCE", "loop\nloop\nloop\nloop\n");
add_simple_case("implicit cast after unreachable", R"SOURCE(
const io = @import("std").io;
pub fn main(args: [][]u8) -> %void {
const x = outer();
if (x == 1234) {
%%io.stdout.printf("OK\n");
}
}
fn inner() -> i32 { 1234 }
fn outer() -> isize {
return inner();
}
)SOURCE", "OK\n");
add_simple_case("@sizeof() and @typeof()", R"SOURCE(
const io = @import("std").io;
const x: u16 = 13;
@@ -431,23 +418,6 @@ pub fn main(args: [][]u8) -> %void {
}
)SOURCE", "2\n");
add_simple_case("member functions", R"SOURCE(
const io = @import("std").io;
struct Rand {
seed: u32,
pub fn get_seed(r: Rand) -> u32 {
r.seed
}
}
pub fn main(args: [][]u8) -> %void {
const r = Rand {.seed = 1234};
if (r.get_seed() != 1234) {
%%io.stdout.printf("BAD seed\n");
}
%%io.stdout.printf("OK\n");
}
)SOURCE", "OK\n");
add_simple_case("pointer dereferencing", R"SOURCE(
const io = @import("std").io;
@@ -565,24 +535,6 @@ pub fn main(args: [][]u8) -> %void {
"min i64: -9223372036854775808\n");
add_simple_case("else if expression", R"SOURCE(
const io = @import("std").io;
pub fn main(args: [][]u8) -> %void {
if (f(1) == 1) {
%%io.stdout.printf("OK\n");
}
}
fn f(c: u8) -> u8 {
if (c == 0) {
0
} else if (c == 1) {
1
} else {
2
}
}
)SOURCE", "OK\n");
add_simple_case("overflow intrinsics", R"SOURCE(
const io = @import("std").io;
pub fn main(args: [][]u8) -> %void {
@@ -730,29 +682,6 @@ pub fn main(args: [][]u8) -> %void {
}
)SOURCE", "OK\n");
add_simple_case("%% binary operator", R"SOURCE(
const io = @import("std").io;
error ItBroke;
fn g(x: bool) -> %isize {
if (x) {
error.ItBroke
} else {
10
}
}
pub fn main(args: [][]u8) -> %void {
const a = g(true) %% 3;
const b = g(false) %% 3;
if (a != 3) {
%%io.stdout.printf("BAD\n");
}
if (b != 10) {
%%io.stdout.printf("BAD\n");
}
%%io.stdout.printf("OK\n");
}
)SOURCE", "OK\n");
add_simple_case("string concatenation", R"SOURCE(
const io = @import("std").io;
pub fn main(args: [][]u8) -> %void {
@@ -808,54 +737,6 @@ pub fn main(args: [][]u8) -> %void {
}
)SOURCE", "OK\n");
add_simple_case("unwrap simple value from error", R"SOURCE(
const io = @import("std").io;
fn do() -> %isize {
13
}
pub fn main(args: [][]u8) -> %void {
const i = %%do();
if (i != 13) {
%%io.stdout.printf("BAD\n");
}
%%io.stdout.printf("OK\n");
}
)SOURCE", "OK\n");
add_simple_case("store member function in variable", R"SOURCE(
const io = @import("std").io;
struct Foo {
x: i32,
fn member(foo: Foo) -> i32 { foo.x }
}
pub fn main(args: [][]u8) -> %void {
const instance = Foo { .x = 1234, };
const member_fn = Foo.member;
const result = member_fn(instance);
if (result != 1234) {
%%io.stdout.printf("BAD\n");
}
%%io.stdout.printf("OK\n");
}
)SOURCE", "OK\n");
add_simple_case("call member function directly", R"SOURCE(
const io = @import("std").io;
struct Foo {
x: i32,
fn member(foo: Foo) -> i32 { foo.x }
}
pub fn main(args: [][]u8) -> %void {
const instance = Foo { .x = 1234, };
const result = Foo.member(instance);
if (result != 1234) {
%%io.stdout.printf("BAD\n");
}
%%io.stdout.printf("OK\n");
}
)SOURCE", "OK\n");
add_simple_case("call result of if else expression", R"SOURCE(
const io = @import("std").io;
fn a() -> []u8 { "a\n" }
@@ -1496,7 +1377,8 @@ fn a(x: i32) {
struct Foo {
y: [get()]u8,
}
fn get() -> isize { 1 }
var global_var: isize = 1;
fn get() -> isize { global_var }
)SOURCE", 1, ".tmp_source.zig:3:9: error: unable to evaluate constant expression");