| 1 | enum MyEnum { |
| 2 | first = 20 |
| 3 | second |
| 4 | third |
| 5 | } |
| 6 | |
| 7 | struct MyStruct { |
| 8 | mut: |
| 9 | e MyEnum = .second |
| 10 | } |
| 11 | |
| 12 | fn test_enum_first_value() { |
| 13 | assert MyEnum.first == unsafe { MyEnum(20) } |
| 14 | } |
| 15 | |
| 16 | fn test_enum_default_value() { |
| 17 | d := MyStruct{} |
| 18 | assert int(d.e) == 21 |
| 19 | assert 'd.e: ${d.e} | int(d.e): ${int(d.e).str()}' == 'd.e: second | int(d.e): 21' |
| 20 | } |
| 21 | |
| 22 | fn test_enum_non_default_value() { |
| 23 | t := MyStruct{ |
| 24 | e: .third |
| 25 | } |
| 26 | assert int(t.e) == 22 |
| 27 | assert 't.e: ${t.e} | int(t.e): ${int(t.e).str()}' == 't.e: third | int(t.e): 22' |
| 28 | } |
| 29 | |
| 30 | fn test_generation_of_string_interpolation_method_for_pointer_to_struct_containing_enum_fields() { |
| 31 | t := &MyStruct{ |
| 32 | e: .third |
| 33 | } |
| 34 | assert 't: ${t}' == 't: &MyStruct{\n e: third\n}' |
| 35 | } |
| 36 | |