Skip to content

Commit

Permalink
Merge pull request #137 from Peefy/refactor-jsonpatch-module-tests
Browse files Browse the repository at this point in the history
refactor: jsonpatch module test and bump version to 0.0.3
  • Loading branch information
Peefy authored May 17, 2024
2 parents 4124a1f + fc2e114 commit 7678be8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion jsonpatch/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
kcl -D __test__
kcl 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.2"
version = "0.0.3"
description = "`jsonpatch` is a module for applying JSON patches (RFC 6902) for KCL values."

33 changes: 3 additions & 30 deletions jsonpatch/main.k
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ set_obj = lambda obj: any, path: str, value: any -> any {
obj | _build_patch_obj_n(obj, value, path.lstrip('/').split('/'), 0)
}

apply_patch = lambda obj: any, patch: Patch {
_apply_patch = lambda obj: any, patch: Patch {
dst = obj
if patch.op == "add":
assert False
Expand All @@ -106,41 +106,14 @@ apply_patch = lambda obj: any, patch: Patch {
dst
}

apply_patchs = lambda obj: any, patch: JsonPatch -> any {
_apply_patchs = lambda obj: any, patch: JsonPatch -> any {
"""Apply list of patches to specified json document."""
assert False, "TODO: PRs welcome"
{}
}

make_patch = lambda src: any, dst: any -> JsonPatch {
_make_patch = lambda src: any, dst: any -> JsonPatch {
"""Generates patch by comparing two document objects."""
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"
27 changes: 27 additions & 0 deletions jsonpatch/main_test.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
test_json_patch = lambda {
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 7678be8

Please sign in to comment.