Skip to content

Commit

Permalink
test: add unit tests for the jsonpatch module
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Nov 9, 2023
1 parent f5bd3e6 commit 0b31291
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions jsonpatch/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
kcl -D __test__
2 changes: 1 addition & 1 deletion jsonpatch/kcl.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "jsonpatch"
version = "0.0.1"
version = "0.0.2"
description = "`jsonpatch` is a module for applying JSON patches (RFC 6902) for KCL values."

27 changes: 27 additions & 0 deletions jsonpatch/main.k
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,30 @@ make_patch = lambda src: any, dst: any -> JsonPatch {
assert False, "TODO: PRs welcome"
[]
}

if option("__test__"):
data = {
"firstName": "John",
"lastName": "Doe",
"age": 30,
"address": {
"streetAddress": "1234 Main St",
"city": "New York",
"state": "NY",
"postalCode": "10001"
},
"phoneNumbers": [
{
"type": "home",
"number": "212-555-1234"
},
{
"type": "work",
"number": "646-555-5678"
}
]
}
phoneNumbers0type: str = get_obj(data, "phoneNumbers/0/type")
newObj = set_obj(data, "phoneNumbers/0/type", "school")
assert phoneNumbers0type == "home"
assert newObj["phoneNumbers"][0]["type"] == "school"

0 comments on commit 0b31291

Please sign in to comment.