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

v2: fixes for most of vlib/builtin/map_test.v .

This commit is contained in:
Delyan Angelov 2020-04-03 00:42:08 +03:00
parent 07c53b1b70
commit 6b9bf8cbf7
5 changed files with 19 additions and 8 deletions

View File

@ -73,8 +73,8 @@ fn test_string_map() {
fn test_large_map() {
//ticks := time.ticks()
mut nums := map[string]int
N := 30 * 1000
for i in 0..N {
n := 30 * 1000
for i in 0..n {
key := i.str()
nums[key] = i
}
@ -166,7 +166,8 @@ fn mut_map(m mut map[string]int) {
fn test_mut_arg() {
mut m := map[string]int
mut_map(mut m)
assert m['a'] == 10
a := m['a']
assert a == 10
}
fn test_delete() {
@ -175,8 +176,8 @@ fn test_delete() {
m['two'] = 2
println(m['two']) // => "2"
m.delete('two')
println(m['two']) // => 0
assert 'two' in m == false
println(m['two'].str()) // => 0
assert ('two' in m) == false
println('two' in m) // => true, on Linux and Windows <-- wrong !
}
@ -205,4 +206,3 @@ fn test_delete_size() {
}
}
}

View File

@ -337,6 +337,7 @@ pub:
index Expr // [0], [start..end] etc
mut:
container_type table.Type // array, map, fixed array
is_setter bool
}
pub struct IfExpr {

View File

@ -77,6 +77,9 @@ pub fn (x Expr) str() string {
ParExpr {
return it.expr.str()
}
IndexExpr {
return '${it.left.str()}[${it.index.str()}]'
}
else {
return '[unhandled expr type ${typeof(x)}]'
}

View File

@ -1681,8 +1681,8 @@ fn (g mut Gen) index_expr(node ast.IndexExpr) {
is_selector = true
}
else {}
}
if g.is_assign_lhs && !is_selector {
}
if g.is_assign_lhs && !is_selector && node.is_setter {
g.is_array_set = true
g.write('array_set(&')
g.expr(node.left)

View File

@ -436,6 +436,13 @@ pub fn (p mut Parser) assign_expr(left ast.Expr) ast.AssignExpr {
op := p.tok.kind
p.next()
val := p.expr(0)
match left {
ast.IndexExpr {
//it.mark_as_setter()
it.is_setter = true
}
else{}
}
node := ast.AssignExpr{
left: left
val: val