| author | |
| committer | |
| log | 6ed835ca67670098da79d4e329c6efcb12419599 |
| tree | fad1400b90b2d0cf7f28dd90562c2b0311d1f33d |
| parent | 3ef6663b723e7391edbe84d3df48fcc79c66bc1f |
3 files changed, 53 insertions(+), 56 deletions(-)
test/cases/eval.zig+21| ... | ... | @@ -73,6 +73,27 @@ fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 { |
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | |
| 76 | fn 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 | } | |
| 84 | const Point = struct { | |
| 85 | x: i32, | |
| 86 | y: i32, | |
| 87 | }; | |
| 88 | const static_point_list = []Point { makePoint(1, 2), makePoint(3, 4) }; | |
| 89 | fn makePoint(x: i32, y: i32) -> Point { | |
| 90 | return Point { | |
| 91 | .x = x, | |
| 92 | .y = y, | |
| 93 | }; | |
| 94 | } | |
| 95 | ||
| 96 | ||
| 76 | 97 | |
| 77 | 98 | // TODO const assert = @import("std").debug.assert; |
| 78 | 99 | fn assert(ok: bool) { |
test/cases/misc.zig+29| ... | ... | @@ -291,6 +291,35 @@ fn memAlloc(inline T: type, n: usize) -> %[]T { |
| 291 | 291 | fn memFree(inline T: type, mem: []T) { } |
| 292 | 292 | |
| 293 | 293 | |
| 294 | fn castUndefined() { | |
| 295 | @setFnTest(this); | |
| 296 | ||
| 297 | const array: [100]u8 = undefined; | |
| 298 | const slice = ([]u8)(array); | |
| 299 | testCastUndefined(slice); | |
| 300 | } | |
| 301 | fn testCastUndefined(x: []const u8) {} | |
| 302 | ||
| 303 | ||
| 304 | fn castSmallUnsignedToLargerSigned() { | |
| 305 | @setFnTest(this); | |
| 306 | ||
| 307 | assert(castSmallUnsignedToLargerSigned1(200) == i16(200)); | |
| 308 | assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999)); | |
| 309 | } | |
| 310 | fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { x } | |
| 311 | fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { x } | |
| 312 | ||
| 313 | ||
| 314 | fn implicitCastAfterUnreachable() { | |
| 315 | @setFnTest(this); | |
| 316 | ||
| 317 | assert(outer() == 1234); | |
| 318 | } | |
| 319 | fn inner() -> i32 { 1234 } | |
| 320 | fn outer() -> i64 { | |
| 321 | return inner(); | |
| 322 | } | |
| 294 | 323 | |
| 295 | 324 | |
| 296 | 325 | // TODO import from std.str |
test/self_hosted.zig+3-56| ... | ... | @@ -4,74 +4,21 @@ const str = std.str; |
| 4 | 4 | const cstr = std.cstr; |
| 5 | 5 | |
| 6 | 6 | |
| 7 | fn castUndefined() { | |
| 8 | @setFnTest(this, true); | |
| 9 | ||
| 10 | const array: [100]u8 = undefined; | |
| 11 | const slice = ([]u8)(array); | |
| 12 | testCastUndefined(slice); | |
| 13 | } | |
| 14 | fn testCastUndefined(x: []u8) {} | |
| 15 | ||
| 16 | ||
| 17 | fn castSmallUnsignedToLargerSigned() { | |
| 18 | @setFnTest(this, true); | |
| 19 | ||
| 20 | assert(castSmallUnsignedToLargerSigned1(200) == i16(200)); | |
| 21 | assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999)); | |
| 22 | } | |
| 23 | fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { x } | |
| 24 | fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { x } | |
| 25 | ||
| 26 | ||
| 27 | fn implicitCastAfterUnreachable() { | |
| 28 | @setFnTest(this, true); | |
| 29 | ||
| 30 | assert(outer() == 1234); | |
| 31 | } | |
| 32 | fn inner() -> i32 { 1234 } | |
| 33 | fn outer() -> i64 { | |
| 34 | return inner(); | |
| 35 | } | |
| 36 | ||
| 37 | ||
| 38 | fn 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 | } | |
| 46 | struct Point { | |
| 47 | x: i32, | |
| 48 | y: i32, | |
| 49 | } | |
| 50 | const static_point_list = []Point { makePoint(1, 2), makePoint(3, 4) }; | |
| 51 | fn makePoint(x: i32, y: i32) -> Point { | |
| 52 | return Point { | |
| 53 | .x = x, | |
| 54 | .y = y, | |
| 55 | }; | |
| 56 | } | |
| 57 | ||
| 58 | ||
| 59 | 7 | fn staticEvalListInit() { |
| 60 | @setFnTest(this, true); | |
| 8 | @setFnTest(this); | |
| 61 | 9 | |
| 62 | 10 | assert(static_vec3.data[2] == 1.0); |
| 63 | 11 | } |
| 64 | 12 | const static_vec3 = vec3(0.0, 0.0, 1.0); |
| 65 | pub struct Vec3 { | |
| 13 | pub const Vec3 = struct { | |
| 66 | 14 | data: [3]f32, |
| 67 | } | |
| 15 | }; | |
| 68 | 16 | pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 { |
| 69 | 17 | Vec3 { |
| 70 | 18 | .data = []f32 { x, y, z, }, |
| 71 | 19 | } |
| 72 | 20 | } |
| 73 | 21 | |
| 74 | ||
| 75 | 22 | fn genericFnWithImplicitCast() { |
| 76 | 23 | @setFnTest(this, true); |
| 77 | 24 |