| 1 | enum Test { |
| 2 | foo |
| 3 | bar |
| 4 | } |
| 5 | |
| 6 | fn test_print_value_name() { |
| 7 | $for value in Test.values { |
| 8 | println(value.name) |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | fn test_print_value_value() { |
| 13 | $for value in Test.values { |
| 14 | println(value.value) |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | fn test_print_both() { |
| 19 | $for values in Test.values { |
| 20 | println(values.name) |
| 21 | println(values.value) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | fn test_comptime_for_in_enum_values() { |
| 26 | $for item in Test.values { |
| 27 | assert item.name in ['foo', 'bar'] |
| 28 | match item.value { |
| 29 | .foo { |
| 30 | println('foo>> item: ${item.name}') |
| 31 | assert item.value == .foo |
| 32 | } |
| 33 | .bar { |
| 34 | println('foo>> item: ${item.name}') |
| 35 | assert item.value == .bar |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | if item.value == .foo { |
| 40 | println('foo>> item: ${item.name}') |
| 41 | assert item.value == .foo |
| 42 | } else if item.value == .bar { |
| 43 | println('foo>> item: ${item.name}') |
| 44 | assert item.value == .bar |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |