Fix JsonValueRef.Object comparison
This commit is contained in:
parent
56c788bb25
commit
7516a92eb8
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue