| 1 | // End-to-end test for v2's conditional struct field parsing. |
| 2 | // Exercises `$if cond { ... }` / `$else $if` / `$else` blocks and the |
| 3 | // per-field `@[if cond ?]` attribute. Compiled and run via the v2 binary. |
| 4 | |
| 5 | module main |
| 6 | |
| 7 | struct Container { |
| 8 | name string |
| 9 | $if !no_log ? { |
| 10 | logger string = 'default' |
| 11 | } |
| 12 | always int = 42 |
| 13 | $if my_feature ? { |
| 14 | feature_val string = 'on' |
| 15 | } $else { |
| 16 | feature_val string = 'off' |
| 17 | } |
| 18 | dev_menu string = 'dev' @[if !no_dev_menu ?] |
| 19 | never_built string = 'nope' @[if absent_flag ?] |
| 20 | } |
| 21 | |
| 22 | fn main() { |
| 23 | c := Container{ |
| 24 | name: 'app' |
| 25 | } |
| 26 | assert c.name == 'app' |
| 27 | assert c.logger == 'default' |
| 28 | assert c.always == 42 |
| 29 | // `my_feature` is not defined → `$else` branch contributes the field. |
| 30 | assert c.feature_val == 'off' |
| 31 | // `no_dev_menu` is not defined → `!no_dev_menu` is true → field kept. |
| 32 | assert c.dev_menu == 'dev' |
| 33 | println('conditional_struct_field_test PASS') |
| 34 | } |
| 35 | |