From 6ed835ca67670098da79d4e329c6efcb12419599 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 26 Dec 2016 03:05:33 -0500 Subject: [PATCH] IR: port more tests --- test/cases/eval.zig | 21 ++++++++++++++++ test/cases/misc.zig | 29 ++++++++++++++++++++++ test/self_hosted.zig | 59 +++----------------------------------------- 3 files changed, 53 insertions(+), 56 deletions(-) diff --git a/test/cases/eval.zig b/test/cases/eval.zig index fb38760ea6..c34d552035 100644 --- a/test/cases/eval.zig +++ b/test/cases/eval.zig @@ -73,6 +73,27 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 { +fn staticallyInitalizedList() { + @setFnTest(this); + + assert(static_point_list[0].x == 1); + assert(static_point_list[0].y == 2); + assert(static_point_list[1].x == 3); + assert(static_point_list[1].y == 4); +} +const Point = struct { + x: i32, + y: i32, +}; +const static_point_list = []Point { makePoint(1, 2), makePoint(3, 4) }; +fn makePoint(x: i32, y: i32) -> Point { + return Point { + .x = x, + .y = y, + }; +} + + // TODO const assert = @import("std").debug.assert; fn assert(ok: bool) { diff --git a/test/cases/misc.zig b/test/cases/misc.zig index 762c5e9298..0cbebf1ab7 100644 --- a/test/cases/misc.zig +++ b/test/cases/misc.zig @@ -291,6 +291,35 @@ fn memAlloc(inline T: type, n: usize) -> %[]T { fn memFree(inline T: type, mem: []T) { } +fn castUndefined() { + @setFnTest(this); + + const array: [100]u8 = undefined; + const slice = ([]u8)(array); + testCastUndefined(slice); +} +fn testCastUndefined(x: []const u8) {} + + +fn castSmallUnsignedToLargerSigned() { + @setFnTest(this); + + assert(castSmallUnsignedToLargerSigned1(200) == i16(200)); + assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999)); +} +fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { x } +fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { x } + + +fn implicitCastAfterUnreachable() { + @setFnTest(this); + + assert(outer() == 1234); +} +fn inner() -> i32 { 1234 } +fn outer() -> i64 { + return inner(); +} // TODO import from std.str diff --git a/test/self_hosted.zig b/test/self_hosted.zig index 24e90da688..4c6c9641bc 100644 --- a/test/self_hosted.zig +++ b/test/self_hosted.zig @@ -4,74 +4,21 @@ const str = std.str; const cstr = std.cstr; -fn castUndefined() { - @setFnTest(this, true); - - const array: [100]u8 = undefined; - const slice = ([]u8)(array); - testCastUndefined(slice); -} -fn testCastUndefined(x: []u8) {} - - -fn castSmallUnsignedToLargerSigned() { - @setFnTest(this, true); - - assert(castSmallUnsignedToLargerSigned1(200) == i16(200)); - assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999)); -} -fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { x } -fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { x } - - -fn implicitCastAfterUnreachable() { - @setFnTest(this, true); - - assert(outer() == 1234); -} -fn inner() -> i32 { 1234 } -fn outer() -> i64 { - return inner(); -} - - -fn staticallyInitalizedList() { - @setFnTest(this, true); - - assert(static_point_list[0].x == 1); - assert(static_point_list[0].y == 2); - assert(static_point_list[1].x == 3); - assert(static_point_list[1].y == 4); -} -struct Point { - x: i32, - y: i32, -} -const static_point_list = []Point { makePoint(1, 2), makePoint(3, 4) }; -fn makePoint(x: i32, y: i32) -> Point { - return Point { - .x = x, - .y = y, - }; -} - - fn staticEvalListInit() { - @setFnTest(this, true); + @setFnTest(this); assert(static_vec3.data[2] == 1.0); } const static_vec3 = vec3(0.0, 0.0, 1.0); -pub struct Vec3 { +pub const Vec3 = struct { data: [3]f32, -} +}; pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 { Vec3 { .data = []f32 { x, y, z, }, } } - fn genericFnWithImplicitCast() { @setFnTest(this, true);