diff --git a/json_serialization/types.nim b/json_serialization/types.nim index e44b905..841a6bb 100644 --- a/json_serialization/types.nim +++ b/json_serialization/types.nim @@ -1,5 +1,5 @@ # json-serialization -# Copyright (c) 2019-2023 Status Research & Development GmbH +# Copyright (c) 2019-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) @@ -152,7 +152,7 @@ func `==`*(lhs, rhs: JsonValueRef): bool = lhs.numVal == rhs.numVal of JsonValueKind.Object: if lhs.objVal.len != rhs.objVal.len: - return true + return false for k, v in lhs.objVal: let rhsVal = rhs.objVal.getOrDefault(k, nil) if rhsVal.isNil: diff --git a/tests/test_all.nim b/tests/test_all.nim index 07d0d6a..67e8229 100644 --- a/tests/test_all.nim +++ b/tests/test_all.nim @@ -1,5 +1,5 @@ # json-serialization -# Copyright (c) 2019-2023 Status Research & Development GmbH +# Copyright (c) 2019-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) @@ -17,4 +17,5 @@ import test_parser, test_line_col, test_reader, - test_writer + test_writer, + test_valueref diff --git a/tests/test_valueref.nim b/tests/test_valueref.nim new file mode 100644 index 0000000..516df85 --- /dev/null +++ b/tests/test_valueref.nim @@ -0,0 +1,43 @@ +# json-serialization +# Copyright (c) 2024 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) +# at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + +import + unittest2, + ../json_serialization + +func jsonBool(x: bool): JsonValueRef[uint64] = + JsonValueRef[uint64](kind: JsonValueKind.Bool, boolVal: x) + +suite "Test JsonValueRef": + test "Test table keys equality": + let a = JsonValueRef[uint64]( + kind: JsonValueKind.Object, + objVal: [ + ("a", jsonBool(true)), + ].toOrderedTable + ) + + let a2 = JsonValueRef[uint64]( + kind: JsonValueKind.Object, + objVal: [ + ("a", jsonBool(true)), + ].toOrderedTable + ) + + let b = JsonValueRef[uint64]( + kind: JsonValueKind.Object, + objVal: [ + ("a", jsonBool(true)), + ("b", jsonBool(true)) + ].toOrderedTable + ) + + check a != b + check a == a2 +