From 81d694b1f8c76227b89c5464a95b19ac58b9c0a9 Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 11 Jul 2022 14:05:36 +0800 Subject: [PATCH] tests: restore interfaces_map_test (#15019) --- vlib/v/tests/interfaces_map_test.v | 46 ++++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/vlib/v/tests/interfaces_map_test.v b/vlib/v/tests/interfaces_map_test.v index 6a21aad9f3..dfeb41b694 100644 --- a/vlib/v/tests/interfaces_map_test.v +++ b/vlib/v/tests/interfaces_map_test.v @@ -4,10 +4,6 @@ interface Speaker { say() string } -fn test_todo() {} - -/* -// QTODO struct ChatRoom { mut: talkers map[string]Speaker @@ -15,7 +11,7 @@ mut: fn new_room() &ChatRoom { return &ChatRoom{ - talkers: map[string]Speaker + talkers: map[string]Speaker{} } } @@ -25,14 +21,14 @@ fn (mut r ChatRoom) add(name string, s Speaker) { fn test_using_a_map_of_speaker_interfaces() { mut room := new_room() - room.add('my cat', Cat{name: 'Tigga'} ) - room.add('my dog', Dog{name: 'Pirin'} ) - room.add('stray dog', Dog{name: 'Anoni'} ) - room.add('me', Human{name: 'Bilbo'} ) - room.add('she', Human{name: 'Maria'} ) + room.add('my cat', Cat{ name: 'Tigga' }) + room.add('my dog', Dog{ name: 'Pirin' }) + room.add('stray dog', Dog{ name: 'Anoni' }) + room.add('me', Human{ name: 'Bilbo' }) + room.add('she', Human{ name: 'Maria' }) mut text := '' for name, subject in room.talkers { - line := '${name:12s}: ${subject.say()}' + line := '${name:12s}: $subject.say()' println(line) text += line } @@ -41,14 +37,26 @@ fn test_using_a_map_of_speaker_interfaces() { assert text.contains(' says ') } -// +struct Cat { + name string +} -struct Cat { name string } -fn (c &Cat) say() string { return '${c.name} meows "MEOW!"' } +fn (c &Cat) say() string { + return '$c.name meows "MEOW!"' +} -struct Dog { name string } -fn (d &Dog) say() string { return '${d.name} barks "Bau Bau!"' } +struct Dog { + name string +} -struct Human { name string } -fn (h &Human) say() string { return '${h.name} says "Hello"' } -*/ +fn (d &Dog) say() string { + return '$d.name barks "Bau Bau!"' +} + +struct Human { + name string +} + +fn (h &Human) say() string { + return '$h.name says "Hello"' +}