aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/vlib/v/tests/interfaces_map_test.v
blob: 6a21aad9f3e02a04dc617985103874a803ad4699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module main

interface Speaker {
	say() string
}

fn test_todo() {}

/*
// QTODO
struct ChatRoom {
mut:
	talkers map[string]Speaker
}

fn new_room() &ChatRoom {
	return &ChatRoom{
		talkers: map[string]Speaker
	}
}

fn (mut r ChatRoom) add(name string, s Speaker) {
	r.talkers[name] = s
}

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'} )
	mut text := ''
	for name, subject in room.talkers {
		line := '${name:12s}: ${subject.say()}'
		println(line)
		text += line
	}
	assert text.contains(' meows ')
	assert text.contains(' barks ')
	assert text.contains(' says ')
}

//

struct Cat { name string }
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 Human { name string }
fn (h &Human) say() string { return '${h.name} says "Hello"' }
*/