| author | |
| committer | |
| log | 8108c9f4d2580680e3ed2fc6a289b1af1c939b5c |
| tree | a1be69b29e073349218b1937c742e82e6790748c |
| parent | 1861423862194e845c631d0e0eea5c7bca5d284b |
23 files changed, 214 insertions(+), 200 deletions(-)
test/behavior/align.zig+6-6| ... | ... | @@ -7,11 +7,11 @@ const assert = std.debug.assert; |
| 7 | 7 | var foo: u8 align(4) = 100; |
| 8 | 8 | |
| 9 | 9 | test "global variable alignment" { |
| 10 | try comptime expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4); | |
| 11 | try comptime expect(@TypeOf(&foo) == *align(4) u8); | |
| 10 | comptime assert(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4); | |
| 11 | comptime assert(@TypeOf(&foo) == *align(4) u8); | |
| 12 | 12 | { |
| 13 | 13 | const slice = @as(*align(4) [1]u8, &foo)[0..]; |
| 14 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); | |
| 14 | comptime assert(@TypeOf(slice) == *align(4) [1]u8); | |
| 15 | 15 | } |
| 16 | 16 | } |
| 17 | 17 | |
| ... | ... | @@ -455,10 +455,10 @@ test "runtime-known array index has best alignment possible" { |
| 455 | 455 | try testIndex2(&array, 3, *u8); |
| 456 | 456 | } |
| 457 | 457 | fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) !void { |
| 458 | try comptime expect(@TypeOf(&smaller[index]) == T); | |
| 458 | comptime assert(@TypeOf(&smaller[index]) == T); | |
| 459 | 459 | } |
| 460 | 460 | fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) !void { |
| 461 | try comptime expect(@TypeOf(&ptr[index]) == T); | |
| 461 | comptime assert(@TypeOf(&ptr[index]) == T); | |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | test "alignment of function with c calling convention" { |
| ... | ... | @@ -524,7 +524,7 @@ test "struct field explicit alignment" { |
| 524 | 524 | var node: S.Node = undefined; |
| 525 | 525 | node.massive_byte = 100; |
| 526 | 526 | try expect(node.massive_byte == 100); |
| 527 | try comptime expect(@TypeOf(&node.massive_byte) == *align(64) u8); | |
| 527 | comptime assert(@TypeOf(&node.massive_byte) == *align(64) u8); | |
| 528 | 528 | try expect(@intFromPtr(&node.massive_byte) % 64 == 0); |
| 529 | 529 | } |
| 530 | 530 |
test/behavior/alignof.zig+3-2| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const assert = std.debug.assert; | |
| 2 | 3 | const expect = std.testing.expect; |
| 3 | 4 | const builtin = @import("builtin"); |
| 4 | 5 | const native_arch = builtin.target.cpu.arch; |
| ... | ... | @@ -11,9 +12,9 @@ const Foo = struct { |
| 11 | 12 | }; |
| 12 | 13 | |
| 13 | 14 | test "@alignOf(T) before referencing T" { |
| 14 | try comptime expect(@alignOf(Foo) != maxInt(usize)); | |
| 15 | comptime assert(@alignOf(Foo) != maxInt(usize)); | |
| 15 | 16 | if (native_arch == .x86_64) { |
| 16 | try comptime expect(@alignOf(Foo) == 4); | |
| 17 | comptime assert(@alignOf(Foo) == 4); | |
| 17 | 18 | } |
| 18 | 19 | } |
| 19 | 20 |
test/behavior/array.zig+4-3| ... | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const testing = std.testing; |
| 4 | 4 | const mem = std.mem; |
| 5 | const assert = std.debug.assert; | |
| 5 | 6 | const expect = testing.expect; |
| 6 | 7 | const expectEqual = testing.expectEqual; |
| 7 | 8 | |
| ... | ... | @@ -149,9 +150,9 @@ test "array len field" { |
| 149 | 150 | var arr = [4]u8{ 0, 0, 0, 0 }; |
| 150 | 151 | const ptr = &arr; |
| 151 | 152 | try expect(arr.len == 4); |
| 152 | try comptime expect(arr.len == 4); | |
| 153 | comptime assert(arr.len == 4); | |
| 153 | 154 | try expect(ptr.len == 4); |
| 154 | try comptime expect(ptr.len == 4); | |
| 155 | comptime assert(ptr.len == 4); | |
| 155 | 156 | try expect(@TypeOf(arr.len) == usize); |
| 156 | 157 | } |
| 157 | 158 | |
| ... | ... | @@ -904,7 +905,7 @@ test "store array of array of structs at comptime" { |
| 904 | 905 | }; |
| 905 | 906 | |
| 906 | 907 | try expect(S.storeArrayOfArrayOfStructs() == 15); |
| 907 | try comptime expect(S.storeArrayOfArrayOfStructs() == 15); | |
| 908 | comptime assert(S.storeArrayOfArrayOfStructs() == 15); | |
| 908 | 909 | } |
| 909 | 910 | |
| 910 | 911 | test "accessing multidimensional global array at comptime" { |
test/behavior/async_fn.zig+5-4| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const assert = std.debug.assert; | |
| 3 | 4 | const expect = std.testing.expect; |
| 4 | 5 | const expectEqual = std.testing.expectEqual; |
| 5 | 6 | const expectEqualStrings = std.testing.expectEqualStrings; |
| ... | ... | @@ -221,7 +222,7 @@ var a_promise: anyframe = undefined; |
| 221 | 222 | var global_result = false; |
| 222 | 223 | fn testSuspendBlock() callconv(.Async) void { |
| 223 | 224 | suspend { |
| 224 | comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable; | |
| 225 | comptime assert(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable; | |
| 225 | 226 | a_promise = @frame(); |
| 226 | 227 | } |
| 227 | 228 | |
| ... | ... | @@ -334,7 +335,7 @@ test "async fn pointer in a struct field" { |
| 334 | 335 | _ = &foo; |
| 335 | 336 | var bytes: [64]u8 align(16) = undefined; |
| 336 | 337 | const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); |
| 337 | try comptime expect(@TypeOf(f) == anyframe->void); | |
| 338 | comptime assert(@TypeOf(f) == anyframe->void); | |
| 338 | 339 | try expect(data == 2); |
| 339 | 340 | resume f; |
| 340 | 341 | try expect(data == 4); |
| ... | ... | @@ -1150,7 +1151,7 @@ test "@asyncCall using the result location inside the frame" { |
| 1150 | 1151 | _ = &foo; |
| 1151 | 1152 | var bytes: [64]u8 align(16) = undefined; |
| 1152 | 1153 | const f = @asyncCall(&bytes, {}, foo.bar, .{&data}); |
| 1153 | try comptime expect(@TypeOf(f) == anyframe->i32); | |
| 1154 | comptime assert(@TypeOf(f) == anyframe->i32); | |
| 1154 | 1155 | try expect(data == 2); |
| 1155 | 1156 | resume f; |
| 1156 | 1157 | try expect(data == 4); |
| ... | ... | @@ -1165,7 +1166,7 @@ test "@TypeOf an async function call of generic fn with error union type" { |
| 1165 | 1166 | const S = struct { |
| 1166 | 1167 | fn func(comptime x: anytype) anyerror!i32 { |
| 1167 | 1168 | const T = @TypeOf(async func(x)); |
| 1168 | try comptime expect(T == @typeInfo(@TypeOf(@frame())).Pointer.child); | |
| 1169 | comptime assert(T == @typeInfo(@TypeOf(@frame())).Pointer.child); | |
| 1169 | 1170 | return undefined; |
| 1170 | 1171 | } |
| 1171 | 1172 | }; |
test/behavior/basic.zig+5-5| ... | ... | @@ -17,7 +17,7 @@ test "empty function with comments" { |
| 17 | 17 | |
| 18 | 18 | test "truncate" { |
| 19 | 19 | try expect(testTruncate(0x10fd) == 0xfd); |
| 20 | try comptime expect(testTruncate(0x10fd) == 0xfd); | |
| 20 | comptime assert(testTruncate(0x10fd) == 0xfd); | |
| 21 | 21 | } |
| 22 | 22 | fn testTruncate(x: u32) u8 { |
| 23 | 23 | return @as(u8, @truncate(x)); |
| ... | ... | @@ -568,7 +568,7 @@ fn emptyFn() void {} |
| 568 | 568 | const addr1 = @as(*const u8, @ptrCast(&emptyFn)); |
| 569 | 569 | test "comptime cast fn to ptr" { |
| 570 | 570 | const addr2 = @as(*const u8, @ptrCast(&emptyFn)); |
| 571 | try comptime expect(addr1 == addr2); | |
| 571 | comptime assert(addr1 == addr2); | |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | test "equality compare fn ptrs" { |
| ... | ... | @@ -678,8 +678,8 @@ test "string concatenation" { |
| 678 | 678 | const a = "OK" ++ " IT " ++ "WORKED"; |
| 679 | 679 | const b = "OK IT WORKED"; |
| 680 | 680 | |
| 681 | try comptime expect(@TypeOf(a) == *const [12:0]u8); | |
| 682 | try comptime expect(@TypeOf(b) == *const [12:0]u8); | |
| 681 | comptime assert(@TypeOf(a) == *const [12:0]u8); | |
| 682 | comptime assert(@TypeOf(b) == *const [12:0]u8); | |
| 683 | 683 | |
| 684 | 684 | const len = b.len; |
| 685 | 685 | const len_with_null = len + 1; |
| ... | ... | @@ -747,7 +747,7 @@ test "auto created variables have correct alignment" { |
| 747 | 747 | } |
| 748 | 748 | }; |
| 749 | 749 | try expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); |
| 750 | try comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); | |
| 750 | comptime assert(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); | |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | test "extern variable with non-pointer opaque type" { |
test/behavior/bitcast.zig+3-2| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const assert = std.debug.assert; | |
| 3 | 4 | const expect = std.testing.expect; |
| 4 | 5 | const expectEqual = std.testing.expectEqual; |
| 5 | 6 | const math = std.math; |
| ... | ... | @@ -273,7 +274,7 @@ test "comptime bitcast used in expression has the correct type" { |
| 273 | 274 | test "bitcast passed as tuple element" { |
| 274 | 275 | const S = struct { |
| 275 | 276 | fn foo(args: anytype) !void { |
| 276 | try comptime expect(@TypeOf(args[0]) == f32); | |
| 277 | comptime assert(@TypeOf(args[0]) == f32); | |
| 277 | 278 | try expect(args[0] == 12.34); |
| 278 | 279 | } |
| 279 | 280 | }; |
| ... | ... | @@ -283,7 +284,7 @@ test "bitcast passed as tuple element" { |
| 283 | 284 | test "triple level result location with bitcast sandwich passed as tuple element" { |
| 284 | 285 | const S = struct { |
| 285 | 286 | fn foo(args: anytype) !void { |
| 286 | try comptime expect(@TypeOf(args[0]) == f64); | |
| 287 | comptime assert(@TypeOf(args[0]) == f64); | |
| 287 | 288 | try expect(args[0] > 12.33 and args[0] < 12.35); |
| 288 | 289 | } |
| 289 | 290 | }; |
test/behavior/call.zig+5-4| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | const assert = std.debug.assert; | |
| 3 | 4 | const expect = std.testing.expect; |
| 4 | 5 | const expectEqual = std.testing.expectEqual; |
| 5 | 6 | |
| ... | ... | @@ -10,11 +11,11 @@ test "super basic invocations" { |
| 10 | 11 | } |
| 11 | 12 | }.foo; |
| 12 | 13 | try expect(@call(.auto, foo, .{}) == 1234); |
| 13 | try comptime expect(@call(.always_inline, foo, .{}) == 1234); | |
| 14 | comptime assert(@call(.always_inline, foo, .{}) == 1234); | |
| 14 | 15 | { |
| 15 | 16 | // comptime call without comptime keyword |
| 16 | 17 | const result = @call(.compile_time, foo, .{}) == 1234; |
| 17 | try comptime expect(result); | |
| 18 | comptime assert(result); | |
| 18 | 19 | } |
| 19 | 20 | } |
| 20 | 21 | |
| ... | ... | @@ -42,7 +43,7 @@ test "basic invocations" { |
| 42 | 43 | { |
| 43 | 44 | // comptime call without comptime keyword |
| 44 | 45 | const result = @call(.compile_time, foo, .{}) == 1234; |
| 45 | try comptime expect(result); | |
| 46 | comptime assert(result); | |
| 46 | 47 | } |
| 47 | 48 | { |
| 48 | 49 | // call of non comptime-known function |
| ... | ... | @@ -73,7 +74,7 @@ test "tuple parameters" { |
| 73 | 74 | try expect(@call(.auto, add, .{ a, b }) == 46); |
| 74 | 75 | try expect(@call(.auto, add, .{ 12, 34 }) == 46); |
| 75 | 76 | if (false) { |
| 76 | try comptime expect(@call(.auto, add, .{ 12, 34 }) == 46); // TODO | |
| 77 | comptime assert(@call(.auto, add, .{ 12, 34 }) == 46); // TODO | |
| 77 | 78 | } |
| 78 | 79 | try expect(comptime @call(.auto, add, .{ 12, 34 }) == 46); |
| 79 | 80 | { |
test/behavior/cast.zig+22-22| ... | ... | @@ -63,7 +63,7 @@ test "implicit cast comptime numbers to any type when the value fits" { |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | test "implicit cast comptime_int to comptime_float" { |
| 66 | try comptime expect(@as(comptime_float, 10) == @as(f32, 10)); | |
| 66 | comptime assert(@as(comptime_float, 10) == @as(f32, 10)); | |
| 67 | 67 | try expect(2 == 2.0); |
| 68 | 68 | } |
| 69 | 69 | |
| ... | ... | @@ -313,11 +313,11 @@ test "peer result null and comptime_int" { |
| 313 | 313 | }; |
| 314 | 314 | |
| 315 | 315 | try expect(S.blah(0) == null); |
| 316 | try comptime expect(S.blah(0) == null); | |
| 316 | comptime assert(S.blah(0) == null); | |
| 317 | 317 | try expect(S.blah(10).? == 1); |
| 318 | try comptime expect(S.blah(10).? == 1); | |
| 318 | comptime assert(S.blah(10).? == 1); | |
| 319 | 319 | try expect(S.blah(-10).? == -1); |
| 320 | try comptime expect(S.blah(-10).? == -1); | |
| 320 | comptime assert(S.blah(-10).? == -1); | |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | test "*const ?[*]const T to [*c]const [*c]const T" { |
| ... | ... | @@ -393,7 +393,7 @@ test "peer type unsigned int to signed" { |
| 393 | 393 | var y: i32 = -5; |
| 394 | 394 | _ = .{ &w, &x, &y }; |
| 395 | 395 | const a = w + y + x; |
| 396 | try comptime expect(@TypeOf(a) == i32); | |
| 396 | comptime assert(@TypeOf(a) == i32); | |
| 397 | 397 | try expect(a == 7); |
| 398 | 398 | } |
| 399 | 399 | |
| ... | ... | @@ -542,9 +542,9 @@ test "peer type resolution: error and [N]T" { |
| 542 | 542 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 543 | 543 | |
| 544 | 544 | try expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); |
| 545 | try comptime expect(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); | |
| 545 | comptime assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); | |
| 546 | 546 | try expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); |
| 547 | try comptime expect(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); | |
| 547 | comptime assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); | |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | fn testPeerErrorAndArray(x: u8) anyerror![]const u8 { |
| ... | ... | @@ -1038,15 +1038,15 @@ test "peer type resolve string lit with sentinel-terminated mutable slice" { |
| 1038 | 1038 | var array: [4:0]u8 = undefined; |
| 1039 | 1039 | array[4] = 0; // TODO remove this when #4372 is solved |
| 1040 | 1040 | const slice: [:0]u8 = array[0..4 :0]; |
| 1041 | try comptime expect(@TypeOf(slice, "hi") == [:0]const u8); | |
| 1042 | try comptime expect(@TypeOf("hi", slice) == [:0]const u8); | |
| 1041 | comptime assert(@TypeOf(slice, "hi") == [:0]const u8); | |
| 1042 | comptime assert(@TypeOf("hi", slice) == [:0]const u8); | |
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | 1045 | test "peer type resolve array pointers, one of them const" { |
| 1046 | 1046 | var array1: [4]u8 = undefined; |
| 1047 | 1047 | const array2: [5]u8 = undefined; |
| 1048 | try comptime expect(@TypeOf(&array1, &array2) == []const u8); | |
| 1049 | try comptime expect(@TypeOf(&array2, &array1) == []const u8); | |
| 1048 | comptime assert(@TypeOf(&array1, &array2) == []const u8); | |
| 1049 | comptime assert(@TypeOf(&array2, &array1) == []const u8); | |
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | 1052 | test "peer type resolve array pointer and unknown pointer" { |
| ... | ... | @@ -1056,17 +1056,17 @@ test "peer type resolve array pointer and unknown pointer" { |
| 1056 | 1056 | var ptr: [*]u8 = undefined; |
| 1057 | 1057 | _ = .{ &const_ptr, &ptr }; |
| 1058 | 1058 | |
| 1059 | try comptime expect(@TypeOf(&array, ptr) == [*]u8); | |
| 1060 | try comptime expect(@TypeOf(ptr, &array) == [*]u8); | |
| 1059 | comptime assert(@TypeOf(&array, ptr) == [*]u8); | |
| 1060 | comptime assert(@TypeOf(ptr, &array) == [*]u8); | |
| 1061 | 1061 | |
| 1062 | try comptime expect(@TypeOf(&const_array, ptr) == [*]const u8); | |
| 1063 | try comptime expect(@TypeOf(ptr, &const_array) == [*]const u8); | |
| 1062 | comptime assert(@TypeOf(&const_array, ptr) == [*]const u8); | |
| 1063 | comptime assert(@TypeOf(ptr, &const_array) == [*]const u8); | |
| 1064 | 1064 | |
| 1065 | try comptime expect(@TypeOf(&array, const_ptr) == [*]const u8); | |
| 1066 | try comptime expect(@TypeOf(const_ptr, &array) == [*]const u8); | |
| 1065 | comptime assert(@TypeOf(&array, const_ptr) == [*]const u8); | |
| 1066 | comptime assert(@TypeOf(const_ptr, &array) == [*]const u8); | |
| 1067 | 1067 | |
| 1068 | try comptime expect(@TypeOf(&const_array, const_ptr) == [*]const u8); | |
| 1069 | try comptime expect(@TypeOf(const_ptr, &const_array) == [*]const u8); | |
| 1068 | comptime assert(@TypeOf(&const_array, const_ptr) == [*]const u8); | |
| 1069 | comptime assert(@TypeOf(const_ptr, &const_array) == [*]const u8); | |
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | 1072 | test "comptime float casts" { |
| ... | ... | @@ -1214,7 +1214,7 @@ test "implicitly cast from [N]T to ?[]const T" { |
| 1214 | 1214 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1215 | 1215 | |
| 1216 | 1216 | try expect(mem.eql(u8, castToOptionalSlice().?, "hi")); |
| 1217 | try comptime expect(mem.eql(u8, castToOptionalSlice().?, "hi")); | |
| 1217 | comptime assert(mem.eql(u8, castToOptionalSlice().?, "hi")); | |
| 1218 | 1218 | } |
| 1219 | 1219 | |
| 1220 | 1220 | fn castToOptionalSlice() ?[]const u8 { |
| ... | ... | @@ -1351,8 +1351,8 @@ test "peer resolve arrays of different size to const slice" { |
| 1351 | 1351 | |
| 1352 | 1352 | try expect(mem.eql(u8, boolToStr(true), "true")); |
| 1353 | 1353 | try expect(mem.eql(u8, boolToStr(false), "false")); |
| 1354 | try comptime expect(mem.eql(u8, boolToStr(true), "true")); | |
| 1355 | try comptime expect(mem.eql(u8, boolToStr(false), "false")); | |
| 1354 | comptime assert(mem.eql(u8, boolToStr(true), "true")); | |
| 1355 | comptime assert(mem.eql(u8, boolToStr(false), "false")); | |
| 1356 | 1356 | } |
| 1357 | 1357 | fn boolToStr(b: bool) []const u8 { |
| 1358 | 1358 | return if (b) "true" else "false"; |
test/behavior/enum.zig+9-9| ... | ... | @@ -773,12 +773,12 @@ test "set enum tag type" { |
| 773 | 773 | { |
| 774 | 774 | var x = Small.One; |
| 775 | 775 | x = Small.Two; |
| 776 | try comptime expect(Tag(Small) == u2); | |
| 776 | comptime assert(Tag(Small) == u2); | |
| 777 | 777 | } |
| 778 | 778 | { |
| 779 | 779 | var x = Small2.One; |
| 780 | 780 | x = Small2.Two; |
| 781 | try comptime expect(Tag(Small2) == u2); | |
| 781 | comptime assert(Tag(Small2) == u2); | |
| 782 | 782 | } |
| 783 | 783 | } |
| 784 | 784 | |
| ... | ... | @@ -795,7 +795,7 @@ test "enum with 1 field but explicit tag type should still have the tag type" { |
| 795 | 795 | const Enum = enum(u8) { |
| 796 | 796 | B = 2, |
| 797 | 797 | }; |
| 798 | try comptime expect(@sizeOf(Enum) == @sizeOf(u8)); | |
| 798 | comptime assert(@sizeOf(Enum) == @sizeOf(u8)); | |
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | test "signed integer as enum tag" { |
| ... | ... | @@ -834,12 +834,12 @@ test "enum with comptime_int tag type" { |
| 834 | 834 | Two = 2, |
| 835 | 835 | Three = 1, |
| 836 | 836 | }; |
| 837 | try comptime expect(Tag(Enum) == comptime_int); | |
| 837 | comptime assert(Tag(Enum) == comptime_int); | |
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | test "enum with one member default to u0 tag type" { |
| 841 | 841 | const E0 = enum { X }; |
| 842 | try comptime expect(Tag(E0) == u0); | |
| 842 | comptime assert(Tag(E0) == u0); | |
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | const EnumWithOneMember = enum { Eof }; |
| ... | ... | @@ -989,7 +989,7 @@ test "@tagName" { |
| 989 | 989 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 990 | 990 | |
| 991 | 991 | try expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); |
| 992 | try comptime expect(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); | |
| 992 | comptime assert(mem.eql(u8, testEnumTagNameBare(BareNumber.Three), "Three")); | |
| 993 | 993 | } |
| 994 | 994 | |
| 995 | 995 | fn testEnumTagNameBare(n: anytype) []const u8 { |
| ... | ... | @@ -1005,7 +1005,7 @@ test "@tagName non-exhaustive enum" { |
| 1005 | 1005 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 1006 | 1006 | |
| 1007 | 1007 | try expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B")); |
| 1008 | try comptime expect(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B")); | |
| 1008 | comptime assert(mem.eql(u8, testEnumTagNameBare(NonExhaustive.B), "B")); | |
| 1009 | 1009 | } |
| 1010 | 1010 | const NonExhaustive = enum(u8) { A, B, _ }; |
| 1011 | 1011 | |
| ... | ... | @@ -1044,7 +1044,7 @@ test "@tagName on enum literals" { |
| 1044 | 1044 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1045 | 1045 | |
| 1046 | 1046 | try expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); |
| 1047 | try comptime expect(mem.eql(u8, @tagName(.FooBar), "FooBar")); | |
| 1047 | comptime assert(mem.eql(u8, @tagName(.FooBar), "FooBar")); | |
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | 1050 | test "tag name with signed enum values" { |
| ... | ... | @@ -1101,7 +1101,7 @@ test "bit field access with enum fields" { |
| 1101 | 1101 | try expect(getA(&data) == A.Two); |
| 1102 | 1102 | try expect(getB(&data) == B.Three3); |
| 1103 | 1103 | try expect(getC(&data) == C.Four4); |
| 1104 | try comptime expect(@sizeOf(BitFieldOfEnums) == 1); | |
| 1104 | comptime assert(@sizeOf(BitFieldOfEnums) == 1); | |
| 1105 | 1105 | |
| 1106 | 1106 | data.b = B.Four3; |
| 1107 | 1107 | try expect(data.b == B.Four3); |
test/behavior/error.zig+5-4| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | const assert = std.debug.assert; | |
| 3 | 4 | const expect = std.testing.expect; |
| 4 | 5 | const expectEqual = std.testing.expectEqual; |
| 5 | 6 | const mem = std.mem; |
| ... | ... | @@ -458,7 +459,7 @@ test "return function call to error set from error union function" { |
| 458 | 459 | } |
| 459 | 460 | }; |
| 460 | 461 | try expectError(error.Failure, S.errorable()); |
| 461 | try comptime expectError(error.Failure, S.errorable()); | |
| 462 | comptime assert(error.Failure == S.errorable()); | |
| 462 | 463 | } |
| 463 | 464 | |
| 464 | 465 | test "optional error set is the same size as error set" { |
| ... | ... | @@ -466,15 +467,15 @@ test "optional error set is the same size as error set" { |
| 466 | 467 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 467 | 468 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 468 | 469 | |
| 469 | try comptime expect(@sizeOf(?anyerror) == @sizeOf(anyerror)); | |
| 470 | try comptime expect(@alignOf(?anyerror) == @alignOf(anyerror)); | |
| 470 | comptime assert(@sizeOf(?anyerror) == @sizeOf(anyerror)); | |
| 471 | comptime assert(@alignOf(?anyerror) == @alignOf(anyerror)); | |
| 471 | 472 | const S = struct { |
| 472 | 473 | fn returnsOptErrSet() ?anyerror { |
| 473 | 474 | return null; |
| 474 | 475 | } |
| 475 | 476 | }; |
| 476 | 477 | try expect(S.returnsOptErrSet() == null); |
| 477 | try comptime expect(S.returnsOptErrSet() == null); | |
| 478 | comptime assert(S.returnsOptErrSet() == null); | |
| 478 | 479 | } |
| 479 | 480 | |
| 480 | 481 | test "nested catch" { |
test/behavior/eval.zig+8-8| ... | ... | @@ -55,7 +55,7 @@ fn staticAdd(a: i32, b: i32) i32 { |
| 55 | 55 | |
| 56 | 56 | test "const expr eval on single expr blocks" { |
| 57 | 57 | try expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3); |
| 58 | try comptime expect(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | |
| 58 | comptime assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) i32 { |
| ... | ... | @@ -426,7 +426,7 @@ test "f64 at compile time is lossy" { |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | test { |
| 429 | try comptime expect(@as(f128, 1 << 113) == 10384593717069655257060992658440192); | |
| 429 | comptime assert(@as(f128, 1 << 113) == 10384593717069655257060992658440192); | |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | fn copyWithPartialInline(s: []u32, b: []u8) void { |
| ... | ... | @@ -613,7 +613,7 @@ test "const global shares pointer with other same one" { |
| 613 | 613 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 614 | 614 | |
| 615 | 615 | try assertEqualPtrs(&hi1[0], &hi2[0]); |
| 616 | try comptime expect(&hi1[0] == &hi2[0]); | |
| 616 | comptime assert(&hi1[0] == &hi2[0]); | |
| 617 | 617 | } |
| 618 | 618 | fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) !void { |
| 619 | 619 | try expect(ptr1 == ptr2); |
| ... | ... | @@ -634,8 +634,8 @@ fn assertEqualPtrs(ptr1: *const u8, ptr2: *const u8) !void { |
| 634 | 634 | test "string literal used as comptime slice is memoized" { |
| 635 | 635 | const a = "link"; |
| 636 | 636 | const b = "link"; |
| 637 | try comptime expect(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node); | |
| 638 | try comptime expect(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node); | |
| 637 | comptime assert(TypeWithCompTimeSlice(a).Node == TypeWithCompTimeSlice(b).Node); | |
| 638 | comptime assert(TypeWithCompTimeSlice("link").Node == TypeWithCompTimeSlice("link").Node); | |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type { |
| ... | ... | @@ -953,7 +953,7 @@ test "const local with comptime init through array init" { |
| 953 | 953 | S.declarations(E1), |
| 954 | 954 | }; |
| 955 | 955 | |
| 956 | try comptime expect(decls[0][0].name[0] == 'a'); | |
| 956 | comptime assert(decls[0][0].name[0] == 'a'); | |
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | test "closure capture type of runtime-known parameter" { |
| ... | ... | @@ -1339,7 +1339,7 @@ test "value in if block is comptime-known" { |
| 1339 | 1339 | const s = if (false) S{ .str = "a" } else S{ .str = "b" }; |
| 1340 | 1340 | break :blk "foo" ++ s.str; |
| 1341 | 1341 | }; |
| 1342 | try comptime expect(std.mem.eql(u8, first, second)); | |
| 1342 | comptime assert(std.mem.eql(u8, first, second)); | |
| 1343 | 1343 | } |
| 1344 | 1344 | |
| 1345 | 1345 | test "lazy sizeof is resolved in division" { |
| ... | ... | @@ -1561,7 +1561,7 @@ test "comptime function turns function value to function pointer" { |
| 1561 | 1561 | fnPtr(Nil), |
| 1562 | 1562 | }; |
| 1563 | 1563 | }; |
| 1564 | try comptime expect(S.foo[0] == &S.Nil); | |
| 1564 | comptime assert(S.foo[0] == &S.Nil); | |
| 1565 | 1565 | } |
| 1566 | 1566 | |
| 1567 | 1567 | test "container level const and var have unique addresses" { |
test/behavior/fn.zig+2-1| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const testing = std.testing; |
| 4 | const assert = std.debug.assert; | |
| 4 | 5 | const expect = testing.expect; |
| 5 | 6 | const expectEqual = testing.expectEqual; |
| 6 | 7 | |
| ... | ... | @@ -207,7 +208,7 @@ test "pass by non-copying value through var arg" { |
| 207 | 208 | } |
| 208 | 209 | |
| 209 | 210 | fn addPointCoordsVar(pt: anytype) !i32 { |
| 210 | try comptime expect(@TypeOf(pt) == Point); | |
| 211 | comptime assert(@TypeOf(pt) == Point); | |
| 211 | 212 | return pt.x + pt.y; |
| 212 | 213 | } |
| 213 | 214 |
test/behavior/math.zig+3-2| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | const assert = std.debug.assert; | |
| 3 | 4 | const expect = std.testing.expect; |
| 4 | 5 | const expectEqual = std.testing.expectEqual; |
| 5 | 6 | const expectEqualSlices = std.testing.expectEqualSlices; |
| ... | ... | @@ -246,7 +247,7 @@ fn testFloatEqualityImpl(x: f64, y: f64) !void { |
| 246 | 247 | } |
| 247 | 248 | |
| 248 | 249 | test "hex float literal parsing" { |
| 249 | try comptime expect(0x1.0 == 1.0); | |
| 250 | comptime assert(0x1.0 == 1.0); | |
| 250 | 251 | } |
| 251 | 252 | |
| 252 | 253 | test "hex float literal within range" { |
| ... | ... | @@ -1530,7 +1531,7 @@ test "@round f32/f64" { |
| 1530 | 1531 | const x = 14.0; |
| 1531 | 1532 | const y = x + 0.4; |
| 1532 | 1533 | const z = @round(y); |
| 1533 | try comptime expect(x == z); | |
| 1534 | comptime assert(x == z); | |
| 1534 | 1535 | } |
| 1535 | 1536 | |
| 1536 | 1537 | test "@round f80" { |
test/behavior/optional.zig+2-1| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const testing = std.testing; |
| 4 | const assert = std.debug.assert; | |
| 4 | 5 | const expect = testing.expect; |
| 5 | 6 | const expectEqual = testing.expectEqual; |
| 6 | 7 | const expectEqualStrings = std.testing.expectEqualStrings; |
| ... | ... | @@ -20,7 +21,7 @@ test "passing an optional integer as a parameter" { |
| 20 | 21 | } |
| 21 | 22 | }; |
| 22 | 23 | try expect(S.entry()); |
| 23 | try comptime expect(S.entry()); | |
| 24 | comptime assert(S.entry()); | |
| 24 | 25 | } |
| 25 | 26 | |
| 26 | 27 | pub const EmptyStruct = struct {}; |
test/behavior/pointers.zig+22-21| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | const testing = std.testing; |
| 4 | const assert = std.debug.assert; | |
| 4 | 5 | const expect = testing.expect; |
| 5 | 6 | const expectError = testing.expectError; |
| 6 | 7 | |
| ... | ... | @@ -42,7 +43,7 @@ test "pointer arithmetic" { |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | 45 | test "double pointer parsing" { |
| 45 | try comptime expect(PtrOf(PtrOf(i32)) == **i32); | |
| 46 | comptime assert(PtrOf(PtrOf(i32)) == **i32); | |
| 46 | 47 | } |
| 47 | 48 | |
| 48 | 49 | fn PtrOf(comptime T: type) type { |
| ... | ... | @@ -62,7 +63,7 @@ test "implicit cast single item pointer to C pointer and back" { |
| 62 | 63 | test "initialize const optional C pointer to null" { |
| 63 | 64 | const a: ?[*c]i32 = null; |
| 64 | 65 | try expect(a == null); |
| 65 | try comptime expect(a == null); | |
| 66 | comptime assert(a == null); | |
| 66 | 67 | } |
| 67 | 68 | |
| 68 | 69 | test "assigning integer to C pointer" { |
| ... | ... | @@ -204,11 +205,11 @@ test "allowzero pointer and slice" { |
| 204 | 205 | var runtime_zero: usize = 0; |
| 205 | 206 | _ = &runtime_zero; |
| 206 | 207 | var slice = ptr[runtime_zero..10]; |
| 207 | try comptime expect(@TypeOf(slice) == []allowzero i32); | |
| 208 | comptime assert(@TypeOf(slice) == []allowzero i32); | |
| 208 | 209 | try expect(@intFromPtr(&slice[5]) == 20); |
| 209 | 210 | |
| 210 | try comptime expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero); | |
| 211 | try comptime expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero); | |
| 211 | comptime assert(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero); | |
| 212 | comptime assert(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero); | |
| 212 | 213 | } |
| 213 | 214 | |
| 214 | 215 | test "assign null directly to C pointer and test null equality" { |
| ... | ... | @@ -230,17 +231,17 @@ test "assign null directly to C pointer and test null equality" { |
| 230 | 231 | try expect((x orelse &otherx) == &otherx); |
| 231 | 232 | |
| 232 | 233 | const y: [*c]i32 = null; |
| 233 | try comptime expect(y == null); | |
| 234 | try comptime expect(null == y); | |
| 235 | try comptime expect(!(y != null)); | |
| 236 | try comptime expect(!(null != y)); | |
| 234 | comptime assert(y == null); | |
| 235 | comptime assert(null == y); | |
| 236 | comptime assert(!(y != null)); | |
| 237 | comptime assert(!(null != y)); | |
| 237 | 238 | if (y) |same_y| { |
| 238 | 239 | _ = same_y; |
| 239 | 240 | @panic("fail"); |
| 240 | 241 | } |
| 241 | 242 | const othery: i32 = undefined; |
| 242 | 243 | const ptr_othery = &othery; |
| 243 | try comptime expect((y orelse ptr_othery) == ptr_othery); | |
| 244 | comptime assert((y orelse ptr_othery) == ptr_othery); | |
| 244 | 245 | |
| 245 | 246 | var n: i32 = 1234; |
| 246 | 247 | const x1: [*c]i32 = &n; |
| ... | ... | @@ -258,17 +259,17 @@ test "assign null directly to C pointer and test null equality" { |
| 258 | 259 | |
| 259 | 260 | const nc: i32 = 1234; |
| 260 | 261 | const y1: [*c]const i32 = &nc; |
| 261 | try comptime expect(!(y1 == null)); | |
| 262 | try comptime expect(!(null == y1)); | |
| 263 | try comptime expect(y1 != null); | |
| 264 | try comptime expect(null != y1); | |
| 265 | try comptime expect(y1.?.* == 1234); | |
| 262 | comptime assert(!(y1 == null)); | |
| 263 | comptime assert(!(null == y1)); | |
| 264 | comptime assert(y1 != null); | |
| 265 | comptime assert(null != y1); | |
| 266 | comptime assert(y1.?.* == 1234); | |
| 266 | 267 | if (y1) |same_y1| { |
| 267 | 268 | try expect(same_y1.* == 1234); |
| 268 | 269 | } else { |
| 269 | 270 | @compileError("fail"); |
| 270 | 271 | } |
| 271 | try comptime expect((y1 orelse &othery) == y1); | |
| 272 | comptime assert((y1 orelse &othery) == y1); | |
| 272 | 273 | } |
| 273 | 274 | |
| 274 | 275 | test "array initialization types" { |
| ... | ... | @@ -325,7 +326,7 @@ test "pointer sentinel with enums" { |
| 325 | 326 | fn doTheTest() !void { |
| 326 | 327 | var ptr: [*:.sentinel]const Number = &[_:.sentinel]Number{ .one, .two, .two, .one }; |
| 327 | 328 | _ = &ptr; |
| 328 | try expect(ptr[4] == .sentinel); // TODO this should be try comptime expect, see #3731 | |
| 329 | try expect(ptr[4] == .sentinel); // TODO this should be comptime assert, see #3731 | |
| 329 | 330 | } |
| 330 | 331 | }; |
| 331 | 332 | try S.doTheTest(); |
| ... | ... | @@ -341,7 +342,7 @@ test "pointer sentinel with optional element" { |
| 341 | 342 | fn doTheTest() !void { |
| 342 | 343 | var ptr: [*:null]const ?i32 = &[_:null]?i32{ 1, 2, 3, 4 }; |
| 343 | 344 | _ = &ptr; |
| 344 | try expect(ptr[4] == null); // TODO this should be try comptime expect, see #3731 | |
| 345 | try expect(ptr[4] == null); // TODO this should be comptime assert, see #3731 | |
| 345 | 346 | } |
| 346 | 347 | }; |
| 347 | 348 | try S.doTheTest(); |
| ... | ... | @@ -358,7 +359,7 @@ test "pointer sentinel with +inf" { |
| 358 | 359 | const inf_f32 = comptime std.math.inf(f32); |
| 359 | 360 | var ptr: [*:inf_f32]const f32 = &[_:inf_f32]f32{ 1.1, 2.2, 3.3, 4.4 }; |
| 360 | 361 | _ = &ptr; |
| 361 | try expect(ptr[4] == inf_f32); // TODO this should be try comptime expect, see #3731 | |
| 362 | try expect(ptr[4] == inf_f32); // TODO this should be comptime assert, see #3731 | |
| 362 | 363 | } |
| 363 | 364 | }; |
| 364 | 365 | try S.doTheTest(); |
| ... | ... | @@ -409,11 +410,11 @@ test "@intFromPtr on null optional at comptime" { |
| 409 | 410 | const pointer = @as(?*u8, @ptrFromInt(0x000)); |
| 410 | 411 | const x = @intFromPtr(pointer); |
| 411 | 412 | _ = x; |
| 412 | try comptime expect(0 == @intFromPtr(pointer)); | |
| 413 | comptime assert(0 == @intFromPtr(pointer)); | |
| 413 | 414 | } |
| 414 | 415 | { |
| 415 | 416 | const pointer = @as(?*u8, @ptrFromInt(0xf00)); |
| 416 | try comptime expect(0xf00 == @intFromPtr(pointer)); | |
| 417 | comptime assert(0xf00 == @intFromPtr(pointer)); | |
| 417 | 418 | } |
| 418 | 419 | } |
| 419 | 420 |
test/behavior/sizeof_and_typeof.zig+9-8| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | const assert = std.debug.assert; | |
| 3 | 4 | const expect = std.testing.expect; |
| 4 | 5 | const expectEqual = std.testing.expectEqual; |
| 5 | 6 | |
| ... | ... | @@ -23,24 +24,24 @@ test "@TypeOf() with multiple arguments" { |
| 23 | 24 | var var_2: u8 = undefined; |
| 24 | 25 | var var_3: u64 = undefined; |
| 25 | 26 | _ = .{ &var_1, &var_2, &var_3 }; |
| 26 | try comptime expect(@TypeOf(var_1, var_2, var_3) == u64); | |
| 27 | comptime assert(@TypeOf(var_1, var_2, var_3) == u64); | |
| 27 | 28 | } |
| 28 | 29 | { |
| 29 | 30 | var var_1: f16 = undefined; |
| 30 | 31 | var var_2: f32 = undefined; |
| 31 | 32 | var var_3: f64 = undefined; |
| 32 | 33 | _ = .{ &var_1, &var_2, &var_3 }; |
| 33 | try comptime expect(@TypeOf(var_1, var_2, var_3) == f64); | |
| 34 | comptime assert(@TypeOf(var_1, var_2, var_3) == f64); | |
| 34 | 35 | } |
| 35 | 36 | { |
| 36 | 37 | var var_1: u16 = undefined; |
| 37 | 38 | _ = &var_1; |
| 38 | try comptime expect(@TypeOf(var_1, 0xffff) == u16); | |
| 39 | comptime assert(@TypeOf(var_1, 0xffff) == u16); | |
| 39 | 40 | } |
| 40 | 41 | { |
| 41 | 42 | var var_1: f32 = undefined; |
| 42 | 43 | _ = &var_1; |
| 43 | try comptime expect(@TypeOf(var_1, 3.1415) == f32); | |
| 44 | comptime assert(@TypeOf(var_1, 3.1415) == f32); | |
| 44 | 45 | } |
| 45 | 46 | } |
| 46 | 47 | |
| ... | ... | @@ -150,7 +151,7 @@ test "@TypeOf() has no runtime side effects" { |
| 150 | 151 | }; |
| 151 | 152 | var data: i32 = 0; |
| 152 | 153 | const T = @TypeOf(S.foo(i32, &data)); |
| 153 | try comptime expect(T == i32); | |
| 154 | comptime assert(T == i32); | |
| 154 | 155 | try expect(data == 0); |
| 155 | 156 | } |
| 156 | 157 | |
| ... | ... | @@ -165,7 +166,7 @@ test "branching logic inside @TypeOf" { |
| 165 | 166 | } |
| 166 | 167 | }; |
| 167 | 168 | const T = @TypeOf(S.foo() catch undefined); |
| 168 | try comptime expect(T == i32); | |
| 169 | comptime assert(T == i32); | |
| 169 | 170 | try expect(S.data == 0); |
| 170 | 171 | } |
| 171 | 172 | |
| ... | ... | @@ -238,7 +239,7 @@ test "hardcoded address in typeof expression" { |
| 238 | 239 | } |
| 239 | 240 | }; |
| 240 | 241 | try expect(S.func() == 0); |
| 241 | try comptime expect(S.func() == 0); | |
| 242 | comptime assert(S.func() == 0); | |
| 242 | 243 | } |
| 243 | 244 | |
| 244 | 245 | test "array access of generic param in typeof expression" { |
| ... | ... | @@ -248,7 +249,7 @@ test "array access of generic param in typeof expression" { |
| 248 | 249 | } |
| 249 | 250 | }; |
| 250 | 251 | try expect(S.first("a") == 'a'); |
| 251 | try comptime expect(S.first("a") == 'a'); | |
| 252 | comptime assert(S.first("a") == 'a'); | |
| 252 | 253 | } |
| 253 | 254 | |
| 254 | 255 | test "lazy size cast to float" { |
test/behavior/slice.zig+77-76| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | const assert = std.debug.assert; | |
| 3 | 4 | const expect = std.testing.expect; |
| 4 | 5 | const expectEqualSlices = std.testing.expectEqualSlices; |
| 5 | 6 | const expectEqualStrings = std.testing.expectEqualStrings; |
| ... | ... | @@ -137,7 +138,7 @@ test "slice of hardcoded address to pointer" { |
| 137 | 138 | const S = struct { |
| 138 | 139 | fn doTheTest() !void { |
| 139 | 140 | const pointer = @as([*]u8, @ptrFromInt(0x04))[0..2]; |
| 140 | try comptime expect(@TypeOf(pointer) == *[2]u8); | |
| 141 | comptime assert(@TypeOf(pointer) == *[2]u8); | |
| 141 | 142 | const slice: []const u8 = pointer; |
| 142 | 143 | try expect(@intFromPtr(slice.ptr) == 4); |
| 143 | 144 | try expect(slice.len == 2); |
| ... | ... | @@ -210,9 +211,9 @@ test "slice string literal has correct type" { |
| 210 | 211 | } |
| 211 | 212 | var runtime_zero: usize = 0; |
| 212 | 213 | _ = &runtime_zero; |
| 213 | try comptime expect(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8); | |
| 214 | comptime assert(@TypeOf("aoeu"[runtime_zero..]) == [:0]const u8); | |
| 214 | 215 | const array = [_]i32{ 1, 2, 3, 4 }; |
| 215 | try comptime expect(@TypeOf(array[runtime_zero..]) == []const i32); | |
| 216 | comptime assert(@TypeOf(array[runtime_zero..]) == []const i32); | |
| 216 | 217 | } |
| 217 | 218 | |
| 218 | 219 | test "result location zero sized array inside struct field implicit cast to slice" { |
| ... | ... | @@ -260,8 +261,8 @@ test "C pointer slice access" { |
| 260 | 261 | |
| 261 | 262 | var runtime_zero: usize = 0; |
| 262 | 263 | _ = &runtime_zero; |
| 263 | try comptime expectEqual([]const u32, @TypeOf(c_ptr[runtime_zero..1])); | |
| 264 | try comptime expectEqual(*const [1]u32, @TypeOf(c_ptr[0..1])); | |
| 264 | comptime assert(@TypeOf(c_ptr[runtime_zero..1]) == []const u32); | |
| 265 | comptime assert(@TypeOf(c_ptr[0..1]) == *const [1]u32); | |
| 265 | 266 | |
| 266 | 267 | for (c_ptr[0..5]) |*cl| { |
| 267 | 268 | try expect(@as(u32, 42) == cl.*); |
| ... | ... | @@ -314,11 +315,11 @@ test "obtaining a null terminated slice" { |
| 314 | 315 | _ = &runtime_len; |
| 315 | 316 | const ptr2 = buf[0..runtime_len :0]; |
| 316 | 317 | // ptr2 is a null-terminated slice |
| 317 | try comptime expect(@TypeOf(ptr2) == [:0]u8); | |
| 318 | try comptime expect(@TypeOf(ptr2[0..2]) == *[2]u8); | |
| 318 | comptime assert(@TypeOf(ptr2) == [:0]u8); | |
| 319 | comptime assert(@TypeOf(ptr2[0..2]) == *[2]u8); | |
| 319 | 320 | var runtime_zero: usize = 0; |
| 320 | 321 | _ = &runtime_zero; |
| 321 | try comptime expect(@TypeOf(ptr2[runtime_zero..2]) == []u8); | |
| 322 | comptime assert(@TypeOf(ptr2[runtime_zero..2]) == []u8); | |
| 322 | 323 | } |
| 323 | 324 | |
| 324 | 325 | test "empty array to slice" { |
| ... | ... | @@ -366,7 +367,7 @@ test "slice multi-pointer without end" { |
| 366 | 367 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 367 | 368 | const pointer: [*]u8 = &array; |
| 368 | 369 | const slice = pointer[1..]; |
| 369 | try comptime expect(@TypeOf(slice) == [*]u8); | |
| 370 | comptime assert(@TypeOf(slice) == [*]u8); | |
| 370 | 371 | try expect(slice[0] == 2); |
| 371 | 372 | try expect(slice[1] == 3); |
| 372 | 373 | } |
| ... | ... | @@ -375,12 +376,12 @@ test "slice multi-pointer without end" { |
| 375 | 376 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 376 | 377 | const pointer: [*:0]u8 = &array; |
| 377 | 378 | |
| 378 | try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8); | |
| 379 | try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8); | |
| 380 | try comptime expect(@TypeOf(pointer[1..5 :0]) == *[4:0]u8); | |
| 379 | comptime assert(@TypeOf(pointer[1..3]) == *[2]u8); | |
| 380 | comptime assert(@TypeOf(pointer[1..3 :4]) == *[2:4]u8); | |
| 381 | comptime assert(@TypeOf(pointer[1..5 :0]) == *[4:0]u8); | |
| 381 | 382 | |
| 382 | 383 | const slice = pointer[1..]; |
| 383 | try comptime expect(@TypeOf(slice) == [*:0]u8); | |
| 384 | comptime assert(@TypeOf(slice) == [*:0]u8); | |
| 384 | 385 | try expect(slice[0] == 2); |
| 385 | 386 | try expect(slice[1] == 3); |
| 386 | 387 | } |
| ... | ... | @@ -422,29 +423,29 @@ test "slice syntax resulting in pointer-to-array" { |
| 422 | 423 | fn testArray() !void { |
| 423 | 424 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 424 | 425 | const slice = array[1..3]; |
| 425 | try comptime expect(@TypeOf(slice) == *[2]u8); | |
| 426 | comptime assert(@TypeOf(slice) == *[2]u8); | |
| 426 | 427 | try expect(slice[0] == 2); |
| 427 | 428 | try expect(slice[1] == 3); |
| 428 | 429 | } |
| 429 | 430 | |
| 430 | 431 | fn testArrayZ() !void { |
| 431 | 432 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 432 | try comptime expect(@TypeOf(array[1..3]) == *[2]u8); | |
| 433 | try comptime expect(@TypeOf(array[1..5]) == *[4:0]u8); | |
| 434 | try comptime expect(@TypeOf(array[1..]) == *[4:0]u8); | |
| 435 | try comptime expect(@TypeOf(array[1..3 :4]) == *[2:4]u8); | |
| 433 | comptime assert(@TypeOf(array[1..3]) == *[2]u8); | |
| 434 | comptime assert(@TypeOf(array[1..5]) == *[4:0]u8); | |
| 435 | comptime assert(@TypeOf(array[1..]) == *[4:0]u8); | |
| 436 | comptime assert(@TypeOf(array[1..3 :4]) == *[2:4]u8); | |
| 436 | 437 | } |
| 437 | 438 | |
| 438 | 439 | fn testArray0() !void { |
| 439 | 440 | { |
| 440 | 441 | var array = [0]u8{}; |
| 441 | 442 | const slice = array[0..0]; |
| 442 | try comptime expect(@TypeOf(slice) == *[0]u8); | |
| 443 | comptime assert(@TypeOf(slice) == *[0]u8); | |
| 443 | 444 | } |
| 444 | 445 | { |
| 445 | 446 | var array = [0:0]u8{}; |
| 446 | 447 | const slice = array[0..0]; |
| 447 | try comptime expect(@TypeOf(slice) == *[0:0]u8); | |
| 448 | comptime assert(@TypeOf(slice) == *[0:0]u8); | |
| 448 | 449 | try expect(slice[0] == 0); |
| 449 | 450 | } |
| 450 | 451 | } |
| ... | ... | @@ -452,16 +453,16 @@ test "slice syntax resulting in pointer-to-array" { |
| 452 | 453 | fn testArrayAlign() !void { |
| 453 | 454 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; |
| 454 | 455 | const slice = array[4..5]; |
| 455 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); | |
| 456 | comptime assert(@TypeOf(slice) == *align(4) [1]u8); | |
| 456 | 457 | try expect(slice[0] == 5); |
| 457 | try comptime expect(@TypeOf(array[0..2]) == *align(4) [2]u8); | |
| 458 | comptime assert(@TypeOf(array[0..2]) == *align(4) [2]u8); | |
| 458 | 459 | } |
| 459 | 460 | |
| 460 | 461 | fn testPointer() !void { |
| 461 | 462 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 462 | 463 | var pointer: [*]u8 = &array; |
| 463 | 464 | const slice = pointer[1..3]; |
| 464 | try comptime expect(@TypeOf(slice) == *[2]u8); | |
| 465 | comptime assert(@TypeOf(slice) == *[2]u8); | |
| 465 | 466 | try expect(slice[0] == 2); |
| 466 | 467 | try expect(slice[1] == 3); |
| 467 | 468 | } |
| ... | ... | @@ -469,14 +470,14 @@ test "slice syntax resulting in pointer-to-array" { |
| 469 | 470 | fn testPointerZ() !void { |
| 470 | 471 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 471 | 472 | var pointer: [*:0]u8 = &array; |
| 472 | try comptime expect(@TypeOf(pointer[1..3]) == *[2]u8); | |
| 473 | try comptime expect(@TypeOf(pointer[1..3 :4]) == *[2:4]u8); | |
| 473 | comptime assert(@TypeOf(pointer[1..3]) == *[2]u8); | |
| 474 | comptime assert(@TypeOf(pointer[1..3 :4]) == *[2:4]u8); | |
| 474 | 475 | } |
| 475 | 476 | |
| 476 | 477 | fn testPointer0() !void { |
| 477 | 478 | var pointer: [*]const u0 = &[1]u0{0}; |
| 478 | 479 | const slice = pointer[0..1]; |
| 479 | try comptime expect(@TypeOf(slice) == *const [1]u0); | |
| 480 | comptime assert(@TypeOf(slice) == *const [1]u0); | |
| 480 | 481 | try expect(slice[0] == 0); |
| 481 | 482 | } |
| 482 | 483 | |
| ... | ... | @@ -484,16 +485,16 @@ test "slice syntax resulting in pointer-to-array" { |
| 484 | 485 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; |
| 485 | 486 | var pointer: [*]align(4) u8 = &array; |
| 486 | 487 | const slice = pointer[4..5]; |
| 487 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); | |
| 488 | comptime assert(@TypeOf(slice) == *align(4) [1]u8); | |
| 488 | 489 | try expect(slice[0] == 5); |
| 489 | try comptime expect(@TypeOf(pointer[0..2]) == *align(4) [2]u8); | |
| 490 | comptime assert(@TypeOf(pointer[0..2]) == *align(4) [2]u8); | |
| 490 | 491 | } |
| 491 | 492 | |
| 492 | 493 | fn testSlice() !void { |
| 493 | 494 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 494 | 495 | var src_slice: []u8 = &array; |
| 495 | 496 | const slice = src_slice[1..3]; |
| 496 | try comptime expect(@TypeOf(slice) == *[2]u8); | |
| 497 | comptime assert(@TypeOf(slice) == *[2]u8); | |
| 497 | 498 | try expect(slice[0] == 2); |
| 498 | 499 | try expect(slice[1] == 3); |
| 499 | 500 | } |
| ... | ... | @@ -501,30 +502,30 @@ test "slice syntax resulting in pointer-to-array" { |
| 501 | 502 | fn testSliceZ() !void { |
| 502 | 503 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 503 | 504 | var slice: [:0]u8 = &array; |
| 504 | try comptime expect(@TypeOf(slice[1..3]) == *[2]u8); | |
| 505 | try comptime expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8); | |
| 505 | comptime assert(@TypeOf(slice[1..3]) == *[2]u8); | |
| 506 | comptime assert(@TypeOf(slice[1..3 :4]) == *[2:4]u8); | |
| 506 | 507 | if (@inComptime()) { |
| 507 | try comptime expect(@TypeOf(slice[1..]) == *[4:0]u8); | |
| 508 | comptime assert(@TypeOf(slice[1..]) == *[4:0]u8); | |
| 508 | 509 | } else { |
| 509 | try comptime expect(@TypeOf(slice[1..]) == [:0]u8); | |
| 510 | comptime assert(@TypeOf(slice[1..]) == [:0]u8); | |
| 510 | 511 | } |
| 511 | 512 | } |
| 512 | 513 | |
| 513 | 514 | fn testSliceOpt() !void { |
| 514 | 515 | var array: [2]u8 = [2]u8{ 1, 2 }; |
| 515 | 516 | var slice: ?[]u8 = &array; |
| 516 | try comptime expect(@TypeOf(&array, slice) == ?[]u8); | |
| 517 | try comptime expect(@TypeOf(slice, &array) == ?[]u8); | |
| 518 | try comptime expect(@TypeOf(slice.?[0..2]) == *[2]u8); | |
| 517 | comptime assert(@TypeOf(&array, slice) == ?[]u8); | |
| 518 | comptime assert(@TypeOf(slice, &array) == ?[]u8); | |
| 519 | comptime assert(@TypeOf(slice.?[0..2]) == *[2]u8); | |
| 519 | 520 | } |
| 520 | 521 | |
| 521 | 522 | fn testSliceAlign() !void { |
| 522 | 523 | var array align(4) = [5]u8{ 1, 2, 3, 4, 5 }; |
| 523 | 524 | var src_slice: []align(4) u8 = &array; |
| 524 | 525 | const slice = src_slice[4..5]; |
| 525 | try comptime expect(@TypeOf(slice) == *align(4) [1]u8); | |
| 526 | comptime assert(@TypeOf(slice) == *align(4) [1]u8); | |
| 526 | 527 | try expect(slice[0] == 5); |
| 527 | try comptime expect(@TypeOf(src_slice[0..2]) == *align(4) [2]u8); | |
| 528 | comptime assert(@TypeOf(src_slice[0..2]) == *align(4) [2]u8); | |
| 528 | 529 | } |
| 529 | 530 | |
| 530 | 531 | fn testConcatStrLiterals() !void { |
| ... | ... | @@ -535,62 +536,62 @@ test "slice syntax resulting in pointer-to-array" { |
| 535 | 536 | fn testSliceLength() !void { |
| 536 | 537 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 537 | 538 | var slice: []u8 = &array; |
| 538 | try comptime expect(@TypeOf(slice[1..][0..2]) == *[2]u8); | |
| 539 | try comptime expect(@TypeOf(slice[1..][0..4]) == *[4]u8); | |
| 540 | try comptime expect(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8); | |
| 539 | comptime assert(@TypeOf(slice[1..][0..2]) == *[2]u8); | |
| 540 | comptime assert(@TypeOf(slice[1..][0..4]) == *[4]u8); | |
| 541 | comptime assert(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8); | |
| 541 | 542 | } |
| 542 | 543 | |
| 543 | 544 | fn testSliceLengthZ() !void { |
| 544 | 545 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 545 | 546 | var slice: [:0]u8 = &array; |
| 546 | try comptime expect(@TypeOf(slice[1..][0..2]) == *[2]u8); | |
| 547 | try comptime expect(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8); | |
| 548 | try comptime expect(@TypeOf(slice[1.. :0][0..2]) == *[2]u8); | |
| 549 | try comptime expect(@TypeOf(slice[1.. :0][0..2 :4]) == *[2:4]u8); | |
| 547 | comptime assert(@TypeOf(slice[1..][0..2]) == *[2]u8); | |
| 548 | comptime assert(@TypeOf(slice[1..][0..2 :4]) == *[2:4]u8); | |
| 549 | comptime assert(@TypeOf(slice[1.. :0][0..2]) == *[2]u8); | |
| 550 | comptime assert(@TypeOf(slice[1.. :0][0..2 :4]) == *[2:4]u8); | |
| 550 | 551 | } |
| 551 | 552 | |
| 552 | 553 | fn testArrayLength() !void { |
| 553 | 554 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 554 | try comptime expect(@TypeOf(array[1..][0..2]) == *[2]u8); | |
| 555 | try comptime expect(@TypeOf(array[1..][0..4]) == *[4]u8); | |
| 556 | try comptime expect(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8); | |
| 555 | comptime assert(@TypeOf(array[1..][0..2]) == *[2]u8); | |
| 556 | comptime assert(@TypeOf(array[1..][0..4]) == *[4]u8); | |
| 557 | comptime assert(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8); | |
| 557 | 558 | } |
| 558 | 559 | |
| 559 | 560 | fn testArrayLengthZ() !void { |
| 560 | 561 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 561 | try comptime expect(@TypeOf(array[1..][0..2]) == *[2]u8); | |
| 562 | try comptime expect(@TypeOf(array[1..][0..4]) == *[4:0]u8); | |
| 563 | try comptime expect(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8); | |
| 564 | try comptime expect(@TypeOf(array[1.. :0][0..2]) == *[2]u8); | |
| 565 | try comptime expect(@TypeOf(array[1.. :0][0..4]) == *[4:0]u8); | |
| 566 | try comptime expect(@TypeOf(array[1.. :0][0..2 :4]) == *[2:4]u8); | |
| 562 | comptime assert(@TypeOf(array[1..][0..2]) == *[2]u8); | |
| 563 | comptime assert(@TypeOf(array[1..][0..4]) == *[4:0]u8); | |
| 564 | comptime assert(@TypeOf(array[1..][0..2 :4]) == *[2:4]u8); | |
| 565 | comptime assert(@TypeOf(array[1.. :0][0..2]) == *[2]u8); | |
| 566 | comptime assert(@TypeOf(array[1.. :0][0..4]) == *[4:0]u8); | |
| 567 | comptime assert(@TypeOf(array[1.. :0][0..2 :4]) == *[2:4]u8); | |
| 567 | 568 | } |
| 568 | 569 | |
| 569 | 570 | fn testMultiPointer() !void { |
| 570 | 571 | var array = [5]u8{ 1, 2, 3, 4, 5 }; |
| 571 | 572 | var ptr: [*]u8 = &array; |
| 572 | try comptime expect(@TypeOf(ptr[1..][0..2]) == *[2]u8); | |
| 573 | try comptime expect(@TypeOf(ptr[1..][0..4]) == *[4]u8); | |
| 574 | try comptime expect(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8); | |
| 573 | comptime assert(@TypeOf(ptr[1..][0..2]) == *[2]u8); | |
| 574 | comptime assert(@TypeOf(ptr[1..][0..4]) == *[4]u8); | |
| 575 | comptime assert(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8); | |
| 575 | 576 | } |
| 576 | 577 | |
| 577 | 578 | fn testMultiPointerLengthZ() !void { |
| 578 | 579 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 579 | 580 | var ptr: [*]u8 = &array; |
| 580 | try comptime expect(@TypeOf(ptr[1..][0..2]) == *[2]u8); | |
| 581 | try comptime expect(@TypeOf(ptr[1..][0..4]) == *[4]u8); | |
| 582 | try comptime expect(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8); | |
| 583 | try comptime expect(@TypeOf(ptr[1.. :0][0..2]) == *[2]u8); | |
| 584 | try comptime expect(@TypeOf(ptr[1.. :0][0..4]) == *[4]u8); | |
| 585 | try comptime expect(@TypeOf(ptr[1.. :0][0..2 :4]) == *[2:4]u8); | |
| 581 | comptime assert(@TypeOf(ptr[1..][0..2]) == *[2]u8); | |
| 582 | comptime assert(@TypeOf(ptr[1..][0..4]) == *[4]u8); | |
| 583 | comptime assert(@TypeOf(ptr[1..][0..2 :4]) == *[2:4]u8); | |
| 584 | comptime assert(@TypeOf(ptr[1.. :0][0..2]) == *[2]u8); | |
| 585 | comptime assert(@TypeOf(ptr[1.. :0][0..4]) == *[4]u8); | |
| 586 | comptime assert(@TypeOf(ptr[1.. :0][0..2 :4]) == *[2:4]u8); | |
| 586 | 587 | |
| 587 | 588 | var ptr_z: [*:0]u8 = &array; |
| 588 | try comptime expect(@TypeOf(ptr_z[1..][0..2]) == *[2]u8); | |
| 589 | try comptime expect(@TypeOf(ptr_z[1..][0..4]) == *[4]u8); | |
| 590 | try comptime expect(@TypeOf(ptr_z[1..][0..2 :4]) == *[2:4]u8); | |
| 591 | try comptime expect(@TypeOf(ptr_z[1.. :0][0..2]) == *[2]u8); | |
| 592 | try comptime expect(@TypeOf(ptr_z[1.. :0][0..4]) == *[4]u8); | |
| 593 | try comptime expect(@TypeOf(ptr_z[1.. :0][0..2 :4]) == *[2:4]u8); | |
| 589 | comptime assert(@TypeOf(ptr_z[1..][0..2]) == *[2]u8); | |
| 590 | comptime assert(@TypeOf(ptr_z[1..][0..4]) == *[4]u8); | |
| 591 | comptime assert(@TypeOf(ptr_z[1..][0..2 :4]) == *[2:4]u8); | |
| 592 | comptime assert(@TypeOf(ptr_z[1.. :0][0..2]) == *[2]u8); | |
| 593 | comptime assert(@TypeOf(ptr_z[1.. :0][0..4]) == *[4]u8); | |
| 594 | comptime assert(@TypeOf(ptr_z[1.. :0][0..2 :4]) == *[2:4]u8); | |
| 594 | 595 | } |
| 595 | 596 | |
| 596 | 597 | fn testSingleItemPointer() !void { |
| ... | ... | @@ -598,10 +599,10 @@ test "slice syntax resulting in pointer-to-array" { |
| 598 | 599 | var ptr = &value; |
| 599 | 600 | |
| 600 | 601 | const slice = ptr[0..1]; |
| 601 | try comptime expect(@TypeOf(slice) == *[1]u8); | |
| 602 | comptime assert(@TypeOf(slice) == *[1]u8); | |
| 602 | 603 | try expect(slice[0] == 1); |
| 603 | 604 | |
| 604 | try comptime expect(@TypeOf(ptr[0..0]) == *[0]u8); | |
| 605 | comptime assert(@TypeOf(ptr[0..0]) == *[0]u8); | |
| 605 | 606 | } |
| 606 | 607 | }; |
| 607 | 608 | |
| ... | ... | @@ -623,9 +624,9 @@ test "slice pointer-to-array null terminated" { |
| 623 | 624 | |
| 624 | 625 | var array = [5:0]u8{ 1, 2, 3, 4, 5 }; |
| 625 | 626 | var slice: [:0]u8 = &array; |
| 626 | try comptime expect(@TypeOf(slice[1..3]) == *[2]u8); | |
| 627 | try comptime expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8); | |
| 628 | try comptime expect(@TypeOf(slice[1..]) == [:0]u8); | |
| 627 | comptime assert(@TypeOf(slice[1..3]) == *[2]u8); | |
| 628 | comptime assert(@TypeOf(slice[1..3 :4]) == *[2:4]u8); | |
| 629 | comptime assert(@TypeOf(slice[1..]) == [:0]u8); | |
| 629 | 630 | } |
| 630 | 631 | |
| 631 | 632 | test "slice pointer-to-array zero length" { |
| ... | ... | @@ -650,13 +651,13 @@ test "slice pointer-to-array zero length" { |
| 650 | 651 | var array = [0]u8{}; |
| 651 | 652 | var src_slice: []u8 = &array; |
| 652 | 653 | const slice = src_slice[0..0]; |
| 653 | try comptime expect(@TypeOf(slice) == *[0]u8); | |
| 654 | comptime assert(@TypeOf(slice) == *[0]u8); | |
| 654 | 655 | } |
| 655 | 656 | { |
| 656 | 657 | var array = [0:0]u8{}; |
| 657 | 658 | var src_slice: [:0]u8 = &array; |
| 658 | 659 | const slice = src_slice[0..0]; |
| 659 | try comptime expect(@TypeOf(slice) == *[0]u8); | |
| 660 | comptime assert(@TypeOf(slice) == *[0]u8); | |
| 660 | 661 | } |
| 661 | 662 | } |
| 662 | 663 |
test/behavior/struct.zig+3-3| ... | ... | @@ -591,7 +591,7 @@ test "bit field access" { |
| 591 | 591 | try expect(getA(&data) == 1); |
| 592 | 592 | try expect(getB(&data) == 2); |
| 593 | 593 | try expect(getC(&data) == 3); |
| 594 | try comptime expect(@sizeOf(BitField1) == 1); | |
| 594 | comptime assert(@sizeOf(BitField1) == 1); | |
| 595 | 595 | |
| 596 | 596 | data.b += 1; |
| 597 | 597 | try expect(data.b == 3); |
| ... | ... | @@ -730,7 +730,7 @@ test "packed struct with u0 field access" { |
| 730 | 730 | }; |
| 731 | 731 | var s = S{ .f0 = 0 }; |
| 732 | 732 | _ = &s; |
| 733 | try comptime expect(s.f0 == 0); | |
| 733 | comptime assert(s.f0 == 0); | |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | test "access to global struct fields" { |
| ... | ... | @@ -947,7 +947,7 @@ test "comptime struct field" { |
| 947 | 947 | |
| 948 | 948 | var foo: T = undefined; |
| 949 | 949 | _ = &foo; |
| 950 | try comptime expect(foo.b == 1234); | |
| 950 | comptime assert(foo.b == 1234); | |
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | test "tuple element initialized with fn call" { |
test/behavior/switch.zig+3-3| ... | ... | @@ -600,9 +600,9 @@ test "switch on pointer type" { |
| 600 | 600 | try expect(1 == S.doTheTest(S.P1)); |
| 601 | 601 | try expect(2 == S.doTheTest(S.P2)); |
| 602 | 602 | try expect(3 == S.doTheTest(S.P3)); |
| 603 | try comptime expect(1 == S.doTheTest(S.P1)); | |
| 604 | try comptime expect(2 == S.doTheTest(S.P2)); | |
| 605 | try comptime expect(3 == S.doTheTest(S.P3)); | |
| 603 | comptime assert(1 == S.doTheTest(S.P1)); | |
| 604 | comptime assert(2 == S.doTheTest(S.P2)); | |
| 605 | comptime assert(3 == S.doTheTest(S.P3)); | |
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | test "switch on error set with single else" { |
test/behavior/truncate.zig+3-2| ... | ... | @@ -1,12 +1,13 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const assert = std.debug.assert; | |
| 3 | 4 | const expect = std.testing.expect; |
| 4 | 5 | |
| 5 | 6 | test "truncate u0 to larger integer allowed and has comptime-known result" { |
| 6 | 7 | var x: u0 = 0; |
| 7 | 8 | _ = &x; |
| 8 | 9 | const y = @as(u8, @truncate(x)); |
| 9 | try comptime expect(y == 0); | |
| 10 | comptime assert(y == 0); | |
| 10 | 11 | } |
| 11 | 12 | |
| 12 | 13 | test "truncate.u0.literal" { |
| ... | ... | @@ -31,7 +32,7 @@ test "truncate i0 to larger integer allowed and has comptime-known result" { |
| 31 | 32 | var x: i0 = 0; |
| 32 | 33 | _ = &x; |
| 33 | 34 | const y: i8 = @truncate(x); |
| 34 | try comptime expect(y == 0); | |
| 35 | comptime assert(y == 0); | |
| 35 | 36 | } |
| 36 | 37 | |
| 37 | 38 | test "truncate.i0.literal" { |
test/behavior/type_info.zig+2-1| ... | ... | @@ -5,6 +5,7 @@ const mem = std.mem; |
| 5 | 5 | const Type = std.builtin.Type; |
| 6 | 6 | const TypeId = std.builtin.TypeId; |
| 7 | 7 | |
| 8 | const assert = std.debug.assert; | |
| 8 | 9 | const expect = std.testing.expect; |
| 9 | 10 | const expectEqualStrings = std.testing.expectEqualStrings; |
| 10 | 11 | |
| ... | ... | @@ -484,7 +485,7 @@ test "@typeInfo does not force declarations into existence" { |
| 484 | 485 | @compileError("test failed"); |
| 485 | 486 | } |
| 486 | 487 | }; |
| 487 | try comptime expect(@typeInfo(S).Struct.fields.len == 1); | |
| 488 | comptime assert(@typeInfo(S).Struct.fields.len == 1); | |
| 488 | 489 | } |
| 489 | 490 | |
| 490 | 491 | fn add(a: i32, b: i32) i32 { |
test/behavior/union.zig+11-11| ... | ... | @@ -109,7 +109,7 @@ const ExternPtrOrInt = extern union { |
| 109 | 109 | int: u64, |
| 110 | 110 | }; |
| 111 | 111 | test "extern union size" { |
| 112 | try comptime expect(@sizeOf(ExternPtrOrInt) == 8); | |
| 112 | comptime assert(@sizeOf(ExternPtrOrInt) == 8); | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | test "0-sized extern union definition" { |
| ... | ... | @@ -161,7 +161,7 @@ test "access a member of tagged union with conflicting enum tag name" { |
| 161 | 161 | const B = void; |
| 162 | 162 | }; |
| 163 | 163 | |
| 164 | try comptime expect(Bar.A == u8); | |
| 164 | comptime assert(Bar.A == u8); | |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | test "constant tagged union with payload" { |
| ... | ... | @@ -371,14 +371,14 @@ const PackedPtrOrInt = packed union { |
| 371 | 371 | int: u64, |
| 372 | 372 | }; |
| 373 | 373 | test "packed union size" { |
| 374 | try comptime expect(@sizeOf(PackedPtrOrInt) == 8); | |
| 374 | comptime assert(@sizeOf(PackedPtrOrInt) == 8); | |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | const ZeroBits = union { |
| 378 | 378 | OnlyField: void, |
| 379 | 379 | }; |
| 380 | 380 | test "union with only 1 field which is void should be zero bits" { |
| 381 | try comptime expect(@sizeOf(ZeroBits) == 0); | |
| 381 | comptime assert(@sizeOf(ZeroBits) == 0); | |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | test "tagged union initialization with runtime void" { |
| ... | ... | @@ -428,7 +428,7 @@ test "union with only 1 field casted to its enum type" { |
| 428 | 428 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 429 | 429 | _ = &e; |
| 430 | 430 | const ExprTag = Tag(Expr); |
| 431 | try comptime expect(Tag(ExprTag) == u0); | |
| 431 | comptime assert(Tag(ExprTag) == u0); | |
| 432 | 432 | var t = @as(ExprTag, e); |
| 433 | 433 | _ = &t; |
| 434 | 434 | try expect(t == Expr.Literal); |
| ... | ... | @@ -438,7 +438,7 @@ test "union with one member defaults to u0 tag type" { |
| 438 | 438 | const U0 = union(enum) { |
| 439 | 439 | X: u32, |
| 440 | 440 | }; |
| 441 | try comptime expect(Tag(Tag(U0)) == u0); | |
| 441 | comptime assert(Tag(Tag(U0)) == u0); | |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | const Foo1 = union(enum) { |
| ... | ... | @@ -629,7 +629,7 @@ test "union(enum(u32)) with specified and unspecified tag values" { |
| 629 | 629 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 630 | 630 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 631 | 631 | |
| 632 | try comptime expect(Tag(Tag(MultipleChoice2)) == u32); | |
| 632 | comptime assert(Tag(Tag(MultipleChoice2)) == u32); | |
| 633 | 633 | try testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 }); |
| 634 | 634 | try comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 }); |
| 635 | 635 | } |
| ... | ... | @@ -709,11 +709,11 @@ test "union with only 1 field casted to its enum type which has enum value speci |
| 709 | 709 | |
| 710 | 710 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 711 | 711 | _ = &e; |
| 712 | try comptime expect(Tag(ExprTag) == comptime_int); | |
| 712 | comptime assert(Tag(ExprTag) == comptime_int); | |
| 713 | 713 | const t = comptime @as(ExprTag, e); |
| 714 | 714 | try expect(t == Expr.Literal); |
| 715 | 715 | try expect(@intFromEnum(t) == 33); |
| 716 | try comptime expect(@intFromEnum(t) == 33); | |
| 716 | comptime assert(@intFromEnum(t) == 33); | |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | test "@intFromEnum works on unions" { |
| ... | ... | @@ -894,7 +894,7 @@ test "union with comptime_int tag" { |
| 894 | 894 | Y: u16, |
| 895 | 895 | Z: u8, |
| 896 | 896 | }; |
| 897 | try comptime expect(Tag(Tag(Union)) == comptime_int); | |
| 897 | comptime assert(Tag(Tag(Union)) == comptime_int); | |
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | test "extern union doesn't trigger field check at comptime" { |
| ... | ... | @@ -904,7 +904,7 @@ test "extern union doesn't trigger field check at comptime" { |
| 904 | 904 | }; |
| 905 | 905 | |
| 906 | 906 | const x = U{ .x = 0x55AAAA55 }; |
| 907 | try comptime expect(x.y == 0x55); | |
| 907 | comptime assert(x.y == 0x55); | |
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | test "anonymous union literal syntax" { |
test/behavior/vector.zig+2-2| ... | ... | @@ -904,9 +904,9 @@ test "vector @reduce comptime" { |
| 904 | 904 | const value = V{ 1, -1, 1, -1 }; |
| 905 | 905 | const result = value > @as(V, @splat(0)); |
| 906 | 906 | // result is { true, false, true, false }; |
| 907 | try comptime expect(@TypeOf(result) == @Vector(4, bool)); | |
| 907 | comptime assert(@TypeOf(result) == @Vector(4, bool)); | |
| 908 | 908 | const is_all_true = @reduce(.And, result); |
| 909 | try comptime expect(@TypeOf(is_all_true) == bool); | |
| 909 | comptime assert(@TypeOf(is_all_true) == bool); | |
| 910 | 910 | try expect(is_all_true == false); |
| 911 | 911 | } |
| 912 | 912 |