aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/v/tests/map_assign_array_of_interface_test.v
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/v/tests/map_assign_array_of_interface_test.v
downloadcli-tools-windows-master.tar.gz
cli-tools-windows-master.tar.bz2
cli-tools-windows-master.zip
Adds most of the toolsHEADmaster
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.v40
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'")
+}