2017-01-05 00:57:48 -08:00
|
|
|
const assert = @import("std").debug.assert;
|
|
|
|
|
2016-12-22 06:35:07 -08:00
|
|
|
const Node = struct {
|
2016-09-25 10:39:46 -07:00
|
|
|
payload: i32,
|
|
|
|
children: []Node,
|
2016-12-22 06:35:07 -08:00
|
|
|
};
|
2016-09-25 10:39:46 -07:00
|
|
|
|
|
|
|
fn structContainsSliceOfItself() {
|
2016-12-22 06:35:07 -08:00
|
|
|
@setFnTest(this);
|
2016-09-27 23:33:32 -07:00
|
|
|
|
2016-09-25 10:39:46 -07:00
|
|
|
var nodes = []Node {
|
|
|
|
Node {
|
|
|
|
.payload = 1,
|
|
|
|
.children = []Node{},
|
|
|
|
},
|
|
|
|
Node {
|
|
|
|
.payload = 2,
|
|
|
|
.children = []Node{},
|
|
|
|
},
|
|
|
|
Node {
|
|
|
|
.payload = 3,
|
2017-02-12 14:22:35 -08:00
|
|
|
.children = ([]Node{
|
2016-09-25 10:39:46 -07:00
|
|
|
Node {
|
|
|
|
.payload = 31,
|
|
|
|
.children = []Node{},
|
|
|
|
},
|
|
|
|
Node {
|
|
|
|
.payload = 32,
|
|
|
|
.children = []Node{},
|
|
|
|
},
|
2017-02-12 14:22:35 -08:00
|
|
|
})[0...],
|
2016-09-25 10:39:46 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
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);
|
|
|
|
}
|