Skip to content

Commit

Permalink
Fix JsonValueRef.Object comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Feb 29, 2024
1 parent 56c788b commit 7516a92
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
4 changes: 2 additions & 2 deletions json_serialization/types.nim
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_all.nim
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -17,4 +17,5 @@ import
test_parser,
test_line_col,
test_reader,
test_writer
test_writer,
test_valueref
43 changes: 43 additions & 0 deletions tests/test_valueref.nim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7516a92

Please sign in to comment.