Fix JsonValueRef.Object comparison

This commit is contained in:
jangko 2024-02-29 13:58:51 +07:00
parent 56c788bb25
commit 7516a92eb8
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
3 changed files with 48 additions and 4 deletions

View File

@ -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:

View File

@ -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

43
tests/test_valueref.nim Normal file
View File

@ -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