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

Add support for null literal in jsonian-path #29

Merged
merged 1 commit into from
Jul 5, 2022
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
7 changes: 7 additions & 0 deletions jsonian-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ We test that all lines are unchanged"
'("fizz" 4 "some")))
(should (= (point) (point-min)))))

(ert-deftest jsonian-path-with-null ()
(with-file-and-point "path-with-null" (point-min)
(should (equal
(jsonian-path nil 19)
'("b")))
(should (= (point) (point-min)))))

(ert-deftest jsonian-simple-segment ()
"Check that we correctly identify simple segments."
(mapc
Expand Down
3 changes: 3 additions & 0 deletions jsonian.el
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ Otherwise it will parse back to the beginning of the file."
(jsonian--backward-true))
;; Boolean literal: false
((eq (char-before) ?e) (jsonian--backward-false))
;; null literal
((eq (char-before) ?l) (jsonian--backward-null))
((bobp) (cl-return nil))
(t (user-error "`jsonian--path': Unexpected character '%s'" (if (bobp) "BOB" (format "%c" (char-before)))))))))

Expand Down Expand Up @@ -420,6 +422,7 @@ and ARG2."

(jsonian--defun-traverse "true")
(jsonian--defun-traverse "false")
(jsonian--defun-traverse "null")

(jsonian--defun-traverse whitespace (x)
(or (= x ?\ )
Expand Down
4 changes: 4 additions & 0 deletions test-assets/path-with-null.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"a": null,
"b": true
}