| ... | @@ -5,6 +5,11 @@ const Node = struct { | ... | @@ -5,6 +5,11 @@ const Node = struct { |
| 5 | children: []Node, | 5 | children: []Node, |
| 6 | }; | 6 | }; |
| 7 | | 7 | |
| | 8 | const NodeAligned = struct { |
| | 9 | payload: i32, |
| | 10 | children: []align(@alignOf(NodeAligned)) NodeAligned, |
| | 11 | }; |
| | 12 | |
| 8 | test "struct contains slice of itself" { | 13 | test "struct contains slice of itself" { |
| 9 | var other_nodes = []Node{ | 14 | var other_nodes = []Node{ |
| 10 | Node{ | 15 | Node{ |
| ... | @@ -41,3 +46,40 @@ test "struct contains slice of itself" { | ... | @@ -41,3 +46,40 @@ test "struct contains slice of itself" { |
| 41 | assert(root.children[2].children[0].payload == 31); | 46 | assert(root.children[2].children[0].payload == 31); |
| 42 | assert(root.children[2].children[1].payload == 32); | 47 | assert(root.children[2].children[1].payload == 32); |
| 43 | } | 48 | } |
| | 49 | |
| | 50 | test "struct contains aligned slice of itself" { |
| | 51 | var other_nodes = []NodeAligned{ |
| | 52 | NodeAligned{ |
| | 53 | .payload = 31, |
| | 54 | .children = []NodeAligned{}, |
| | 55 | }, |
| | 56 | NodeAligned{ |
| | 57 | .payload = 32, |
| | 58 | .children = []NodeAligned{}, |
| | 59 | }, |
| | 60 | }; |
| | 61 | var nodes = []NodeAligned{ |
| | 62 | NodeAligned{ |
| | 63 | .payload = 1, |
| | 64 | .children = []NodeAligned{}, |
| | 65 | }, |
| | 66 | NodeAligned{ |
| | 67 | .payload = 2, |
| | 68 | .children = []NodeAligned{}, |
| | 69 | }, |
| | 70 | NodeAligned{ |
| | 71 | .payload = 3, |
| | 72 | .children = other_nodes[0..], |
| | 73 | }, |
| | 74 | }; |
| | 75 | const root = NodeAligned{ |
| | 76 | .payload = 1234, |
| | 77 | .children = nodes[0..], |
| | 78 | }; |
| | 79 | assert(root.payload == 1234); |
| | 80 | assert(root.children[0].payload == 1); |
| | 81 | assert(root.children[1].payload == 2); |
| | 82 | assert(root.children[2].payload == 3); |
| | 83 | assert(root.children[2].children[0].payload == 31); |
| | 84 | assert(root.children[2].children[1].payload == 32); |
| | 85 | } |