diff options
Diffstat (limited to 'v_windows/v/vlib/v/tests/map_assign_array_of_interface_test.v')
-rw-r--r-- | v_windows/v/vlib/v/tests/map_assign_array_of_interface_test.v | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/v_windows/v/vlib/v/tests/map_assign_array_of_interface_test.v b/v_windows/v/vlib/v/tests/map_assign_array_of_interface_test.v new file mode 100644 index 0000000..d04a789 --- /dev/null +++ b/v_windows/v/vlib/v/tests/map_assign_array_of_interface_test.v @@ -0,0 +1,40 @@ +interface Animal { + say(message string) ? +} + +struct Cat { + name string +} + +struct Dog { + name string +} + +pub fn (cat Cat) say(message string) ? { + println('$message, meow') +} + +pub fn (dog Dog) say(message string) ? { + println('$message, wooff') +} + +fn test_map_assign_array_of_interface() { + mut owner_and_animals := map[string][]Animal{} + + owner_and_animals = { + 'John Doe': [ + Cat{ + name: 'Bobby' + }, + Dog{ + name: 'Hulk' + }, + ] + } + println(owner_and_animals) + assert owner_and_animals['John Doe'].len == 2 + println(owner_and_animals['John Doe'][0]) + assert '${owner_and_animals['John Doe'][0]}'.contains("name: 'Bobby'") + println(owner_and_animals['John Doe'][1]) + assert '${owner_and_animals['John Doe'][1]}'.contains("name: 'Hulk'") +} |