Skip to content

Commit

Permalink
gen_map_equality_fn, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ntrel committed Dec 18, 2020
1 parent bc6cb4b commit 76fb6d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 5 additions & 5 deletions vlib/v/gen/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -4549,14 +4549,14 @@ fn (mut g Gen) gen_map_equality_fn(left table.Type) string {
g.definitions.write(', ')
}
}
g.definitions.writeln(') = (*(voidptr*)map_get(a, k, &(voidptr[]){ 0 }));')
g.definitions.writeln(') = (*(voidptr*)map_get_1(&a, &k, &(voidptr[]){ 0 }));')
} else {
g.definitions.writeln('\t\t$value_typ v = (*($value_typ*)map_get(a, k, &($value_typ[]){ 0 }));')
g.definitions.writeln('\t\t$value_typ v = (*($value_typ*)map_get_1(&a, &k, &($value_typ[]){ 0 }));')
}
match value_sym.kind {
.string { g.definitions.writeln('\t\tif (!map_exists(b, k) || string_ne((*($value_typ*)map_get(b, k, &($value_typ[]){_SLIT("")})), v)) {') }
.function { g.definitions.writeln('\t\tif (!map_exists(b, k) || (*(voidptr*)map_get(b, k, &(voidptr[]){ 0 })) != v) {') }
else { g.definitions.writeln('\t\tif (!map_exists(b, k) || (*($value_typ*)map_get(b, k, &($value_typ[]){ 0 })) != v) {') }
.string { g.definitions.writeln('\t\tif (!map_exists(b, k) || string_ne((*(string*)map_get_1(&b, &k, &(string[]){_SLIT("")})), v)) {') }
.function { g.definitions.writeln('\t\tif (!map_exists(b, k) || (*(voidptr*)map_get_1(&b, &k, &(voidptr[]){ 0 })) != v) {') }
else { g.definitions.writeln('\t\tif (!map_exists(b, k) || (*($value_typ*)map_get_1(&b, &k, &($value_typ[]){ 0 })) != v) {') }
}
g.definitions.writeln('\t\t\treturn false;')
g.definitions.writeln('\t\t}')
Expand Down
9 changes: 9 additions & 0 deletions vlib/v/tests/maps_equal_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn test_string_int() {
mut m := {'hi':4}
m2:= {'hi':5}
assert m != m2
m['hi']++
assert m == m2
m.delete('hi')
assert m != m2
}

0 comments on commit 76fb6d8

Please sign in to comment.