authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-26 03:05:33-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-26 03:05:33-05:00
log6ed835ca67670098da79d4e329c6efcb12419599
treefad1400b90b2d0cf7f28dd90562c2b0311d1f33d
parent3ef6663b723e7391edbe84d3df48fcc79c66bc1f

IR: port more tests


3 files changed, 53 insertions(+), 56 deletions(-)

test/cases/eval.zig+21
...@@ -73,6 +73,27 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 {...@@ -73,6 +73,27 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 {
7373
7474
7575
76fn staticallyInitalizedList() {
77 @setFnTest(this);
78
79 assert(static_point_list[0].x == 1);
80 assert(static_point_list[0].y == 2);
81 assert(static_point_list[1].x == 3);
82 assert(static_point_list[1].y == 4);
83}
84const Point = struct {
85 x: i32,
86 y: i32,
87};
88const static_point_list = []Point { makePoint(1, 2), makePoint(3, 4) };
89fn makePoint(x: i32, y: i32) -> Point {
90 return Point {
91 .x = x,
92 .y = y,
93 };
94}
95
96
7697
77// TODO const assert = @import("std").debug.assert;98// TODO const assert = @import("std").debug.assert;
78fn assert(ok: bool) {99fn assert(ok: bool) {
test/cases/misc.zig+29
...@@ -291,6 +291,35 @@ fn memAlloc(inline T: type, n: usize) -> %[]T {...@@ -291,6 +291,35 @@ fn memAlloc(inline T: type, n: usize) -> %[]T {
291fn memFree(inline T: type, mem: []T) { }291fn memFree(inline T: type, mem: []T) { }
292292
293293
294fn castUndefined() {
295 @setFnTest(this);
296
297 const array: [100]u8 = undefined;
298 const slice = ([]u8)(array);
299 testCastUndefined(slice);
300}
301fn testCastUndefined(x: []const u8) {}
302
303
304fn castSmallUnsignedToLargerSigned() {
305 @setFnTest(this);
306
307 assert(castSmallUnsignedToLargerSigned1(200) == i16(200));
308 assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999));
309}
310fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { x }
311fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { x }
312
313
314fn implicitCastAfterUnreachable() {
315 @setFnTest(this);
316
317 assert(outer() == 1234);
318}
319fn inner() -> i32 { 1234 }
320fn outer() -> i64 {
321 return inner();
322}
294323
295324
296// TODO import from std.str325// TODO import from std.str
test/self_hosted.zig+3-56
...@@ -4,74 +4,21 @@ const str = std.str;...@@ -4,74 +4,21 @@ const str = std.str;
4const cstr = std.cstr;4const cstr = std.cstr;
55
66
7fn castUndefined() {
8 @setFnTest(this, true);
9
10 const array: [100]u8 = undefined;
11 const slice = ([]u8)(array);
12 testCastUndefined(slice);
13}
14fn testCastUndefined(x: []u8) {}
15
16
17fn castSmallUnsignedToLargerSigned() {
18 @setFnTest(this, true);
19
20 assert(castSmallUnsignedToLargerSigned1(200) == i16(200));
21 assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999));
22}
23fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { x }
24fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { x }
25
26
27fn implicitCastAfterUnreachable() {
28 @setFnTest(this, true);
29
30 assert(outer() == 1234);
31}
32fn inner() -> i32 { 1234 }
33fn outer() -> i64 {
34 return inner();
35}
36
37
38fn staticallyInitalizedList() {
39 @setFnTest(this, true);
40
41 assert(static_point_list[0].x == 1);
42 assert(static_point_list[0].y == 2);
43 assert(static_point_list[1].x == 3);
44 assert(static_point_list[1].y == 4);
45}
46struct Point {
47 x: i32,
48 y: i32,
49}
50const static_point_list = []Point { makePoint(1, 2), makePoint(3, 4) };
51fn makePoint(x: i32, y: i32) -> Point {
52 return Point {
53 .x = x,
54 .y = y,
55 };
56}
57
58
59fn staticEvalListInit() {7fn staticEvalListInit() {
60 @setFnTest(this, true);8 @setFnTest(this);
619
62 assert(static_vec3.data[2] == 1.0);10 assert(static_vec3.data[2] == 1.0);
63}11}
64const static_vec3 = vec3(0.0, 0.0, 1.0);12const static_vec3 = vec3(0.0, 0.0, 1.0);
65pub struct Vec3 {13pub const Vec3 = struct {
66 data: [3]f32,14 data: [3]f32,
67}15};
68pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 {16pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 {
69 Vec3 {17 Vec3 {
70 .data = []f32 { x, y, z, },18 .data = []f32 { x, y, z, },
71 }19 }
72}20}
7321
74
75fn genericFnWithImplicitCast() {22fn genericFnWithImplicitCast() {
76 @setFnTest(this, true);23 @setFnTest(this, true);
7724