1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/builtin/map_test.v

36 lines
578 B
Go
Raw Normal View History

struct User {
name string
}
2019-06-30 14:44:08 +03:00
struct A {
m map[string]int
users map[string]User
2019-06-30 14:44:08 +03: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 14:44:08 +03:00
mut a := A{
m: map[string]int{}
users: map[string]User{}
2019-06-30 14:44:08 +03:00
}
a.users['Bob'] = User{'Bob'}
q := a.users['Bob']
assert q.name == 'Bob'
2019-06-30 14:44:08 +03:00
a.m['one'] = 1
a.set('two', 2)
assert a.m['one'] == 1
assert a.m['two'] == 2
}