v/vlib/builtin/map_test.v

36 lines
578 B
Go
Raw Normal View History

struct User {
name string
}
2019-06-30 13:44:08 +02:00
struct A {
m map[string]int
users map[string]User
2019-06-30 13:44:08 +02:00
}
fn (a mut A) set(key string, val int) {
a.m[key] = val
}
fn test_map() {
mut m := map[string]int{}
m['hi'] = 80
assert m['hi'] == 80
////
mut users := map[string]User{}
users['1'] = User{'Peter'}
peter := users['1']
assert peter.name == 'Peter'
2019-06-30 13:44:08 +02:00
mut a := A{
m: map[string]int{}
users: map[string]User{}
2019-06-30 13:44:08 +02:00
}
a.users['Bob'] = User{'Bob'}
q := a.users['Bob']
assert q.name == 'Bob'
2019-06-30 13:44:08 +02:00
a.m['one'] = 1
a.set('two', 2)
assert a.m['one'] == 1
assert a.m['two'] == 2
}