zig/test/cases/struct_contains_slice_of_itself.zig
Andrew Kelley b581da41f8 remove compiler directives
* add `setFnTest`, `setFnVisible`, `setFnStaticEval`,
   `setFnNoInline` builtin functions to replace previous
   directive functionality
 * add `coldcc` and `nakedcc` as keywords which can be used as part
   of a function prototype.
 * `setDebugSafety` builtin can be used to set debug safety features
   at a per block scope level.
 * closes #169
2016-09-28 02:33:32 -04:00

45 lines
1.0 KiB
Zig

const assert = @import("std").debug.assert;
struct Node {
payload: i32,
children: []Node,
}
fn structContainsSliceOfItself() {
@setFnTest(this, true);
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);
}