zig/test/cases/struct_contains_slice_of_it...

44 lines
1019 B
Zig
Raw Normal View History

2017-01-05 00:57:48 -08:00
const assert = @import("std").debug.assert;
const Node = struct {
payload: i32,
children: []Node,
};
test "struct contains slice of itself" {
2018-05-28 17:23:55 -07:00
var other_nodes = []Node{
Node{
.payload = 31,
.children = []Node{},
},
2018-05-28 17:23:55 -07:00
Node{
.payload = 32,
.children = []Node{},
},
};
2018-05-28 17:23:55 -07:00
var nodes = []Node{
Node{
.payload = 1,
.children = []Node{},
},
2018-05-28 17:23:55 -07:00
Node{
.payload = 2,
.children = []Node{},
},
2018-05-28 17:23:55 -07:00
Node{
.payload = 3,
.children = other_nodes[0..],
},
};
2018-05-28 17:23:55 -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);
}