| 1 | struct MapRefShapes { |
| 2 | mut: |
| 3 | rectangles []MapRefRectangle |
| 4 | } |
| 5 | |
| 6 | struct MapRefRectangle { |
| 7 | mut: |
| 8 | id int |
| 9 | square bool |
| 10 | } |
| 11 | |
| 12 | fn (shapes MapRefShapes) get_squares() []&MapRefRectangle { |
| 13 | return shapes.rectangles.filter(it.square).filter(it.id > 0).map(&it) |
| 14 | } |
| 15 | |
| 16 | fn test_array_map_ref_it_after_filter_keeps_struct_fields() { |
| 17 | mut shapes := MapRefShapes{} |
| 18 | shapes.rectangles << MapRefRectangle{ |
| 19 | id: 1 |
| 20 | square: true |
| 21 | } |
| 22 | shapes.rectangles << MapRefRectangle{ |
| 23 | id: 2 |
| 24 | square: false |
| 25 | } |
| 26 | |
| 27 | squares := shapes.get_squares() |
| 28 | rendered := '${squares}' |
| 29 | |
| 30 | assert squares.len == 1 |
| 31 | assert squares[0].id == 1 |
| 32 | assert squares[0].square |
| 33 | assert rendered.contains('id: 1') |
| 34 | assert rendered.contains('square: true') |
| 35 | } |
| 36 | |