mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tests: restore interfaces_map_test (#15019)
This commit is contained in:
@@ -4,10 +4,6 @@ interface Speaker {
|
|||||||
say() string
|
say() string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_todo() {}
|
|
||||||
|
|
||||||
/*
|
|
||||||
// QTODO
|
|
||||||
struct ChatRoom {
|
struct ChatRoom {
|
||||||
mut:
|
mut:
|
||||||
talkers map[string]Speaker
|
talkers map[string]Speaker
|
||||||
@@ -15,7 +11,7 @@ mut:
|
|||||||
|
|
||||||
fn new_room() &ChatRoom {
|
fn new_room() &ChatRoom {
|
||||||
return &ChatRoom{
|
return &ChatRoom{
|
||||||
talkers: map[string]Speaker
|
talkers: map[string]Speaker{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +28,7 @@ fn test_using_a_map_of_speaker_interfaces() {
|
|||||||
room.add('she', Human{ name: 'Maria' })
|
room.add('she', Human{ name: 'Maria' })
|
||||||
mut text := ''
|
mut text := ''
|
||||||
for name, subject in room.talkers {
|
for name, subject in room.talkers {
|
||||||
line := '${name:12s}: ${subject.say()}'
|
line := '${name:12s}: $subject.say()'
|
||||||
println(line)
|
println(line)
|
||||||
text += line
|
text += line
|
||||||
}
|
}
|
||||||
@@ -41,14 +37,26 @@ fn test_using_a_map_of_speaker_interfaces() {
|
|||||||
assert text.contains(' says ')
|
assert text.contains(' says ')
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
struct Cat {
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
struct Cat { name string }
|
fn (c &Cat) say() string {
|
||||||
fn (c &Cat) say() string { return '${c.name} meows "MEOW!"' }
|
return '$c.name meows "MEOW!"'
|
||||||
|
}
|
||||||
|
|
||||||
struct Dog { name string }
|
struct Dog {
|
||||||
fn (d &Dog) say() string { return '${d.name} barks "Bau Bau!"' }
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
struct Human { name string }
|
fn (d &Dog) say() string {
|
||||||
fn (h &Human) say() string { return '${h.name} says "Hello"' }
|
return '$d.name barks "Bau Bau!"'
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
struct Human {
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (h &Human) say() string {
|
||||||
|
return '$h.name says "Hello"'
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user