Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JsonValueRef.Object comparison #88

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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