| author | |
| committer | |
| log | 804cee3b93cb7084c16ee61d3bcb57f7d3c9f0bc |
| tree | 3d8c534b1adc352b248255ef2906ef2bdf11dffc |
| parent | 282ff8d3bd4a0d870a98f145aa87039e0409b745 |
175 files changed, 2109 insertions(+), 3297 deletions(-)
test/behavior.zig+1-130| ... | @@ -12,136 +12,6 @@ test { | ... | @@ -12,136 +12,6 @@ test { |
| 12 | _ = @import("behavior/bitcast.zig"); | 12 | _ = @import("behavior/bitcast.zig"); |
| 13 | _ = @import("behavior/bitreverse.zig"); | 13 | _ = @import("behavior/bitreverse.zig"); |
| 14 | _ = @import("behavior/bool.zig"); | 14 | _ = @import("behavior/bool.zig"); |
| 15 | // Ideally, all tests would be categorized and independent from GitHub, but | ||
| 16 | // if that's too much trouble, having test coverage this way is better than nothing. | ||
| 17 | _ = @import("behavior/bugs/394.zig"); | ||
| 18 | _ = @import("behavior/bugs/421.zig"); | ||
| 19 | _ = @import("behavior/bugs/529.zig"); | ||
| 20 | _ = @import("behavior/bugs/624.zig"); | ||
| 21 | _ = @import("behavior/bugs/655.zig"); | ||
| 22 | _ = @import("behavior/bugs/656.zig"); | ||
| 23 | _ = @import("behavior/bugs/679.zig"); | ||
| 24 | _ = @import("behavior/bugs/704.zig"); | ||
| 25 | _ = @import("behavior/bugs/718.zig"); | ||
| 26 | _ = @import("behavior/bugs/726.zig"); | ||
| 27 | _ = @import("behavior/bugs/828.zig"); | ||
| 28 | _ = @import("behavior/bugs/920.zig"); | ||
| 29 | _ = @import("behavior/bugs/1025.zig"); | ||
| 30 | _ = @import("behavior/bugs/1076.zig"); | ||
| 31 | _ = @import("behavior/bugs/1277.zig"); | ||
| 32 | _ = @import("behavior/bugs/1310.zig"); | ||
| 33 | _ = @import("behavior/bugs/1381.zig"); | ||
| 34 | _ = @import("behavior/bugs/1421.zig"); | ||
| 35 | _ = @import("behavior/bugs/1442.zig"); | ||
| 36 | _ = @import("behavior/bugs/1486.zig"); | ||
| 37 | _ = @import("behavior/bugs/1500.zig"); | ||
| 38 | _ = @import("behavior/bugs/1607.zig"); | ||
| 39 | _ = @import("behavior/bugs/1735.zig"); | ||
| 40 | _ = @import("behavior/bugs/1851.zig"); | ||
| 41 | _ = @import("behavior/bugs/1914.zig"); | ||
| 42 | _ = @import("behavior/bugs/2006.zig"); | ||
| 43 | _ = @import("behavior/bugs/2114.zig"); | ||
| 44 | _ = @import("behavior/bugs/2346.zig"); | ||
| 45 | _ = @import("behavior/bugs/2557.zig"); | ||
| 46 | _ = @import("behavior/bugs/2578.zig"); | ||
| 47 | _ = @import("behavior/bugs/2622.zig"); | ||
| 48 | _ = @import("behavior/bugs/2692.zig"); | ||
| 49 | _ = @import("behavior/bugs/2727.zig"); | ||
| 50 | _ = @import("behavior/bugs/2889.zig"); | ||
| 51 | _ = @import("behavior/bugs/3007.zig"); | ||
| 52 | _ = @import("behavior/bugs/3046.zig"); | ||
| 53 | _ = @import("behavior/bugs/3112.zig"); | ||
| 54 | _ = @import("behavior/bugs/3367.zig"); | ||
| 55 | _ = @import("behavior/bugs/3384.zig"); | ||
| 56 | _ = @import("behavior/bugs/3586.zig"); | ||
| 57 | _ = @import("behavior/bugs/3742.zig"); | ||
| 58 | _ = @import("behavior/bugs/4328.zig"); | ||
| 59 | _ = @import("behavior/bugs/4560.zig"); | ||
| 60 | _ = @import("behavior/bugs/4769_a.zig"); | ||
| 61 | _ = @import("behavior/bugs/4769_b.zig"); | ||
| 62 | _ = @import("behavior/bugs/4954.zig"); | ||
| 63 | _ = @import("behavior/bugs/5398.zig"); | ||
| 64 | _ = @import("behavior/bugs/5413.zig"); | ||
| 65 | _ = @import("behavior/bugs/5474.zig"); | ||
| 66 | _ = @import("behavior/bugs/5487.zig"); | ||
| 67 | _ = @import("behavior/bugs/6047.zig"); | ||
| 68 | _ = @import("behavior/bugs/6456.zig"); | ||
| 69 | _ = @import("behavior/bugs/6781.zig"); | ||
| 70 | _ = @import("behavior/bugs/6850.zig"); | ||
| 71 | _ = @import("behavior/bugs/6905.zig"); | ||
| 72 | _ = @import("behavior/bugs/6947.zig"); | ||
| 73 | _ = @import("behavior/bugs/7003.zig"); | ||
| 74 | _ = @import("behavior/bugs/7047.zig"); | ||
| 75 | _ = @import("behavior/bugs/7187.zig"); | ||
| 76 | _ = @import("behavior/bugs/7325.zig"); | ||
| 77 | _ = @import("behavior/bugs/8277.zig"); | ||
| 78 | _ = @import("behavior/bugs/8646.zig"); | ||
| 79 | _ = @import("behavior/bugs/9584.zig"); | ||
| 80 | _ = @import("behavior/bugs/10138.zig"); | ||
| 81 | _ = @import("behavior/bugs/10147.zig"); | ||
| 82 | _ = @import("behavior/bugs/10970.zig"); | ||
| 83 | _ = @import("behavior/bugs/10684.zig"); | ||
| 84 | _ = @import("behavior/bugs/11046.zig"); | ||
| 85 | _ = @import("behavior/bugs/11100.zig"); | ||
| 86 | _ = @import("behavior/bugs/11139.zig"); | ||
| 87 | _ = @import("behavior/bugs/11159.zig"); | ||
| 88 | _ = @import("behavior/bugs/11162.zig"); | ||
| 89 | _ = @import("behavior/bugs/11165.zig"); | ||
| 90 | _ = @import("behavior/bugs/11179.zig"); | ||
| 91 | _ = @import("behavior/bugs/11181.zig"); | ||
| 92 | _ = @import("behavior/bugs/11213.zig"); | ||
| 93 | _ = @import("behavior/bugs/11787.zig"); | ||
| 94 | _ = @import("behavior/bugs/11816.zig"); | ||
| 95 | _ = @import("behavior/bugs/11995.zig"); | ||
| 96 | _ = @import("behavior/bugs/12000.zig"); | ||
| 97 | _ = @import("behavior/bugs/12003.zig"); | ||
| 98 | _ = @import("behavior/bugs/12025.zig"); | ||
| 99 | _ = @import("behavior/bugs/12033.zig"); | ||
| 100 | _ = @import("behavior/bugs/12043.zig"); | ||
| 101 | _ = @import("behavior/bugs/12051.zig"); | ||
| 102 | _ = @import("behavior/bugs/12092.zig"); | ||
| 103 | _ = @import("behavior/bugs/12119.zig"); | ||
| 104 | _ = @import("behavior/bugs/12142.zig"); | ||
| 105 | _ = @import("behavior/bugs/12169.zig"); | ||
| 106 | _ = @import("behavior/bugs/12430.zig"); | ||
| 107 | _ = @import("behavior/bugs/12450.zig"); | ||
| 108 | _ = @import("behavior/bugs/12486.zig"); | ||
| 109 | _ = @import("behavior/bugs/12498.zig"); | ||
| 110 | _ = @import("behavior/bugs/12551.zig"); | ||
| 111 | _ = @import("behavior/bugs/12571.zig"); | ||
| 112 | _ = @import("behavior/bugs/12644.zig"); | ||
| 113 | _ = @import("behavior/bugs/12723.zig"); | ||
| 114 | _ = @import("behavior/bugs/12776.zig"); | ||
| 115 | _ = @import("behavior/bugs/12786.zig"); | ||
| 116 | _ = @import("behavior/bugs/12794.zig"); | ||
| 117 | _ = @import("behavior/bugs/12801-1.zig"); | ||
| 118 | _ = @import("behavior/bugs/12801-2.zig"); | ||
| 119 | _ = @import("behavior/bugs/12885.zig"); | ||
| 120 | _ = @import("behavior/bugs/12890.zig"); | ||
| 121 | _ = @import("behavior/bugs/12891.zig"); | ||
| 122 | _ = @import("behavior/bugs/12911.zig"); | ||
| 123 | _ = @import("behavior/bugs/12928.zig"); | ||
| 124 | _ = @import("behavior/bugs/12945.zig"); | ||
| 125 | _ = @import("behavior/bugs/12972.zig"); | ||
| 126 | _ = @import("behavior/bugs/12984.zig"); | ||
| 127 | _ = @import("behavior/bugs/13064.zig"); | ||
| 128 | _ = @import("behavior/bugs/13065.zig"); | ||
| 129 | _ = @import("behavior/bugs/13068.zig"); | ||
| 130 | _ = @import("behavior/bugs/13069.zig"); | ||
| 131 | _ = @import("behavior/bugs/13112.zig"); | ||
| 132 | _ = @import("behavior/bugs/13113.zig"); | ||
| 133 | _ = @import("behavior/bugs/13128.zig"); | ||
| 134 | _ = @import("behavior/bugs/13159.zig"); | ||
| 135 | _ = @import("behavior/bugs/13171.zig"); | ||
| 136 | _ = @import("behavior/bugs/13209.zig"); | ||
| 137 | _ = @import("behavior/bugs/13285.zig"); | ||
| 138 | _ = @import("behavior/bugs/13366.zig"); | ||
| 139 | _ = @import("behavior/bugs/13435.zig"); | ||
| 140 | _ = @import("behavior/bugs/13664.zig"); | ||
| 141 | _ = @import("behavior/bugs/13714.zig"); | ||
| 142 | _ = @import("behavior/bugs/13785.zig"); | ||
| 143 | _ = @import("behavior/bugs/14854.zig"); | ||
| 144 | _ = @import("behavior/bugs/15778.zig"); | ||
| 145 | _ = @import("behavior/byteswap.zig"); | 15 | _ = @import("behavior/byteswap.zig"); |
| 146 | _ = @import("behavior/byval_arg_var.zig"); | 16 | _ = @import("behavior/byval_arg_var.zig"); |
| 147 | _ = @import("behavior/c_char_signedness.zig"); | 17 | _ = @import("behavior/c_char_signedness.zig"); |
| ... | @@ -189,6 +59,7 @@ test { | ... | @@ -189,6 +59,7 @@ test { |
| 189 | _ = @import("behavior/memset.zig"); | 59 | _ = @import("behavior/memset.zig"); |
| 190 | _ = @import("behavior/merge_error_sets.zig"); | 60 | _ = @import("behavior/merge_error_sets.zig"); |
| 191 | _ = @import("behavior/muladd.zig"); | 61 | _ = @import("behavior/muladd.zig"); |
| 62 | _ = @import("behavior/multiple_externs_with_conflicting_types.zig"); | ||
| 192 | _ = @import("behavior/namespace_depends_on_compile_var.zig"); | 63 | _ = @import("behavior/namespace_depends_on_compile_var.zig"); |
| 193 | _ = @import("behavior/nan.zig"); | 64 | _ = @import("behavior/nan.zig"); |
| 194 | _ = @import("behavior/null.zig"); | 65 | _ = @import("behavior/null.zig"); |
test/behavior/array.zig+118| ... | @@ -827,3 +827,121 @@ test "tuple initialized through reference to anonymous array init provides resul | ... | @@ -827,3 +827,121 @@ test "tuple initialized through reference to anonymous array init provides resul |
| 827 | try expect(foo[0] == 12345); | 827 | try expect(foo[0] == 12345); |
| 828 | try expect(@intFromPtr(foo[1]) == 0x1000); | 828 | try expect(@intFromPtr(foo[1]) == 0x1000); |
| 829 | } | 829 | } |
| 830 | |||
| 831 | test "copied array element doesn't alias source" { | ||
| 832 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 833 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 834 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 835 | |||
| 836 | var x: [10][10]u32 = undefined; | ||
| 837 | |||
| 838 | x[0][1] = 0; | ||
| 839 | const a = x[0]; | ||
| 840 | x[0][1] = 15; | ||
| 841 | |||
| 842 | try expect(a[1] == 0); | ||
| 843 | } | ||
| 844 | |||
| 845 | test "array initialized with string literal" { | ||
| 846 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 847 | |||
| 848 | const S = struct { | ||
| 849 | a: u32, | ||
| 850 | c: [5]u8, | ||
| 851 | }; | ||
| 852 | const U = union { | ||
| 853 | s: S, | ||
| 854 | }; | ||
| 855 | const s_1 = S{ | ||
| 856 | .a = undefined, | ||
| 857 | .c = "12345".*, // this caused problems | ||
| 858 | }; | ||
| 859 | |||
| 860 | var u_2 = U{ .s = s_1 }; | ||
| 861 | _ = &u_2; | ||
| 862 | try std.testing.expectEqualStrings("12345", &u_2.s.c); | ||
| 863 | } | ||
| 864 | |||
| 865 | test "array initialized with array with sentinel" { | ||
| 866 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 867 | |||
| 868 | const S = struct { | ||
| 869 | a: u32, | ||
| 870 | c: [5]u8, | ||
| 871 | }; | ||
| 872 | const U = union { | ||
| 873 | s: S, | ||
| 874 | }; | ||
| 875 | const c = [5:0]u8{ 1, 2, 3, 4, 5 }; | ||
| 876 | const s_1 = S{ | ||
| 877 | .a = undefined, | ||
| 878 | .c = c, // this caused problems | ||
| 879 | }; | ||
| 880 | var u_2 = U{ .s = s_1 }; | ||
| 881 | _ = &u_2; | ||
| 882 | try std.testing.expectEqualSlices(u8, &.{ 1, 2, 3, 4, 5 }, &u_2.s.c); | ||
| 883 | } | ||
| 884 | |||
| 885 | test "store array of array of structs at comptime" { | ||
| 886 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 887 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 888 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 889 | |||
| 890 | const S = struct { | ||
| 891 | fn storeArrayOfArrayOfStructs() u8 { | ||
| 892 | const S = struct { | ||
| 893 | x: u8, | ||
| 894 | }; | ||
| 895 | |||
| 896 | var cases = [_][1]S{ | ||
| 897 | [_]S{ | ||
| 898 | S{ .x = 15 }, | ||
| 899 | }, | ||
| 900 | }; | ||
| 901 | _ = &cases; | ||
| 902 | return cases[0][0].x; | ||
| 903 | } | ||
| 904 | }; | ||
| 905 | |||
| 906 | try expect(S.storeArrayOfArrayOfStructs() == 15); | ||
| 907 | try comptime expect(S.storeArrayOfArrayOfStructs() == 15); | ||
| 908 | } | ||
| 909 | |||
| 910 | test "accessing multidimensional global array at comptime" { | ||
| 911 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 912 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 913 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 914 | |||
| 915 | const S = struct { | ||
| 916 | const array = [_][]const []const u8{ | ||
| 917 | &.{"hello"}, | ||
| 918 | &.{ "world", "hello" }, | ||
| 919 | }; | ||
| 920 | }; | ||
| 921 | |||
| 922 | try std.testing.expect(S.array[0].len == 1); | ||
| 923 | try std.testing.expectEqualStrings("hello", S.array[0][0]); | ||
| 924 | } | ||
| 925 | |||
| 926 | test "union that needs padding bytes inside an array" { | ||
| 927 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 928 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 929 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 930 | |||
| 931 | const B = union(enum) { | ||
| 932 | D: u8, | ||
| 933 | E: u16, | ||
| 934 | }; | ||
| 935 | const A = union(enum) { | ||
| 936 | B: B, | ||
| 937 | C: u8, | ||
| 938 | }; | ||
| 939 | var as = [_]A{ | ||
| 940 | A{ .B = B{ .D = 1 } }, | ||
| 941 | A{ .B = B{ .D = 1 } }, | ||
| 942 | }; | ||
| 943 | _ = &as; | ||
| 944 | |||
| 945 | const a = as[0].B; | ||
| 946 | try std.testing.expect(a.D == 1); | ||
| 947 | } |
test/behavior/basic.zig+181| ... | @@ -1219,3 +1219,184 @@ test "integer compare" { | ... | @@ -1219,3 +1219,184 @@ test "integer compare" { |
| 1219 | try comptime S.doTheTestSigned(T); | 1219 | try comptime S.doTheTestSigned(T); |
| 1220 | } | 1220 | } |
| 1221 | } | 1221 | } |
| 1222 | |||
| 1223 | test "reference to inferred local variable works as expected" { | ||
| 1224 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1225 | |||
| 1226 | const Crasher = struct { | ||
| 1227 | lets_crash: u64 = 0, | ||
| 1228 | }; | ||
| 1229 | |||
| 1230 | var a: Crasher = undefined; | ||
| 1231 | const crasher_ptr = &a; | ||
| 1232 | var crasher_local = crasher_ptr.*; | ||
| 1233 | const crasher_local_ptr = &crasher_local; | ||
| 1234 | crasher_local_ptr.lets_crash = 1; | ||
| 1235 | |||
| 1236 | try expect(crasher_local.lets_crash != a.lets_crash); | ||
| 1237 | } | ||
| 1238 | |||
| 1239 | test "@Type returned from block" { | ||
| 1240 | const T = comptime b: { | ||
| 1241 | break :b @Type(.{ .Int = .{ | ||
| 1242 | .signedness = .unsigned, | ||
| 1243 | .bits = 8, | ||
| 1244 | } }); | ||
| 1245 | }; | ||
| 1246 | try std.testing.expect(T == u8); | ||
| 1247 | } | ||
| 1248 | |||
| 1249 | test "comptime variable initialized with addresses of literals" { | ||
| 1250 | comptime var st = .{ | ||
| 1251 | .foo = &1, | ||
| 1252 | .bar = &2, | ||
| 1253 | }; | ||
| 1254 | _ = &st; | ||
| 1255 | |||
| 1256 | inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| { | ||
| 1257 | _ = field; | ||
| 1258 | } | ||
| 1259 | } | ||
| 1260 | |||
| 1261 | test "pointer to tuple field can be dereferenced at comptime" { | ||
| 1262 | comptime { | ||
| 1263 | const tuple_with_ptrs = .{ &0, &0 }; | ||
| 1264 | const field_ptr = (&tuple_with_ptrs.@"0"); | ||
| 1265 | _ = field_ptr.*; | ||
| 1266 | } | ||
| 1267 | } | ||
| 1268 | |||
| 1269 | test "proper value is returned from labeled block" { | ||
| 1270 | const S = struct { | ||
| 1271 | fn hash(v: *u32, key: anytype) void { | ||
| 1272 | const Key = @TypeOf(key); | ||
| 1273 | if (@typeInfo(Key) == .ErrorSet) { | ||
| 1274 | v.* += 1; | ||
| 1275 | return; | ||
| 1276 | } | ||
| 1277 | switch (@typeInfo(Key)) { | ||
| 1278 | .ErrorUnion => blk: { | ||
| 1279 | const payload = key catch |err| { | ||
| 1280 | hash(v, err); | ||
| 1281 | break :blk; | ||
| 1282 | }; | ||
| 1283 | |||
| 1284 | hash(v, payload); | ||
| 1285 | }, | ||
| 1286 | |||
| 1287 | else => unreachable, | ||
| 1288 | } | ||
| 1289 | } | ||
| 1290 | }; | ||
| 1291 | const g: error{Test}!void = error.Test; | ||
| 1292 | |||
| 1293 | var v: u32 = 0; | ||
| 1294 | S.hash(&v, g); | ||
| 1295 | try expect(v == 1); | ||
| 1296 | } | ||
| 1297 | |||
| 1298 | test "const inferred array of slices" { | ||
| 1299 | const T = struct { v: bool }; | ||
| 1300 | |||
| 1301 | const decls = [_][]const T{ | ||
| 1302 | &[_]T{ | ||
| 1303 | .{ .v = false }, | ||
| 1304 | }, | ||
| 1305 | }; | ||
| 1306 | _ = decls; | ||
| 1307 | } | ||
| 1308 | |||
| 1309 | test "var inferred array of slices" { | ||
| 1310 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1311 | |||
| 1312 | const T = struct { v: bool }; | ||
| 1313 | |||
| 1314 | var decls = [_][]const T{ | ||
| 1315 | &[_]T{ | ||
| 1316 | .{ .v = false }, | ||
| 1317 | }, | ||
| 1318 | }; | ||
| 1319 | _ = &decls; | ||
| 1320 | } | ||
| 1321 | |||
| 1322 | test "copy array of self-referential struct" { | ||
| 1323 | const ListNode = struct { | ||
| 1324 | next: ?*const @This() = null, | ||
| 1325 | }; | ||
| 1326 | comptime var nodes = [_]ListNode{ .{}, .{} }; | ||
| 1327 | nodes[0].next = &nodes[1]; | ||
| 1328 | const copied_nodes = nodes; | ||
| 1329 | _ = copied_nodes; | ||
| 1330 | } | ||
| 1331 | |||
| 1332 | test "break out of block based on comptime known values" { | ||
| 1333 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 1334 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 1335 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1336 | |||
| 1337 | const S = struct { | ||
| 1338 | const source = "A-"; | ||
| 1339 | |||
| 1340 | fn parseNote() ?i32 { | ||
| 1341 | const letter = source[0]; | ||
| 1342 | const modifier = source[1]; | ||
| 1343 | |||
| 1344 | const semitone = blk: { | ||
| 1345 | if (letter == 'C' and modifier == '-') break :blk @as(i32, 0); | ||
| 1346 | if (letter == 'C' and modifier == '#') break :blk @as(i32, 1); | ||
| 1347 | if (letter == 'D' and modifier == '-') break :blk @as(i32, 2); | ||
| 1348 | if (letter == 'D' and modifier == '#') break :blk @as(i32, 3); | ||
| 1349 | if (letter == 'E' and modifier == '-') break :blk @as(i32, 4); | ||
| 1350 | if (letter == 'F' and modifier == '-') break :blk @as(i32, 5); | ||
| 1351 | if (letter == 'F' and modifier == '#') break :blk @as(i32, 6); | ||
| 1352 | if (letter == 'G' and modifier == '-') break :blk @as(i32, 7); | ||
| 1353 | if (letter == 'G' and modifier == '#') break :blk @as(i32, 8); | ||
| 1354 | if (letter == 'A' and modifier == '-') break :blk @as(i32, 9); | ||
| 1355 | if (letter == 'A' and modifier == '#') break :blk @as(i32, 10); | ||
| 1356 | if (letter == 'B' and modifier == '-') break :blk @as(i32, 11); | ||
| 1357 | return null; | ||
| 1358 | }; | ||
| 1359 | |||
| 1360 | return semitone; | ||
| 1361 | } | ||
| 1362 | }; | ||
| 1363 | const result = S.parseNote(); | ||
| 1364 | try std.testing.expect(result.? == 9); | ||
| 1365 | } | ||
| 1366 | |||
| 1367 | test "allocation and looping over 3-byte integer" { | ||
| 1368 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1369 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1370 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1371 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 1372 | |||
| 1373 | if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .macos) { | ||
| 1374 | return error.SkipZigTest; // TODO | ||
| 1375 | } | ||
| 1376 | |||
| 1377 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .wasm32) { | ||
| 1378 | return error.SkipZigTest; // TODO | ||
| 1379 | } | ||
| 1380 | |||
| 1381 | try expect(@sizeOf(u24) == 4); | ||
| 1382 | try expect(@sizeOf([1]u24) == 4); | ||
| 1383 | try expect(@alignOf(u24) == 4); | ||
| 1384 | try expect(@alignOf([1]u24) == 4); | ||
| 1385 | |||
| 1386 | var x = try std.testing.allocator.alloc(u24, 2); | ||
| 1387 | defer std.testing.allocator.free(x); | ||
| 1388 | try expect(x.len == 2); | ||
| 1389 | x[0] = 0xFFFFFF; | ||
| 1390 | x[1] = 0xFFFFFF; | ||
| 1391 | |||
| 1392 | const bytes = std.mem.sliceAsBytes(x); | ||
| 1393 | try expect(@TypeOf(bytes) == []align(4) u8); | ||
| 1394 | try expect(bytes.len == 8); | ||
| 1395 | |||
| 1396 | for (bytes) |*b| { | ||
| 1397 | b.* = 0x00; | ||
| 1398 | } | ||
| 1399 | |||
| 1400 | try expect(x[0] == 0x00); | ||
| 1401 | try expect(x[1] == 0x00); | ||
| 1402 | } |
test/behavior/bit_shifting.zig+6| ... | @@ -152,3 +152,9 @@ test "Saturating Shift Left where lhs is of a computed type" { | ... | @@ -152,3 +152,9 @@ test "Saturating Shift Left where lhs is of a computed type" { |
| 152 | try expect(value.value == 2); | 152 | try expect(value.value == 2); |
| 153 | try expect(value.exponent == 0); | 153 | try expect(value.exponent == 0); |
| 154 | } | 154 | } |
| 155 | |||
| 156 | comptime { | ||
| 157 | var image: [1]u8 = undefined; | ||
| 158 | _ = ℑ | ||
| 159 | _ = @shlExact(@as(u16, image[0]), 8); | ||
| 160 | } |
test/behavior/bool.zig+9| ... | @@ -90,3 +90,12 @@ fn testShortCircuit(f: bool, t: bool) !void { | ... | @@ -90,3 +90,12 @@ fn testShortCircuit(f: bool, t: bool) !void { |
| 90 | try expect(hit_3); | 90 | try expect(hit_3); |
| 91 | try expect(hit_4); | 91 | try expect(hit_4); |
| 92 | } | 92 | } |
| 93 | |||
| 94 | test "or with noreturn operand" { | ||
| 95 | const S = struct { | ||
| 96 | fn foo(a: u32, b: u32) bool { | ||
| 97 | return a == 5 or b == 2 or @panic("oh no"); | ||
| 98 | } | ||
| 99 | }; | ||
| 100 | _ = S.foo(2, 2); | ||
| 101 | } |
test/behavior/bugs/10138.zig deleted-34| ... | @@ -1,34 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test "registers get overwritten when ignoring return" { | ||
| 5 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 6 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 7 | if (builtin.cpu.arch != .x86_64 or builtin.os.tag != .linux) return error.SkipZigTest; | ||
| 8 | |||
| 9 | const fd = open(); | ||
| 10 | _ = write(fd, "a", 1); | ||
| 11 | _ = close(fd); | ||
| 12 | } | ||
| 13 | |||
| 14 | fn open() usize { | ||
| 15 | return 42; | ||
| 16 | } | ||
| 17 | |||
| 18 | fn write(fd: usize, a: [*]const u8, len: usize) usize { | ||
| 19 | return syscall4(.WRITE, fd, @intFromPtr(a), len); | ||
| 20 | } | ||
| 21 | |||
| 22 | fn syscall4(n: enum { WRITE }, a: usize, b: usize, c: usize) usize { | ||
| 23 | _ = n; | ||
| 24 | _ = a; | ||
| 25 | _ = b; | ||
| 26 | _ = c; | ||
| 27 | return 23; | ||
| 28 | } | ||
| 29 | |||
| 30 | fn close(fd: usize) usize { | ||
| 31 | if (fd != 42) | ||
| 32 | unreachable; | ||
| 33 | return 0; | ||
| 34 | } | ||
test/behavior/bugs/10147.zig deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | |||
| 4 | test "test calling @clz on both vector and scalar inputs" { | ||
| 5 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 6 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 9 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 10 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 11 | |||
| 12 | var x: u32 = 0x1; | ||
| 13 | _ = &x; | ||
| 14 | var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 }; | ||
| 15 | _ = &y; | ||
| 16 | const a = @clz(x); | ||
| 17 | const b = @clz(y); | ||
| 18 | try std.testing.expectEqual(@as(u6, 31), a); | ||
| 19 | try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b); | ||
| 20 | } | ||
test/behavior/bugs/1025.zig deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | const A = struct { | ||
| 4 | B: type, | ||
| 5 | }; | ||
| 6 | |||
| 7 | fn getA() A { | ||
| 8 | return A{ .B = u8 }; | ||
| 9 | } | ||
| 10 | |||
| 11 | test "bug 1025" { | ||
| 12 | const a = getA(); | ||
| 13 | try @import("std").testing.expect(a.B == u8); | ||
| 14 | } | ||
test/behavior/bugs/10684.zig deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const expectEqualStrings = std.testing.expectEqualStrings; | ||
| 4 | |||
| 5 | test "slicing slices" { | ||
| 6 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 9 | |||
| 10 | const foo = "1234"; | ||
| 11 | const bar = foo[0..4]; | ||
| 12 | try expectEqualStrings("1234", bar); | ||
| 13 | try expectEqualStrings("2", bar[1..2]); | ||
| 14 | try expectEqualStrings("3", bar[2..3]); | ||
| 15 | try expectEqualStrings("4", bar[3..4]); | ||
| 16 | try expectEqualStrings("34", bar[2..4]); | ||
| 17 | } | ||
test/behavior/bugs/1076.zig deleted-27| ... | @@ -1,27 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const mem = std.mem; | ||
| 4 | const expect = std.testing.expect; | ||
| 5 | |||
| 6 | test "comptime code should not modify constant data" { | ||
| 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 9 | |||
| 10 | try testCastPtrOfArrayToSliceAndPtr(); | ||
| 11 | try comptime testCastPtrOfArrayToSliceAndPtr(); | ||
| 12 | } | ||
| 13 | |||
| 14 | fn testCastPtrOfArrayToSliceAndPtr() !void { | ||
| 15 | { | ||
| 16 | var array = "aoeu".*; | ||
| 17 | const x: [*]u8 = &array; | ||
| 18 | x[0] += 1; | ||
| 19 | try expect(mem.eql(u8, array[0..], "boeu")); | ||
| 20 | } | ||
| 21 | { | ||
| 22 | var array: [4]u8 = "aoeu".*; | ||
| 23 | const x: [*]u8 = &array; | ||
| 24 | x[0] += 1; | ||
| 25 | try expect(mem.eql(u8, array[0..], "boeu")); | ||
| 26 | } | ||
| 27 | } | ||
test/behavior/bugs/10970.zig deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | fn retOpt() ?u32 { | ||
| 4 | return null; | ||
| 5 | } | ||
| 6 | test "breaking from a loop in an if statement" { | ||
| 7 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 8 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 9 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 10 | |||
| 11 | var cond = true; | ||
| 12 | _ = &cond; | ||
| 13 | const opt = while (cond) { | ||
| 14 | if (retOpt()) |opt| { | ||
| 15 | break opt; | ||
| 16 | } | ||
| 17 | break 1; | ||
| 18 | } else 2; | ||
| 19 | _ = opt; | ||
| 20 | } | ||
test/behavior/bugs/11046.zig deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | fn foo() !void { | ||
| 4 | var a = true; | ||
| 5 | _ = &a; | ||
| 6 | if (a) return error.Foo; | ||
| 7 | return error.Bar; | ||
| 8 | } | ||
| 9 | fn bar() !void { | ||
| 10 | try foo(); | ||
| 11 | } | ||
| 12 | |||
| 13 | test "fixed" { | ||
| 14 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 15 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 16 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 17 | |||
| 18 | bar() catch |err| switch (err) { | ||
| 19 | error.Foo => {}, // error: expected (inferred error set of bar), found error{Foo} | ||
| 20 | error.Bar => {}, | ||
| 21 | }; | ||
| 22 | } | ||
test/behavior/bugs/11100.zig deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | pub fn do() bool { | ||
| 5 | inline for (.{"a"}) |_| { | ||
| 6 | if (true) return false; | ||
| 7 | } | ||
| 8 | return true; | ||
| 9 | } | ||
| 10 | |||
| 11 | test "bug" { | ||
| 12 | try std.testing.expect(!do()); | ||
| 13 | } | ||
test/behavior/bugs/11139.zig deleted-26| ... | @@ -1,26 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | test "store array of array of structs at comptime" { | ||
| 6 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 9 | |||
| 10 | try expect(storeArrayOfArrayOfStructs() == 15); | ||
| 11 | try comptime expect(storeArrayOfArrayOfStructs() == 15); | ||
| 12 | } | ||
| 13 | |||
| 14 | fn storeArrayOfArrayOfStructs() u8 { | ||
| 15 | const S = struct { | ||
| 16 | x: u8, | ||
| 17 | }; | ||
| 18 | |||
| 19 | var cases = [_][1]S{ | ||
| 20 | [_]S{ | ||
| 21 | S{ .x = 15 }, | ||
| 22 | }, | ||
| 23 | }; | ||
| 24 | _ = &cases; | ||
| 25 | return cases[0][0].x; | ||
| 26 | } | ||
test/behavior/bugs/11159.zig deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test { | ||
| 5 | const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); | ||
| 6 | var a: T = .{ 0, 0 }; | ||
| 7 | _ = &a; | ||
| 8 | } | ||
| 9 | |||
| 10 | test { | ||
| 11 | const S = struct { | ||
| 12 | comptime x: i32 = 0, | ||
| 13 | comptime y: u32 = 0, | ||
| 14 | }; | ||
| 15 | var a: S = .{}; | ||
| 16 | _ = &a; | ||
| 17 | var b = S{}; | ||
| 18 | _ = &b; | ||
| 19 | } | ||
test/behavior/bugs/11162.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | test "aggregate initializers should allow initializing comptime fields, verifying equality" { | ||
| 6 | if (true) return error.SkipZigTest; // TODO | ||
| 7 | |||
| 8 | var x: u32 = 15; | ||
| 9 | _ = &x; | ||
| 10 | const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); | ||
| 11 | const a: T = .{ -1234, 5678, x + 1 }; | ||
| 12 | |||
| 13 | try expect(a[0] == -1234); | ||
| 14 | try expect(a[1] == 5678); | ||
| 15 | try expect(a[2] == 16); | ||
| 16 | } | ||
test/behavior/bugs/11165.zig deleted-44| ... | @@ -1,44 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | test "bytes" { | ||
| 4 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 5 | |||
| 6 | const S = struct { | ||
| 7 | a: u32, | ||
| 8 | c: [5]u8, | ||
| 9 | }; | ||
| 10 | |||
| 11 | const U = union { | ||
| 12 | s: S, | ||
| 13 | }; | ||
| 14 | |||
| 15 | const s_1 = S{ | ||
| 16 | .a = undefined, | ||
| 17 | .c = "12345".*, // this caused problems | ||
| 18 | }; | ||
| 19 | |||
| 20 | var u_2 = U{ .s = s_1 }; | ||
| 21 | _ = &u_2; | ||
| 22 | } | ||
| 23 | |||
| 24 | test "aggregate" { | ||
| 25 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 26 | |||
| 27 | const S = struct { | ||
| 28 | a: u32, | ||
| 29 | c: [5]u8, | ||
| 30 | }; | ||
| 31 | |||
| 32 | const U = union { | ||
| 33 | s: S, | ||
| 34 | }; | ||
| 35 | |||
| 36 | const c = [5:0]u8{ 1, 2, 3, 4, 5 }; | ||
| 37 | const s_1 = S{ | ||
| 38 | .a = undefined, | ||
| 39 | .c = c, // this caused problems | ||
| 40 | }; | ||
| 41 | |||
| 42 | var u_2 = U{ .s = s_1 }; | ||
| 43 | _ = &u_2; | ||
| 44 | } | ||
test/behavior/bugs/11179.zig deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const Type = std.builtin.Type; | ||
| 4 | |||
| 5 | test "Tuple" { | ||
| 6 | const fields_list = fields(@TypeOf(.{})); | ||
| 7 | if (fields_list.len != 0) | ||
| 8 | @compileError("Argument count mismatch"); | ||
| 9 | } | ||
| 10 | |||
| 11 | pub fn fields(comptime T: type) switch (@typeInfo(T)) { | ||
| 12 | .Struct => []const Type.StructField, | ||
| 13 | else => unreachable, | ||
| 14 | } { | ||
| 15 | return switch (@typeInfo(T)) { | ||
| 16 | .Struct => |info| info.fields, | ||
| 17 | else => unreachable, | ||
| 18 | }; | ||
| 19 | } | ||
test/behavior/bugs/11181.zig deleted-25| ... | @@ -1,25 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | test "const inferred array of slices" { | ||
| 4 | const T = struct { v: bool }; | ||
| 5 | |||
| 6 | const decls = [_][]const T{ | ||
| 7 | &[_]T{ | ||
| 8 | .{ .v = false }, | ||
| 9 | }, | ||
| 10 | }; | ||
| 11 | _ = decls; | ||
| 12 | } | ||
| 13 | |||
| 14 | test "var inferred array of slices" { | ||
| 15 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 16 | |||
| 17 | const T = struct { v: bool }; | ||
| 18 | |||
| 19 | var decls = [_][]const T{ | ||
| 20 | &[_]T{ | ||
| 21 | .{ .v = false }, | ||
| 22 | }, | ||
| 23 | }; | ||
| 24 | _ = &decls; | ||
| 25 | } | ||
test/behavior/bugs/11213.zig deleted-33| ... | @@ -1,33 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const testing = std.testing; | ||
| 4 | |||
| 5 | test { | ||
| 6 | const g: error{Test}!void = error.Test; | ||
| 7 | |||
| 8 | var v: u32 = 0; | ||
| 9 | hash(&v, g); | ||
| 10 | try testing.expect(v == 1); | ||
| 11 | } | ||
| 12 | |||
| 13 | fn hash(v: *u32, key: anytype) void { | ||
| 14 | const Key = @TypeOf(key); | ||
| 15 | |||
| 16 | if (@typeInfo(Key) == .ErrorSet) { | ||
| 17 | v.* += 1; | ||
| 18 | return; | ||
| 19 | } | ||
| 20 | |||
| 21 | switch (@typeInfo(Key)) { | ||
| 22 | .ErrorUnion => blk: { | ||
| 23 | const payload = key catch |err| { | ||
| 24 | hash(v, err); | ||
| 25 | break :blk; | ||
| 26 | }; | ||
| 27 | |||
| 28 | hash(v, payload); | ||
| 29 | }, | ||
| 30 | |||
| 31 | else => unreachable, | ||
| 32 | } | ||
| 33 | } | ||
test/behavior/bugs/11787.zig deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const testing = std.testing; | ||
| 4 | |||
| 5 | test "slicing zero length array field of struct" { | ||
| 6 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 9 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 10 | |||
| 11 | const S = struct { | ||
| 12 | a: [0]usize, | ||
| 13 | fn foo(self: *@This(), start: usize, end: usize) []usize { | ||
| 14 | return self.a[start..end]; | ||
| 15 | } | ||
| 16 | }; | ||
| 17 | var s: S = undefined; | ||
| 18 | try testing.expect(s.foo(0, 0).len == 0); | ||
| 19 | } | ||
test/behavior/bugs/11816.zig deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test { | ||
| 5 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 6 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 7 | |||
| 8 | var x: u32 = 3; | ||
| 9 | const val: usize = while (true) switch (x) { | ||
| 10 | 1 => break 2, | ||
| 11 | else => x -= 1, | ||
| 12 | }; | ||
| 13 | try std.testing.expect(val == 2); | ||
| 14 | } | ||
test/behavior/bugs/11995.zig deleted-33| ... | @@ -1,33 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const testing = std.testing; | ||
| 3 | const builtin = @import("builtin"); | ||
| 4 | |||
| 5 | fn wuffs_base__make_io_buffer(arg_data: wuffs_base__slice_u8, arg_meta: *wuffs_base__io_buffer_meta) callconv(.C) void { | ||
| 6 | arg_data.ptr[0] = 'w'; | ||
| 7 | arg_meta.closed = false; | ||
| 8 | } | ||
| 9 | const wuffs_base__io_buffer_meta = extern struct { | ||
| 10 | wi: usize, | ||
| 11 | ri: usize, | ||
| 12 | pos: u64, | ||
| 13 | closed: bool, | ||
| 14 | }; | ||
| 15 | const wuffs_base__slice_u8 = extern struct { | ||
| 16 | ptr: [*c]u8, | ||
| 17 | len: usize, | ||
| 18 | }; | ||
| 19 | test { | ||
| 20 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 21 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 22 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 23 | |||
| 24 | var string: [5]u8 = "hello".*; | ||
| 25 | const arg_data = wuffs_base__slice_u8{ .ptr = @as([*c]u8, @ptrCast(&string)), .len = string.len }; | ||
| 26 | var arg_meta = wuffs_base__io_buffer_meta{ .wi = 1, .ri = 2, .pos = 3, .closed = true }; | ||
| 27 | wuffs_base__make_io_buffer(arg_data, &arg_meta); | ||
| 28 | try std.testing.expectEqualStrings("wello", arg_data.ptr[0..arg_data.len]); | ||
| 29 | try std.testing.expectEqual(@as(usize, 1), arg_meta.wi); | ||
| 30 | try std.testing.expectEqual(@as(usize, 2), arg_meta.ri); | ||
| 31 | try std.testing.expectEqual(@as(u64, 3), arg_meta.pos); | ||
| 32 | try std.testing.expect(!arg_meta.closed); | ||
| 33 | } | ||
test/behavior/bugs/12000.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const T = struct { | ||
| 5 | next: @TypeOf(null, @as(*const T, undefined)), | ||
| 6 | }; | ||
| 7 | |||
| 8 | test { | ||
| 9 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 10 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 11 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 12 | |||
| 13 | var t: T = .{ .next = null }; | ||
| 14 | _ = &t; | ||
| 15 | try std.testing.expect(t.next == null); | ||
| 16 | } | ||
test/behavior/bugs/12003.zig deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | test { | ||
| 2 | comptime { | ||
| 3 | const tuple_with_ptrs = .{ &0, &0 }; | ||
| 4 | const field_ptr = (&tuple_with_ptrs.@"0"); | ||
| 5 | _ = field_ptr.*; | ||
| 6 | } | ||
| 7 | } | ||
test/behavior/bugs/12025.zig deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | test { | ||
| 4 | comptime var st = .{ | ||
| 5 | .foo = &1, | ||
| 6 | .bar = &2, | ||
| 7 | }; | ||
| 8 | _ = &st; | ||
| 9 | |||
| 10 | inline for (@typeInfo(@TypeOf(st)).Struct.fields) |field| { | ||
| 11 | _ = field; | ||
| 12 | } | ||
| 13 | } | ||
test/behavior/bugs/12033.zig deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test { | ||
| 5 | const string = "Hello!\x00World!"; | ||
| 6 | try std.testing.expect(@TypeOf(string) == *const [13:0]u8); | ||
| 7 | |||
| 8 | const slice_without_sentinel: []const u8 = string[0..6]; | ||
| 9 | try std.testing.expect(@TypeOf(slice_without_sentinel) == []const u8); | ||
| 10 | |||
| 11 | const slice_with_sentinel: [:0]const u8 = string[0..6 :0]; | ||
| 12 | try std.testing.expect(@TypeOf(slice_with_sentinel) == [:0]const u8); | ||
| 13 | } | ||
test/behavior/bugs/12043.zig deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | var ok = false; | ||
| 6 | fn foo(x: anytype) void { | ||
| 7 | ok = x; | ||
| 8 | } | ||
| 9 | test { | ||
| 10 | const x = &foo; | ||
| 11 | x(true); | ||
| 12 | try expect(ok); | ||
| 13 | } | ||
test/behavior/bugs/12051.zig deleted-40| ... | @@ -1,40 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test { | ||
| 5 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 6 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 9 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 10 | |||
| 11 | const x = X{}; | ||
| 12 | try std.testing.expectEqual(@as(u16, 0), x.y.a); | ||
| 13 | try std.testing.expectEqual(false, x.y.b); | ||
| 14 | try std.testing.expectEqual(Z{ .a = 0 }, x.y.c); | ||
| 15 | try std.testing.expectEqual(Z{ .a = 0 }, x.y.d); | ||
| 16 | } | ||
| 17 | |||
| 18 | const X = struct { | ||
| 19 | y: Y = Y.init(), | ||
| 20 | }; | ||
| 21 | |||
| 22 | const Y = struct { | ||
| 23 | a: u16, | ||
| 24 | b: bool, | ||
| 25 | c: Z, | ||
| 26 | d: Z, | ||
| 27 | |||
| 28 | fn init() Y { | ||
| 29 | return .{ | ||
| 30 | .a = 0, | ||
| 31 | .b = false, | ||
| 32 | .c = @as(Z, @bitCast(@as(u32, 0))), | ||
| 33 | .d = @as(Z, @bitCast(@as(u32, 0))), | ||
| 34 | }; | ||
| 35 | } | ||
| 36 | }; | ||
| 37 | |||
| 38 | const Z = packed struct { | ||
| 39 | a: u32, | ||
| 40 | }; | ||
test/behavior/bugs/12092.zig deleted-28| ... | @@ -1,28 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const Foo = struct { | ||
| 5 | a: Bar, | ||
| 6 | }; | ||
| 7 | |||
| 8 | const Bar = struct { | ||
| 9 | b: u32, | ||
| 10 | }; | ||
| 11 | |||
| 12 | fn takeFoo(foo: *const Foo) !void { | ||
| 13 | try std.testing.expectEqual(@as(u32, 24), foo.a.b); | ||
| 14 | } | ||
| 15 | |||
| 16 | test { | ||
| 17 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 18 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 19 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 20 | |||
| 21 | var baz: u32 = 24; | ||
| 22 | _ = &baz; | ||
| 23 | try takeFoo(&.{ | ||
| 24 | .a = .{ | ||
| 25 | .b = baz, | ||
| 26 | }, | ||
| 27 | }); | ||
| 28 | } | ||
test/behavior/bugs/12119.zig deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const u8x32 = @Vector(32, u8); | ||
| 5 | const u32x8 = @Vector(8, u32); | ||
| 6 | |||
| 7 | test { | ||
| 8 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 9 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 10 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 11 | |||
| 12 | const zerox32: u8x32 = [_]u8{0} ** 32; | ||
| 13 | const bigsum: u32x8 = @as(u32x8, @bitCast(zerox32)); | ||
| 14 | try std.testing.expectEqual(0, @reduce(.Add, bigsum)); | ||
| 15 | } | ||
test/behavior/bugs/12142.zig deleted-36| ... | @@ -1,36 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const Holder = struct { | ||
| 5 | array: []const u8, | ||
| 6 | }; | ||
| 7 | |||
| 8 | const Test = struct { | ||
| 9 | holders: []const Holder, | ||
| 10 | }; | ||
| 11 | |||
| 12 | const Letter = enum(u8) { | ||
| 13 | A = 0x41, | ||
| 14 | B, | ||
| 15 | }; | ||
| 16 | |||
| 17 | fn letter(e: Letter) u8 { | ||
| 18 | return @intFromEnum(e); | ||
| 19 | } | ||
| 20 | |||
| 21 | test { | ||
| 22 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 23 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 24 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 25 | |||
| 26 | const test_struct = Test{ | ||
| 27 | .holders = &.{ | ||
| 28 | Holder{ | ||
| 29 | .array = &.{ | ||
| 30 | letter(.A), | ||
| 31 | }, | ||
| 32 | }, | ||
| 33 | }, | ||
| 34 | }; | ||
| 35 | try std.testing.expectEqualStrings("A", test_struct.holders[0].array); | ||
| 36 | } | ||
test/behavior/bugs/12169.zig deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test { | ||
| 5 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 6 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 9 | |||
| 10 | if (comptime builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.endian() == .big) { | ||
| 11 | // https://github.com/ziglang/zig/issues/13782 | ||
| 12 | return error.SkipZigTest; | ||
| 13 | } | ||
| 14 | |||
| 15 | const a = @Vector(2, bool){ true, true }; | ||
| 16 | const b = @Vector(1, bool){true}; | ||
| 17 | try std.testing.expect(@reduce(.And, a)); | ||
| 18 | try std.testing.expect(@reduce(.And, b)); | ||
| 19 | } | ||
test/behavior/bugs/12430.zig deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | test { | ||
| 4 | const T = comptime b: { | ||
| 5 | break :b @Type(.{ .Int = .{ | ||
| 6 | .signedness = .unsigned, | ||
| 7 | .bits = 8, | ||
| 8 | } }); | ||
| 9 | }; | ||
| 10 | try std.testing.expect(T == u8); | ||
| 11 | } | ||
test/behavior/bugs/12450.zig deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | const expect = @import("std").testing.expect; | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const Foo = packed struct { | ||
| 5 | a: i32, | ||
| 6 | b: u8, | ||
| 7 | }; | ||
| 8 | |||
| 9 | var buffer: [256]u8 = undefined; | ||
| 10 | |||
| 11 | test { | ||
| 12 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 13 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 14 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 15 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 16 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 17 | |||
| 18 | var f1: *align(16) Foo = @alignCast(@as(*align(1) Foo, @ptrCast(&buffer[0]))); | ||
| 19 | try expect(@typeInfo(@TypeOf(f1)).Pointer.alignment == 16); | ||
| 20 | try expect(@intFromPtr(f1) == @intFromPtr(&f1.a)); | ||
| 21 | try expect(@typeInfo(@TypeOf(&f1.a)).Pointer.alignment == 16); | ||
| 22 | } | ||
test/behavior/bugs/12486.zig deleted-49| ... | @@ -1,49 +0,0 @@ | ||
| 1 | const SomeEnum = union(enum) { | ||
| 2 | EnumVariant: u8, | ||
| 3 | }; | ||
| 4 | |||
| 5 | const SomeStruct = struct { | ||
| 6 | struct_field: u8, | ||
| 7 | }; | ||
| 8 | |||
| 9 | const OptEnum = struct { | ||
| 10 | opt_enum: ?SomeEnum, | ||
| 11 | }; | ||
| 12 | |||
| 13 | const ErrEnum = struct { | ||
| 14 | err_enum: anyerror!SomeEnum, | ||
| 15 | }; | ||
| 16 | |||
| 17 | const OptStruct = struct { | ||
| 18 | opt_struct: ?SomeStruct, | ||
| 19 | }; | ||
| 20 | |||
| 21 | const ErrStruct = struct { | ||
| 22 | err_struct: anyerror!SomeStruct, | ||
| 23 | }; | ||
| 24 | |||
| 25 | test { | ||
| 26 | _ = OptEnum{ | ||
| 27 | .opt_enum = .{ | ||
| 28 | .EnumVariant = 1, | ||
| 29 | }, | ||
| 30 | }; | ||
| 31 | |||
| 32 | _ = ErrEnum{ | ||
| 33 | .err_enum = .{ | ||
| 34 | .EnumVariant = 1, | ||
| 35 | }, | ||
| 36 | }; | ||
| 37 | |||
| 38 | _ = OptStruct{ | ||
| 39 | .opt_struct = .{ | ||
| 40 | .struct_field = 1, | ||
| 41 | }, | ||
| 42 | }; | ||
| 43 | |||
| 44 | _ = ErrStruct{ | ||
| 45 | .err_struct = .{ | ||
| 46 | .struct_field = 1, | ||
| 47 | }, | ||
| 48 | }; | ||
| 49 | } | ||
test/behavior/bugs/12498.zig deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | |||
| 4 | const S = struct { a: usize }; | ||
| 5 | test "lazy abi size used in comparison" { | ||
| 6 | var rhs: i32 = 100; | ||
| 7 | _ = &rhs; | ||
| 8 | try expect(@sizeOf(S) < rhs); | ||
| 9 | } | ||
test/behavior/bugs/12551.zig deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test { | ||
| 5 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 6 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 7 | |||
| 8 | try std.testing.expect(for ([1]u8{0}) |x| { | ||
| 9 | if (x == 0) break true; | ||
| 10 | } else false); | ||
| 11 | } | ||
test/behavior/bugs/12571.zig deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | const Frame = packed struct { | ||
| 6 | num: u20, | ||
| 7 | }; | ||
| 8 | |||
| 9 | const Entry = packed struct { | ||
| 10 | other: u12, | ||
| 11 | frame: Frame, | ||
| 12 | }; | ||
| 13 | |||
| 14 | test { | ||
| 15 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 16 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 17 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 18 | |||
| 19 | const frame = Frame{ .num = 0x7FDE }; | ||
| 20 | var entry = Entry{ .other = 0, .frame = .{ .num = 0xFFFFF } }; | ||
| 21 | entry.frame = frame; | ||
| 22 | try expect(entry.frame.num == 0x7FDE); | ||
| 23 | } | ||
test/behavior/bugs/12644.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | inline fn foo(comptime T: type) !T { | ||
| 5 | return error.AnError; | ||
| 6 | } | ||
| 7 | |||
| 8 | fn main0() !void { | ||
| 9 | _ = try foo(u8); | ||
| 10 | } | ||
| 11 | |||
| 12 | test "issue12644" { | ||
| 13 | main0() catch |e| { | ||
| 14 | try std.testing.expect(e == error.AnError); | ||
| 15 | }; | ||
| 16 | } | ||
test/behavior/bugs/12723.zig deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | const expect = @import("std").testing.expect; | ||
| 2 | |||
| 3 | test "Non-exhaustive enum backed by comptime_int" { | ||
| 4 | const E = enum(comptime_int) { a, b, c, _ }; | ||
| 5 | comptime var e: E = .a; | ||
| 6 | e = @as(E, @enumFromInt(378089457309184723749)); | ||
| 7 | try expect(@intFromEnum(e) == 378089457309184723749); | ||
| 8 | } | ||
test/behavior/bugs/1277.zig deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const S = struct { | ||
| 5 | f: ?*const fn () i32, | ||
| 6 | }; | ||
| 7 | |||
| 8 | const s = S{ .f = &f }; | ||
| 9 | |||
| 10 | fn f() i32 { | ||
| 11 | return 1234; | ||
| 12 | } | ||
| 13 | |||
| 14 | test "don't emit an LLVM global for a const function when it's in an optional in a struct" { | ||
| 15 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 16 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 17 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 18 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 19 | |||
| 20 | try std.testing.expect(s.f.?() == 1234); | ||
| 21 | } | ||
test/behavior/bugs/12776.zig deleted-47| ... | @@ -1,47 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const RAM = struct { | ||
| 5 | data: [0xFFFF + 1]u8, | ||
| 6 | fn new() !RAM { | ||
| 7 | return RAM{ .data = [_]u8{0} ** 0x10000 }; | ||
| 8 | } | ||
| 9 | fn get(self: *RAM, addr: u16) u8 { | ||
| 10 | return self.data[addr]; | ||
| 11 | } | ||
| 12 | }; | ||
| 13 | |||
| 14 | const CPU = packed struct { | ||
| 15 | interrupts: bool, | ||
| 16 | ram: *RAM, | ||
| 17 | fn new(ram: *RAM) !CPU { | ||
| 18 | return CPU{ | ||
| 19 | .ram = ram, | ||
| 20 | .interrupts = false, | ||
| 21 | }; | ||
| 22 | } | ||
| 23 | fn tick(self: *CPU) !void { | ||
| 24 | var queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F); | ||
| 25 | _ = &queued_interrupts; | ||
| 26 | if (self.interrupts and queued_interrupts != 0) { | ||
| 27 | self.interrupts = false; | ||
| 28 | } | ||
| 29 | } | ||
| 30 | }; | ||
| 31 | |||
| 32 | test { | ||
| 33 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 34 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 35 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 36 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; | ||
| 37 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 38 | if (builtin.zig_backend == .stage2_x86_64) { | ||
| 39 | // Careful enabling this test, fails randomly. | ||
| 40 | return error.SkipZigTest; | ||
| 41 | } | ||
| 42 | |||
| 43 | var ram = try RAM.new(); | ||
| 44 | var cpu = try CPU.new(&ram); | ||
| 45 | try cpu.tick(); | ||
| 46 | try std.testing.expect(cpu.interrupts == false); | ||
| 47 | } | ||
test/behavior/bugs/12786.zig deleted-28| ... | @@ -1,28 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | fn NamespacedGlobals(comptime modules: anytype) type { | ||
| 4 | return @Type(.{ | ||
| 5 | .Struct = .{ | ||
| 6 | .layout = .Auto, | ||
| 7 | .is_tuple = false, | ||
| 8 | .fields = &.{ | ||
| 9 | .{ | ||
| 10 | .name = "globals", | ||
| 11 | .type = modules.mach.globals, | ||
| 12 | .default_value = null, | ||
| 13 | .is_comptime = false, | ||
| 14 | .alignment = @alignOf(modules.mach.globals), | ||
| 15 | }, | ||
| 16 | }, | ||
| 17 | .decls = &[_]std.builtin.Type.Declaration{}, | ||
| 18 | }, | ||
| 19 | }); | ||
| 20 | } | ||
| 21 | |||
| 22 | test { | ||
| 23 | _ = NamespacedGlobals(.{ | ||
| 24 | .mach = .{ | ||
| 25 | .globals = struct {}, | ||
| 26 | }, | ||
| 27 | }); | ||
| 28 | } | ||
test/behavior/bugs/12794.zig deleted-38| ... | @@ -1,38 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | fn NamespacedComponents(comptime modules: anytype) type { | ||
| 4 | return @Type(.{ | ||
| 5 | .Struct = .{ | ||
| 6 | .layout = .Auto, | ||
| 7 | .is_tuple = false, | ||
| 8 | .fields = &.{.{ | ||
| 9 | .name = "components", | ||
| 10 | .type = @TypeOf(modules.components), | ||
| 11 | .default_value = null, | ||
| 12 | .is_comptime = false, | ||
| 13 | .alignment = @alignOf(@TypeOf(modules.components)), | ||
| 14 | }}, | ||
| 15 | .decls = &[_]std.builtin.Type.Declaration{}, | ||
| 16 | }, | ||
| 17 | }); | ||
| 18 | } | ||
| 19 | |||
| 20 | fn namespacedComponents(comptime modules: anytype) NamespacedComponents(modules) { | ||
| 21 | var x: NamespacedComponents(modules) = undefined; | ||
| 22 | x.components = modules.components; | ||
| 23 | return x; | ||
| 24 | } | ||
| 25 | |||
| 26 | pub fn World(comptime modules: anytype) type { | ||
| 27 | const all_components = namespacedComponents(modules); | ||
| 28 | _ = all_components; | ||
| 29 | return struct {}; | ||
| 30 | } | ||
| 31 | |||
| 32 | test { | ||
| 33 | _ = World(.{ | ||
| 34 | .components = .{ | ||
| 35 | .location = struct {}, | ||
| 36 | }, | ||
| 37 | }); | ||
| 38 | } | ||
test/behavior/bugs/12801-1.zig deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | comptime capacity: fn () u64 = capacity_, | ||
| 5 | fn capacity_() u64 { | ||
| 6 | return 64; | ||
| 7 | } | ||
| 8 | |||
| 9 | test { | ||
| 10 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 11 | |||
| 12 | try std.testing.expect((@This(){}).capacity() == 64); | ||
| 13 | } | ||
test/behavior/bugs/12801-2.zig deleted-25| ... | @@ -1,25 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const Auto = struct { | ||
| 5 | auto: [max_len]u8 = undefined, | ||
| 6 | offset: u64 = 0, | ||
| 7 | |||
| 8 | comptime capacity: *const fn () u64 = capacity, | ||
| 9 | |||
| 10 | const max_len: u64 = 32; | ||
| 11 | |||
| 12 | fn capacity() u64 { | ||
| 13 | return max_len; | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | test { | ||
| 17 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 18 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 19 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 20 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 21 | |||
| 22 | const a: Auto = .{ .offset = 16, .capacity = Auto.capacity }; | ||
| 23 | try std.testing.expect(a.capacity() == 32); | ||
| 24 | try std.testing.expect((a.capacity)() == 32); | ||
| 25 | } | ||
test/behavior/bugs/12885.zig deleted-34| ... | @@ -1,34 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = std.builtin; | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | const info = .{ | ||
| 6 | .args = [_]builtin.Type.Error{ | ||
| 7 | .{ .name = "bar" }, | ||
| 8 | }, | ||
| 9 | }; | ||
| 10 | const Foo = @Type(.{ | ||
| 11 | .ErrorSet = &info.args, | ||
| 12 | }); | ||
| 13 | test "ErrorSet comptime_field_ptr" { | ||
| 14 | try expect(Foo == error{bar}); | ||
| 15 | } | ||
| 16 | |||
| 17 | const fn_info = .{ | ||
| 18 | .params = [_]builtin.Type.Fn.Param{ | ||
| 19 | .{ .is_generic = false, .is_noalias = false, .type = u8 }, | ||
| 20 | }, | ||
| 21 | }; | ||
| 22 | const Bar = @Type(.{ | ||
| 23 | .Fn = .{ | ||
| 24 | .calling_convention = .Unspecified, | ||
| 25 | .alignment = 0, | ||
| 26 | .is_generic = false, | ||
| 27 | .is_var_args = false, | ||
| 28 | .return_type = void, | ||
| 29 | .params = &fn_info.params, | ||
| 30 | }, | ||
| 31 | }); | ||
| 32 | test "fn comptime_field_ptr" { | ||
| 33 | try expect(@typeInfo(Bar) == .Fn); | ||
| 34 | } | ||
test/behavior/bugs/12890.zig deleted-18| ... | @@ -1,18 +0,0 @@ | ||
| 1 | const expect = @import("std").testing.expect; | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | fn a(b: []u3, c: u3) void { | ||
| 5 | switch (c) { | ||
| 6 | 0...1 => b[c] = c, | ||
| 7 | 2...3 => b[c] = c, | ||
| 8 | 4...7 => |d| b[d] = c, | ||
| 9 | } | ||
| 10 | } | ||
| 11 | test { | ||
| 12 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 13 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 14 | |||
| 15 | var arr: [8]u3 = undefined; | ||
| 16 | a(&arr, 5); | ||
| 17 | try expect(arr[5] == 5); | ||
| 18 | } | ||
test/behavior/bugs/12891.zig deleted-83| ... | @@ -1,83 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test "issue12891" { | ||
| 5 | const f = 10.0; | ||
| 6 | var i: usize = 0; | ||
| 7 | _ = &i; | ||
| 8 | try std.testing.expect(i < f); | ||
| 9 | } | ||
| 10 | test "nan" { | ||
| 11 | const f = comptime std.math.nan(f64); | ||
| 12 | var i: usize = 0; | ||
| 13 | _ = &i; | ||
| 14 | try std.testing.expect(!(f < i)); | ||
| 15 | } | ||
| 16 | test "inf" { | ||
| 17 | const f = comptime std.math.inf(f64); | ||
| 18 | var i: usize = 0; | ||
| 19 | _ = &i; | ||
| 20 | try std.testing.expect(f > i); | ||
| 21 | } | ||
| 22 | test "-inf < 0" { | ||
| 23 | const f = comptime -std.math.inf(f64); | ||
| 24 | var i: usize = 0; | ||
| 25 | _ = &i; | ||
| 26 | try std.testing.expect(f < i); | ||
| 27 | } | ||
| 28 | test "inf >= 1" { | ||
| 29 | const f = comptime std.math.inf(f64); | ||
| 30 | var i: usize = 1; | ||
| 31 | _ = &i; | ||
| 32 | try std.testing.expect(f >= i); | ||
| 33 | } | ||
| 34 | test "isNan(nan * 1)" { | ||
| 35 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 36 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 37 | |||
| 38 | const nan_times_one = comptime std.math.nan(f64) * 1; | ||
| 39 | try std.testing.expect(std.math.isNan(nan_times_one)); | ||
| 40 | } | ||
| 41 | test "runtime isNan(nan * 1)" { | ||
| 42 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 43 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 44 | |||
| 45 | const nan_times_one = std.math.nan(f64) * 1; | ||
| 46 | try std.testing.expect(std.math.isNan(nan_times_one)); | ||
| 47 | } | ||
| 48 | test "isNan(nan * 0)" { | ||
| 49 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 50 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 51 | |||
| 52 | const nan_times_zero = comptime std.math.nan(f64) * 0; | ||
| 53 | try std.testing.expect(std.math.isNan(nan_times_zero)); | ||
| 54 | const zero_times_nan = 0 * comptime std.math.nan(f64); | ||
| 55 | try std.testing.expect(std.math.isNan(zero_times_nan)); | ||
| 56 | } | ||
| 57 | test "isNan(inf * 0)" { | ||
| 58 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 59 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 60 | |||
| 61 | const inf_times_zero = comptime std.math.inf(f64) * 0; | ||
| 62 | try std.testing.expect(std.math.isNan(inf_times_zero)); | ||
| 63 | const zero_times_inf = 0 * comptime std.math.inf(f64); | ||
| 64 | try std.testing.expect(std.math.isNan(zero_times_inf)); | ||
| 65 | } | ||
| 66 | test "runtime isNan(nan * 0)" { | ||
| 67 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 68 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 69 | |||
| 70 | const nan_times_zero = std.math.nan(f64) * 0; | ||
| 71 | try std.testing.expect(std.math.isNan(nan_times_zero)); | ||
| 72 | const zero_times_nan = 0 * std.math.nan(f64); | ||
| 73 | try std.testing.expect(std.math.isNan(zero_times_nan)); | ||
| 74 | } | ||
| 75 | test "runtime isNan(inf * 0)" { | ||
| 76 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 77 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 78 | |||
| 79 | const inf_times_zero = std.math.inf(f64) * 0; | ||
| 80 | try std.testing.expect(std.math.isNan(inf_times_zero)); | ||
| 81 | const zero_times_inf = 0 * std.math.inf(f64); | ||
| 82 | try std.testing.expect(std.math.isNan(zero_times_inf)); | ||
| 83 | } | ||
test/behavior/bugs/12911.zig deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | const Item = struct { field: u8 }; | ||
| 4 | const Thing = struct { | ||
| 5 | array: [1]Item, | ||
| 6 | }; | ||
| 7 | test { | ||
| 8 | _ = Thing{ .array = undefined }; | ||
| 9 | } | ||
test/behavior/bugs/12928.zig deleted-30| ... | @@ -1,30 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | const A = extern struct { | ||
| 6 | value: *volatile B, | ||
| 7 | }; | ||
| 8 | const B = extern struct { | ||
| 9 | a: u32, | ||
| 10 | b: i32, | ||
| 11 | }; | ||
| 12 | |||
| 13 | test { | ||
| 14 | var a: *A = undefined; | ||
| 15 | try expect(@TypeOf(&a.value.a) == *volatile u32); | ||
| 16 | try expect(@TypeOf(&a.value.b) == *volatile i32); | ||
| 17 | } | ||
| 18 | |||
| 19 | const C = extern struct { | ||
| 20 | value: *volatile D, | ||
| 21 | }; | ||
| 22 | const D = extern union { | ||
| 23 | a: u32, | ||
| 24 | b: i32, | ||
| 25 | }; | ||
| 26 | test { | ||
| 27 | var c: *C = undefined; | ||
| 28 | try expect(@TypeOf(&c.value.a) == *volatile u32); | ||
| 29 | try expect(@TypeOf(&c.value.b) == *volatile i32); | ||
| 30 | } | ||
test/behavior/bugs/12945.zig deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | |||
| 4 | fn A( | ||
| 5 | comptime T: type, | ||
| 6 | comptime destroycb: ?*const fn (?*T) callconv(.C) void, | ||
| 7 | ) !void { | ||
| 8 | try expect(destroycb == null); | ||
| 9 | } | ||
| 10 | |||
| 11 | test { | ||
| 12 | try A(u32, null); | ||
| 13 | } | ||
test/behavior/bugs/12972.zig deleted-18| ... | @@ -1,18 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | pub fn f(_: [:null]const ?u8) void {} | ||
| 4 | |||
| 5 | test { | ||
| 6 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 9 | |||
| 10 | const c: u8 = 42; | ||
| 11 | f(&[_:null]?u8{c}); | ||
| 12 | f(&.{c}); | ||
| 13 | |||
| 14 | var v: u8 = 42; | ||
| 15 | _ = &v; | ||
| 16 | f(&[_:null]?u8{v}); | ||
| 17 | f(&.{v}); | ||
| 18 | } | ||
test/behavior/bugs/12984.zig deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | pub fn DeleagateWithContext(comptime Function: type) type { | ||
| 5 | const ArgArgs = std.meta.ArgsTuple(Function); | ||
| 6 | return struct { | ||
| 7 | t: ArgArgs, | ||
| 8 | }; | ||
| 9 | } | ||
| 10 | |||
| 11 | pub const OnConfirm = DeleagateWithContext(fn (bool) void); | ||
| 12 | pub const CustomDraw = DeleagateWithContext(fn (?OnConfirm) void); | ||
| 13 | |||
| 14 | test "simple test" { | ||
| 15 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 16 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 17 | |||
| 18 | var c: CustomDraw = undefined; | ||
| 19 | _ = &c; | ||
| 20 | } | ||
test/behavior/bugs/13064.zig deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | test { | ||
| 6 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 9 | |||
| 10 | var x: [10][10]u32 = undefined; | ||
| 11 | |||
| 12 | x[0][1] = 0; | ||
| 13 | const a = x[0]; | ||
| 14 | x[0][1] = 15; | ||
| 15 | |||
| 16 | try expect(a[1] == 0); | ||
| 17 | } | ||
test/behavior/bugs/13065.zig deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | const U = union(enum) { | ||
| 6 | array: [10]u32, | ||
| 7 | other: u32, | ||
| 8 | }; | ||
| 9 | |||
| 10 | test { | ||
| 11 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 12 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 13 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 14 | |||
| 15 | var x = U{ .array = undefined }; | ||
| 16 | |||
| 17 | x.array[1] = 0; | ||
| 18 | const a = x.array; | ||
| 19 | x.array[1] = 15; | ||
| 20 | |||
| 21 | try expect(a[1] == 0); | ||
| 22 | } | ||
test/behavior/bugs/13068.zig deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | pub const allocator = std.heap.page_allocator; | ||
| 5 | var list = std.ArrayList(u32).init(allocator); | ||
| 6 | |||
| 7 | test { | ||
| 8 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 9 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 10 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 11 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 12 | |||
| 13 | list.items.len = 0; | ||
| 14 | } | ||
test/behavior/bugs/13069.zig deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | test { | ||
| 6 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 9 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 10 | |||
| 11 | var opt_x: ?[3]f32 = [_]f32{0.0} ** 3; | ||
| 12 | |||
| 13 | const x = opt_x.?; | ||
| 14 | opt_x.?[0] = 15.0; | ||
| 15 | |||
| 16 | try expect(x[0] == 0.0); | ||
| 17 | } | ||
test/behavior/bugs/1310.zig deleted-27| ... | @@ -1,27 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | const builtin = @import("builtin"); | ||
| 4 | |||
| 5 | pub const VM = ?[*]const struct_InvocationTable_; | ||
| 6 | pub const struct_InvocationTable_ = extern struct { | ||
| 7 | GetVM: ?*const fn (?[*]VM) callconv(.C) c_int, | ||
| 8 | }; | ||
| 9 | |||
| 10 | pub const struct_VM_ = extern struct { | ||
| 11 | functions: ?[*]const struct_InvocationTable_, | ||
| 12 | }; | ||
| 13 | |||
| 14 | //excised output from stdlib.h etc | ||
| 15 | |||
| 16 | pub const InvocationTable_ = struct_InvocationTable_; | ||
| 17 | pub const VM_ = struct_VM_; | ||
| 18 | |||
| 19 | fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 { | ||
| 20 | _ = _vm; | ||
| 21 | _ = options; | ||
| 22 | return 11; | ||
| 23 | } | ||
| 24 | |||
| 25 | test { | ||
| 26 | try expect(agent_callback(undefined, undefined) == 11); | ||
| 27 | } | ||
test/behavior/bugs/13112.zig deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | fn nice(a: u32, b: u32) bool { | ||
| 2 | return a == 5 or b == 2 or @panic("oh no"); | ||
| 3 | } | ||
| 4 | |||
| 5 | test { | ||
| 6 | _ = nice(2, 2); | ||
| 7 | } | ||
test/behavior/bugs/13113.zig deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const Foo = extern struct { | ||
| 5 | a: u8 align(1), | ||
| 6 | b: u16 align(1), | ||
| 7 | }; | ||
| 8 | |||
| 9 | test { | ||
| 10 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 11 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 12 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 13 | |||
| 14 | const foo = Foo{ | ||
| 15 | .a = 1, | ||
| 16 | .b = 2, | ||
| 17 | }; | ||
| 18 | try std.testing.expectEqual(1, foo.a); | ||
| 19 | try std.testing.expectEqual(2, foo.b); | ||
| 20 | } | ||
test/behavior/bugs/13128.zig deleted-29| ... | @@ -1,29 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | const U = union(enum) { | ||
| 6 | x: u128, | ||
| 7 | y: [17]u8, | ||
| 8 | }; | ||
| 9 | |||
| 10 | fn foo(val: U) !void { | ||
| 11 | try expect(val.x == 1); | ||
| 12 | } | ||
| 13 | |||
| 14 | test "runtime union init, most-aligned field != largest" { | ||
| 15 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 16 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 17 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 18 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 19 | |||
| 20 | var x: u8 = 1; | ||
| 21 | _ = &x; | ||
| 22 | try foo(.{ .x = x }); | ||
| 23 | |||
| 24 | const val: U = @unionInit(U, "x", x); | ||
| 25 | try expect(val.x == 1); | ||
| 26 | |||
| 27 | const val2: U = .{ .x = x }; | ||
| 28 | try expect(val2.x == 1); | ||
| 29 | } | ||
test/behavior/bugs/13159.zig deleted-18| ... | @@ -1,18 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | const Bar = packed struct { | ||
| 6 | const Baz = enum { | ||
| 7 | fizz, | ||
| 8 | buzz, | ||
| 9 | }; | ||
| 10 | }; | ||
| 11 | |||
| 12 | test { | ||
| 13 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 14 | |||
| 15 | var foo = Bar.Baz.fizz; | ||
| 16 | _ = &foo; | ||
| 17 | try expect(foo == .fizz); | ||
| 18 | } | ||
test/behavior/bugs/13171.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | |||
| 4 | fn BuildType(comptime T: type) type { | ||
| 5 | return struct { | ||
| 6 | val: union { | ||
| 7 | b: T, | ||
| 8 | }, | ||
| 9 | }; | ||
| 10 | } | ||
| 11 | |||
| 12 | test { | ||
| 13 | const TestStruct = BuildType(u32); | ||
| 14 | const c = TestStruct{ .val = .{ .b = 10 } }; | ||
| 15 | try expect(c.val.b == 10); | ||
| 16 | } | ||
test/behavior/bugs/13209.zig deleted-5| ... | @@ -1,5 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | test { | ||
| 3 | try std.testing.expect(-1 == @as(i8, -3) >> 2); | ||
| 4 | try std.testing.expect(-1 == -3 >> 2000); | ||
| 5 | } | ||
test/behavior/bugs/13285.zig deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | const Crasher = struct { | ||
| 4 | lets_crash: u64 = 0, | ||
| 5 | }; | ||
| 6 | |||
| 7 | test { | ||
| 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 9 | |||
| 10 | var a: Crasher = undefined; | ||
| 11 | const crasher_ptr = &a; | ||
| 12 | var crasher_local = crasher_ptr.*; | ||
| 13 | const crasher_local_ptr = &crasher_local; | ||
| 14 | crasher_local_ptr.lets_crash = 1; | ||
| 15 | } | ||
test/behavior/bugs/13366.zig deleted-28| ... | @@ -1,28 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | const ComptimeReason = union(enum) { | ||
| 6 | c_import: struct { | ||
| 7 | a: u32, | ||
| 8 | }, | ||
| 9 | }; | ||
| 10 | |||
| 11 | const Block = struct { | ||
| 12 | reason: ?*const ComptimeReason, | ||
| 13 | }; | ||
| 14 | |||
| 15 | test { | ||
| 16 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 17 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 18 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 19 | |||
| 20 | var a: u32 = 16; | ||
| 21 | _ = &a; | ||
| 22 | var reason = .{ .c_import = .{ .a = a } }; | ||
| 23 | var block = Block{ | ||
| 24 | .reason = &reason, | ||
| 25 | }; | ||
| 26 | _ = &block; | ||
| 27 | try expect(block.reason.?.c_import.a == 16); | ||
| 28 | } | ||
test/behavior/bugs/13435.zig deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | fn CreateUnion(comptime T: type) type { | ||
| 4 | return @Type(.{ | ||
| 5 | .Union = .{ | ||
| 6 | .layout = .Auto, | ||
| 7 | .tag_type = null, | ||
| 8 | .fields = &[_]std.builtin.Type.UnionField{ | ||
| 9 | .{ | ||
| 10 | .name = "field", | ||
| 11 | .type = T, | ||
| 12 | .alignment = @alignOf(T), | ||
| 13 | }, | ||
| 14 | }, | ||
| 15 | .decls = &[_]std.builtin.Type.Declaration{}, | ||
| 16 | }, | ||
| 17 | }); | ||
| 18 | } | ||
| 19 | |||
| 20 | test { | ||
| 21 | _ = CreateUnion(struct {}); | ||
| 22 | } | ||
test/behavior/bugs/13664.zig deleted-28| ... | @@ -1,28 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const Fields = packed struct { | ||
| 5 | timestamp: u50, | ||
| 6 | random_bits: u13, | ||
| 7 | }; | ||
| 8 | const ID = packed union { | ||
| 9 | value: u63, | ||
| 10 | fields: Fields, | ||
| 11 | }; | ||
| 12 | fn value() i64 { | ||
| 13 | return 1341; | ||
| 14 | } | ||
| 15 | test { | ||
| 16 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 17 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 18 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 19 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 20 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | ||
| 21 | |||
| 22 | const timestamp: i64 = value(); | ||
| 23 | const id = ID{ .fields = Fields{ | ||
| 24 | .timestamp = @as(u50, @intCast(timestamp)), | ||
| 25 | .random_bits = 420, | ||
| 26 | } }; | ||
| 27 | try std.testing.expect((ID{ .value = id.value }).fields.timestamp == timestamp); | ||
| 28 | } | ||
test/behavior/bugs/13714.zig deleted-5| ... | @@ -1,5 +0,0 @@ | ||
| 1 | comptime { | ||
| 2 | var image: [1]u8 = undefined; | ||
| 3 | _ = &image; | ||
| 4 | _ = @shlExact(@as(u16, image[0]), 8); | ||
| 5 | } | ||
test/behavior/bugs/13785.zig deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | |||
| 4 | const S = packed struct { a: u0 = 0 }; | ||
| 5 | test { | ||
| 6 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 9 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 10 | |||
| 11 | var a: u8 = 0; | ||
| 12 | _ = &a; | ||
| 13 | try std.io.null_writer.print("\n{} {}\n", .{ a, S{} }); | ||
| 14 | } | ||
test/behavior/bugs/1381.zig deleted-27| ... | @@ -1,27 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const B = union(enum) { | ||
| 5 | D: u8, | ||
| 6 | E: u16, | ||
| 7 | }; | ||
| 8 | |||
| 9 | const A = union(enum) { | ||
| 10 | B: B, | ||
| 11 | C: u8, | ||
| 12 | }; | ||
| 13 | |||
| 14 | test "union that needs padding bytes inside an array" { | ||
| 15 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 16 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 17 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 18 | |||
| 19 | var as = [_]A{ | ||
| 20 | A{ .B = B{ .D = 1 } }, | ||
| 21 | A{ .B = B{ .D = 1 } }, | ||
| 22 | }; | ||
| 23 | _ = &as; | ||
| 24 | |||
| 25 | const a = as[0].B; | ||
| 26 | try std.testing.expect(a.D == 1); | ||
| 27 | } | ||
test/behavior/bugs/1421.zig deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | const builtin = @import("builtin"); | ||
| 4 | |||
| 5 | const S = struct { | ||
| 6 | fn method() std.builtin.Type { | ||
| 7 | return @typeInfo(S); | ||
| 8 | } | ||
| 9 | }; | ||
| 10 | |||
| 11 | test "functions with return type required to be comptime are generic" { | ||
| 12 | const ti = S.method(); | ||
| 13 | try expect(@as(std.builtin.TypeId, ti) == std.builtin.TypeId.Struct); | ||
| 14 | } | ||
test/behavior/bugs/1442.zig deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const Union = union(enum) { | ||
| 5 | Text: []const u8, | ||
| 6 | Color: u32, | ||
| 7 | }; | ||
| 8 | |||
| 9 | test "const error union field alignment" { | ||
| 10 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 11 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 12 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 13 | |||
| 14 | var union_or_err: anyerror!Union = Union{ .Color = 1234 }; | ||
| 15 | _ = &union_or_err; | ||
| 16 | try std.testing.expect((union_or_err catch unreachable).Color == 1234); | ||
| 17 | } | ||
test/behavior/bugs/1467.zig deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | pub const E = enum(u32) { A, B, C }; | ||
| 2 | pub const S = extern struct { | ||
| 3 | e: E, | ||
| 4 | }; | ||
| 5 | test "bug 1467" { | ||
| 6 | const s: S = undefined; | ||
| 7 | _ = s; | ||
| 8 | } | ||
test/behavior/bugs/14854.zig deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | const testing = @import("std").testing; | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test { | ||
| 5 | try testing.expect(getGeneric(u8, getU8) == 123); | ||
| 6 | } | ||
| 7 | |||
| 8 | fn getU8() callconv(.C) u8 { | ||
| 9 | return 123; | ||
| 10 | } | ||
| 11 | |||
| 12 | fn getGeneric(comptime T: type, supplier: fn () callconv(.C) T) T { | ||
| 13 | return supplier(); | ||
| 14 | } | ||
test/behavior/bugs/1486.zig deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | const builtin = @import("builtin"); | ||
| 4 | |||
| 5 | const ptr = &global; | ||
| 6 | var global: usize = 123; | ||
| 7 | |||
| 8 | test "constant pointer to global variable causes runtime load" { | ||
| 9 | if (builtin.zig_backend == .stage2_aarch64 and builtin.os.tag == .macos) return error.SkipZigTest; | ||
| 10 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 11 | global = 1234; | ||
| 12 | try expect(&global == ptr); | ||
| 13 | try expect(ptr.* == 1234); | ||
| 14 | } | ||
test/behavior/bugs/1500.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const A = struct { | ||
| 3 | b: B, | ||
| 4 | }; | ||
| 5 | |||
| 6 | const B = *const fn (A) void; | ||
| 7 | |||
| 8 | test "allow these dependencies" { | ||
| 9 | var a: A = undefined; | ||
| 10 | var b: B = undefined; | ||
| 11 | _ = .{ &a, &b }; | ||
| 12 | if (false) { | ||
| 13 | a; | ||
| 14 | b; | ||
| 15 | } | ||
| 16 | } | ||
test/behavior/bugs/15778.zig deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | test { | ||
| 4 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 5 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 6 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 9 | const a = @Vector(0, i32){}; | ||
| 10 | const b = @Vector(0, i32){}; | ||
| 11 | _ = a + b; | ||
| 12 | } | ||
| 13 | |||
| 14 | test { | ||
| 15 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 16 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 17 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 18 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO | ||
| 19 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 20 | const a = @Vector(0, f32){}; | ||
| 21 | const b = @Vector(0, f32){}; | ||
| 22 | _ = a - b; | ||
| 23 | } | ||
test/behavior/bugs/1607.zig deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const testing = std.testing; | ||
| 3 | const builtin = @import("builtin"); | ||
| 4 | |||
| 5 | const a = [_]u8{ 1, 2, 3 }; | ||
| 6 | |||
| 7 | fn checkAddress(s: []const u8) !void { | ||
| 8 | for (s, 0..) |*i, j| { | ||
| 9 | try testing.expect(i == &a[j]); | ||
| 10 | } | ||
| 11 | } | ||
| 12 | |||
| 13 | test "slices pointing at the same address as global array." { | ||
| 14 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 15 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 16 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 17 | |||
| 18 | try checkAddress(&a); | ||
| 19 | try comptime checkAddress(&a); | ||
| 20 | } | ||
test/behavior/bugs/1735.zig deleted-50| ... | @@ -1,50 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const mystruct = struct { | ||
| 5 | pending: ?listofstructs, | ||
| 6 | }; | ||
| 7 | pub fn DoublyLinkedList(comptime T: type) type { | ||
| 8 | return struct { | ||
| 9 | const Self = @This(); | ||
| 10 | |||
| 11 | pub const Node = struct { | ||
| 12 | prev: ?*Node, | ||
| 13 | next: ?*Node, | ||
| 14 | data: T, | ||
| 15 | }; | ||
| 16 | |||
| 17 | first: ?*Node, | ||
| 18 | last: ?*Node, | ||
| 19 | len: usize, | ||
| 20 | |||
| 21 | pub fn init() Self { | ||
| 22 | return Self{ | ||
| 23 | .first = null, | ||
| 24 | .last = null, | ||
| 25 | .len = 0, | ||
| 26 | }; | ||
| 27 | } | ||
| 28 | }; | ||
| 29 | } | ||
| 30 | const listofstructs = DoublyLinkedList(mystruct); | ||
| 31 | |||
| 32 | const a = struct { | ||
| 33 | const Self = @This(); | ||
| 34 | |||
| 35 | foo: listofstructs, | ||
| 36 | |||
| 37 | pub fn init() Self { | ||
| 38 | return Self{ | ||
| 39 | .foo = listofstructs.init(), | ||
| 40 | }; | ||
| 41 | } | ||
| 42 | }; | ||
| 43 | |||
| 44 | test "initialization" { | ||
| 45 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 46 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 47 | |||
| 48 | const t = a.init(); | ||
| 49 | try std.testing.expect(t.foo.len == 0); | ||
| 50 | } | ||
test/behavior/bugs/1851.zig deleted-40| ... | @@ -1,40 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | test "allocation and looping over 3-byte integer" { | ||
| 6 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 9 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 10 | |||
| 11 | if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .macos) { | ||
| 12 | return error.SkipZigTest; // TODO | ||
| 13 | } | ||
| 14 | |||
| 15 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .wasm32) { | ||
| 16 | return error.SkipZigTest; // TODO | ||
| 17 | } | ||
| 18 | |||
| 19 | try expect(@sizeOf(u24) == 4); | ||
| 20 | try expect(@sizeOf([1]u24) == 4); | ||
| 21 | try expect(@alignOf(u24) == 4); | ||
| 22 | try expect(@alignOf([1]u24) == 4); | ||
| 23 | |||
| 24 | var x = try std.testing.allocator.alloc(u24, 2); | ||
| 25 | defer std.testing.allocator.free(x); | ||
| 26 | try expect(x.len == 2); | ||
| 27 | x[0] = 0xFFFFFF; | ||
| 28 | x[1] = 0xFFFFFF; | ||
| 29 | |||
| 30 | const bytes = std.mem.sliceAsBytes(x); | ||
| 31 | try expect(@TypeOf(bytes) == []align(4) u8); | ||
| 32 | try expect(bytes.len == 8); | ||
| 33 | |||
| 34 | for (bytes) |*b| { | ||
| 35 | b.* = 0x00; | ||
| 36 | } | ||
| 37 | |||
| 38 | try expect(x[0] == 0x00); | ||
| 39 | try expect(x[1] == 0x00); | ||
| 40 | } | ||
test/behavior/bugs/1914.zig deleted-32| ... | @@ -1,32 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const A = struct { | ||
| 5 | b_list_pointer: *const []B, | ||
| 6 | }; | ||
| 7 | const B = struct { | ||
| 8 | a_pointer: *const A, | ||
| 9 | }; | ||
| 10 | |||
| 11 | const b_list: []B = &[_]B{}; | ||
| 12 | const a = A{ .b_list_pointer = &b_list }; | ||
| 13 | |||
| 14 | test "segfault bug" { | ||
| 15 | const assert = std.debug.assert; | ||
| 16 | const obj = B{ .a_pointer = &a }; | ||
| 17 | assert(obj.a_pointer == &a); // this makes zig crash | ||
| 18 | } | ||
| 19 | |||
| 20 | const A2 = struct { | ||
| 21 | pointer: *B, | ||
| 22 | }; | ||
| 23 | |||
| 24 | pub const B2 = struct { | ||
| 25 | pointer_array: []*A2, | ||
| 26 | }; | ||
| 27 | |||
| 28 | var b_value = B2{ .pointer_array = &[_]*A2{} }; | ||
| 29 | |||
| 30 | test "basic stuff" { | ||
| 31 | std.debug.assert(&b_value == &b_value); | ||
| 32 | } | ||
test/behavior/bugs/2006.zig deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | const builtin = @import("builtin"); | ||
| 4 | |||
| 5 | const S = struct { | ||
| 6 | p: *S, | ||
| 7 | }; | ||
| 8 | test "bug 2006" { | ||
| 9 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 10 | |||
| 11 | var a: S = undefined; | ||
| 12 | a = S{ .p = undefined }; | ||
| 13 | try expect(@sizeOf(S) != 0); | ||
| 14 | try expect(@sizeOf(*void) == @sizeOf(*i32)); | ||
| 15 | } | ||
test/behavior/bugs/2114.zig deleted-27| ... | @@ -1,27 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | const math = std.math; | ||
| 5 | |||
| 6 | fn ctz(x: anytype) usize { | ||
| 7 | return @ctz(x); | ||
| 8 | } | ||
| 9 | |||
| 10 | test "fixed" { | ||
| 11 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 12 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | ||
| 13 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 14 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 15 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 16 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 17 | |||
| 18 | try testCtz(); | ||
| 19 | try comptime testCtz(); | ||
| 20 | } | ||
| 21 | |||
| 22 | fn testCtz() !void { | ||
| 23 | try expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126); | ||
| 24 | try expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000)); | ||
| 25 | try expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127); | ||
| 26 | try expect(ctz(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127); | ||
| 27 | } | ||
test/behavior/bugs/2346.zig deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | test "fixed" { | ||
| 4 | const a: *void = undefined; | ||
| 5 | const b: *[1]void = a; | ||
| 6 | _ = b; | ||
| 7 | const c: *[0]u8 = undefined; | ||
| 8 | const d: []u8 = c; | ||
| 9 | _ = d; | ||
| 10 | } | ||
test/behavior/bugs/2557.zig deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | test { | ||
| 2 | var a = if (true) { | ||
| 3 | return; | ||
| 4 | } else true; | ||
| 5 | _ = &a; | ||
| 6 | } | ||
test/behavior/bugs/2578.zig deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | const Foo = struct { | ||
| 4 | y: u8, | ||
| 5 | }; | ||
| 6 | |||
| 7 | var foo: Foo = undefined; | ||
| 8 | const t = &foo; | ||
| 9 | |||
| 10 | fn bar(pointer: ?*anyopaque) void { | ||
| 11 | _ = pointer; | ||
| 12 | } | ||
| 13 | |||
| 14 | test "fixed" { | ||
| 15 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 16 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 17 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 18 | |||
| 19 | bar(t); | ||
| 20 | } | ||
test/behavior/bugs/2622.zig deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | var buf: []u8 = undefined; | ||
| 4 | |||
| 5 | test "reslice of undefined global var slice" { | ||
| 6 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 9 | |||
| 10 | var mem: [100]u8 = [_]u8{0} ** 100; | ||
| 11 | buf = &mem; | ||
| 12 | const x = buf[0..1]; | ||
| 13 | try @import("std").testing.expect(x.len == 1 and x[0] == 0); | ||
| 14 | } | ||
test/behavior/bugs/2692.zig deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | fn foo(a: []u8) void { | ||
| 4 | _ = a; | ||
| 5 | } | ||
| 6 | |||
| 7 | test "address of 0 length array" { | ||
| 8 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 9 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 10 | |||
| 11 | var pt: [0]u8 = undefined; | ||
| 12 | foo(&pt); | ||
| 13 | } | ||
test/behavior/bugs/2727.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | fn t() bool { | ||
| 4 | return true; | ||
| 5 | } | ||
| 6 | |||
| 7 | test { | ||
| 8 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 9 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 10 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 11 | |||
| 12 | comptime var i: usize = 0; | ||
| 13 | inline while (i < 2) : (i += 1) { | ||
| 14 | if (t()) {} else return; | ||
| 15 | } | ||
| 16 | } | ||
test/behavior/bugs/2889.zig deleted-36| ... | @@ -1,36 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const source = "A-"; | ||
| 5 | |||
| 6 | fn parseNote() ?i32 { | ||
| 7 | const letter = source[0]; | ||
| 8 | const modifier = source[1]; | ||
| 9 | |||
| 10 | const semitone = blk: { | ||
| 11 | if (letter == 'C' and modifier == '-') break :blk @as(i32, 0); | ||
| 12 | if (letter == 'C' and modifier == '#') break :blk @as(i32, 1); | ||
| 13 | if (letter == 'D' and modifier == '-') break :blk @as(i32, 2); | ||
| 14 | if (letter == 'D' and modifier == '#') break :blk @as(i32, 3); | ||
| 15 | if (letter == 'E' and modifier == '-') break :blk @as(i32, 4); | ||
| 16 | if (letter == 'F' and modifier == '-') break :blk @as(i32, 5); | ||
| 17 | if (letter == 'F' and modifier == '#') break :blk @as(i32, 6); | ||
| 18 | if (letter == 'G' and modifier == '-') break :blk @as(i32, 7); | ||
| 19 | if (letter == 'G' and modifier == '#') break :blk @as(i32, 8); | ||
| 20 | if (letter == 'A' and modifier == '-') break :blk @as(i32, 9); | ||
| 21 | if (letter == 'A' and modifier == '#') break :blk @as(i32, 10); | ||
| 22 | if (letter == 'B' and modifier == '-') break :blk @as(i32, 11); | ||
| 23 | return null; | ||
| 24 | }; | ||
| 25 | |||
| 26 | return semitone; | ||
| 27 | } | ||
| 28 | |||
| 29 | test "fixed" { | ||
| 30 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 31 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 32 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 33 | |||
| 34 | const result = parseNote(); | ||
| 35 | try std.testing.expect(result.? == 9); | ||
| 36 | } | ||
test/behavior/bugs/3007.zig deleted-28| ... | @@ -1,28 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const Foo = struct { | ||
| 5 | free: bool, | ||
| 6 | |||
| 7 | pub const FooError = error{NotFree}; | ||
| 8 | }; | ||
| 9 | |||
| 10 | var foo = Foo{ .free = true }; | ||
| 11 | var default_foo: ?*Foo = null; | ||
| 12 | |||
| 13 | fn get_foo() Foo.FooError!*Foo { | ||
| 14 | if (foo.free) { | ||
| 15 | foo.free = false; | ||
| 16 | return &foo; | ||
| 17 | } | ||
| 18 | return error.NotFree; | ||
| 19 | } | ||
| 20 | |||
| 21 | test "fixed" { | ||
| 22 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 23 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 24 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 25 | |||
| 26 | default_foo = get_foo() catch null; // This Line | ||
| 27 | try std.testing.expect(!default_foo.?.free); | ||
| 28 | } | ||
test/behavior/bugs/3046.zig deleted-24| ... | @@ -1,24 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | const SomeStruct = struct { | ||
| 6 | field: i32, | ||
| 7 | }; | ||
| 8 | |||
| 9 | fn couldFail() anyerror!i32 { | ||
| 10 | return 1; | ||
| 11 | } | ||
| 12 | |||
| 13 | var some_struct: SomeStruct = undefined; | ||
| 14 | |||
| 15 | test "fixed" { | ||
| 16 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 17 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 18 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 19 | |||
| 20 | some_struct = SomeStruct{ | ||
| 21 | .field = couldFail() catch @as(i32, 0), | ||
| 22 | }; | ||
| 23 | try expect(some_struct.field == 1); | ||
| 24 | } | ||
test/behavior/bugs/3112.zig deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | const State = struct { | ||
| 6 | const Self = @This(); | ||
| 7 | enter: *const fn (previous: ?Self) void, | ||
| 8 | }; | ||
| 9 | |||
| 10 | fn prev(p: ?State) void { | ||
| 11 | expect(p == null) catch @panic("test failure"); | ||
| 12 | } | ||
| 13 | |||
| 14 | test "zig test crash" { | ||
| 15 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 16 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 17 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 18 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 19 | |||
| 20 | var global: State = undefined; | ||
| 21 | global.enter = prev; | ||
| 22 | global.enter(null); | ||
| 23 | } | ||
test/behavior/bugs/3367.zig deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const Foo = struct { | ||
| 3 | usingnamespace Mixin; | ||
| 4 | }; | ||
| 5 | |||
| 6 | const Mixin = struct { | ||
| 7 | pub fn two(self: Foo) void { | ||
| 8 | _ = self; | ||
| 9 | } | ||
| 10 | }; | ||
| 11 | |||
| 12 | test "container member access usingnamespace decls" { | ||
| 13 | var foo = Foo{}; | ||
| 14 | foo.two(); | ||
| 15 | } | ||
test/behavior/bugs/3384.zig deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | |||
| 4 | test "resolve array slice using builtin" { | ||
| 5 | try expect(@hasDecl(@This(), "std") == true); | ||
| 6 | try expect(@hasDecl(@This(), "std"[0..0]) == false); | ||
| 7 | try expect(@hasDecl(@This(), "std"[0..1]) == false); | ||
| 8 | try expect(@hasDecl(@This(), "std"[0..2]) == false); | ||
| 9 | try expect(@hasDecl(@This(), "std"[0..3]) == true); | ||
| 10 | try expect(@hasDecl(@This(), "std"[0..]) == true); | ||
| 11 | } | ||
test/behavior/bugs/3468.zig deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | // zig fmt: off | ||
| 2 | test "pointer deref next to assignment" { | ||
| 3 | var a:i32=2; | ||
| 4 | var b=&a; | ||
| 5 | b.*=3; | ||
| 6 | _=&b; | ||
| 7 | } | ||
test/behavior/bugs/3586.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | const NoteParams = struct {}; | ||
| 4 | |||
| 5 | const Container = struct { | ||
| 6 | params: ?NoteParams, | ||
| 7 | }; | ||
| 8 | |||
| 9 | test "fixed" { | ||
| 10 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 11 | |||
| 12 | var ctr = Container{ | ||
| 13 | .params = NoteParams{}, | ||
| 14 | }; | ||
| 15 | _ = &ctr; | ||
| 16 | } | ||
test/behavior/bugs/3742.zig deleted-45| ... | @@ -1,45 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | pub const GET = struct { | ||
| 5 | key: []const u8, | ||
| 6 | |||
| 7 | pub fn init(key: []const u8) GET { | ||
| 8 | return .{ .key = key }; | ||
| 9 | } | ||
| 10 | |||
| 11 | pub const Redis = struct { | ||
| 12 | pub const Command = struct { | ||
| 13 | pub fn serialize(self: GET, comptime rootSerializer: type) void { | ||
| 14 | return rootSerializer.serializeCommand(.{ "GET", self.key }); | ||
| 15 | } | ||
| 16 | }; | ||
| 17 | }; | ||
| 18 | }; | ||
| 19 | |||
| 20 | pub fn isCommand(comptime T: type) bool { | ||
| 21 | const tid = @typeInfo(T); | ||
| 22 | return (tid == .Struct or tid == .Enum or tid == .Union) and | ||
| 23 | @hasDecl(T, "Redis") and @hasDecl(T.Redis, "Command"); | ||
| 24 | } | ||
| 25 | |||
| 26 | pub const ArgSerializer = struct { | ||
| 27 | pub fn serializeCommand(command: anytype) void { | ||
| 28 | const CmdT = @TypeOf(command); | ||
| 29 | |||
| 30 | if (comptime isCommand(CmdT)) { | ||
| 31 | // COMMENTING THE NEXT LINE REMOVES THE ERROR | ||
| 32 | return CmdT.Redis.Command.serialize(command, ArgSerializer); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | }; | ||
| 36 | |||
| 37 | test "fixed" { | ||
| 38 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 39 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 40 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 41 | if (builtin.zig_backend == .stage2_llvm and | ||
| 42 | builtin.cpu.arch == .aarch64 and builtin.os.tag == .windows) return error.SkipZigTest; | ||
| 43 | |||
| 44 | ArgSerializer.serializeCommand(GET.init("banana")); | ||
| 45 | } | ||
test/behavior/bugs/394.zig deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | const E = union(enum) { | ||
| 2 | A: [9]u8, | ||
| 3 | B: u64, | ||
| 4 | }; | ||
| 5 | const S = struct { | ||
| 6 | x: u8, | ||
| 7 | y: E, | ||
| 8 | }; | ||
| 9 | |||
| 10 | const expect = @import("std").testing.expect; | ||
| 11 | const builtin = @import("builtin"); | ||
| 12 | |||
| 13 | test "fixed" { | ||
| 14 | const x = S{ | ||
| 15 | .x = 3, | ||
| 16 | .y = E{ .B = 1 }, | ||
| 17 | }; | ||
| 18 | try expect(x.x == 3); | ||
| 19 | } | ||
test/behavior/bugs/421.zig deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const expect = @import("std").testing.expect; | ||
| 3 | |||
| 4 | test "bitCast to array" { | ||
| 5 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 6 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 8 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 9 | |||
| 10 | try comptime testBitCastArray(); | ||
| 11 | try testBitCastArray(); | ||
| 12 | } | ||
| 13 | |||
| 14 | fn testBitCastArray() !void { | ||
| 15 | try expect(extractOne64(0x0123456789abcdef0123456789abcdef) == 0x0123456789abcdef); | ||
| 16 | } | ||
| 17 | |||
| 18 | fn extractOne64(a: u128) u64 { | ||
| 19 | const x = @as([2]u64, @bitCast(a)); | ||
| 20 | return x[1]; | ||
| 21 | } | ||
test/behavior/bugs/4328.zig deleted-82| ... | @@ -1,82 +0,0 @@ | ||
| 1 | const expect = @import("std").testing.expect; | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const FILE = extern struct { | ||
| 5 | dummy_field: u8, | ||
| 6 | }; | ||
| 7 | |||
| 8 | extern fn c_printf([*c]const u8, ...) c_int; | ||
| 9 | extern fn c_fputs([*c]const u8, noalias [*c]FILE) c_int; | ||
| 10 | extern fn c_ftell([*c]FILE) c_long; | ||
| 11 | extern fn c_fopen([*c]const u8, [*c]const u8) [*c]FILE; | ||
| 12 | |||
| 13 | const S = extern struct { | ||
| 14 | state: c_short, | ||
| 15 | |||
| 16 | extern fn s_do_thing([*c]const S, b: c_int) c_short; | ||
| 17 | }; | ||
| 18 | |||
| 19 | test "Extern function calls in @TypeOf" { | ||
| 20 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 21 | |||
| 22 | const Test = struct { | ||
| 23 | fn test_fn_1(a: anytype, b: anytype) @TypeOf(c_printf("%d %s\n", a, b)) { | ||
| 24 | return 0; | ||
| 25 | } | ||
| 26 | |||
| 27 | fn test_fn_2(s: anytype, a: anytype) @TypeOf(s.s_do_thing(a)) { | ||
| 28 | return 1; | ||
| 29 | } | ||
| 30 | |||
| 31 | fn doTheTest() !void { | ||
| 32 | try expect(@TypeOf(test_fn_1(0, 42)) == c_int); | ||
| 33 | try expect(@TypeOf(test_fn_2(&S{ .state = 1 }, 0)) == c_short); | ||
| 34 | } | ||
| 35 | }; | ||
| 36 | |||
| 37 | try Test.doTheTest(); | ||
| 38 | try comptime Test.doTheTest(); | ||
| 39 | } | ||
| 40 | |||
| 41 | test "Peer resolution of extern function calls in @TypeOf" { | ||
| 42 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 43 | |||
| 44 | const Test = struct { | ||
| 45 | fn test_fn() @TypeOf(c_ftell(null), c_fputs(null, null)) { | ||
| 46 | return 0; | ||
| 47 | } | ||
| 48 | |||
| 49 | fn doTheTest() !void { | ||
| 50 | try expect(@TypeOf(test_fn()) == c_long); | ||
| 51 | } | ||
| 52 | }; | ||
| 53 | |||
| 54 | try Test.doTheTest(); | ||
| 55 | try comptime Test.doTheTest(); | ||
| 56 | } | ||
| 57 | |||
| 58 | test "Extern function calls, dereferences and field access in @TypeOf" { | ||
| 59 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 60 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 61 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 62 | |||
| 63 | const Test = struct { | ||
| 64 | fn test_fn_1(a: c_long) @TypeOf(c_fopen("test", "r").*) { | ||
| 65 | _ = a; | ||
| 66 | return .{ .dummy_field = 0 }; | ||
| 67 | } | ||
| 68 | |||
| 69 | fn test_fn_2(a: anytype) @TypeOf(c_fopen("test", "r").*.dummy_field) { | ||
| 70 | _ = a; | ||
| 71 | return 255; | ||
| 72 | } | ||
| 73 | |||
| 74 | fn doTheTest() !void { | ||
| 75 | try expect(@TypeOf(test_fn_1(0)) == FILE); | ||
| 76 | try expect(@TypeOf(test_fn_2(0)) == u8); | ||
| 77 | } | ||
| 78 | }; | ||
| 79 | |||
| 80 | try Test.doTheTest(); | ||
| 81 | try comptime Test.doTheTest(); | ||
| 82 | } | ||
test/behavior/bugs/4560.zig deleted-40| ... | @@ -1,40 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test "fixed" { | ||
| 5 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 6 | |||
| 7 | var s: S = .{ | ||
| 8 | .a = 1, | ||
| 9 | .b = .{ | ||
| 10 | .size = 123, | ||
| 11 | .max_distance_from_start_index = 456, | ||
| 12 | }, | ||
| 13 | }; | ||
| 14 | _ = &s; | ||
| 15 | try std.testing.expect(s.a == 1); | ||
| 16 | try std.testing.expect(s.b.size == 123); | ||
| 17 | try std.testing.expect(s.b.max_distance_from_start_index == 456); | ||
| 18 | } | ||
| 19 | |||
| 20 | const S = struct { | ||
| 21 | a: u32, | ||
| 22 | b: Map, | ||
| 23 | |||
| 24 | const Map = StringHashMap(*S); | ||
| 25 | }; | ||
| 26 | |||
| 27 | pub fn StringHashMap(comptime V: type) type { | ||
| 28 | return HashMap([]const u8, V); | ||
| 29 | } | ||
| 30 | |||
| 31 | pub fn HashMap(comptime K: type, comptime V: type) type { | ||
| 32 | if (false) { | ||
| 33 | K; | ||
| 34 | V; | ||
| 35 | } | ||
| 36 | return struct { | ||
| 37 | size: usize, | ||
| 38 | max_distance_from_start_index: usize, | ||
| 39 | }; | ||
| 40 | } | ||
test/behavior/bugs/4769_a.zig deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | // | ||
test/behavior/bugs/4769_b.zig deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | //! | ||
test/behavior/bugs/4954.zig deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | fn f(buf: []u8) void { | ||
| 4 | _ = &buf[@sizeOf(u32)]; | ||
| 5 | } | ||
| 6 | |||
| 7 | test "crash" { | ||
| 8 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 9 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 10 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 11 | |||
| 12 | var buf: [4096]u8 = undefined; | ||
| 13 | f(&buf); | ||
| 14 | } | ||
test/behavior/bugs/529.zig deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | const A = extern struct { | ||
| 2 | field: c_int, | ||
| 3 | }; | ||
| 4 | |||
| 5 | extern fn issue529(?*A) void; | ||
| 6 | |||
| 7 | comptime { | ||
| 8 | _ = @import("529_other_file_2.zig"); | ||
| 9 | } | ||
| 10 | |||
| 11 | const builtin = @import("builtin"); | ||
| 12 | |||
| 13 | test "issue 529 fixed" { | ||
| 14 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 15 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 16 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 17 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 18 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | ||
| 19 | |||
| 20 | @import("529_other_file.zig").issue529(null); | ||
| 21 | issue529(null); | ||
| 22 | } | ||
test/behavior/bugs/529_other_file.zig deleted-5| ... | @@ -1,5 +0,0 @@ | ||
| 1 | pub const A = extern struct { | ||
| 2 | field: c_int, | ||
| 3 | }; | ||
| 4 | |||
| 5 | pub extern fn issue529(?*A) void; | ||
test/behavior/bugs/529_other_file_2.zig deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | pub const A = extern struct { | ||
| 2 | field: c_int, | ||
| 3 | }; | ||
| 4 | export fn issue529(a: ?*A) void { | ||
| 5 | _ = a; | ||
| 6 | } | ||
test/behavior/bugs/5398.zig deleted-36| ... | @@ -1,36 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const testing = std.testing; | ||
| 3 | const builtin = @import("builtin"); | ||
| 4 | |||
| 5 | pub const Mesh = struct { | ||
| 6 | id: u32, | ||
| 7 | }; | ||
| 8 | pub const Material = struct { | ||
| 9 | transparent: bool = true, | ||
| 10 | emits_shadows: bool = true, | ||
| 11 | render_color: bool = true, | ||
| 12 | }; | ||
| 13 | pub const Renderable = struct { | ||
| 14 | material: Material, | ||
| 15 | // The compiler inserts some padding here to ensure Mesh is correctly aligned. | ||
| 16 | mesh: Mesh, | ||
| 17 | }; | ||
| 18 | |||
| 19 | var renderable: Renderable = undefined; | ||
| 20 | |||
| 21 | test "assignment of field with padding" { | ||
| 22 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 23 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 24 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 25 | |||
| 26 | renderable = Renderable{ | ||
| 27 | .mesh = Mesh{ .id = 0 }, | ||
| 28 | .material = Material{ | ||
| 29 | .transparent = false, | ||
| 30 | .emits_shadows = false, | ||
| 31 | }, | ||
| 32 | }; | ||
| 33 | try testing.expect(false == renderable.material.transparent); | ||
| 34 | try testing.expect(false == renderable.material.emits_shadows); | ||
| 35 | try testing.expect(true == renderable.material.render_color); | ||
| 36 | } | ||
test/behavior/bugs/5413.zig deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | const expect = @import("std").testing.expect; | ||
| 2 | |||
| 3 | test "Peer type resolution with string literals and unknown length u8 pointers" { | ||
| 4 | try expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8); | ||
| 5 | try expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8); | ||
| 6 | } | ||
test/behavior/bugs/5474.zig deleted-63| ... | @@ -1,63 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | // baseline (control) struct with array of scalar | ||
| 5 | const Box0 = struct { | ||
| 6 | items: [4]Item, | ||
| 7 | |||
| 8 | const Item = struct { | ||
| 9 | num: u32, | ||
| 10 | }; | ||
| 11 | }; | ||
| 12 | |||
| 13 | // struct with array of empty struct | ||
| 14 | const Box1 = struct { | ||
| 15 | items: [4]Item, | ||
| 16 | |||
| 17 | const Item = struct {}; | ||
| 18 | }; | ||
| 19 | |||
| 20 | // struct with array of zero-size struct | ||
| 21 | const Box2 = struct { | ||
| 22 | items: [4]Item, | ||
| 23 | |||
| 24 | const Item = struct { | ||
| 25 | nothing: void, | ||
| 26 | }; | ||
| 27 | }; | ||
| 28 | |||
| 29 | fn mutable() !void { | ||
| 30 | var box0: Box0 = .{ .items = undefined }; | ||
| 31 | try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == false); | ||
| 32 | |||
| 33 | var box1: Box1 = .{ .items = undefined }; | ||
| 34 | try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == false); | ||
| 35 | |||
| 36 | var box2: Box2 = .{ .items = undefined }; | ||
| 37 | try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == false); | ||
| 38 | } | ||
| 39 | |||
| 40 | fn constant() !void { | ||
| 41 | const box0: Box0 = .{ .items = undefined }; | ||
| 42 | try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == true); | ||
| 43 | |||
| 44 | const box1: Box1 = .{ .items = undefined }; | ||
| 45 | try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == true); | ||
| 46 | |||
| 47 | const box2: Box2 = .{ .items = undefined }; | ||
| 48 | try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == true); | ||
| 49 | } | ||
| 50 | |||
| 51 | test "pointer-to-array constness for zero-size elements, var" { | ||
| 52 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 53 | |||
| 54 | try mutable(); | ||
| 55 | try comptime mutable(); | ||
| 56 | } | ||
| 57 | |||
| 58 | test "pointer-to-array constness for zero-size elements, const" { | ||
| 59 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 60 | |||
| 61 | try constant(); | ||
| 62 | try comptime constant(); | ||
| 63 | } | ||
test/behavior/bugs/5487.zig deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | const io = @import("std").io; | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | pub fn write(_: void, bytes: []const u8) !usize { | ||
| 5 | _ = bytes; | ||
| 6 | return 0; | ||
| 7 | } | ||
| 8 | pub fn writer() io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write) { | ||
| 9 | return io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write){ .context = {} }; | ||
| 10 | } | ||
| 11 | |||
| 12 | test "crash" { | ||
| 13 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 14 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 15 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 16 | _ = io.multiWriter(.{writer()}); | ||
| 17 | } | ||
test/behavior/bugs/6047.zig deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | fn getError() !void { | ||
| 4 | return error.Test; | ||
| 5 | } | ||
| 6 | |||
| 7 | fn getError2() !void { | ||
| 8 | var a: u8 = 'c'; | ||
| 9 | _ = &a; | ||
| 10 | try if (a == 'a') getError() else if (a == 'b') getError() else getError(); | ||
| 11 | } | ||
| 12 | |||
| 13 | test "`try`ing an if/else expression" { | ||
| 14 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 15 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 16 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 17 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 18 | |||
| 19 | try @import("std").testing.expectError(error.Test, getError2()); | ||
| 20 | } | ||
test/behavior/bugs/624.zig deleted-30| ... | @@ -1,30 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | const TestContext = struct { | ||
| 6 | server_context: *ListenerContext, | ||
| 7 | }; | ||
| 8 | |||
| 9 | const ListenerContext = struct { | ||
| 10 | context_alloc: *ContextAllocator, | ||
| 11 | }; | ||
| 12 | |||
| 13 | const ContextAllocator = MemoryPool(TestContext); | ||
| 14 | |||
| 15 | fn MemoryPool(comptime T: type) type { | ||
| 16 | _ = T; | ||
| 17 | return struct { | ||
| 18 | n: usize, | ||
| 19 | }; | ||
| 20 | } | ||
| 21 | |||
| 22 | test "foo" { | ||
| 23 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 24 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 25 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 26 | |||
| 27 | var allocator = ContextAllocator{ .n = 10 }; | ||
| 28 | _ = &allocator; | ||
| 29 | try expect(allocator.n == 10); | ||
| 30 | } | ||
test/behavior/bugs/6305.zig deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | const ListNode = struct { | ||
| 2 | next: ?*const @This() = null, | ||
| 3 | }; | ||
| 4 | |||
| 5 | test "copy array of self-referential struct" { | ||
| 6 | comptime var nodes = [_]ListNode{ .{}, .{} }; | ||
| 7 | nodes[0].next = &nodes[1]; | ||
| 8 | const copy = nodes; | ||
| 9 | _ = copy; | ||
| 10 | } | ||
test/behavior/bugs/6456.zig deleted-46| ... | @@ -1,46 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | const testing = std.testing; | ||
| 4 | const StructField = std.builtin.Type.StructField; | ||
| 5 | const Declaration = std.builtin.Type.Declaration; | ||
| 6 | |||
| 7 | const text = | ||
| 8 | \\f1 | ||
| 9 | \\f2 | ||
| 10 | \\f3 | ||
| 11 | ; | ||
| 12 | |||
| 13 | test "issue 6456" { | ||
| 14 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 15 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 16 | |||
| 17 | comptime { | ||
| 18 | var fields: []const StructField = &[0]StructField{}; | ||
| 19 | |||
| 20 | var it = std.mem.tokenizeScalar(u8, text, '\n'); | ||
| 21 | while (it.next()) |name| { | ||
| 22 | fields = fields ++ &[_]StructField{StructField{ | ||
| 23 | .alignment = 0, | ||
| 24 | .name = name, | ||
| 25 | .type = usize, | ||
| 26 | .default_value = null, | ||
| 27 | .is_comptime = false, | ||
| 28 | }}; | ||
| 29 | } | ||
| 30 | |||
| 31 | const T = @Type(.{ | ||
| 32 | .Struct = .{ | ||
| 33 | .layout = .Auto, | ||
| 34 | .is_tuple = false, | ||
| 35 | .fields = fields, | ||
| 36 | .decls = &[_]Declaration{}, | ||
| 37 | }, | ||
| 38 | }); | ||
| 39 | |||
| 40 | const gen_fields = @typeInfo(T).Struct.fields; | ||
| 41 | try testing.expectEqual(3, gen_fields.len); | ||
| 42 | try testing.expectEqualStrings("f1", gen_fields[0].name); | ||
| 43 | try testing.expectEqualStrings("f2", gen_fields[1].name); | ||
| 44 | try testing.expectEqualStrings("f3", gen_fields[2].name); | ||
| 45 | } | ||
| 46 | } | ||
test/behavior/bugs/655.zig deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const other_file = @import("655_other_file.zig"); | ||
| 3 | |||
| 4 | test "function with *const parameter with type dereferenced by namespace" { | ||
| 5 | const x: other_file.Integer = 1234; | ||
| 6 | try comptime std.testing.expect(@TypeOf(&x) == *const other_file.Integer); | ||
| 7 | try foo(&x); | ||
| 8 | } | ||
| 9 | |||
| 10 | fn foo(x: *const other_file.Integer) !void { | ||
| 11 | try std.testing.expect(x.* == 1234); | ||
| 12 | } | ||
test/behavior/bugs/655_other_file.zig deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | pub const Integer = u32; | ||
test/behavior/bugs/656.zig deleted-37| ... | @@ -1,37 +0,0 @@ | ||
| 1 | const expect = @import("std").testing.expect; | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const PrefixOp = union(enum) { | ||
| 5 | Return, | ||
| 6 | AddrOf: Value, | ||
| 7 | }; | ||
| 8 | |||
| 9 | const Value = struct { | ||
| 10 | align_expr: ?u32, | ||
| 11 | }; | ||
| 12 | |||
| 13 | test "optional if after an if in a switch prong of a switch with 2 prongs in an else" { | ||
| 14 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 15 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 16 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 17 | |||
| 18 | try foo(false, true); | ||
| 19 | } | ||
| 20 | |||
| 21 | fn foo(a: bool, b: bool) !void { | ||
| 22 | var prefix_op = PrefixOp{ | ||
| 23 | .AddrOf = Value{ .align_expr = 1234 }, | ||
| 24 | }; | ||
| 25 | _ = &prefix_op; | ||
| 26 | if (a) {} else { | ||
| 27 | switch (prefix_op) { | ||
| 28 | PrefixOp.AddrOf => |addr_of_info| { | ||
| 29 | if (b) {} | ||
| 30 | if (addr_of_info.align_expr) |align_expr| { | ||
| 31 | try expect(align_expr == 1234); | ||
| 32 | } | ||
| 33 | }, | ||
| 34 | PrefixOp.Return => {}, | ||
| 35 | } | ||
| 36 | } | ||
| 37 | } | ||
test/behavior/bugs/6781.zig deleted-84| ... | @@ -1,84 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | const assert = std.debug.assert; | ||
| 4 | |||
| 5 | const segfault = true; | ||
| 6 | |||
| 7 | pub const JournalHeader = packed struct { | ||
| 8 | hash_chain_root: u128 = undefined, | ||
| 9 | prev_hash_chain_root: u128, | ||
| 10 | checksum: u128 = undefined, | ||
| 11 | magic: u64, | ||
| 12 | command: u32, | ||
| 13 | size: u32, | ||
| 14 | |||
| 15 | pub fn calculate_checksum(self: *const JournalHeader, entry: []const u8) u128 { | ||
| 16 | assert(entry.len >= @sizeOf(JournalHeader)); | ||
| 17 | assert(entry.len == self.size); | ||
| 18 | |||
| 19 | const checksum_offset = @offsetOf(JournalHeader, "checksum"); | ||
| 20 | const checksum_size = @sizeOf(@TypeOf(self.checksum)); | ||
| 21 | assert(checksum_offset == 0 + 16 + 16); | ||
| 22 | assert(checksum_size == 16); | ||
| 23 | |||
| 24 | var target: [32]u8 = undefined; | ||
| 25 | std.crypto.hash.Blake3.hash(entry[checksum_offset + checksum_size ..], target[0..], .{}); | ||
| 26 | return @as(u128, @bitCast(target[0..checksum_size].*)); | ||
| 27 | } | ||
| 28 | |||
| 29 | pub fn calculate_hash_chain_root(self: *const JournalHeader) u128 { | ||
| 30 | const hash_chain_root_size = @sizeOf(@TypeOf(self.hash_chain_root)); | ||
| 31 | assert(hash_chain_root_size == 16); | ||
| 32 | |||
| 33 | const prev_hash_chain_root_offset = @offsetOf(JournalHeader, "prev_hash_chain_root"); | ||
| 34 | const prev_hash_chain_root_size = @sizeOf(@TypeOf(self.prev_hash_chain_root)); | ||
| 35 | assert(prev_hash_chain_root_offset == 0 + 16); | ||
| 36 | assert(prev_hash_chain_root_size == 16); | ||
| 37 | |||
| 38 | const checksum_offset = @offsetOf(JournalHeader, "checksum"); | ||
| 39 | const checksum_size = @sizeOf(@TypeOf(self.checksum)); | ||
| 40 | assert(checksum_offset == 0 + 16 + 16); | ||
| 41 | assert(checksum_size == 16); | ||
| 42 | |||
| 43 | assert(prev_hash_chain_root_offset + prev_hash_chain_root_size == checksum_offset); | ||
| 44 | |||
| 45 | const header = @as([@sizeOf(JournalHeader)]u8, @bitCast(self.*)); | ||
| 46 | const source = header[prev_hash_chain_root_offset .. checksum_offset + checksum_size]; | ||
| 47 | assert(source.len == prev_hash_chain_root_size + checksum_size); | ||
| 48 | var target: [32]u8 = undefined; | ||
| 49 | std.crypto.hash.Blake3.hash(source, target[0..], .{}); | ||
| 50 | if (segfault) { | ||
| 51 | return @as(u128, @bitCast(target[0..hash_chain_root_size].*)); | ||
| 52 | } else { | ||
| 53 | var array = target[0..hash_chain_root_size].*; | ||
| 54 | _ = &array; | ||
| 55 | return @bitCast(array); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | pub fn set_checksum_and_hash_chain_root(self: *JournalHeader, entry: []const u8) void { | ||
| 60 | self.checksum = self.calculate_checksum(entry); | ||
| 61 | self.hash_chain_root = self.calculate_hash_chain_root(); | ||
| 62 | } | ||
| 63 | }; | ||
| 64 | |||
| 65 | test "fixed" { | ||
| 66 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 67 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | ||
| 68 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 69 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 70 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 71 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 72 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | ||
| 73 | |||
| 74 | var buffer align(@alignOf(JournalHeader)) = [_]u8{0} ** 65536; | ||
| 75 | var entry = std.mem.bytesAsValue(JournalHeader, buffer[0..@sizeOf(JournalHeader)]); | ||
| 76 | entry.* = .{ | ||
| 77 | .prev_hash_chain_root = 0, | ||
| 78 | .magic = 0, | ||
| 79 | .command = 0, | ||
| 80 | .size = 64 + 128, | ||
| 81 | }; | ||
| 82 | entry.set_checksum_and_hash_chain_root(buffer[0..entry.size]); | ||
| 83 | try std.io.null_writer.print("{}\n", .{entry}); | ||
| 84 | } | ||
test/behavior/bugs/679.zig deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const expect = std.testing.expect; | ||
| 3 | |||
| 4 | pub fn List(comptime T: type) type { | ||
| 5 | _ = T; | ||
| 6 | return u32; | ||
| 7 | } | ||
| 8 | |||
| 9 | const ElementList = List(Element); | ||
| 10 | const Element = struct { | ||
| 11 | link: ElementList, | ||
| 12 | }; | ||
| 13 | |||
| 14 | test "false dependency loop in struct definition" { | ||
| 15 | const listType = ElementList; | ||
| 16 | var x: listType = 42; | ||
| 17 | _ = &x; | ||
| 18 | try expect(x == 42); | ||
| 19 | } | ||
test/behavior/bugs/6850.zig deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | test "lazy sizeof comparison with zero" { | ||
| 4 | const Empty = struct {}; | ||
| 5 | const T = *Empty; | ||
| 6 | |||
| 7 | try std.testing.expect(hasNoBits(T)); | ||
| 8 | } | ||
| 9 | |||
| 10 | fn hasNoBits(comptime T: type) bool { | ||
| 11 | return @sizeOf(T) == @sizeOf(*i32); | ||
| 12 | } | ||
test/behavior/bugs/6905.zig deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | const expect = @import("std").testing.expect; | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test "sentinel-terminated 0-length slices" { | ||
| 5 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 6 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 7 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 8 | |||
| 9 | const u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 }; | ||
| 10 | |||
| 11 | var index: u8 = 2; | ||
| 12 | _ = &index; | ||
| 13 | const slice = u32s[index..index :2]; | ||
| 14 | const array_ptr = u32s[2..2 :2]; | ||
| 15 | const comptime_known_array_value = u32s[2..2 :2].*; | ||
| 16 | var runtime_array_value = u32s[2..2 :2].*; | ||
| 17 | _ = &runtime_array_value; | ||
| 18 | |||
| 19 | try expect(slice[0] == 2); | ||
| 20 | try expect(array_ptr[0] == 2); | ||
| 21 | try expect(comptime_known_array_value[0] == 2); | ||
| 22 | try expect(runtime_array_value[0] == 2); | ||
| 23 | } | ||
test/behavior/bugs/6947.zig deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | fn destroy(ptr: *void) void { | ||
| 4 | _ = ptr; | ||
| 5 | } | ||
| 6 | |||
| 7 | test { | ||
| 8 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 9 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 10 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 11 | |||
| 12 | var slice: []void = undefined; | ||
| 13 | destroy(&slice[0]); | ||
| 14 | } | ||
test/behavior/bugs/7003.zig deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | test "@Type should resolve its children types" { | ||
| 2 | const sparse = enum(u2) { a, b, c }; | ||
| 3 | const dense = enum(u2) { a, b, c, d }; | ||
| 4 | |||
| 5 | comptime var sparse_info = @typeInfo(anyerror!sparse); | ||
| 6 | sparse_info.ErrorUnion.payload = dense; | ||
| 7 | const B = @Type(sparse_info); | ||
| 8 | _ = B; | ||
| 9 | } | ||
test/behavior/bugs/704.zig deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | const xxx = struct { | ||
| 4 | pub fn bar(self: *xxx) void { | ||
| 5 | _ = self; | ||
| 6 | } | ||
| 7 | }; | ||
| 8 | test "bug 704" { | ||
| 9 | var x: xxx = undefined; | ||
| 10 | x.bar(); | ||
| 11 | } | ||
test/behavior/bugs/7047.zig deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const U = union(enum) { | ||
| 5 | T: type, | ||
| 6 | N: void, | ||
| 7 | }; | ||
| 8 | |||
| 9 | fn S(comptime query: U) type { | ||
| 10 | return struct { | ||
| 11 | fn tag() type { | ||
| 12 | return query.T; | ||
| 13 | } | ||
| 14 | }; | ||
| 15 | } | ||
| 16 | |||
| 17 | test "compiler doesn't consider equal unions with different 'type' payload" { | ||
| 18 | const s1 = S(U{ .T = u32 }).tag(); | ||
| 19 | try std.testing.expectEqual(u32, s1); | ||
| 20 | |||
| 21 | const s2 = S(U{ .T = u64 }).tag(); | ||
| 22 | try std.testing.expectEqual(u64, s2); | ||
| 23 | } | ||
test/behavior/bugs/718.zig deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const mem = std.mem; | ||
| 4 | const expect = std.testing.expect; | ||
| 5 | const Keys = struct { | ||
| 6 | up: bool, | ||
| 7 | down: bool, | ||
| 8 | left: bool, | ||
| 9 | right: bool, | ||
| 10 | }; | ||
| 11 | var keys: Keys = undefined; | ||
| 12 | test "zero keys with @memset" { | ||
| 13 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 14 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 15 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 16 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 17 | |||
| 18 | @memset(@as([*]u8, @ptrCast(&keys))[0..@sizeOf(@TypeOf(keys))], 0); | ||
| 19 | try expect(!keys.up); | ||
| 20 | try expect(!keys.down); | ||
| 21 | try expect(!keys.left); | ||
| 22 | try expect(!keys.right); | ||
| 23 | } | ||
test/behavior/bugs/7187.zig deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const expect = std.testing.expect; | ||
| 4 | |||
| 5 | test "miscompilation with bool return type" { | ||
| 6 | var x: usize = 1; | ||
| 7 | var y: bool = getFalse(); | ||
| 8 | _ = .{ &x, &y }; | ||
| 9 | |||
| 10 | try expect(x == 1); | ||
| 11 | } | ||
| 12 | |||
| 13 | fn getFalse() bool { | ||
| 14 | return false; | ||
| 15 | } | ||
test/behavior/bugs/726.zig deleted-26| ... | @@ -1,26 +0,0 @@ | ||
| 1 | const expect = @import("std").testing.expect; | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test "@ptrCast from const to nullable" { | ||
| 5 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 6 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 7 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 8 | |||
| 9 | const c: u8 = 4; | ||
| 10 | var x: ?*const u8 = @ptrCast(&c); | ||
| 11 | _ = &x; | ||
| 12 | try expect(x.?.* == 4); | ||
| 13 | } | ||
| 14 | |||
| 15 | test "@ptrCast from var in empty struct to nullable" { | ||
| 16 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 17 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 18 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 19 | |||
| 20 | const container = struct { | ||
| 21 | var c: u8 = 4; | ||
| 22 | }; | ||
| 23 | var x: ?*const u8 = @ptrCast(&container.c); | ||
| 24 | _ = &x; | ||
| 25 | try expect(x.?.* == 4); | ||
| 26 | } | ||
test/behavior/bugs/7325.zig deleted-113| ... | @@ -1,113 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const testing = std.testing; | ||
| 4 | |||
| 5 | const string = "hello world"; | ||
| 6 | |||
| 7 | const TempRef = struct { | ||
| 8 | index: usize, | ||
| 9 | is_weak: bool, | ||
| 10 | }; | ||
| 11 | |||
| 12 | const BuiltinEnum = struct { | ||
| 13 | name: []const u8, | ||
| 14 | }; | ||
| 15 | |||
| 16 | const ParamType = union(enum) { | ||
| 17 | boolean, | ||
| 18 | buffer, | ||
| 19 | one_of: BuiltinEnum, | ||
| 20 | }; | ||
| 21 | |||
| 22 | const CallArg = struct { | ||
| 23 | value: Expression, | ||
| 24 | }; | ||
| 25 | |||
| 26 | const Expression = union(enum) { | ||
| 27 | literal_boolean: bool, | ||
| 28 | literal_enum_value: EnumLiteral, | ||
| 29 | }; | ||
| 30 | |||
| 31 | const EnumLiteral = struct { | ||
| 32 | label: []const u8, | ||
| 33 | }; | ||
| 34 | |||
| 35 | const ExpressionResult = union(enum) { | ||
| 36 | temp_buffer: TempRef, | ||
| 37 | literal_boolean: bool, | ||
| 38 | literal_enum_value: []const u8, | ||
| 39 | }; | ||
| 40 | |||
| 41 | fn commitCalleeParam(result: ExpressionResult, callee_param_type: ParamType) ExpressionResult { | ||
| 42 | switch (callee_param_type) { | ||
| 43 | .boolean => { | ||
| 44 | return result; | ||
| 45 | }, | ||
| 46 | .buffer => { | ||
| 47 | return ExpressionResult{ | ||
| 48 | .temp_buffer = .{ .index = 0, .is_weak = false }, | ||
| 49 | }; | ||
| 50 | }, | ||
| 51 | .one_of => { | ||
| 52 | return result; | ||
| 53 | }, | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | fn genExpression(expr: Expression) !ExpressionResult { | ||
| 58 | switch (expr) { | ||
| 59 | .literal_boolean => |value| { | ||
| 60 | return ExpressionResult{ | ||
| 61 | .literal_boolean = value, | ||
| 62 | }; | ||
| 63 | }, | ||
| 64 | .literal_enum_value => |v| { | ||
| 65 | try testing.expectEqualStrings(string, v.label); | ||
| 66 | const result: ExpressionResult = .{ | ||
| 67 | .literal_enum_value = v.label, | ||
| 68 | }; | ||
| 69 | switch (result) { | ||
| 70 | .literal_enum_value => |w| { | ||
| 71 | try testing.expectEqualStrings(string, w); | ||
| 72 | }, | ||
| 73 | else => {}, | ||
| 74 | } | ||
| 75 | return result; | ||
| 76 | }, | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | test { | ||
| 81 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 82 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 83 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 84 | |||
| 85 | var param: ParamType = .{ | ||
| 86 | .one_of = .{ .name = "name" }, | ||
| 87 | }; | ||
| 88 | _ = &param; | ||
| 89 | var arg: CallArg = .{ | ||
| 90 | .value = .{ | ||
| 91 | .literal_enum_value = .{ | ||
| 92 | .label = string, | ||
| 93 | }, | ||
| 94 | }, | ||
| 95 | }; | ||
| 96 | _ = &arg; | ||
| 97 | |||
| 98 | const result = try genExpression(arg.value); | ||
| 99 | switch (result) { | ||
| 100 | .literal_enum_value => |w| { | ||
| 101 | try testing.expectEqualStrings(string, w); | ||
| 102 | }, | ||
| 103 | else => {}, | ||
| 104 | } | ||
| 105 | |||
| 106 | const derp = commitCalleeParam(result, param); | ||
| 107 | switch (derp) { | ||
| 108 | .literal_enum_value => |w| { | ||
| 109 | try testing.expectEqualStrings(string, w); | ||
| 110 | }, | ||
| 111 | else => {}, | ||
| 112 | } | ||
| 113 | } | ||
test/behavior/bugs/8277.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | test "@sizeOf reified union zero-size payload fields" { | ||
| 5 | comptime { | ||
| 6 | try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union {})))); | ||
| 7 | try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void })))); | ||
| 8 | if (builtin.mode == .Debug or builtin.mode == .ReleaseSafe) { | ||
| 9 | try std.testing.expect(1 == @sizeOf(@Type(@typeInfo(union { a: void, b: void })))); | ||
| 10 | try std.testing.expect(1 == @sizeOf(@Type(@typeInfo(union { a: void, b: void, c: void })))); | ||
| 11 | } else { | ||
| 12 | try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void, b: void })))); | ||
| 13 | try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void, b: void, c: void })))); | ||
| 14 | } | ||
| 15 | } | ||
| 16 | } | ||
test/behavior/bugs/828.zig deleted-43| ... | @@ -1,43 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | |||
| 3 | const CountBy = struct { | ||
| 4 | a: usize, | ||
| 5 | |||
| 6 | const One = CountBy{ .a = 1 }; | ||
| 7 | |||
| 8 | pub fn counter(self: *const CountBy) Counter { | ||
| 9 | _ = self; | ||
| 10 | return Counter{ .i = 0 }; | ||
| 11 | } | ||
| 12 | }; | ||
| 13 | |||
| 14 | const Counter = struct { | ||
| 15 | i: usize, | ||
| 16 | |||
| 17 | pub fn count(self: *Counter) bool { | ||
| 18 | self.i += 1; | ||
| 19 | return self.i <= 10; | ||
| 20 | } | ||
| 21 | }; | ||
| 22 | |||
| 23 | fn constCount(comptime cb: *const CountBy, comptime unused: u32) void { | ||
| 24 | _ = unused; | ||
| 25 | comptime { | ||
| 26 | var cnt = cb.counter(); | ||
| 27 | if (cnt.i != 0) @compileError("Counter instance reused!"); | ||
| 28 | while (cnt.count()) {} | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | test "comptime struct return should not return the same instance" { | ||
| 33 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 34 | |||
| 35 | //the first parameter must be passed by reference to trigger the bug | ||
| 36 | //a second parameter is required to trigger the bug | ||
| 37 | const ValA = constCount(&CountBy.One, 12); | ||
| 38 | const ValB = constCount(&CountBy.One, 15); | ||
| 39 | if (false) { | ||
| 40 | ValA; | ||
| 41 | ValB; | ||
| 42 | } | ||
| 43 | } | ||
test/behavior/bugs/8646.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | const array = [_][]const []const u8{ | ||
| 5 | &.{"hello"}, | ||
| 6 | &.{ "world", "hello" }, | ||
| 7 | }; | ||
| 8 | |||
| 9 | test { | ||
| 10 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 11 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 12 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 13 | |||
| 14 | try std.testing.expect(array[0].len == 1); | ||
| 15 | try std.testing.expectEqualStrings("hello", array[0][0]); | ||
| 16 | } | ||
test/behavior/bugs/920.zig deleted-80| ... | @@ -1,80 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | const Random = std.rand.Random; | ||
| 4 | |||
| 5 | const ZigTable = struct { | ||
| 6 | r: f64, | ||
| 7 | x: [257]f64, | ||
| 8 | f: [257]f64, | ||
| 9 | |||
| 10 | pdf: *const fn (f64) f64, | ||
| 11 | is_symmetric: bool, | ||
| 12 | zero_case: *const fn (*Random, f64) f64, | ||
| 13 | }; | ||
| 14 | |||
| 15 | fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, comptime f: fn (f64) f64, comptime f_inv: fn (f64) f64, comptime zero_case: fn (*Random, f64) f64) ZigTable { | ||
| 16 | var tables: ZigTable = undefined; | ||
| 17 | |||
| 18 | tables.is_symmetric = is_symmetric; | ||
| 19 | tables.r = r; | ||
| 20 | tables.pdf = f; | ||
| 21 | tables.zero_case = zero_case; | ||
| 22 | |||
| 23 | tables.x[0] = v / f(r); | ||
| 24 | tables.x[1] = r; | ||
| 25 | |||
| 26 | for (tables.x[2..256], 0..) |*entry, i| { | ||
| 27 | const last = tables.x[2 + i - 1]; | ||
| 28 | entry.* = f_inv(v / last + f(last)); | ||
| 29 | } | ||
| 30 | tables.x[256] = 0; | ||
| 31 | |||
| 32 | for (tables.f[0..], 0..) |*entry, i| { | ||
| 33 | entry.* = f(tables.x[i]); | ||
| 34 | } | ||
| 35 | |||
| 36 | return tables; | ||
| 37 | } | ||
| 38 | |||
| 39 | const norm_r = 3.6541528853610088; | ||
| 40 | const norm_v = 0.00492867323399; | ||
| 41 | |||
| 42 | fn norm_f(x: f64) f64 { | ||
| 43 | return @exp(-x * x / 2.0); | ||
| 44 | } | ||
| 45 | fn norm_f_inv(y: f64) f64 { | ||
| 46 | return @sqrt(-2.0 * @log(y)); | ||
| 47 | } | ||
| 48 | fn norm_zero_case(random: *Random, u: f64) f64 { | ||
| 49 | _ = random; | ||
| 50 | _ = u; | ||
| 51 | return 0.0; | ||
| 52 | } | ||
| 53 | |||
| 54 | const NormalDist = blk: { | ||
| 55 | @setEvalBranchQuota(30000); | ||
| 56 | break :blk ZigTableGen(true, norm_r, norm_v, norm_f, norm_f_inv, norm_zero_case); | ||
| 57 | }; | ||
| 58 | |||
| 59 | test "bug 920 fixed" { | ||
| 60 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 61 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 62 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 63 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 64 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | ||
| 65 | |||
| 66 | const NormalDist1 = blk: { | ||
| 67 | break :blk ZigTableGen(true, norm_r, norm_v, norm_f, norm_f_inv, norm_zero_case); | ||
| 68 | }; | ||
| 69 | |||
| 70 | for (NormalDist1.f, 0..) |_, i| { | ||
| 71 | // Here we use `expectApproxEqAbs` instead of `expectEqual` to account for the small | ||
| 72 | // differences in math functions of different libcs. For example, if the compiler | ||
| 73 | // links against glibc, but the target is musl libc, then these values might be | ||
| 74 | // slightly different. | ||
| 75 | // Arguably, this is a bug in the compiler because comptime should emulate the target, | ||
| 76 | // including rounding errors in libc math functions. However that behavior is not | ||
| 77 | // what this particular test is intended to cover. | ||
| 78 | try std.testing.expectApproxEqAbs(NormalDist1.f[i], NormalDist.f[i], @sqrt(std.math.floatEps(f64))); | ||
| 79 | } | ||
| 80 | } | ||
test/behavior/bugs/9584.zig deleted-69| ... | @@ -1,69 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | |||
| 4 | const A = packed struct { | ||
| 5 | a: bool, | ||
| 6 | b: bool, | ||
| 7 | c: bool, | ||
| 8 | d: bool, | ||
| 9 | |||
| 10 | e: bool, | ||
| 11 | f: bool, | ||
| 12 | g: bool, | ||
| 13 | h: bool, | ||
| 14 | }; | ||
| 15 | |||
| 16 | const X = union { | ||
| 17 | x: A, | ||
| 18 | y: u64, | ||
| 19 | }; | ||
| 20 | |||
| 21 | pub fn a( | ||
| 22 | x0: i32, | ||
| 23 | x1: i32, | ||
| 24 | x2: i32, | ||
| 25 | x3: i32, | ||
| 26 | x4: i32, | ||
| 27 | flag_a: bool, | ||
| 28 | flag_b: bool, | ||
| 29 | ) !void { | ||
| 30 | _ = x0; | ||
| 31 | _ = x1; | ||
| 32 | _ = x2; | ||
| 33 | _ = x3; | ||
| 34 | _ = x4; | ||
| 35 | _ = flag_a; | ||
| 36 | // With this bug present, `flag_b` would actually contain the value 17. | ||
| 37 | // Note: this bug only presents itself on debug mode. | ||
| 38 | const flag_b_byte: u8 = @intFromBool(flag_b); | ||
| 39 | try std.testing.expect(flag_b_byte == 1); | ||
| 40 | } | ||
| 41 | |||
| 42 | pub fn b(x: *X) !void { | ||
| 43 | try a(0, 1, 2, 3, 4, x.x.a, x.x.b); | ||
| 44 | } | ||
| 45 | |||
| 46 | test { | ||
| 47 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 48 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 49 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 50 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 51 | |||
| 52 | var flags = A{ | ||
| 53 | .a = false, | ||
| 54 | .b = true, | ||
| 55 | .c = false, | ||
| 56 | .d = false, | ||
| 57 | |||
| 58 | .e = false, | ||
| 59 | .f = true, | ||
| 60 | .g = false, | ||
| 61 | .h = false, | ||
| 62 | }; | ||
| 63 | _ = &flags; | ||
| 64 | var x = X{ | ||
| 65 | .x = flags, | ||
| 66 | }; | ||
| 67 | try b(&x); | ||
| 68 | comptime if (@sizeOf(A) != 1) unreachable; | ||
| 69 | } | ||
test/behavior/call.zig+127| ... | @@ -520,3 +520,130 @@ test "call coerced function" { | ... | @@ -520,3 +520,130 @@ test "call coerced function" { |
| 520 | const a = T{ .x = 3 }; | 520 | const a = T{ .x = 3 }; |
| 521 | try std.testing.expect(a.incr().x == 4); | 521 | try std.testing.expect(a.incr().x == 4); |
| 522 | } | 522 | } |
| 523 | |||
| 524 | test "call function in comptime field" { | ||
| 525 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 526 | |||
| 527 | const S = struct { | ||
| 528 | comptime capacity: fn () u64 = capacity_, | ||
| 529 | fn capacity_() u64 { | ||
| 530 | return 64; | ||
| 531 | } | ||
| 532 | }; | ||
| 533 | try std.testing.expect((S{}).capacity() == 64); | ||
| 534 | } | ||
| 535 | |||
| 536 | test "call function pointer in comptime field" { | ||
| 537 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 538 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 539 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 540 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 541 | |||
| 542 | const Auto = struct { | ||
| 543 | auto: [max_len]u8 = undefined, | ||
| 544 | offset: u64 = 0, | ||
| 545 | |||
| 546 | comptime capacity: *const fn () u64 = capacity, | ||
| 547 | |||
| 548 | const max_len: u64 = 32; | ||
| 549 | |||
| 550 | fn capacity() u64 { | ||
| 551 | return max_len; | ||
| 552 | } | ||
| 553 | }; | ||
| 554 | |||
| 555 | const a: Auto = .{ .offset = 16, .capacity = Auto.capacity }; | ||
| 556 | try std.testing.expect(a.capacity() == 32); | ||
| 557 | try std.testing.expect((a.capacity)() == 32); | ||
| 558 | } | ||
| 559 | |||
| 560 | test "generic function pointer can be called" { | ||
| 561 | const S = struct { | ||
| 562 | var ok = false; | ||
| 563 | fn foo(x: anytype) void { | ||
| 564 | ok = x; | ||
| 565 | } | ||
| 566 | }; | ||
| 567 | const x = &S.foo; | ||
| 568 | x(true); | ||
| 569 | try expect(S.ok); | ||
| 570 | } | ||
| 571 | |||
| 572 | test "value returned from comptime function is comptime known" { | ||
| 573 | const S = struct { | ||
| 574 | fn fields(comptime T: type) switch (@typeInfo(T)) { | ||
| 575 | .Struct => []const std.builtin.Type.StructField, | ||
| 576 | else => unreachable, | ||
| 577 | } { | ||
| 578 | return switch (@typeInfo(T)) { | ||
| 579 | .Struct => |info| info.fields, | ||
| 580 | else => unreachable, | ||
| 581 | }; | ||
| 582 | } | ||
| 583 | }; | ||
| 584 | const fields_list = S.fields(@TypeOf(.{})); | ||
| 585 | if (fields_list.len != 0) | ||
| 586 | @compileError("Argument count mismatch"); | ||
| 587 | } | ||
| 588 | |||
| 589 | test "registers get overwritten when ignoring return" { | ||
| 590 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 591 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 592 | if (builtin.cpu.arch != .x86_64 or builtin.os.tag != .linux) return error.SkipZigTest; | ||
| 593 | |||
| 594 | const S = struct { | ||
| 595 | fn open() usize { | ||
| 596 | return 42; | ||
| 597 | } | ||
| 598 | fn write(fd: usize, a: [*]const u8, len: usize) usize { | ||
| 599 | return syscall4(.WRITE, fd, @intFromPtr(a), len); | ||
| 600 | } | ||
| 601 | fn syscall4(_: enum { WRITE }, _: usize, _: usize, _: usize) usize { | ||
| 602 | return 23; | ||
| 603 | } | ||
| 604 | fn close(fd: usize) usize { | ||
| 605 | if (fd != 42) | ||
| 606 | unreachable; | ||
| 607 | return 0; | ||
| 608 | } | ||
| 609 | }; | ||
| 610 | |||
| 611 | const fd = S.open(); | ||
| 612 | _ = S.write(fd, "a", 1); | ||
| 613 | _ = S.close(fd); | ||
| 614 | } | ||
| 615 | |||
| 616 | test "call with union with zero sized field is not memorized incorrectly" { | ||
| 617 | const U = union(enum) { | ||
| 618 | T: type, | ||
| 619 | N: void, | ||
| 620 | fn S(comptime query: @This()) type { | ||
| 621 | return struct { | ||
| 622 | fn tag() type { | ||
| 623 | return query.T; | ||
| 624 | } | ||
| 625 | }; | ||
| 626 | } | ||
| 627 | }; | ||
| 628 | const s1 = U.S(U{ .T = u32 }).tag(); | ||
| 629 | try std.testing.expectEqual(u32, s1); | ||
| 630 | |||
| 631 | const s2 = U.S(U{ .T = u64 }).tag(); | ||
| 632 | try std.testing.expectEqual(u64, s2); | ||
| 633 | } | ||
| 634 | |||
| 635 | test "function call with cast to anyopaque pointer" { | ||
| 636 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 637 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 638 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 639 | const Foo = struct { | ||
| 640 | y: u8, | ||
| 641 | var foo: @This() = undefined; | ||
| 642 | const t = &foo; | ||
| 643 | |||
| 644 | fn bar(pointer: ?*anyopaque) void { | ||
| 645 | _ = pointer; | ||
| 646 | } | ||
| 647 | }; | ||
| 648 | Foo.bar(Foo.t); | ||
| 649 | } |
test/behavior/cast.zig+38| ... | @@ -2521,3 +2521,41 @@ test "result type is preserved into comptime block" { | ... | @@ -2521,3 +2521,41 @@ test "result type is preserved into comptime block" { |
| 2521 | const x: u32 = comptime @intCast(123); | 2521 | const x: u32 = comptime @intCast(123); |
| 2522 | try expect(x == 123); | 2522 | try expect(x == 123); |
| 2523 | } | 2523 | } |
| 2524 | |||
| 2525 | test "implicit cast from ptr to tuple to ptr to struct" { | ||
| 2526 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 2527 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 2528 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 2529 | |||
| 2530 | const ComptimeReason = union(enum) { | ||
| 2531 | c_import: struct { | ||
| 2532 | a: u32, | ||
| 2533 | }, | ||
| 2534 | }; | ||
| 2535 | |||
| 2536 | const Block = struct { | ||
| 2537 | reason: ?*const ComptimeReason, | ||
| 2538 | }; | ||
| 2539 | |||
| 2540 | var a: u32 = 16; | ||
| 2541 | _ = &a; | ||
| 2542 | var reason = .{ .c_import = .{ .a = a } }; | ||
| 2543 | var block = Block{ | ||
| 2544 | .reason = &reason, | ||
| 2545 | }; | ||
| 2546 | _ = &block; | ||
| 2547 | try expect(block.reason.?.c_import.a == 16); | ||
| 2548 | } | ||
| 2549 | |||
| 2550 | test "bitcast vector" { | ||
| 2551 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 2552 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 2553 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 2554 | |||
| 2555 | const u8x32 = @Vector(32, u8); | ||
| 2556 | const u32x8 = @Vector(8, u32); | ||
| 2557 | |||
| 2558 | const zerox32: u8x32 = [_]u8{0} ** 32; | ||
| 2559 | const bigsum: u32x8 = @bitCast(zerox32); | ||
| 2560 | try std.testing.expectEqual(0, @reduce(.Add, bigsum)); | ||
| 2561 | } |
test/behavior/conflicting_externs/a.zig created+4| ... | @@ -0,0 +1,4 @@ | ||
| 1 | pub const A = extern struct { | ||
| 2 | field: c_int, | ||
| 3 | }; | ||
| 4 | pub extern fn issue529(?*A) void; | ||
test/behavior/conflicting_externs/b.zig created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | pub const A = extern struct { | ||
| 2 | field: c_int, | ||
| 3 | }; | ||
| 4 | export fn issue529(a: ?*A) void { | ||
| 5 | _ = a; | ||
| 6 | } | ||
test/behavior/enum.zig+7| ... | @@ -1235,3 +1235,10 @@ fn getLazyInitialized(param: enum(u8) { | ... | @@ -1235,3 +1235,10 @@ fn getLazyInitialized(param: enum(u8) { |
| 1235 | }) u8 { | 1235 | }) u8 { |
| 1236 | return @intFromEnum(param); | 1236 | return @intFromEnum(param); |
| 1237 | } | 1237 | } |
| 1238 | |||
| 1239 | test "Non-exhaustive enum backed by comptime_int" { | ||
| 1240 | const E = enum(comptime_int) { a, b, c, _ }; | ||
| 1241 | comptime var e: E = .a; | ||
| 1242 | e = @as(E, @enumFromInt(378089457309184723749)); | ||
| 1243 | try expect(@intFromEnum(e) == 378089457309184723749); | ||
| 1244 | } |
test/behavior/error.zig+56| ... | @@ -970,3 +970,59 @@ test "try used in recursive function with inferred error set" { | ... | @@ -970,3 +970,59 @@ test "try used in recursive function with inferred error set" { |
| 970 | }; | 970 | }; |
| 971 | try expectError(error.a, Value.x(a)); | 971 | try expectError(error.a, Value.x(a)); |
| 972 | } | 972 | } |
| 973 | |||
| 974 | test "generic inline function returns inferred error set" { | ||
| 975 | const S = struct { | ||
| 976 | inline fn retErr(comptime T: type) !T { | ||
| 977 | return error.AnError; | ||
| 978 | } | ||
| 979 | |||
| 980 | fn main0() !void { | ||
| 981 | _ = try retErr(u8); | ||
| 982 | } | ||
| 983 | }; | ||
| 984 | S.main0() catch |e| { | ||
| 985 | try std.testing.expect(e == error.AnError); | ||
| 986 | }; | ||
| 987 | } | ||
| 988 | |||
| 989 | test "function called at runtime is properly analyzed for inferred error set" { | ||
| 990 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 991 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 992 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 993 | |||
| 994 | const S = struct { | ||
| 995 | fn foo() !void { | ||
| 996 | var a = true; | ||
| 997 | _ = &a; | ||
| 998 | if (a) return error.Foo; | ||
| 999 | return error.Bar; | ||
| 1000 | } | ||
| 1001 | fn bar() !void { | ||
| 1002 | try @This().foo(); | ||
| 1003 | } | ||
| 1004 | }; | ||
| 1005 | |||
| 1006 | S.bar() catch |err| switch (err) { | ||
| 1007 | error.Foo => {}, | ||
| 1008 | error.Bar => {}, | ||
| 1009 | }; | ||
| 1010 | } | ||
| 1011 | |||
| 1012 | test "generic type constructed from inferred error set of unresolved function" { | ||
| 1013 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 1014 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 1015 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1016 | |||
| 1017 | const S = struct { | ||
| 1018 | fn write(_: void, bytes: []const u8) !usize { | ||
| 1019 | _ = bytes; | ||
| 1020 | return 0; | ||
| 1021 | } | ||
| 1022 | const T = std.io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write); | ||
| 1023 | fn writer() T { | ||
| 1024 | return .{ .context = {} }; | ||
| 1025 | } | ||
| 1026 | }; | ||
| 1027 | _ = std.io.multiWriter(.{S.writer()}); | ||
| 1028 | } |
test/behavior/floatop.zig+81| ... | @@ -1556,3 +1556,84 @@ test "comptime fixed-width float non-zero divided by zero produces signed Inf" { | ... | @@ -1556,3 +1556,84 @@ test "comptime fixed-width float non-zero divided by zero produces signed Inf" { |
| 1556 | test "comptime_float zero divided by zero produces zero" { | 1556 | test "comptime_float zero divided by zero produces zero" { |
| 1557 | try expect((0.0 / 0.0) == 0.0); | 1557 | try expect((0.0 / 0.0) == 0.0); |
| 1558 | } | 1558 | } |
| 1559 | |||
| 1560 | test "comptime float compared with runtime int" { | ||
| 1561 | const f = 10.0; | ||
| 1562 | var i: usize = 0; | ||
| 1563 | _ = &i; | ||
| 1564 | try std.testing.expect(i < f); | ||
| 1565 | } | ||
| 1566 | test "comptime nan < runtime 0" { | ||
| 1567 | const f = comptime std.math.nan(f64); | ||
| 1568 | var i: usize = 0; | ||
| 1569 | _ = &i; | ||
| 1570 | try std.testing.expect(!(f < i)); | ||
| 1571 | } | ||
| 1572 | test "comptime inf > runtime 0" { | ||
| 1573 | const f = comptime std.math.inf(f64); | ||
| 1574 | var i: usize = 0; | ||
| 1575 | _ = &i; | ||
| 1576 | try std.testing.expect(f > i); | ||
| 1577 | } | ||
| 1578 | test "comptime -inf < runtime 0" { | ||
| 1579 | const f = comptime -std.math.inf(f64); | ||
| 1580 | var i: usize = 0; | ||
| 1581 | _ = &i; | ||
| 1582 | try std.testing.expect(f < i); | ||
| 1583 | } | ||
| 1584 | test "comptime inf >= runtime 1" { | ||
| 1585 | const f = comptime std.math.inf(f64); | ||
| 1586 | var i: usize = 1; | ||
| 1587 | _ = &i; | ||
| 1588 | try std.testing.expect(f >= i); | ||
| 1589 | } | ||
| 1590 | test "comptime isNan(nan * 1)" { | ||
| 1591 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1592 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1593 | |||
| 1594 | const nan_times_one = comptime std.math.nan(f64) * 1; | ||
| 1595 | try std.testing.expect(std.math.isNan(nan_times_one)); | ||
| 1596 | } | ||
| 1597 | test "runtime isNan(nan * 1)" { | ||
| 1598 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1599 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1600 | |||
| 1601 | const nan_times_one = std.math.nan(f64) * 1; | ||
| 1602 | try std.testing.expect(std.math.isNan(nan_times_one)); | ||
| 1603 | } | ||
| 1604 | test "comptime isNan(nan * 0)" { | ||
| 1605 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1606 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1607 | |||
| 1608 | const nan_times_zero = comptime std.math.nan(f64) * 0; | ||
| 1609 | try std.testing.expect(std.math.isNan(nan_times_zero)); | ||
| 1610 | const zero_times_nan = 0 * comptime std.math.nan(f64); | ||
| 1611 | try std.testing.expect(std.math.isNan(zero_times_nan)); | ||
| 1612 | } | ||
| 1613 | test "runtime isNan(nan * 0)" { | ||
| 1614 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1615 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1616 | |||
| 1617 | const nan_times_zero = std.math.nan(f64) * 0; | ||
| 1618 | try std.testing.expect(std.math.isNan(nan_times_zero)); | ||
| 1619 | const zero_times_nan = 0 * std.math.nan(f64); | ||
| 1620 | try std.testing.expect(std.math.isNan(zero_times_nan)); | ||
| 1621 | } | ||
| 1622 | test "comptime isNan(inf * 0)" { | ||
| 1623 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1624 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1625 | |||
| 1626 | const inf_times_zero = comptime std.math.inf(f64) * 0; | ||
| 1627 | try std.testing.expect(std.math.isNan(inf_times_zero)); | ||
| 1628 | const zero_times_inf = 0 * comptime std.math.inf(f64); | ||
| 1629 | try std.testing.expect(std.math.isNan(zero_times_inf)); | ||
| 1630 | } | ||
| 1631 | test "runtime isNan(inf * 0)" { | ||
| 1632 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1633 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1634 | |||
| 1635 | const inf_times_zero = std.math.inf(f64) * 0; | ||
| 1636 | try std.testing.expect(std.math.isNan(inf_times_zero)); | ||
| 1637 | const zero_times_inf = 0 * std.math.inf(f64); | ||
| 1638 | try std.testing.expect(std.math.isNan(zero_times_inf)); | ||
| 1639 | } |
test/behavior/for.zig+21| ... | @@ -504,3 +504,24 @@ test "inferred alloc ptr of for loop" { | ... | @@ -504,3 +504,24 @@ test "inferred alloc ptr of for loop" { |
| 504 | try expectEqual(@as(?bool, true), opt); | 504 | try expectEqual(@as(?bool, true), opt); |
| 505 | } | 505 | } |
| 506 | } | 506 | } |
| 507 | |||
| 508 | test "for loop results in a bool" { | ||
| 509 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 510 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 511 | |||
| 512 | try std.testing.expect(for ([1]u8{0}) |x| { | ||
| 513 | if (x == 0) break true; | ||
| 514 | } else false); | ||
| 515 | } | ||
| 516 | |||
| 517 | test "return from inline for" { | ||
| 518 | const S = struct { | ||
| 519 | fn do() bool { | ||
| 520 | inline for (.{"a"}) |_| { | ||
| 521 | if (true) return false; | ||
| 522 | } | ||
| 523 | return true; | ||
| 524 | } | ||
| 525 | }; | ||
| 526 | try std.testing.expect(!S.do()); | ||
| 527 | } |
test/behavior/generics.zig+98| ... | @@ -460,3 +460,101 @@ test "coerced function body has inequal value with its uncoerced body" { | ... | @@ -460,3 +460,101 @@ test "coerced function body has inequal value with its uncoerced body" { |
| 460 | }; | 460 | }; |
| 461 | try expect(S.A.do() == 1234); | 461 | try expect(S.A.do() == 1234); |
| 462 | } | 462 | } |
| 463 | |||
| 464 | test "generic function returns value from callconv(.C) function" { | ||
| 465 | const S = struct { | ||
| 466 | fn getU8() callconv(.C) u8 { | ||
| 467 | return 123; | ||
| 468 | } | ||
| 469 | |||
| 470 | fn getGeneric(comptime T: type, supplier: fn () callconv(.C) T) T { | ||
| 471 | return supplier(); | ||
| 472 | } | ||
| 473 | }; | ||
| 474 | |||
| 475 | try testing.expect(S.getGeneric(u8, S.getU8) == 123); | ||
| 476 | } | ||
| 477 | |||
| 478 | test "union in struct captures argument" { | ||
| 479 | const S = struct { | ||
| 480 | fn BuildType(comptime T: type) type { | ||
| 481 | return struct { | ||
| 482 | val: union { | ||
| 483 | b: T, | ||
| 484 | }, | ||
| 485 | }; | ||
| 486 | } | ||
| 487 | }; | ||
| 488 | const TestStruct = S.BuildType(u32); | ||
| 489 | const c = TestStruct{ .val = .{ .b = 10 } }; | ||
| 490 | try expect(c.val.b == 10); | ||
| 491 | } | ||
| 492 | |||
| 493 | test "function argument tuple used as struct field" { | ||
| 494 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 495 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 496 | |||
| 497 | const S = struct { | ||
| 498 | fn DeleagateWithContext(comptime Function: type) type { | ||
| 499 | const ArgArgs = std.meta.ArgsTuple(Function); | ||
| 500 | return struct { | ||
| 501 | t: ArgArgs, | ||
| 502 | }; | ||
| 503 | } | ||
| 504 | |||
| 505 | const OnConfirm = DeleagateWithContext(fn (bool) void); | ||
| 506 | const CustomDraw = DeleagateWithContext(fn (?OnConfirm) void); | ||
| 507 | }; | ||
| 508 | |||
| 509 | var c: S.CustomDraw = undefined; | ||
| 510 | c.t[0] = null; | ||
| 511 | try expect(c.t[0] == null); | ||
| 512 | } | ||
| 513 | |||
| 514 | test "comptime callconv(.C) function ptr uses comptime type argument" { | ||
| 515 | const S = struct { | ||
| 516 | fn A( | ||
| 517 | comptime T: type, | ||
| 518 | comptime destroycb: ?*const fn (?*T) callconv(.C) void, | ||
| 519 | ) !void { | ||
| 520 | try expect(destroycb == null); | ||
| 521 | } | ||
| 522 | }; | ||
| 523 | try S.A(u32, null); | ||
| 524 | } | ||
| 525 | |||
| 526 | test "call generic function with from function called by the generic function" { | ||
| 527 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 528 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 529 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 530 | if (builtin.zig_backend == .stage2_llvm and | ||
| 531 | builtin.cpu.arch == .aarch64 and builtin.os.tag == .windows) return error.SkipZigTest; | ||
| 532 | |||
| 533 | const GET = struct { | ||
| 534 | key: []const u8, | ||
| 535 | const GET = @This(); | ||
| 536 | const Redis = struct { | ||
| 537 | const Command = struct { | ||
| 538 | fn serialize(self: GET, comptime RootSerializer: type) void { | ||
| 539 | return RootSerializer.serializeCommand(.{ "GET", self.key }); | ||
| 540 | } | ||
| 541 | }; | ||
| 542 | }; | ||
| 543 | }; | ||
| 544 | const ArgSerializer = struct { | ||
| 545 | fn isCommand(comptime T: type) bool { | ||
| 546 | const tid = @typeInfo(T); | ||
| 547 | return (tid == .Struct or tid == .Enum or tid == .Union) and | ||
| 548 | @hasDecl(T, "Redis") and @hasDecl(T.Redis, "Command"); | ||
| 549 | } | ||
| 550 | fn serializeCommand(command: anytype) void { | ||
| 551 | const CmdT = @TypeOf(command); | ||
| 552 | |||
| 553 | if (comptime isCommand(CmdT)) { | ||
| 554 | return CmdT.Redis.Command.serialize(command, @This()); | ||
| 555 | } | ||
| 556 | } | ||
| 557 | }; | ||
| 558 | |||
| 559 | ArgSerializer.serializeCommand(GET{ .key = "banana" }); | ||
| 560 | } |
test/behavior/globals.zig+19| ... | @@ -27,3 +27,22 @@ test "store to global vector" { | ... | @@ -27,3 +27,22 @@ test "store to global vector" { |
| 27 | vpos = @Vector(2, f32){ 0.0, 1.0 }; | 27 | vpos = @Vector(2, f32){ 0.0, 1.0 }; |
| 28 | try expect(vpos[1] == 1.0); | 28 | try expect(vpos[1] == 1.0); |
| 29 | } | 29 | } |
| 30 | |||
| 31 | test "slices pointing at the same address as global array." { | ||
| 32 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 33 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 34 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 35 | |||
| 36 | const S = struct { | ||
| 37 | const a = [_]u8{ 1, 2, 3 }; | ||
| 38 | |||
| 39 | fn checkAddress(s: []const u8) !void { | ||
| 40 | for (s, 0..) |*i, j| { | ||
| 41 | try expect(i == &a[j]); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | }; | ||
| 45 | |||
| 46 | try S.checkAddress(&S.a); | ||
| 47 | try comptime S.checkAddress(&S.a); | ||
| 48 | } |
test/behavior/hasdecl.zig+9| ... | @@ -19,3 +19,12 @@ test "@hasDecl" { | ... | @@ -19,3 +19,12 @@ test "@hasDecl" { |
| 19 | try expect(@hasDecl(Bar, "blah")); | 19 | try expect(@hasDecl(Bar, "blah")); |
| 20 | try expect(!@hasDecl(Bar, "nope")); | 20 | try expect(!@hasDecl(Bar, "nope")); |
| 21 | } | 21 | } |
| 22 | |||
| 23 | test "@hasDecl using a sliced string literal" { | ||
| 24 | try expect(@hasDecl(@This(), "std") == true); | ||
| 25 | try expect(@hasDecl(@This(), "std"[0..0]) == false); | ||
| 26 | try expect(@hasDecl(@This(), "std"[0..1]) == false); | ||
| 27 | try expect(@hasDecl(@This(), "std"[0..2]) == false); | ||
| 28 | try expect(@hasDecl(@This(), "std"[0..3]) == true); | ||
| 29 | try expect(@hasDecl(@This(), "std"[0..]) == true); | ||
| 30 | } |
test/behavior/if.zig+8| ... | @@ -200,3 +200,11 @@ test "if value shouldn't be load-elided if used later (optionals)" { | ... | @@ -200,3 +200,11 @@ test "if value shouldn't be load-elided if used later (optionals)" { |
| 200 | 200 | ||
| 201 | try std.testing.expectEqual(c, 1); | 201 | try std.testing.expectEqual(c, 1); |
| 202 | } | 202 | } |
| 203 | |||
| 204 | test "variable type inferred from if expression" { | ||
| 205 | var a = if (true) { | ||
| 206 | return; | ||
| 207 | } else true; | ||
| 208 | _ = &a; | ||
| 209 | return error.TestFailed; | ||
| 210 | } |
test/behavior/int_comparison_elision.zig+5| ... | @@ -106,3 +106,8 @@ fn testIntEdges(comptime T: type) void { | ... | @@ -106,3 +106,8 @@ fn testIntEdges(comptime T: type) void { |
| 106 | if (undef_const == max + 1) @compileError("analyzed impossible branch"); | 106 | if (undef_const == max + 1) @compileError("analyzed impossible branch"); |
| 107 | if (undef_const != max + 1) {} else @compileError("analyzed impossible branch"); | 107 | if (undef_const != max + 1) {} else @compileError("analyzed impossible branch"); |
| 108 | } | 108 | } |
| 109 | |||
| 110 | test "comparison elided on large integer value" { | ||
| 111 | try std.testing.expect(-1 == @as(i8, -3) >> 2); | ||
| 112 | try std.testing.expect(-1 == -3 >> 2000); | ||
| 113 | } |
test/behavior/math.zig+37| ... | @@ -164,6 +164,25 @@ fn testOneCtz(comptime T: type, x: T) u32 { | ... | @@ -164,6 +164,25 @@ fn testOneCtz(comptime T: type, x: T) u32 { |
| 164 | return @ctz(x); | 164 | return @ctz(x); |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | test "@ctz 128-bit integers" { | ||
| 168 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 169 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | ||
| 170 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 171 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 172 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 173 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 174 | |||
| 175 | try testCtz128(); | ||
| 176 | try comptime testCtz128(); | ||
| 177 | } | ||
| 178 | |||
| 179 | fn testCtz128() !void { | ||
| 180 | try expect(testOneCtz(u128, @as(u128, 0x40000000000000000000000000000000)) == 126); | ||
| 181 | try expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000)); | ||
| 182 | try expect(testOneCtz(u128, @as(u128, 0x80000000000000000000000000000000)) == 127); | ||
| 183 | try expect(testOneCtz(u128, math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1))) == 127); | ||
| 184 | } | ||
| 185 | |||
| 167 | test "@ctz vectors" { | 186 | test "@ctz vectors" { |
| 168 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 187 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 169 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 188 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| ... | @@ -1700,3 +1719,21 @@ test "mod lazy values" { | ... | @@ -1700,3 +1719,21 @@ test "mod lazy values" { |
| 1700 | _ = y; | 1719 | _ = y; |
| 1701 | } | 1720 | } |
| 1702 | } | 1721 | } |
| 1722 | |||
| 1723 | test "@clz works on both vector and scalar inputs" { | ||
| 1724 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 1725 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 1726 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1727 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1728 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1729 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 1730 | |||
| 1731 | var x: u32 = 0x1; | ||
| 1732 | _ = &x; | ||
| 1733 | var y: @Vector(4, u32) = [_]u32{ 0x1, 0x1, 0x1, 0x1 }; | ||
| 1734 | _ = &y; | ||
| 1735 | const a = @clz(x); | ||
| 1736 | const b = @clz(y); | ||
| 1737 | try std.testing.expectEqual(@as(u6, 31), a); | ||
| 1738 | try std.testing.expectEqual([_]u6{ 31, 31, 31, 31 }, b); | ||
| 1739 | } |
test/behavior/memset.zig+20| ... | @@ -156,3 +156,23 @@ test "@memset provides result type" { | ... | @@ -156,3 +156,23 @@ test "@memset provides result type" { |
| 156 | for (buf1) |s| try expect(s.x == 12); | 156 | for (buf1) |s| try expect(s.x == 12); |
| 157 | for (buf2) |s| try expect(s.x == 34); | 157 | for (buf2) |s| try expect(s.x == 34); |
| 158 | } | 158 | } |
| 159 | |||
| 160 | test "zero keys with @memset" { | ||
| 161 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 162 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 163 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 164 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 165 | |||
| 166 | const Keys = struct { | ||
| 167 | up: bool, | ||
| 168 | down: bool, | ||
| 169 | left: bool, | ||
| 170 | right: bool, | ||
| 171 | var keys: @This() = undefined; | ||
| 172 | }; | ||
| 173 | @memset(@as([*]u8, @ptrCast(&Keys.keys))[0..@sizeOf(@TypeOf(Keys.keys))], 0); | ||
| 174 | try expect(!Keys.keys.up); | ||
| 175 | try expect(!Keys.keys.down); | ||
| 176 | try expect(!Keys.keys.left); | ||
| 177 | try expect(!Keys.keys.right); | ||
| 178 | } |
test/behavior/multiple_externs_with_conflicting_types.zig created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | const A = extern struct { | ||
| 2 | field: c_int, | ||
| 3 | }; | ||
| 4 | |||
| 5 | extern fn issue529(?*A) void; | ||
| 6 | |||
| 7 | comptime { | ||
| 8 | _ = @import("conflicting_externs/b.zig"); | ||
| 9 | } | ||
| 10 | |||
| 11 | const builtin = @import("builtin"); | ||
| 12 | |||
| 13 | test "call extern function defined with conflicting type" { | ||
| 14 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 15 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 16 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 17 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 18 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest; | ||
| 19 | |||
| 20 | @import("conflicting_externs/a.zig").issue529(null); | ||
| 21 | issue529(null); | ||
| 22 | } | ||
test/behavior/optional.zig+14| ... | @@ -495,3 +495,17 @@ test "variable of optional of noreturn" { | ... | @@ -495,3 +495,17 @@ test "variable of optional of noreturn" { |
| 495 | _ = &null_opv; | 495 | _ = &null_opv; |
| 496 | try std.testing.expectEqual(@as(?noreturn, null), null_opv); | 496 | try std.testing.expectEqual(@as(?noreturn, null), null_opv); |
| 497 | } | 497 | } |
| 498 | |||
| 499 | test "copied optional doesn't alias source" { | ||
| 500 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 501 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 502 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 503 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 504 | |||
| 505 | var opt_x: ?[3]f32 = [_]f32{0.0} ** 3; | ||
| 506 | |||
| 507 | const x = opt_x.?; | ||
| 508 | opt_x.?[0] = 15.0; | ||
| 509 | |||
| 510 | try expect(x[0] == 0.0); | ||
| 511 | } |
test/behavior/packed-struct.zig+158| ... | @@ -1071,3 +1071,161 @@ test "assigning packed struct inside another packed struct" { | ... | @@ -1071,3 +1071,161 @@ test "assigning packed struct inside another packed struct" { |
| 1071 | try expectEqual(val, S.mem.inner); | 1071 | try expectEqual(val, S.mem.inner); |
| 1072 | try expect(S.mem.padding == 0); | 1072 | try expect(S.mem.padding == 0); |
| 1073 | } | 1073 | } |
| 1074 | |||
| 1075 | test "packed struct used as part of anon decl name" { | ||
| 1076 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1077 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1078 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1079 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 1080 | |||
| 1081 | const S = packed struct { a: u0 = 0 }; | ||
| 1082 | var a: u8 = 0; | ||
| 1083 | _ = &a; | ||
| 1084 | try std.io.null_writer.print("\n{} {}\n", .{ a, S{} }); | ||
| 1085 | } | ||
| 1086 | |||
| 1087 | test "packed struct acts as a namespace" { | ||
| 1088 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1089 | |||
| 1090 | const Bar = packed struct { | ||
| 1091 | const Baz = enum { | ||
| 1092 | fizz, | ||
| 1093 | buzz, | ||
| 1094 | }; | ||
| 1095 | }; | ||
| 1096 | var foo = Bar.Baz.fizz; | ||
| 1097 | _ = &foo; | ||
| 1098 | try expect(foo == .fizz); | ||
| 1099 | } | ||
| 1100 | |||
| 1101 | test "pointer loaded correctly from packed struct" { | ||
| 1102 | const RAM = struct { | ||
| 1103 | data: [0xFFFF + 1]u8, | ||
| 1104 | fn new() !@This() { | ||
| 1105 | return .{ .data = [_]u8{0} ** 0x10000 }; | ||
| 1106 | } | ||
| 1107 | fn get(self: *@This(), addr: u16) u8 { | ||
| 1108 | return self.data[addr]; | ||
| 1109 | } | ||
| 1110 | }; | ||
| 1111 | |||
| 1112 | const CPU = packed struct { | ||
| 1113 | interrupts: bool, | ||
| 1114 | ram: *RAM, | ||
| 1115 | fn new(ram: *RAM) !@This() { | ||
| 1116 | return .{ | ||
| 1117 | .ram = ram, | ||
| 1118 | .interrupts = false, | ||
| 1119 | }; | ||
| 1120 | } | ||
| 1121 | fn tick(self: *@This()) !void { | ||
| 1122 | const queued_interrupts = self.ram.get(0xFFFF) & self.ram.get(0xFF0F); | ||
| 1123 | if (self.interrupts and queued_interrupts != 0) { | ||
| 1124 | self.interrupts = false; | ||
| 1125 | } | ||
| 1126 | } | ||
| 1127 | }; | ||
| 1128 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1129 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 1130 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 1131 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; | ||
| 1132 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 1133 | if (builtin.zig_backend == .stage2_x86_64) { | ||
| 1134 | // Careful enabling this test, fails randomly. | ||
| 1135 | return error.SkipZigTest; | ||
| 1136 | } | ||
| 1137 | |||
| 1138 | var ram = try RAM.new(); | ||
| 1139 | var cpu = try CPU.new(&ram); | ||
| 1140 | try cpu.tick(); | ||
| 1141 | try std.testing.expect(cpu.interrupts == false); | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | test "assignment to non-byte-aligned field in packed struct" { | ||
| 1145 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1146 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1147 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 1148 | |||
| 1149 | const Frame = packed struct { | ||
| 1150 | num: u20, | ||
| 1151 | }; | ||
| 1152 | |||
| 1153 | const Entry = packed struct { | ||
| 1154 | other: u12, | ||
| 1155 | frame: Frame, | ||
| 1156 | }; | ||
| 1157 | |||
| 1158 | const frame = Frame{ .num = 0x7FDE }; | ||
| 1159 | var entry = Entry{ .other = 0, .frame = .{ .num = 0xFFFFF } }; | ||
| 1160 | entry.frame = frame; | ||
| 1161 | try expect(entry.frame.num == 0x7FDE); | ||
| 1162 | } | ||
| 1163 | |||
| 1164 | test "packed struct field pointer aligned properly" { | ||
| 1165 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 1166 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1167 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1168 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1169 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO | ||
| 1170 | |||
| 1171 | const Foo = packed struct { | ||
| 1172 | a: i32, | ||
| 1173 | b: u8, | ||
| 1174 | |||
| 1175 | var buffer: [256]u8 = undefined; | ||
| 1176 | }; | ||
| 1177 | |||
| 1178 | var f1: *align(16) Foo = @alignCast(@as(*align(1) Foo, @ptrCast(&Foo.buffer[0]))); | ||
| 1179 | try expect(@typeInfo(@TypeOf(f1)).Pointer.alignment == 16); | ||
| 1180 | try expect(@intFromPtr(f1) == @intFromPtr(&f1.a)); | ||
| 1181 | try expect(@typeInfo(@TypeOf(&f1.a)).Pointer.alignment == 16); | ||
| 1182 | } | ||
| 1183 | |||
| 1184 | test "load flag from packed struct in union" { | ||
| 1185 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1186 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1187 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1188 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 1189 | |||
| 1190 | const A = packed struct { | ||
| 1191 | a: bool, | ||
| 1192 | b: bool, | ||
| 1193 | c: bool, | ||
| 1194 | d: bool, | ||
| 1195 | |||
| 1196 | e: bool, | ||
| 1197 | f: bool, | ||
| 1198 | g: bool, | ||
| 1199 | h: bool, | ||
| 1200 | }; | ||
| 1201 | |||
| 1202 | const X = union { | ||
| 1203 | x: A, | ||
| 1204 | y: u64, | ||
| 1205 | |||
| 1206 | pub fn a(_: i32, _: i32, _: i32, _: i32, _: i32, _: bool, flag_b: bool) !void { | ||
| 1207 | const flag_b_byte: u8 = @intFromBool(flag_b); | ||
| 1208 | try std.testing.expect(flag_b_byte == 1); | ||
| 1209 | } | ||
| 1210 | pub fn b(x: *@This()) !void { | ||
| 1211 | try a(0, 1, 2, 3, 4, x.x.a, x.x.b); | ||
| 1212 | } | ||
| 1213 | }; | ||
| 1214 | var flags = A{ | ||
| 1215 | .a = false, | ||
| 1216 | .b = true, | ||
| 1217 | .c = false, | ||
| 1218 | .d = false, | ||
| 1219 | |||
| 1220 | .e = false, | ||
| 1221 | .f = true, | ||
| 1222 | .g = false, | ||
| 1223 | .h = false, | ||
| 1224 | }; | ||
| 1225 | _ = &flags; | ||
| 1226 | var x = X{ | ||
| 1227 | .x = flags, | ||
| 1228 | }; | ||
| 1229 | try X.b(&x); | ||
| 1230 | comptime if (@sizeOf(A) != 1) unreachable; | ||
| 1231 | } |
test/behavior/packed-union.zig+28| ... | @@ -114,3 +114,31 @@ test "packed union in packed struct" { | ... | @@ -114,3 +114,31 @@ test "packed union in packed struct" { |
| 114 | 114 | ||
| 115 | try std.testing.expectEqual(RequestType.read, Request.init(.{ .key = 3 }).active_type); | 115 | try std.testing.expectEqual(RequestType.read, Request.init(.{ .key = 3 }).active_type); |
| 116 | } | 116 | } |
| 117 | |||
| 118 | test "packed union initialized with a runtime value" { | ||
| 119 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 120 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 121 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 122 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 123 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | ||
| 124 | |||
| 125 | const Fields = packed struct { | ||
| 126 | timestamp: u50, | ||
| 127 | random_bits: u13, | ||
| 128 | }; | ||
| 129 | const ID = packed union { | ||
| 130 | value: u63, | ||
| 131 | fields: Fields, | ||
| 132 | |||
| 133 | fn value() i64 { | ||
| 134 | return 1341; | ||
| 135 | } | ||
| 136 | }; | ||
| 137 | |||
| 138 | const timestamp: i64 = ID.value(); | ||
| 139 | const id = ID{ .fields = Fields{ | ||
| 140 | .timestamp = @as(u50, @intCast(timestamp)), | ||
| 141 | .random_bits = 420, | ||
| 142 | } }; | ||
| 143 | try std.testing.expect((ID{ .value = id.value }).fields.timestamp == timestamp); | ||
| 144 | } |
test/behavior/pointers.zig+65| ... | @@ -555,3 +555,68 @@ test "result type found through optional pointer" { | ... | @@ -555,3 +555,68 @@ test "result type found through optional pointer" { |
| 555 | try expect(ptr2.?[0] == 123); | 555 | try expect(ptr2.?[0] == 123); |
| 556 | try expect(ptr2.?[1] == 0xCD); | 556 | try expect(ptr2.?[1] == 0xCD); |
| 557 | } | 557 | } |
| 558 | |||
| 559 | const Box0 = struct { | ||
| 560 | items: [4]Item, | ||
| 561 | |||
| 562 | const Item = struct { | ||
| 563 | num: u32, | ||
| 564 | }; | ||
| 565 | }; | ||
| 566 | const Box1 = struct { | ||
| 567 | items: [4]Item, | ||
| 568 | |||
| 569 | const Item = struct {}; | ||
| 570 | }; | ||
| 571 | const Box2 = struct { | ||
| 572 | items: [4]Item, | ||
| 573 | |||
| 574 | const Item = struct { | ||
| 575 | nothing: void, | ||
| 576 | }; | ||
| 577 | }; | ||
| 578 | |||
| 579 | fn mutable() !void { | ||
| 580 | var box0: Box0 = .{ .items = undefined }; | ||
| 581 | try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == false); | ||
| 582 | |||
| 583 | var box1: Box1 = .{ .items = undefined }; | ||
| 584 | try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == false); | ||
| 585 | |||
| 586 | var box2: Box2 = .{ .items = undefined }; | ||
| 587 | try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == false); | ||
| 588 | } | ||
| 589 | |||
| 590 | fn constant() !void { | ||
| 591 | const box0: Box0 = .{ .items = undefined }; | ||
| 592 | try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).Pointer.is_const == true); | ||
| 593 | |||
| 594 | const box1: Box1 = .{ .items = undefined }; | ||
| 595 | try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).Pointer.is_const == true); | ||
| 596 | |||
| 597 | const box2: Box2 = .{ .items = undefined }; | ||
| 598 | try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).Pointer.is_const == true); | ||
| 599 | } | ||
| 600 | |||
| 601 | test "pointer-to-array constness for zero-size elements, var" { | ||
| 602 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 603 | |||
| 604 | try mutable(); | ||
| 605 | try comptime mutable(); | ||
| 606 | } | ||
| 607 | |||
| 608 | test "pointer-to-array constness for zero-size elements, const" { | ||
| 609 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 610 | |||
| 611 | try constant(); | ||
| 612 | try comptime constant(); | ||
| 613 | } | ||
| 614 | |||
| 615 | test "cast pointers with zero sized elements" { | ||
| 616 | const a: *void = undefined; | ||
| 617 | const b: *[1]void = a; | ||
| 618 | _ = b; | ||
| 619 | const c: *[0]u8 = undefined; | ||
| 620 | const d: []u8 = c; | ||
| 621 | _ = d; | ||
| 622 | } |
test/behavior/sizeof_and_typeof.zig+114| ... | @@ -314,3 +314,117 @@ test "@bitSizeOf on array of structs" { | ... | @@ -314,3 +314,117 @@ test "@bitSizeOf on array of structs" { |
| 314 | 314 | ||
| 315 | try expectEqual(128, @bitSizeOf([2]S)); | 315 | try expectEqual(128, @bitSizeOf([2]S)); |
| 316 | } | 316 | } |
| 317 | |||
| 318 | test "lazy abi size used in comparison" { | ||
| 319 | const S = struct { a: usize }; | ||
| 320 | var rhs: i32 = 100; | ||
| 321 | _ = &rhs; | ||
| 322 | try expect(@sizeOf(S) < rhs); | ||
| 323 | } | ||
| 324 | |||
| 325 | test "peer type resolution with @TypeOf doesn't trigger dependency loop check" { | ||
| 326 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 327 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 328 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 329 | |||
| 330 | const T = struct { | ||
| 331 | next: @TypeOf(null, @as(*const @This(), undefined)), | ||
| 332 | }; | ||
| 333 | var t: T = .{ .next = null }; | ||
| 334 | _ = &t; | ||
| 335 | try std.testing.expect(t.next == null); | ||
| 336 | } | ||
| 337 | |||
| 338 | test "@sizeOf reified union zero-size payload fields" { | ||
| 339 | comptime { | ||
| 340 | try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union {})))); | ||
| 341 | try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void })))); | ||
| 342 | if (builtin.mode == .Debug or builtin.mode == .ReleaseSafe) { | ||
| 343 | try std.testing.expect(1 == @sizeOf(@Type(@typeInfo(union { a: void, b: void })))); | ||
| 344 | try std.testing.expect(1 == @sizeOf(@Type(@typeInfo(union { a: void, b: void, c: void })))); | ||
| 345 | } else { | ||
| 346 | try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void, b: void })))); | ||
| 347 | try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void, b: void, c: void })))); | ||
| 348 | } | ||
| 349 | } | ||
| 350 | } | ||
| 351 | |||
| 352 | const FILE = extern struct { | ||
| 353 | dummy_field: u8, | ||
| 354 | }; | ||
| 355 | |||
| 356 | extern fn c_printf([*c]const u8, ...) c_int; | ||
| 357 | extern fn c_fputs([*c]const u8, noalias [*c]FILE) c_int; | ||
| 358 | extern fn c_ftell([*c]FILE) c_long; | ||
| 359 | extern fn c_fopen([*c]const u8, [*c]const u8) [*c]FILE; | ||
| 360 | |||
| 361 | test "Extern function calls in @TypeOf" { | ||
| 362 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 363 | |||
| 364 | const S = extern struct { | ||
| 365 | state: c_short, | ||
| 366 | |||
| 367 | extern fn s_do_thing([*c]const @This(), b: c_int) c_short; | ||
| 368 | }; | ||
| 369 | |||
| 370 | const Test = struct { | ||
| 371 | fn test_fn_1(a: anytype, b: anytype) @TypeOf(c_printf("%d %s\n", a, b)) { | ||
| 372 | return 0; | ||
| 373 | } | ||
| 374 | |||
| 375 | fn test_fn_2(s: anytype, a: anytype) @TypeOf(s.s_do_thing(a)) { | ||
| 376 | return 1; | ||
| 377 | } | ||
| 378 | |||
| 379 | fn doTheTest() !void { | ||
| 380 | try expect(@TypeOf(test_fn_1(0, 42)) == c_int); | ||
| 381 | try expect(@TypeOf(test_fn_2(&S{ .state = 1 }, 0)) == c_short); | ||
| 382 | } | ||
| 383 | }; | ||
| 384 | |||
| 385 | try Test.doTheTest(); | ||
| 386 | try comptime Test.doTheTest(); | ||
| 387 | } | ||
| 388 | |||
| 389 | test "Peer resolution of extern function calls in @TypeOf" { | ||
| 390 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 391 | |||
| 392 | const Test = struct { | ||
| 393 | fn test_fn() @TypeOf(c_ftell(null), c_fputs(null, null)) { | ||
| 394 | return 0; | ||
| 395 | } | ||
| 396 | |||
| 397 | fn doTheTest() !void { | ||
| 398 | try expect(@TypeOf(test_fn()) == c_long); | ||
| 399 | } | ||
| 400 | }; | ||
| 401 | |||
| 402 | try Test.doTheTest(); | ||
| 403 | try comptime Test.doTheTest(); | ||
| 404 | } | ||
| 405 | |||
| 406 | test "Extern function calls, dereferences and field access in @TypeOf" { | ||
| 407 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 408 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 409 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 410 | |||
| 411 | const Test = struct { | ||
| 412 | fn test_fn_1(a: c_long) @TypeOf(c_fopen("test", "r").*) { | ||
| 413 | _ = a; | ||
| 414 | return .{ .dummy_field = 0 }; | ||
| 415 | } | ||
| 416 | |||
| 417 | fn test_fn_2(a: anytype) @TypeOf(c_fopen("test", "r").*.dummy_field) { | ||
| 418 | _ = a; | ||
| 419 | return 255; | ||
| 420 | } | ||
| 421 | |||
| 422 | fn doTheTest() !void { | ||
| 423 | try expect(@TypeOf(test_fn_1(0)) == FILE); | ||
| 424 | try expect(@TypeOf(test_fn_2(0)) == u8); | ||
| 425 | } | ||
| 426 | }; | ||
| 427 | |||
| 428 | try Test.doTheTest(); | ||
| 429 | try comptime Test.doTheTest(); | ||
| 430 | } |
test/behavior/slice.zig+64| ... | @@ -912,3 +912,67 @@ test "modify slice length at comptime" { | ... | @@ -912,3 +912,67 @@ test "modify slice length at comptime" { |
| 912 | try expectEqualSlices(u8, &.{10}, a); | 912 | try expectEqualSlices(u8, &.{10}, a); |
| 913 | try expectEqualSlices(u8, &.{ 10, 20 }, b); | 913 | try expectEqualSlices(u8, &.{ 10, 20 }, b); |
| 914 | } | 914 | } |
| 915 | |||
| 916 | test "slicing zero length array field of struct" { | ||
| 917 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 918 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 919 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 920 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 921 | |||
| 922 | const S = struct { | ||
| 923 | a: [0]usize, | ||
| 924 | fn foo(self: *@This(), start: usize, end: usize) []usize { | ||
| 925 | return self.a[start..end]; | ||
| 926 | } | ||
| 927 | }; | ||
| 928 | var s: S = undefined; | ||
| 929 | try expect(s.foo(0, 0).len == 0); | ||
| 930 | } | ||
| 931 | |||
| 932 | test "slicing slices gives correct result" { | ||
| 933 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 934 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 935 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 936 | |||
| 937 | const foo = "1234"; | ||
| 938 | const bar = foo[0..4]; | ||
| 939 | try expectEqualStrings("1234", bar); | ||
| 940 | try expectEqualStrings("2", bar[1..2]); | ||
| 941 | try expectEqualStrings("3", bar[2..3]); | ||
| 942 | try expectEqualStrings("4", bar[3..4]); | ||
| 943 | try expectEqualStrings("34", bar[2..4]); | ||
| 944 | } | ||
| 945 | |||
| 946 | test "get address of element of zero-sized slice" { | ||
| 947 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 948 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 949 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 950 | |||
| 951 | const S = struct { | ||
| 952 | fn destroy(_: *void) void {} | ||
| 953 | }; | ||
| 954 | |||
| 955 | var slice: []void = undefined; | ||
| 956 | S.destroy(&slice[0]); | ||
| 957 | } | ||
| 958 | |||
| 959 | test "sentinel-terminated 0-length slices" { | ||
| 960 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 961 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 962 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 963 | |||
| 964 | const u32s: [4]u32 = [_]u32{ 0, 1, 2, 3 }; | ||
| 965 | |||
| 966 | var index: u8 = 2; | ||
| 967 | _ = &index; | ||
| 968 | const slice = u32s[index..index :2]; | ||
| 969 | const array_ptr = u32s[2..2 :2]; | ||
| 970 | const comptime_known_array_value = u32s[2..2 :2].*; | ||
| 971 | var runtime_array_value = u32s[2..2 :2].*; | ||
| 972 | _ = &runtime_array_value; | ||
| 973 | |||
| 974 | try expect(slice[0] == 2); | ||
| 975 | try expect(array_ptr[0] == 2); | ||
| 976 | try expect(comptime_known_array_value[0] == 2); | ||
| 977 | try expect(runtime_array_value[0] == 2); | ||
| 978 | } |
test/behavior/string_literals.zig+16| ... | @@ -80,3 +80,19 @@ test "string literal pointer sentinel" { | ... | @@ -80,3 +80,19 @@ test "string literal pointer sentinel" { |
| 80 | 80 | ||
| 81 | try std.testing.expect(@TypeOf(string_literal.ptr) == [*:0]const u8); | 81 | try std.testing.expect(@TypeOf(string_literal.ptr) == [*:0]const u8); |
| 82 | } | 82 | } |
| 83 | |||
| 84 | test "sentinel slice of string literal" { | ||
| 85 | const string = "Hello!\x00World!"; | ||
| 86 | try std.testing.expect(@TypeOf(string) == *const [13:0]u8); | ||
| 87 | |||
| 88 | const slice_without_sentinel: []const u8 = string[0..6]; | ||
| 89 | try std.testing.expect(@TypeOf(slice_without_sentinel) == []const u8); | ||
| 90 | |||
| 91 | const slice_with_sentinel: [:0]const u8 = string[0..6 :0]; | ||
| 92 | try std.testing.expect(@TypeOf(slice_with_sentinel) == [:0]const u8); | ||
| 93 | } | ||
| 94 | |||
| 95 | test "Peer type resolution with string literals and unknown length u8 pointers" { | ||
| 96 | try std.testing.expect(@TypeOf("", "a", @as([*:0]const u8, "")) == [*:0]const u8); | ||
| 97 | try std.testing.expect(@TypeOf(@as([*:0]const u8, "baz"), "foo", "bar") == [*:0]const u8); | ||
| 98 | } |
test/behavior/struct.zig+238-14| ... | @@ -203,18 +203,18 @@ test "return struct byval from function" { | ... | @@ -203,18 +203,18 @@ test "return struct byval from function" { |
| 203 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | 203 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 204 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 204 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 205 | 205 | ||
| 206 | const bar = makeBar2(1234, 5678); | 206 | const Bar = struct { |
| 207 | try expect(bar.y == 5678); | 207 | x: i32, |
| 208 | } | 208 | y: i32, |
| 209 | const Bar = struct { | 209 | fn makeBar2(x: i32, y: i32) @This() { |
| 210 | x: i32, | 210 | return .{ |
| 211 | y: i32, | 211 | .x = x, |
| 212 | }; | 212 | .y = y, |
| 213 | fn makeBar2(x: i32, y: i32) Bar { | 213 | }; |
| 214 | return Bar{ | 214 | } |
| 215 | .x = x, | ||
| 216 | .y = y, | ||
| 217 | }; | 215 | }; |
| 216 | const bar = Bar.makeBar2(1234, 5678); | ||
| 217 | try expect(bar.y == 5678); | ||
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | test "call method with mutable reference to struct with no fields" { | 220 | test "call method with mutable reference to struct with no fields" { |
| ... | @@ -1883,10 +1883,234 @@ test "field calls do not force struct field init resolution" { | ... | @@ -1883,10 +1883,234 @@ test "field calls do not force struct field init resolution" { |
| 1883 | } | 1883 | } |
| 1884 | 1884 | ||
| 1885 | test "tuple with comptime-only field" { | 1885 | test "tuple with comptime-only field" { |
| 1886 | const x = getTuple(); | 1886 | const S = struct { |
| 1887 | fn getTuple() struct { comptime_int } { | ||
| 1888 | return struct { comptime comptime_int = 0 }{0}; | ||
| 1889 | } | ||
| 1890 | }; | ||
| 1891 | |||
| 1892 | const x = S.getTuple(); | ||
| 1887 | try expect(x.@"0" == 0); | 1893 | try expect(x.@"0" == 0); |
| 1888 | } | 1894 | } |
| 1889 | 1895 | ||
| 1890 | fn getTuple() struct { comptime_int } { | 1896 | test "extern struct fields are aligned to 1" { |
| 1891 | return struct { comptime comptime_int = 0 }{0}; | 1897 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO |
| 1898 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1899 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1900 | |||
| 1901 | const Foo = extern struct { | ||
| 1902 | a: u8 align(1), | ||
| 1903 | b: u16 align(1), | ||
| 1904 | }; | ||
| 1905 | |||
| 1906 | const foo = Foo{ | ||
| 1907 | .a = 1, | ||
| 1908 | .b = 2, | ||
| 1909 | }; | ||
| 1910 | try std.testing.expectEqual(1, foo.a); | ||
| 1911 | try std.testing.expectEqual(2, foo.b); | ||
| 1912 | } | ||
| 1913 | |||
| 1914 | test "assign to slice.len of global variable" { | ||
| 1915 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1916 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1917 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1918 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 1919 | |||
| 1920 | const S = struct { | ||
| 1921 | const allocator = std.testing.allocator; | ||
| 1922 | var list = std.ArrayList(u32).init(allocator); | ||
| 1923 | }; | ||
| 1924 | |||
| 1925 | S.list.items.len = 0; | ||
| 1926 | try expect(S.list.items.len == 0); | ||
| 1927 | } | ||
| 1928 | |||
| 1929 | test "pointers to fields of volatile pointer to struct are also volatile" { | ||
| 1930 | const B = extern struct { | ||
| 1931 | a: u32, | ||
| 1932 | b: i32, | ||
| 1933 | }; | ||
| 1934 | const A = extern struct { | ||
| 1935 | value: *volatile B, | ||
| 1936 | }; | ||
| 1937 | |||
| 1938 | var a: *A = undefined; | ||
| 1939 | try expect(@TypeOf(&a.value.a) == *volatile u32); | ||
| 1940 | try expect(@TypeOf(&a.value.b) == *volatile i32); | ||
| 1941 | } | ||
| 1942 | |||
| 1943 | test "pointers to fields of volatile pointer to union are also volatile" { | ||
| 1944 | const D = extern union { | ||
| 1945 | a: u32, | ||
| 1946 | b: i32, | ||
| 1947 | }; | ||
| 1948 | const C = extern struct { | ||
| 1949 | value: *volatile D, | ||
| 1950 | }; | ||
| 1951 | |||
| 1952 | var c: *C = undefined; | ||
| 1953 | try expect(@TypeOf(&c.value.a) == *volatile u32); | ||
| 1954 | try expect(@TypeOf(&c.value.b) == *volatile i32); | ||
| 1955 | } | ||
| 1956 | |||
| 1957 | test "array of structs inside struct initialized with undefined" { | ||
| 1958 | const Item = struct { field: u8 }; | ||
| 1959 | const Thing = struct { | ||
| 1960 | array: [1]Item, | ||
| 1961 | }; | ||
| 1962 | _ = Thing{ .array = undefined }; | ||
| 1963 | } | ||
| 1964 | |||
| 1965 | test "runtime call in nested initializer" { | ||
| 1966 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 1967 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1968 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1969 | |||
| 1970 | const Holder = struct { | ||
| 1971 | array: []const u8, | ||
| 1972 | }; | ||
| 1973 | const Test = struct { | ||
| 1974 | holders: []const Holder, | ||
| 1975 | }; | ||
| 1976 | const Letter = enum(u8) { | ||
| 1977 | A = 0x41, | ||
| 1978 | B, | ||
| 1979 | |||
| 1980 | fn letter(e: @This()) u8 { | ||
| 1981 | return @intFromEnum(e); | ||
| 1982 | } | ||
| 1983 | }; | ||
| 1984 | |||
| 1985 | const test_struct = Test{ | ||
| 1986 | .holders = &.{ | ||
| 1987 | Holder{ | ||
| 1988 | .array = &.{ | ||
| 1989 | Letter.letter(.A), | ||
| 1990 | }, | ||
| 1991 | }, | ||
| 1992 | }, | ||
| 1993 | }; | ||
| 1994 | try std.testing.expectEqualStrings("A", test_struct.holders[0].array); | ||
| 1995 | } | ||
| 1996 | |||
| 1997 | test "runtime value in nested initializer passed as pointer to function" { | ||
| 1998 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 1999 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 2000 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 2001 | |||
| 2002 | const Bar = struct { | ||
| 2003 | b: u32, | ||
| 2004 | }; | ||
| 2005 | const Foo = struct { | ||
| 2006 | a: Bar, | ||
| 2007 | |||
| 2008 | fn takeFoo(foo: *const @This()) !void { | ||
| 2009 | try std.testing.expectEqual(@as(u32, 24), foo.a.b); | ||
| 2010 | } | ||
| 2011 | }; | ||
| 2012 | |||
| 2013 | var baz: u32 = 24; | ||
| 2014 | _ = &baz; | ||
| 2015 | try Foo.takeFoo(&.{ | ||
| 2016 | .a = .{ | ||
| 2017 | .b = baz, | ||
| 2018 | }, | ||
| 2019 | }); | ||
| 2020 | } | ||
| 2021 | |||
| 2022 | test "struct field default value is a call" { | ||
| 2023 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 2024 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 2025 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 2026 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 2027 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 2028 | |||
| 2029 | const Z = packed struct { | ||
| 2030 | a: u32, | ||
| 2031 | }; | ||
| 2032 | const Y = struct { | ||
| 2033 | a: u16, | ||
| 2034 | b: bool, | ||
| 2035 | c: Z, | ||
| 2036 | d: Z, | ||
| 2037 | |||
| 2038 | fn init() @This() { | ||
| 2039 | return .{ | ||
| 2040 | .a = 0, | ||
| 2041 | .b = false, | ||
| 2042 | .c = @as(Z, @bitCast(@as(u32, 0))), | ||
| 2043 | .d = @as(Z, @bitCast(@as(u32, 0))), | ||
| 2044 | }; | ||
| 2045 | } | ||
| 2046 | }; | ||
| 2047 | const X = struct { | ||
| 2048 | y: Y = Y.init(), | ||
| 2049 | }; | ||
| 2050 | |||
| 2051 | const x = X{}; | ||
| 2052 | try std.testing.expectEqual(@as(u16, 0), x.y.a); | ||
| 2053 | try std.testing.expectEqual(false, x.y.b); | ||
| 2054 | try std.testing.expectEqual(Z{ .a = 0 }, x.y.c); | ||
| 2055 | try std.testing.expectEqual(Z{ .a = 0 }, x.y.d); | ||
| 2056 | } | ||
| 2057 | |||
| 2058 | test "aggregate initializers should allow initializing comptime fields, verifying equality" { | ||
| 2059 | var x: u32 = 15; | ||
| 2060 | _ = &x; | ||
| 2061 | const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x }); | ||
| 2062 | const a: T = .{ -1234, 5678, x + 1 }; | ||
| 2063 | |||
| 2064 | try expect(a[0] == -1234); | ||
| 2065 | try expect(a[1] == 5678); | ||
| 2066 | try expect(a[2] == 16); | ||
| 2067 | } | ||
| 2068 | |||
| 2069 | test "assignment of field with padding" { | ||
| 2070 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 2071 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 2072 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 2073 | |||
| 2074 | const Mesh = extern struct { | ||
| 2075 | id: u32, | ||
| 2076 | }; | ||
| 2077 | const Material = extern struct { | ||
| 2078 | transparent: bool = true, | ||
| 2079 | emits_shadows: bool = true, | ||
| 2080 | render_color: bool = true, | ||
| 2081 | }; | ||
| 2082 | const Renderable = extern struct { | ||
| 2083 | material: Material, | ||
| 2084 | mesh: Mesh, | ||
| 2085 | }; | ||
| 2086 | var renderable: Renderable = undefined; | ||
| 2087 | renderable = Renderable{ | ||
| 2088 | .mesh = Mesh{ .id = 0 }, | ||
| 2089 | .material = Material{ | ||
| 2090 | .transparent = false, | ||
| 2091 | .emits_shadows = false, | ||
| 2092 | }, | ||
| 2093 | }; | ||
| 2094 | try expect(false == renderable.material.transparent); | ||
| 2095 | try expect(false == renderable.material.emits_shadows); | ||
| 2096 | try expect(true == renderable.material.render_color); | ||
| 2097 | } | ||
| 2098 | |||
| 2099 | test "initiate global variable with runtime value" { | ||
| 2100 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 2101 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 2102 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 2103 | |||
| 2104 | const S = struct { | ||
| 2105 | field: i32, | ||
| 2106 | fn couldFail() anyerror!i32 { | ||
| 2107 | return 1; | ||
| 2108 | } | ||
| 2109 | var some_struct: @This() = undefined; | ||
| 2110 | }; | ||
| 2111 | |||
| 2112 | S.some_struct = .{ | ||
| 2113 | .field = S.couldFail() catch 0, | ||
| 2114 | }; | ||
| 2115 | try expect(S.some_struct.field == 1); | ||
| 1892 | } | 2116 | } |
test/behavior/switch.zig+19| ... | @@ -831,3 +831,22 @@ test "peer type resolution on switch captures ignores unused payload bits" { | ... | @@ -831,3 +831,22 @@ test "peer type resolution on switch captures ignores unused payload bits" { |
| 831 | 831 | ||
| 832 | try expect(x == 123); | 832 | try expect(x == 123); |
| 833 | } | 833 | } |
| 834 | |||
| 835 | test "switch prong captures range" { | ||
| 836 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 837 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 838 | |||
| 839 | const S = struct { | ||
| 840 | fn a(b: []u3, c: u3) void { | ||
| 841 | switch (c) { | ||
| 842 | 0...1 => b[c] = c, | ||
| 843 | 2...3 => b[c] = c, | ||
| 844 | 4...7 => |d| b[d] = c, | ||
| 845 | } | ||
| 846 | } | ||
| 847 | }; | ||
| 848 | |||
| 849 | var arr: [8]u3 = undefined; | ||
| 850 | S.a(&arr, 5); | ||
| 851 | try expect(arr[5] == 5); | ||
| 852 | } |
test/behavior/this.zig+20| ... | @@ -35,3 +35,23 @@ test "this refer to container" { | ... | @@ -35,3 +35,23 @@ test "this refer to container" { |
| 35 | try expect(pt.x == 13); | 35 | try expect(pt.x == 13); |
| 36 | try expect(pt.y == 35); | 36 | try expect(pt.y == 35); |
| 37 | } | 37 | } |
| 38 | |||
| 39 | const State = struct { | ||
| 40 | const Self = @This(); | ||
| 41 | enter: *const fn (previous: ?Self) void, | ||
| 42 | }; | ||
| 43 | |||
| 44 | fn prev(p: ?State) void { | ||
| 45 | expect(p == null) catch @panic("test failure"); | ||
| 46 | } | ||
| 47 | |||
| 48 | test "this used as optional function parameter" { | ||
| 49 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 50 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 51 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 52 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 53 | |||
| 54 | var global: State = undefined; | ||
| 55 | global.enter = prev; | ||
| 56 | global.enter(null); | ||
| 57 | } |
test/behavior/try.zig+21| ... | @@ -45,3 +45,24 @@ test "try then not executed with assignment" { | ... | @@ -45,3 +45,24 @@ test "try then not executed with assignment" { |
| 45 | try expect(err == error.ItBroke); | 45 | try expect(err == error.ItBroke); |
| 46 | } | 46 | } |
| 47 | } | 47 | } |
| 48 | |||
| 49 | test "`try`ing an if/else expression" { | ||
| 50 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 51 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 52 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 53 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 54 | |||
| 55 | const S = struct { | ||
| 56 | fn getError() !void { | ||
| 57 | return error.Test; | ||
| 58 | } | ||
| 59 | |||
| 60 | fn getError2() !void { | ||
| 61 | var a: u8 = 'c'; | ||
| 62 | _ = &a; | ||
| 63 | try if (a == 'a') getError() else if (a == 'b') getError() else getError(); | ||
| 64 | } | ||
| 65 | }; | ||
| 66 | |||
| 67 | try std.testing.expectError(error.Test, S.getError2()); | ||
| 68 | } |
test/behavior/tuple.zig+73| ... | @@ -488,3 +488,76 @@ test "tuple with comptime fields with non empty initializer" { | ... | @@ -488,3 +488,76 @@ test "tuple with comptime fields with non empty initializer" { |
| 488 | const a: struct { comptime comptime_int = 0 } = .{0}; | 488 | const a: struct { comptime comptime_int = 0 } = .{0}; |
| 489 | _ = a; | 489 | _ = a; |
| 490 | } | 490 | } |
| 491 | |||
| 492 | test "tuple with runtime value coerced into a slice with a sentinel" { | ||
| 493 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 494 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 495 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 496 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 497 | |||
| 498 | const S = struct { | ||
| 499 | fn f(a: [:null]const ?u8) !void { | ||
| 500 | try expect(a[0] == 42); | ||
| 501 | } | ||
| 502 | }; | ||
| 503 | |||
| 504 | const c: u8 = 42; | ||
| 505 | try S.f(&[_:null]?u8{c}); | ||
| 506 | try S.f(&.{c}); | ||
| 507 | |||
| 508 | var v: u8 = 42; | ||
| 509 | _ = &v; | ||
| 510 | try S.f(&[_:null]?u8{v}); | ||
| 511 | try S.f(&.{v}); | ||
| 512 | } | ||
| 513 | |||
| 514 | test "tuple implicitly coerced to optional/error union struct/union" { | ||
| 515 | const SomeUnion = union(enum) { | ||
| 516 | variant: u8, | ||
| 517 | }; | ||
| 518 | const SomeStruct = struct { | ||
| 519 | struct_field: u8, | ||
| 520 | }; | ||
| 521 | const OptEnum = struct { | ||
| 522 | opt_union: ?SomeUnion, | ||
| 523 | }; | ||
| 524 | const ErrEnum = struct { | ||
| 525 | err_union: anyerror!SomeUnion, | ||
| 526 | }; | ||
| 527 | const OptStruct = struct { | ||
| 528 | opt_struct: ?SomeStruct, | ||
| 529 | }; | ||
| 530 | const ErrStruct = struct { | ||
| 531 | err_struct: anyerror!SomeStruct, | ||
| 532 | }; | ||
| 533 | |||
| 534 | try expect((OptEnum{ | ||
| 535 | .opt_union = .{ | ||
| 536 | .variant = 1, | ||
| 537 | }, | ||
| 538 | }).opt_union.?.variant == 1); | ||
| 539 | |||
| 540 | try expect(((ErrEnum{ | ||
| 541 | .err_union = .{ | ||
| 542 | .variant = 1, | ||
| 543 | }, | ||
| 544 | }).err_union catch unreachable).variant == 1); | ||
| 545 | |||
| 546 | try expect((OptStruct{ | ||
| 547 | .opt_struct = .{ | ||
| 548 | .struct_field = 1, | ||
| 549 | }, | ||
| 550 | }).opt_struct.?.struct_field == 1); | ||
| 551 | |||
| 552 | try expect(((ErrStruct{ | ||
| 553 | .err_struct = .{ | ||
| 554 | .struct_field = 1, | ||
| 555 | }, | ||
| 556 | }).err_struct catch unreachable).struct_field == 1); | ||
| 557 | } | ||
| 558 | |||
| 559 | test "comptime fields in tuple can be initialized" { | ||
| 560 | const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) }); | ||
| 561 | var a: T = .{ 0, 0 }; | ||
| 562 | _ = &a; | ||
| 563 | } |
test/behavior/type.zig+166| ... | @@ -568,3 +568,169 @@ test "reified struct field name from optional payload" { | ... | @@ -568,3 +568,169 @@ test "reified struct field name from optional payload" { |
| 568 | } | 568 | } |
| 569 | } | 569 | } |
| 570 | } | 570 | } |
| 571 | |||
| 572 | test "reified union uses @alignOf" { | ||
| 573 | const S = struct { | ||
| 574 | fn CreateUnion(comptime T: type) type { | ||
| 575 | return @Type(.{ | ||
| 576 | .Union = .{ | ||
| 577 | .layout = .Auto, | ||
| 578 | .tag_type = null, | ||
| 579 | .fields = &[_]std.builtin.Type.UnionField{ | ||
| 580 | .{ | ||
| 581 | .name = "field", | ||
| 582 | .type = T, | ||
| 583 | .alignment = @alignOf(T), | ||
| 584 | }, | ||
| 585 | }, | ||
| 586 | .decls = &.{}, | ||
| 587 | }, | ||
| 588 | }); | ||
| 589 | } | ||
| 590 | }; | ||
| 591 | _ = S.CreateUnion(struct {}); | ||
| 592 | } | ||
| 593 | |||
| 594 | test "reified struct uses @alignOf" { | ||
| 595 | const S = struct { | ||
| 596 | fn NamespacedGlobals(comptime modules: anytype) type { | ||
| 597 | return @Type(.{ | ||
| 598 | .Struct = .{ | ||
| 599 | .layout = .Auto, | ||
| 600 | .is_tuple = false, | ||
| 601 | .fields = &.{ | ||
| 602 | .{ | ||
| 603 | .name = "globals", | ||
| 604 | .type = modules.mach.globals, | ||
| 605 | .default_value = null, | ||
| 606 | .is_comptime = false, | ||
| 607 | .alignment = @alignOf(modules.mach.globals), | ||
| 608 | }, | ||
| 609 | }, | ||
| 610 | .decls = &.{}, | ||
| 611 | }, | ||
| 612 | }); | ||
| 613 | } | ||
| 614 | }; | ||
| 615 | _ = S.NamespacedGlobals(.{ | ||
| 616 | .mach = .{ | ||
| 617 | .globals = struct {}, | ||
| 618 | }, | ||
| 619 | }); | ||
| 620 | } | ||
| 621 | |||
| 622 | test "reified error set initialized with field pointer" { | ||
| 623 | const S = struct { | ||
| 624 | const info = .{ | ||
| 625 | .args = [_]Type.Error{ | ||
| 626 | .{ .name = "bar" }, | ||
| 627 | }, | ||
| 628 | }; | ||
| 629 | const Foo = @Type(.{ | ||
| 630 | .ErrorSet = &info.args, | ||
| 631 | }); | ||
| 632 | }; | ||
| 633 | try testing.expect(S.Foo == error{bar}); | ||
| 634 | } | ||
| 635 | test "reified function type params initialized with field pointer" { | ||
| 636 | const S = struct { | ||
| 637 | const fn_info = .{ | ||
| 638 | .params = [_]Type.Fn.Param{ | ||
| 639 | .{ .is_generic = false, .is_noalias = false, .type = u8 }, | ||
| 640 | }, | ||
| 641 | }; | ||
| 642 | const Bar = @Type(.{ | ||
| 643 | .Fn = .{ | ||
| 644 | .calling_convention = .Unspecified, | ||
| 645 | .alignment = 0, | ||
| 646 | .is_generic = false, | ||
| 647 | .is_var_args = false, | ||
| 648 | .return_type = void, | ||
| 649 | .params = &fn_info.params, | ||
| 650 | }, | ||
| 651 | }); | ||
| 652 | }; | ||
| 653 | try testing.expect(@typeInfo(S.Bar) == .Fn); | ||
| 654 | } | ||
| 655 | |||
| 656 | test "empty struct assigned to reified struct field" { | ||
| 657 | const S = struct { | ||
| 658 | fn NamespacedComponents(comptime modules: anytype) type { | ||
| 659 | return @Type(.{ | ||
| 660 | .Struct = .{ | ||
| 661 | .layout = .Auto, | ||
| 662 | .is_tuple = false, | ||
| 663 | .fields = &.{.{ | ||
| 664 | .name = "components", | ||
| 665 | .type = @TypeOf(modules.components), | ||
| 666 | .default_value = null, | ||
| 667 | .is_comptime = false, | ||
| 668 | .alignment = @alignOf(@TypeOf(modules.components)), | ||
| 669 | }}, | ||
| 670 | .decls = &.{}, | ||
| 671 | }, | ||
| 672 | }); | ||
| 673 | } | ||
| 674 | |||
| 675 | fn namespacedComponents(comptime modules: anytype) NamespacedComponents(modules) { | ||
| 676 | var x: NamespacedComponents(modules) = undefined; | ||
| 677 | x.components = modules.components; | ||
| 678 | return x; | ||
| 679 | } | ||
| 680 | }; | ||
| 681 | _ = S.namespacedComponents(.{ | ||
| 682 | .components = .{ | ||
| 683 | .location = struct {}, | ||
| 684 | }, | ||
| 685 | }); | ||
| 686 | } | ||
| 687 | |||
| 688 | test "@Type should resolve its children types" { | ||
| 689 | const sparse = enum(u2) { a, b, c }; | ||
| 690 | const dense = enum(u2) { a, b, c, d }; | ||
| 691 | |||
| 692 | comptime var sparse_info = @typeInfo(anyerror!sparse); | ||
| 693 | sparse_info.ErrorUnion.payload = dense; | ||
| 694 | const B = @Type(sparse_info); | ||
| 695 | try testing.expectEqual(anyerror!dense, B); | ||
| 696 | } | ||
| 697 | |||
| 698 | test "struct field names sliced at comptime from larger string" { | ||
| 699 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 700 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 701 | |||
| 702 | const text = | ||
| 703 | \\f1 | ||
| 704 | \\f2 | ||
| 705 | \\f3 | ||
| 706 | ; | ||
| 707 | comptime { | ||
| 708 | var fields: []const Type.StructField = &[0]Type.StructField{}; | ||
| 709 | |||
| 710 | var it = std.mem.tokenizeScalar(u8, text, '\n'); | ||
| 711 | while (it.next()) |name| { | ||
| 712 | fields = fields ++ &[_]Type.StructField{.{ | ||
| 713 | .alignment = 0, | ||
| 714 | .name = name, | ||
| 715 | .type = usize, | ||
| 716 | .default_value = null, | ||
| 717 | .is_comptime = false, | ||
| 718 | }}; | ||
| 719 | } | ||
| 720 | |||
| 721 | const T = @Type(.{ | ||
| 722 | .Struct = .{ | ||
| 723 | .layout = .Auto, | ||
| 724 | .is_tuple = false, | ||
| 725 | .fields = fields, | ||
| 726 | .decls = &.{}, | ||
| 727 | }, | ||
| 728 | }); | ||
| 729 | |||
| 730 | const gen_fields = @typeInfo(T).Struct.fields; | ||
| 731 | try testing.expectEqual(3, gen_fields.len); | ||
| 732 | try testing.expectEqualStrings("f1", gen_fields[0].name); | ||
| 733 | try testing.expectEqualStrings("f2", gen_fields[1].name); | ||
| 734 | try testing.expectEqualStrings("f3", gen_fields[2].name); | ||
| 735 | } | ||
| 736 | } |
test/behavior/undefined.zig+13| ... | @@ -84,3 +84,16 @@ test "type name of undefined" { | ... | @@ -84,3 +84,16 @@ test "type name of undefined" { |
| 84 | const x = undefined; | 84 | const x = undefined; |
| 85 | try expect(mem.eql(u8, @typeName(@TypeOf(x)), "@TypeOf(undefined)")); | 85 | try expect(mem.eql(u8, @typeName(@TypeOf(x)), "@TypeOf(undefined)")); |
| 86 | } | 86 | } |
| 87 | |||
| 88 | var buf: []u8 = undefined; | ||
| 89 | |||
| 90 | test "reslice of undefined global var slice" { | ||
| 91 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 92 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 93 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 94 | |||
| 95 | var stack_buf: [100]u8 = [_]u8{0} ** 100; | ||
| 96 | buf = &stack_buf; | ||
| 97 | const x = buf[0..1]; | ||
| 98 | try @import("std").testing.expect(x.len == 1 and x[0] == 0); | ||
| 99 | } |
test/behavior/union.zig+140| ... | @@ -2112,3 +2112,143 @@ test "pass nested union with rls" { | ... | @@ -2112,3 +2112,143 @@ test "pass nested union with rls" { |
| 2112 | _ = &c; | 2112 | _ = &c; |
| 2113 | try expectEqual(@as(u7, 32), Union.getC(.{ .b = .{ .c = c } })); | 2113 | try expectEqual(@as(u7, 32), Union.getC(.{ .b = .{ .c = c } })); |
| 2114 | } | 2114 | } |
| 2115 | |||
| 2116 | test "runtime union init, most-aligned field != largest" { | ||
| 2117 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 2118 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 2119 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 2120 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | ||
| 2121 | |||
| 2122 | const U = union(enum) { | ||
| 2123 | x: u128, | ||
| 2124 | y: [17]u8, | ||
| 2125 | |||
| 2126 | fn foo(val: @This()) !void { | ||
| 2127 | try expect(val.x == 1); | ||
| 2128 | } | ||
| 2129 | }; | ||
| 2130 | var x: u8 = 1; | ||
| 2131 | _ = &x; | ||
| 2132 | try U.foo(.{ .x = x }); | ||
| 2133 | |||
| 2134 | const val: U = @unionInit(U, "x", x); | ||
| 2135 | try expect(val.x == 1); | ||
| 2136 | |||
| 2137 | const val2: U = .{ .x = x }; | ||
| 2138 | try expect(val2.x == 1); | ||
| 2139 | } | ||
| 2140 | |||
| 2141 | test "copied union field doesn't alias source" { | ||
| 2142 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 2143 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 2144 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 2145 | |||
| 2146 | const U = union(enum) { | ||
| 2147 | array: [10]u32, | ||
| 2148 | other: u32, | ||
| 2149 | }; | ||
| 2150 | |||
| 2151 | var x = U{ .array = undefined }; | ||
| 2152 | |||
| 2153 | x.array[1] = 0; | ||
| 2154 | const a = x.array; | ||
| 2155 | x.array[1] = 15; | ||
| 2156 | |||
| 2157 | try expect(a[1] == 0); | ||
| 2158 | } | ||
| 2159 | |||
| 2160 | test "create union(enum) from other union(enum)" { | ||
| 2161 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 2162 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 2163 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 2164 | |||
| 2165 | const string = "hello world"; | ||
| 2166 | const TempRef = struct { | ||
| 2167 | index: usize, | ||
| 2168 | is_weak: bool, | ||
| 2169 | }; | ||
| 2170 | const BuiltinEnum = struct { | ||
| 2171 | name: []const u8, | ||
| 2172 | }; | ||
| 2173 | const ParamType = union(enum) { | ||
| 2174 | boolean, | ||
| 2175 | buffer, | ||
| 2176 | one_of: BuiltinEnum, | ||
| 2177 | }; | ||
| 2178 | const EnumLiteral = struct { | ||
| 2179 | label: []const u8, | ||
| 2180 | }; | ||
| 2181 | |||
| 2182 | const ExpressionResult = union(enum) { | ||
| 2183 | temp_buffer: TempRef, | ||
| 2184 | literal_boolean: bool, | ||
| 2185 | literal_enum_value: []const u8, | ||
| 2186 | |||
| 2187 | fn commitCalleeParam(result: @This(), callee_param_type: ParamType) @This() { | ||
| 2188 | switch (callee_param_type) { | ||
| 2189 | .boolean => return result, | ||
| 2190 | .buffer => return .{ | ||
| 2191 | .temp_buffer = .{ .index = 0, .is_weak = false }, | ||
| 2192 | }, | ||
| 2193 | .one_of => return result, | ||
| 2194 | } | ||
| 2195 | } | ||
| 2196 | }; | ||
| 2197 | const Expression = union(enum) { | ||
| 2198 | literal_boolean: bool, | ||
| 2199 | literal_enum_value: EnumLiteral, | ||
| 2200 | |||
| 2201 | fn genExpression(expr: @This()) !ExpressionResult { | ||
| 2202 | switch (expr) { | ||
| 2203 | .literal_boolean => |value| return .{ | ||
| 2204 | .literal_boolean = value, | ||
| 2205 | }, | ||
| 2206 | .literal_enum_value => |v| { | ||
| 2207 | try std.testing.expectEqualStrings(string, v.label); | ||
| 2208 | const result: ExpressionResult = .{ | ||
| 2209 | .literal_enum_value = v.label, | ||
| 2210 | }; | ||
| 2211 | switch (result) { | ||
| 2212 | .literal_enum_value => |w| { | ||
| 2213 | try std.testing.expectEqualStrings(string, w); | ||
| 2214 | }, | ||
| 2215 | else => {}, | ||
| 2216 | } | ||
| 2217 | return result; | ||
| 2218 | }, | ||
| 2219 | } | ||
| 2220 | } | ||
| 2221 | }; | ||
| 2222 | const CallArg = struct { | ||
| 2223 | value: Expression, | ||
| 2224 | }; | ||
| 2225 | |||
| 2226 | var param: ParamType = .{ | ||
| 2227 | .one_of = .{ .name = "name" }, | ||
| 2228 | }; | ||
| 2229 | _ = &param; | ||
| 2230 | var arg: CallArg = .{ | ||
| 2231 | .value = .{ | ||
| 2232 | .literal_enum_value = .{ | ||
| 2233 | .label = string, | ||
| 2234 | }, | ||
| 2235 | }, | ||
| 2236 | }; | ||
| 2237 | _ = &arg; | ||
| 2238 | |||
| 2239 | const result = try arg.value.genExpression(); | ||
| 2240 | switch (result) { | ||
| 2241 | .literal_enum_value => |w| { | ||
| 2242 | try std.testing.expectEqualStrings(string, w); | ||
| 2243 | }, | ||
| 2244 | else => {}, | ||
| 2245 | } | ||
| 2246 | |||
| 2247 | const derp = result.commitCalleeParam(param); | ||
| 2248 | switch (derp) { | ||
| 2249 | .literal_enum_value => |w| { | ||
| 2250 | try std.testing.expectEqualStrings(string, w); | ||
| 2251 | }, | ||
| 2252 | else => {}, | ||
| 2253 | } | ||
| 2254 | } |
test/behavior/usingnamespace.zig+15| ... | @@ -82,3 +82,18 @@ test { | ... | @@ -82,3 +82,18 @@ test { |
| 82 | comptime { | 82 | comptime { |
| 83 | _ = @import("usingnamespace/file_1.zig"); | 83 | _ = @import("usingnamespace/file_1.zig"); |
| 84 | } | 84 | } |
| 85 | |||
| 86 | const Bar = struct { | ||
| 87 | usingnamespace Mixin; | ||
| 88 | }; | ||
| 89 | |||
| 90 | const Mixin = struct { | ||
| 91 | pub fn two(self: Bar) void { | ||
| 92 | _ = self; | ||
| 93 | } | ||
| 94 | }; | ||
| 95 | |||
| 96 | test "container member access usingnamespace decls" { | ||
| 97 | var foo = Bar{}; | ||
| 98 | foo.two(); | ||
| 99 | } |
test/behavior/vector.zig+36| ... | @@ -1530,3 +1530,39 @@ test "index into comptime-known vector is comptime-known" { | ... | @@ -1530,3 +1530,39 @@ test "index into comptime-known vector is comptime-known" { |
| 1530 | const vec: @Vector(2, f16) = [2]f16{ 1.5, 3.5 }; | 1530 | const vec: @Vector(2, f16) = [2]f16{ 1.5, 3.5 }; |
| 1531 | if (vec[0] != 1.5) @compileError("vec should be comptime"); | 1531 | if (vec[0] != 1.5) @compileError("vec should be comptime"); |
| 1532 | } | 1532 | } |
| 1533 | |||
| 1534 | test "arithmetic on zero-length vectors" { | ||
| 1535 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 1536 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1537 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1538 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO | ||
| 1539 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 1540 | |||
| 1541 | { | ||
| 1542 | const a = @Vector(0, i32){}; | ||
| 1543 | const b = @Vector(0, i32){}; | ||
| 1544 | _ = a + b; | ||
| 1545 | } | ||
| 1546 | { | ||
| 1547 | const a = @Vector(0, i32){}; | ||
| 1548 | const b = @Vector(0, i32){}; | ||
| 1549 | _ = a - b; | ||
| 1550 | } | ||
| 1551 | } | ||
| 1552 | |||
| 1553 | test "@reduce on bool vector" { | ||
| 1554 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 1555 | if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO | ||
| 1556 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 1557 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 1558 | |||
| 1559 | if (comptime builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.endian() == .big) { | ||
| 1560 | // https://github.com/ziglang/zig/issues/13782 | ||
| 1561 | return error.SkipZigTest; | ||
| 1562 | } | ||
| 1563 | |||
| 1564 | const a = @Vector(2, bool){ true, true }; | ||
| 1565 | const b = @Vector(1, bool){true}; | ||
| 1566 | try std.testing.expect(@reduce(.And, a)); | ||
| 1567 | try std.testing.expect(@reduce(.And, b)); | ||
| 1568 | } |
test/behavior/while.zig+34| ... | @@ -367,3 +367,37 @@ test "while loop with comptime true condition needs no else block to return valu | ... | @@ -367,3 +367,37 @@ test "while loop with comptime true condition needs no else block to return valu |
| 367 | }; | 367 | }; |
| 368 | try expect(x == 69); | 368 | try expect(x == 69); |
| 369 | } | 369 | } |
| 370 | |||
| 371 | test "int returned from switch in while" { | ||
| 372 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 373 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 374 | |||
| 375 | var x: u32 = 3; | ||
| 376 | const val: usize = while (true) switch (x) { | ||
| 377 | 1 => break 2, | ||
| 378 | else => x -= 1, | ||
| 379 | }; | ||
| 380 | try std.testing.expect(val == 2); | ||
| 381 | } | ||
| 382 | |||
| 383 | test "breaking from a loop in an if statement" { | ||
| 384 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 385 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 386 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 387 | |||
| 388 | const S = struct { | ||
| 389 | fn retOpt() ?u32 { | ||
| 390 | return null; | ||
| 391 | } | ||
| 392 | }; | ||
| 393 | |||
| 394 | var cond = true; | ||
| 395 | _ = &cond; | ||
| 396 | const opt = while (cond) { | ||
| 397 | if (S.retOpt()) |opt| { | ||
| 398 | break opt; | ||
| 399 | } | ||
| 400 | break 1; | ||
| 401 | } else 2; | ||
| 402 | _ = opt; | ||
| 403 | } |
test/cases/compile_errors/extern_function_with_unspecified_calling_convention.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | const Foo = extern struct { | 1 | const Foo = extern struct { |
| 2 | f: *const fn() void, | 2 | f: *const fn () void, |
| 3 | }; | 3 | }; |
| 4 | 4 | ||
| 5 | export fn entry() void { | 5 | export fn entry() void { |
test/cases/compile_errors/invalid_extern_function_call.zig+1-1| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | const x = @extern(*const fn() callconv(.C) void, .{ .name = "foo" }); | 1 | const x = @extern(*const fn () callconv(.C) void, .{ .name = "foo" }); |
| 2 | 2 | ||
| 3 | export fn entry0() void { | 3 | export fn entry0() void { |
| 4 | comptime x(); | 4 | comptime x(); |