2020-10-02 13:06:02 +02:00
|
|
|
enum MyEnum {
|
2020-04-12 12:35:54 +02:00
|
|
|
first = 20
|
|
|
|
second
|
|
|
|
third
|
|
|
|
}
|
|
|
|
|
2020-10-02 13:06:02 +02:00
|
|
|
struct MyStruct {
|
2020-04-12 12:35:54 +02:00
|
|
|
mut:
|
|
|
|
e MyEnum = .second
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_enum_first_value() {
|
|
|
|
assert MyEnum.first == 20
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_enum_default_value() {
|
|
|
|
d := MyStruct{}
|
|
|
|
assert int(d.e) == 21
|
|
|
|
assert 'd.e: $d.e | int(d.e): ${int(d.e).str()}' == 'd.e: second | int(d.e): 21'
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_enum_non_default_value() {
|
|
|
|
t := MyStruct{
|
|
|
|
e: .third
|
|
|
|
}
|
|
|
|
assert int(t.e) == 22
|
|
|
|
assert 't.e: $t.e | int(t.e): ${int(t.e).str()}' == 't.e: third | int(t.e): 22'
|
|
|
|
}
|
2020-04-21 12:26:46 +02:00
|
|
|
|
|
|
|
fn test_generation_of_string_interpolation_method_for_pointer_to_struct_containing_enum_fields(){
|
|
|
|
t := &MyStruct{
|
|
|
|
e: .third
|
|
|
|
}
|
2020-10-02 13:06:02 +02:00
|
|
|
assert 't: $t' == 't: &MyStruct{\n e: third\n}'
|
2020-04-21 12:26:46 +02:00
|
|
|
}
|