| 1 | struct Dog { |
| 2 | breed string |
| 3 | } |
| 4 | |
| 5 | struct Cat { |
| 6 | breed string |
| 7 | } |
| 8 | |
| 9 | interface Animal { |
| 10 | breed string |
| 11 | } |
| 12 | |
| 13 | fn test_auto_str_gen_for_interfaces() { |
| 14 | x := Animal(Cat{'Siamese'}) |
| 15 | assert '${x}' == " |
| 16 | Animal(Cat{ |
| 17 | breed: 'Siamese' |
| 18 | }) |
| 19 | ".trim_space() |
| 20 | } |
| 21 | |
| 22 | struct Holder { |
| 23 | x Animal |
| 24 | } |
| 25 | |
| 26 | struct Holder2 { |
| 27 | x map[string]Holder |
| 28 | breed string |
| 29 | } |
| 30 | |
| 31 | fn test_auto_str_gen_for_complex_interface_types() { |
| 32 | a := Animal(Dog{'hi'}) |
| 33 | h := Holder{a} |
| 34 | m := { |
| 35 | 'dsa': h |
| 36 | } |
| 37 | h2 := Holder2{m, 'N/A'} |
| 38 | a2 := Animal(h2) |
| 39 | |
| 40 | assert '${a2}' == r" |
| 41 | Animal(Holder2{ |
| 42 | x: {'dsa': Holder{ |
| 43 | x: Animal(Dog{ |
| 44 | breed: 'hi' |
| 45 | }) |
| 46 | }} |
| 47 | breed: 'N/A' |
| 48 | }) |
| 49 | ".trim_space() |
| 50 | } |
| 51 |