diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-09-25 13:39:46 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-09-25 13:39:46 -0400 |
| commit | 683da0e4ecd336f9a74098d49d5748bdc1ed2f70 (patch) | |
| tree | fa16c8486981f6d8497c0eca319c3fcdb5bf75fa /test | |
| parent | e06885d64e3569719e9479c7069da7ad426a70d3 (diff) | |
| download | zig-683da0e4ecd336f9a74098d49d5748bdc1ed2f70.tar.gz zig-683da0e4ecd336f9a74098d49d5748bdc1ed2f70.zip | |
ability to have struct to have a field which is slice of itself
closes #197
Diffstat (limited to 'test')
| -rw-r--r-- | test/cases/struct_contains_slice_of_itself.zig | 43 | ||||
| -rw-r--r-- | test/self_hosted.zig | 1 |
2 files changed, 44 insertions, 0 deletions
diff --git a/test/cases/struct_contains_slice_of_itself.zig b/test/cases/struct_contains_slice_of_itself.zig new file mode 100644 index 0000000000..24b5c92116 --- /dev/null +++ b/test/cases/struct_contains_slice_of_itself.zig @@ -0,0 +1,43 @@ +const assert = @import("std").debug.assert; + +struct Node { + payload: i32, + children: []Node, +} + +#attribute("test") +fn structContainsSliceOfItself() { + var nodes = []Node { + Node { + .payload = 1, + .children = []Node{}, + }, + Node { + .payload = 2, + .children = []Node{}, + }, + Node { + .payload = 3, + .children = []Node{ + Node { + .payload = 31, + .children = []Node{}, + }, + Node { + .payload = 32, + .children = []Node{}, + }, + }, + }, + }; + const root = Node { + .payload = 1234, + .children = nodes[0...], + }; + assert(root.payload == 1234); + assert(root.children[0].payload == 1); + assert(root.children[1].payload == 2); + assert(root.children[2].payload == 3); + assert(root.children[2].children[0].payload == 31); + assert(root.children[2].children[1].payload == 32); +} diff --git a/test/self_hosted.zig b/test/self_hosted.zig index 80920758a4..62be85c64f 100644 --- a/test/self_hosted.zig +++ b/test/self_hosted.zig @@ -14,6 +14,7 @@ const test_const_slice_child = @import("cases/const_slice_child.zig"); const test_switch_prong_implicit_cast = @import("cases/switch_prong_implicit_cast.zig"); const test_switch_prong_err_enum = @import("cases/switch_prong_err_enum.zig"); const test_enum_with_members = @import("cases/enum_with_members.zig"); +const test_struct_contains_slice_of_itself = @import("cases/struct_contains_slice_of_itself.zig"); // normal comment /// this is a documentation comment |
