authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-30 16:14:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-30 16:15:42-07:00
log1e0addcf73ee71d23a41b744995848bcca38e8d3
tree13105910aae6857bffc9fa81ccab893b6507c0f6
parent04286e8c3b1a815488c73c011988eb4fa985202b

put the passing stage2 behavior tests back

This mostly reverts commit 692c254336da71cbe21aaf9fbc21240fd1269b95. The test "for loop over pointers to struct, getting field from struct pointer" is still failing on the CI so that one is not moved over.

6 files changed, 248 insertions(+), 262 deletions(-)

test/behavior.zig+16-18
......@@ -10,32 +10,41 @@ test {
1010 _ = @import("behavior/bugs/655.zig");
1111 _ = @import("behavior/bugs/679.zig");
1212 _ = @import("behavior/bugs/704.zig");
13 _ = @import("behavior/bugs/1111.zig");
1314 _ = @import("behavior/bugs/1486.zig");
1415 _ = @import("behavior/bugs/2346.zig");
1516 _ = @import("behavior/bugs/2692.zig");
1617 _ = @import("behavior/bugs/2889.zig");
18 _ = @import("behavior/bugs/3046.zig");
1719 _ = @import("behavior/bugs/3586.zig");
1820 _ = @import("behavior/bugs/4560.zig");
1921 _ = @import("behavior/bugs/4769_a.zig");
2022 _ = @import("behavior/bugs/4769_b.zig");
23 _ = @import("behavior/bugs/4954.zig");
2124 _ = @import("behavior/bugs/6850.zig");
25 _ = @import("behavior/byval_arg_var.zig");
2226 _ = @import("behavior/call.zig");
2327 _ = @import("behavior/cast.zig");
2428 _ = @import("behavior/defer.zig");
2529 _ = @import("behavior/enum.zig");
2630 _ = @import("behavior/error.zig");
31 _ = @import("behavior/fn_in_struct_in_comptime.zig");
2732 _ = @import("behavior/generics.zig");
2833 _ = @import("behavior/hasdecl.zig");
2934 _ = @import("behavior/hasfield.zig");
3035 _ = @import("behavior/if.zig");
3136 _ = @import("behavior/import.zig");
37 _ = @import("behavior/incomplete_struct_param_tld.zig");
3238 _ = @import("behavior/int128.zig");
39 _ = @import("behavior/inttoptr.zig");
3340 _ = @import("behavior/member_func.zig");
3441 _ = @import("behavior/null.zig");
3542 _ = @import("behavior/optional.zig");
3643 _ = @import("behavior/pointers.zig");
3744 _ = @import("behavior/ptrcast.zig");
3845 _ = @import("behavior/pub_enum.zig");
46 _ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig");
47 _ = @import("behavior/slice_sentinel_comptime.zig");
3948 _ = @import("behavior/struct.zig");
4049 _ = @import("behavior/this.zig");
4150 _ = @import("behavior/translate_c_macros.zig");
......@@ -47,17 +56,22 @@ test {
4756 if (builtin.object_format != .c) {
4857 // Tests that pass for stage1 and stage2 but not the C backend.
4958 _ = @import("behavior/align_llvm.zig");
59 _ = @import("behavior/alignof.zig");
5060 _ = @import("behavior/array.zig");
5161 _ = @import("behavior/atomics.zig");
5262 _ = @import("behavior/basic_llvm.zig");
5363 _ = @import("behavior/bugs/394.zig");
64 _ = @import("behavior/bugs/656.zig");
5465 _ = @import("behavior/bugs/1277.zig");
66 _ = @import("behavior/bugs/1381.zig");
5567 _ = @import("behavior/bugs/1500.zig");
5668 _ = @import("behavior/bugs/1741.zig");
5769 _ = @import("behavior/bugs/2006.zig");
70 _ = @import("behavior/bugs/2578.zig");
71 _ = @import("behavior/bugs/3007.zig");
5872 _ = @import("behavior/bugs/3112.zig");
73 _ = @import("behavior/bugs/7250.zig");
5974 _ = @import("behavior/cast_llvm.zig");
60 _ = @import("behavior/error.zig");
6175 _ = @import("behavior/eval.zig");
6276 _ = @import("behavior/floatop.zig");
6377 _ = @import("behavior/fn.zig");
......@@ -65,6 +79,7 @@ test {
6579 _ = @import("behavior/generics_llvm.zig");
6680 _ = @import("behavior/math.zig");
6781 _ = @import("behavior/maximum_minimum.zig");
82 _ = @import("behavior/namespace_depends_on_compile_var.zig");
6883 _ = @import("behavior/null_llvm.zig");
6984 _ = @import("behavior/optional_llvm.zig");
7085 _ = @import("behavior/popcount.zig");
......@@ -84,7 +99,6 @@ test {
8499 _ = @import("behavior/slice_stage2.zig");
85100 } else {
86101 _ = @import("behavior/align_stage1.zig");
87 _ = @import("behavior/alignof.zig");
88102 _ = @import("behavior/array_stage1.zig");
89103 if (builtin.os.tag != .wasi) {
90104 _ = @import("behavior/asm.zig");
......@@ -96,18 +110,15 @@ test {
96110 _ = @import("behavior/bitreverse.zig");
97111 _ = @import("behavior/bugs/421.zig");
98112 _ = @import("behavior/bugs/529.zig");
99 _ = @import("behavior/bugs/656.zig");
100113 _ = @import("behavior/bugs/718.zig");
101114 _ = @import("behavior/bugs/726.zig");
102115 _ = @import("behavior/bugs/828.zig");
103116 _ = @import("behavior/bugs/920.zig");
104117 _ = @import("behavior/bugs/1025.zig");
105118 _ = @import("behavior/bugs/1076.zig");
106 _ = @import("behavior/bugs/1111.zig");
107119 _ = @import("behavior/bugs/1120.zig");
108120 _ = @import("behavior/bugs/1310.zig");
109121 _ = @import("behavior/bugs/1322.zig");
110 _ = @import("behavior/bugs/1381.zig");
111122 _ = @import("behavior/bugs/1421.zig");
112123 _ = @import("behavior/bugs/1442.zig");
113124 _ = @import("behavior/bugs/1607.zig");
......@@ -115,15 +126,11 @@ test {
115126 _ = @import("behavior/bugs/1851.zig");
116127 _ = @import("behavior/bugs/1914.zig");
117128 _ = @import("behavior/bugs/2114.zig");
118 _ = @import("behavior/bugs/2578.zig");
119 _ = @import("behavior/bugs/3007.zig");
120 _ = @import("behavior/bugs/3046.zig");
121129 _ = @import("behavior/bugs/3367.zig");
122130 _ = @import("behavior/bugs/3384.zig");
123131 _ = @import("behavior/bugs/3742.zig");
124132 _ = @import("behavior/bugs/3779.zig");
125133 _ = @import("behavior/bugs/4328.zig");
126 _ = @import("behavior/bugs/4954.zig");
127134 _ = @import("behavior/bugs/5398.zig");
128135 _ = @import("behavior/bugs/5413.zig");
129136 _ = @import("behavior/bugs/5474.zig");
......@@ -133,12 +140,10 @@ test {
133140 _ = @import("behavior/bugs/7003.zig");
134141 _ = @import("behavior/bugs/7027.zig");
135142 _ = @import("behavior/bugs/7047.zig");
136 _ = @import("behavior/bugs/7250.zig");
137143 _ = @import("behavior/bugs/9584.zig");
138144 _ = @import("behavior/bugs/9967.zig");
139145 _ = @import("behavior/bugs/10147.zig");
140146 _ = @import("behavior/byteswap.zig");
141 _ = @import("behavior/byval_arg_var.zig");
142147 _ = @import("behavior/call_stage1.zig");
143148 _ = @import("behavior/cast_stage1.zig");
144149 _ = @import("behavior/const_slice_child.zig");
......@@ -150,28 +155,22 @@ test {
150155 _ = @import("behavior/floatop_stage1.zig");
151156 _ = @import("behavior/fn_stage1.zig");
152157 _ = @import("behavior/fn_delegation.zig");
153 _ = @import("behavior/fn_in_struct_in_comptime.zig");
154158 _ = @import("behavior/for_stage1.zig");
155159 _ = @import("behavior/if_stage1.zig");
156 _ = @import("behavior/incomplete_struct_param_tld.zig");
157 _ = @import("behavior/inttoptr.zig");
158160 _ = @import("behavior/ir_block_deps.zig");
159161 _ = @import("behavior/math_stage1.zig");
160162 _ = @import("behavior/merge_error_sets.zig");
161163 _ = @import("behavior/misc.zig");
162164 _ = @import("behavior/muladd.zig");
163 _ = @import("behavior/namespace_depends_on_compile_var.zig");
164165 _ = @import("behavior/null_stage1.zig");
165166 _ = @import("behavior/optional_stage1.zig");
166167 _ = @import("behavior/pointers_stage1.zig");
167168 _ = @import("behavior/popcount_stage1.zig");
168169 _ = @import("behavior/ptrcast_stage1.zig");
169 _ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig");
170170 _ = @import("behavior/reflection.zig");
171171 _ = @import("behavior/select.zig");
172172 _ = @import("behavior/shuffle.zig");
173173 _ = @import("behavior/sizeof_and_typeof_stage1.zig");
174 _ = @import("behavior/slice_sentinel_comptime.zig");
175174 _ = @import("behavior/slice_stage1.zig");
176175 _ = @import("behavior/struct_contains_null_ptr_itself.zig");
177176 _ = @import("behavior/struct_contains_slice_of_itself.zig");
......@@ -186,7 +185,6 @@ test {
186185 _ = @import("behavior/typename.zig");
187186 _ = @import("behavior/union_stage1.zig");
188187 _ = @import("behavior/union_with_members.zig");
189 _ = @import("behavior/usingnamespace_stage1.zig");
190188 _ = @import("behavior/var_args.zig");
191189 _ = @import("behavior/vector.zig");
192190 if (builtin.target.cpu.arch == .wasm32) {
test/behavior/struct.zig+141
......@@ -6,12 +6,55 @@ const expectEqual = std.testing.expectEqual;
66const expectEqualSlices = std.testing.expectEqualSlices;
77const maxInt = std.math.maxInt;
88
9top_level_field: i32,
10
11test "top level fields" {
12 var instance = @This(){
13 .top_level_field = 1234,
14 };
15 instance.top_level_field += 1;
16 try expect(@as(i32, 1235) == instance.top_level_field);
17}
18
919const StructWithNoFields = struct {
1020 fn add(a: i32, b: i32) i32 {
1121 return a + b;
1222 }
1323};
1424
25const StructFoo = struct {
26 a: i32,
27 b: bool,
28 c: f32,
29};
30
31test "structs" {
32 var foo: StructFoo = undefined;
33 @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
34 foo.a += 1;
35 foo.b = foo.a == 1;
36 try testFoo(foo);
37 testMutation(&foo);
38 try expect(foo.c == 100);
39}
40fn testFoo(foo: StructFoo) !void {
41 try expect(foo.b);
42}
43fn testMutation(foo: *StructFoo) void {
44 foo.c = 100;
45}
46
47test "struct byval assign" {
48 var foo1: StructFoo = undefined;
49 var foo2: StructFoo = undefined;
50
51 foo1.a = 1234;
52 foo2.a = 0;
53 try expect(foo2.a == 0);
54 foo2 = foo1;
55 try expect(foo2.a == 1234);
56}
57
1558test "call struct static method" {
1659 const result = StructWithNoFields.add(3, 4);
1760 try expect(result == 7);
......@@ -41,6 +84,23 @@ const Val = struct {
4184 x: i32,
4285};
4386
87test "fn call of struct field" {
88 const Foo = struct {
89 ptr: fn () i32,
90 };
91 const S = struct {
92 fn aFunc() i32 {
93 return 13;
94 }
95
96 fn callStructField(foo: Foo) i32 {
97 return foo.ptr();
98 }
99 };
100
101 try expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13);
102}
103
44104test "struct initializer" {
45105 const val = Val{ .x = 42 };
46106 try expect(val.x == 42);
......@@ -58,3 +118,84 @@ test "call member function directly" {
58118 const result = MemberFnTestFoo.member(instance);
59119 try expect(result == 1234);
60120}
121
122test "store member function in variable" {
123 const instance = MemberFnTestFoo{ .x = 1234 };
124 const memberFn = MemberFnTestFoo.member;
125 const result = memberFn(instance);
126 try expect(result == 1234);
127}
128
129test "member functions" {
130 const r = MemberFnRand{ .seed = 1234 };
131 try expect(r.getSeed() == 1234);
132}
133const MemberFnRand = struct {
134 seed: u32,
135 pub fn getSeed(r: *const MemberFnRand) u32 {
136 return r.seed;
137 }
138};
139
140test "return struct byval from function" {
141 const bar = makeBar2(1234, 5678);
142 try expect(bar.y == 5678);
143}
144const Bar = struct {
145 x: i32,
146 y: i32,
147};
148fn makeBar2(x: i32, y: i32) Bar {
149 return Bar{
150 .x = x,
151 .y = y,
152 };
153}
154
155test "call method with mutable reference to struct with no fields" {
156 const S = struct {
157 fn doC(s: *const @This()) bool {
158 _ = s;
159 return true;
160 }
161 fn do(s: *@This()) bool {
162 _ = s;
163 return true;
164 }
165 };
166
167 var s = S{};
168 try expect(S.doC(&s));
169 try expect(s.doC());
170 try expect(S.do(&s));
171 try expect(s.do());
172}
173
174test "usingnamespace within struct scope" {
175 const S = struct {
176 usingnamespace struct {
177 pub fn inner() i32 {
178 return 42;
179 }
180 };
181 };
182 try expect(@as(i32, 42) == S.inner());
183}
184
185test "struct field init with catch" {
186 const S = struct {
187 fn doTheTest() !void {
188 var x: anyerror!isize = 1;
189 var req = Foo{
190 .field = x catch undefined,
191 };
192 try expect(req.field == 1);
193 }
194
195 pub const Foo = extern struct {
196 field: isize,
197 };
198 };
199 try S.doTheTest();
200 comptime try S.doTheTest();
201}
test/behavior/struct_llvm.zig+16-64
......@@ -6,44 +6,6 @@ const expectEqual = std.testing.expectEqual;
66const expectEqualSlices = std.testing.expectEqualSlices;
77const maxInt = std.math.maxInt;
88
9const StructWithNoFields = struct {
10 fn add(a: i32, b: i32) i32 {
11 return a + b;
12 }
13};
14
15const StructFoo = struct {
16 a: i32,
17 b: bool,
18 c: f32,
19};
20test "structs" {
21 var foo: StructFoo = undefined;
22 @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
23 foo.a += 1;
24 foo.b = foo.a == 1;
25 try testFoo(foo);
26 testMutation(&foo);
27 try expect(foo.c == 100);
28}
29fn testFoo(foo: StructFoo) !void {
30 try expect(foo.b);
31}
32fn testMutation(foo: *StructFoo) void {
33 foo.c = 100;
34}
35
36test "struct byval assign" {
37 var foo1: StructFoo = undefined;
38 var foo2: StructFoo = undefined;
39
40 foo1.a = 1234;
41 foo2.a = 0;
42 try expect(foo2.a == 0);
43 foo2 = foo1;
44 try expect(foo2.a == 1234);
45}
46
479const Node = struct {
4810 val: Val,
4911 next: *Node,
......@@ -81,32 +43,6 @@ const VoidStructFieldsFoo = struct {
8143 c: void,
8244};
8345
84test "member functions" {
85 const r = MemberFnRand{ .seed = 1234 };
86 try expect(r.getSeed() == 1234);
87}
88const MemberFnRand = struct {
89 seed: u32,
90 pub fn getSeed(r: *const MemberFnRand) u32 {
91 return r.seed;
92 }
93};
94
95test "return struct byval from function" {
96 const bar = makeBar2(1234, 5678);
97 try expect(bar.y == 5678);
98}
99const Bar = struct {
100 x: i32,
101 y: i32,
102};
103fn makeBar2(x: i32, y: i32) Bar {
104 return Bar{
105 .x = x,
106 .y = y,
107 };
108}
109
11046test "return empty struct from fn" {
11147 _ = testReturnEmptyStructFromFn();
11248}
......@@ -114,3 +50,19 @@ const EmptyStruct2 = struct {};
11450fn testReturnEmptyStructFromFn() EmptyStruct2 {
11551 return EmptyStruct2{};
11652}
53
54test "pass slice of empty struct to fn" {
55 try expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
56}
57fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
58 return slice.len;
59}
60
61test "self-referencing struct via array member" {
62 const T = struct {
63 children: [1]*@This(),
64 };
65 var x: T = undefined;
66 x = T{ .children = .{&x} };
67 try expect(x.children[0] == &x);
68}
test/behavior/struct_stage1.zig+35-139
......@@ -6,16 +6,6 @@ const expectEqual = std.testing.expectEqual;
66const expectEqualSlices = std.testing.expectEqualSlices;
77const maxInt = std.math.maxInt;
88
9top_level_field: i32,
10
11test "top level fields" {
12 var instance = @This(){
13 .top_level_field = 1234,
14 };
15 instance.top_level_field += 1;
16 try expectEqual(@as(i32, 1235), instance.top_level_field);
17}
18
199const StructFoo = struct {
2010 a: i32,
2111 b: bool,
......@@ -31,36 +21,6 @@ const Val = struct {
3121 x: i32,
3222};
3323
34test "fn call of struct field" {
35 const Foo = struct {
36 ptr: fn () i32,
37 };
38 const S = struct {
39 fn aFunc() i32 {
40 return 13;
41 }
42
43 fn callStructField(foo: Foo) i32 {
44 return foo.ptr();
45 }
46 };
47
48 try expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13);
49}
50
51const MemberFnTestFoo = struct {
52 x: i32,
53 fn member(foo: MemberFnTestFoo) i32 {
54 return foo.x;
55 }
56};
57test "store member function in variable" {
58 const instance = MemberFnTestFoo{ .x = 1234 };
59 const memberFn = MemberFnTestFoo.member;
60 const result = memberFn(instance);
61 try expect(result == 1234);
62}
63
6424test "empty struct method call" {
6525 const es = EmptyStruct{};
6626 try expect(es.method() == 1234);
......@@ -77,13 +37,6 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
7737 return EmptyStruct2{};
7838}
7939
80test "pass slice of empty struct to fn" {
81 try expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
82}
83fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
84 return slice.len;
85}
86
8740const APackedStruct = packed struct {
8841 x: u8,
8942 y: u8,
......@@ -332,25 +285,6 @@ fn alloc(comptime T: type) []T {
332285 return &[_]T{};
333286}
334287
335test "call method with mutable reference to struct with no fields" {
336 const S = struct {
337 fn doC(s: *const @This()) bool {
338 _ = s;
339 return true;
340 }
341 fn do(s: *@This()) bool {
342 _ = s;
343 return true;
344 }
345 };
346
347 var s = S{};
348 try expect(S.doC(&s));
349 try expect(s.doC());
350 try expect(S.do(&s));
351 try expect(s.do());
352}
353
354288test "implicit cast packed struct field to const ptr" {
355289 const LevelUpMove = packed struct {
356290 move_id: u9,
......@@ -450,17 +384,6 @@ test "packed struct with fp fields" {
450384 try expectEqual(@as(f32, 20.0), s.data[2]);
451385}
452386
453test "use within struct scope" {
454 const S = struct {
455 usingnamespace struct {
456 pub fn inner() i32 {
457 return 42;
458 }
459 };
460 };
461 try expectEqual(@as(i32, 42), S.inner());
462}
463
464387test "default struct initialization fields" {
465388 const S = struct {
466389 a: i32 = 1234,
......@@ -501,41 +424,6 @@ test "fn with C calling convention returns struct by value" {
501424 comptime try S.entry();
502425}
503426
504test "for loop over pointers to struct, getting field from struct pointer" {
505 const S = struct {
506 const Foo = struct {
507 name: []const u8,
508 };
509
510 var ok = true;
511
512 fn eql(a: []const u8) bool {
513 _ = a;
514 return true;
515 }
516
517 const ArrayList = struct {
518 fn toSlice(self: *ArrayList) []*Foo {
519 _ = self;
520 return @as([*]*Foo, undefined)[0..0];
521 }
522 };
523
524 fn doTheTest() !void {
525 var objects: ArrayList = undefined;
526
527 for (objects.toSlice()) |obj| {
528 if (eql(obj.name)) {
529 ok = false;
530 }
531 }
532
533 try expect(ok);
534 }
535 };
536 try S.doTheTest();
537}
538
539427test "zero-bit field in packed struct" {
540428 const S = packed struct {
541429 x: u10,
......@@ -545,24 +433,6 @@ test "zero-bit field in packed struct" {
545433 _ = x;
546434}
547435
548test "struct field init with catch" {
549 const S = struct {
550 fn doTheTest() !void {
551 var x: anyerror!isize = 1;
552 var req = Foo{
553 .field = x catch undefined,
554 };
555 try expect(req.field == 1);
556 }
557
558 pub const Foo = extern struct {
559 field: isize,
560 };
561 };
562 try S.doTheTest();
563 comptime try S.doTheTest();
564}
565
566436test "packed struct with non-ABI-aligned field" {
567437 const S = packed struct {
568438 x: u9,
......@@ -717,15 +587,6 @@ test "anon struct literal field value initialized with fn call" {
717587 comptime try S.doTheTest();
718588}
719589
720test "self-referencing struct via array member" {
721 const T = struct {
722 children: [1]*@This(),
723 };
724 var x: T = undefined;
725 x = T{ .children = .{&x} };
726 try expect(x.children[0] == &x);
727}
728
729590test "struct with union field" {
730591 const Value = struct {
731592 ref: u32 = 2,
......@@ -833,3 +694,38 @@ test "packed struct with undefined initializers" {
833694 try S.doTheTest();
834695 comptime try S.doTheTest();
835696}
697
698test "for loop over pointers to struct, getting field from struct pointer" {
699 const S = struct {
700 const Foo = struct {
701 name: []const u8,
702 };
703
704 var ok = true;
705
706 fn eql(a: []const u8) bool {
707 _ = a;
708 return true;
709 }
710
711 const ArrayList = struct {
712 fn toSlice(self: *ArrayList) []*Foo {
713 _ = self;
714 return @as([*]*Foo, undefined)[0..0];
715 }
716 };
717
718 fn doTheTest() !void {
719 var objects: ArrayList = undefined;
720
721 for (objects.toSlice()) |obj| {
722 if (eql(obj.name)) {
723 ok = false;
724 }
725 }
726
727 try expect(ok);
728 }
729 };
730 try S.doTheTest();
731}
test/behavior/usingnamespace.zig+40
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const expect = std.testing.expect;
23
34const A = struct {
45 pub const B = bool;
......@@ -11,3 +12,42 @@ const C = struct {
1112test "basic usingnamespace" {
1213 try std.testing.expect(C.B == bool);
1314}
15
16fn Foo(comptime T: type) type {
17 return struct {
18 usingnamespace T;
19 };
20}
21
22test "usingnamespace inside a generic struct" {
23 const std2 = Foo(std);
24 const testing2 = Foo(std.testing);
25 try std2.testing.expect(true);
26 try testing2.expect(true);
27}
28
29usingnamespace struct {
30 pub const foo = 42;
31};
32
33test "usingnamespace does not redeclare an imported variable" {
34 comptime try std.testing.expect(@This().foo == 42);
35}
36
37usingnamespace @import("usingnamespace/foo.zig");
38test "usingnamespace omits mixing in private functions" {
39 try expect(@This().privateFunction());
40 try expect(!@This().printText());
41}
42fn privateFunction() bool {
43 return true;
44}
45
46test {
47 _ = @import("usingnamespace/import_segregation.zig");
48}
49
50usingnamespace @import("usingnamespace/a.zig");
51test "two files usingnamespace import each other" {
52 try expect(@This().ok());
53}
test/behavior/usingnamespace_stage1.zig deleted-41
......@@ -1,41 +0,0 @@
1const std = @import("std");
2const expect = std.testing.expect;
3
4fn Foo(comptime T: type) type {
5 return struct {
6 usingnamespace T;
7 };
8}
9
10test "usingnamespace inside a generic struct" {
11 const std2 = Foo(std);
12 const testing2 = Foo(std.testing);
13 try std2.testing.expect(true);
14 try testing2.expect(true);
15}
16
17usingnamespace struct {
18 pub const foo = 42;
19};
20
21test "usingnamespace does not redeclare an imported variable" {
22 comptime try std.testing.expect(@This().foo == 42);
23}
24
25usingnamespace @import("usingnamespace/foo.zig");
26test "usingnamespace omits mixing in private functions" {
27 try expect(@This().privateFunction());
28 try expect(!@This().printText());
29}
30fn privateFunction() bool {
31 return true;
32}
33
34test {
35 _ = @import("usingnamespace/import_segregation.zig");
36}
37
38usingnamespace @import("usingnamespace/a.zig");
39test "two files usingnamespace import each other" {
40 try expect(@This().ok());
41}