Skip to content

Commit

Permalink
Fix broken namespace issue. #9
Browse files Browse the repository at this point in the history
  • Loading branch information
aw committed Feb 15, 2018
1 parent bffd3b2 commit 459da5a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
14 changes: 8 additions & 6 deletions json.l
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Copyright (c) 2017-2018 Alexander Williams, Unscramble <[email protected]>

(unless (= "false" (sys "PIL_NAMESPACES"))
(and symbols (not (= "false" (sys "PIL_NAMESPACES")))
(symbols 'json 'pico)

(local MODULE_INFO *Msg err-throw)
Expand Down Expand Up @@ -76,26 +76,28 @@
(err-throw (text "Invalid Object separator '@1', must be ':'", Separator) ]

# internal
[de link-generic (Type Bracket Iterator)
[de link-generic (Checker Linker Bracket Iterator)
(let Name (car *Json)
(when Name
((any (pack "json-" Type "-check")) Name)
(eval Checker)
(unless (= Bracket Name) (eval Iterator)) )

(if (= Bracket (car *Json))
(pop '*Json)
(when (= "," (car *Json))
(pop '*Json)
((any (pack "link-" Type))) ]
(eval Linker) ]

[de link-array (Make)
(when Make (link T))
(link-generic "array"
(link-generic '(json-array-check Name)
'(link-array)
"]"
'(link (iterate-object)) ]

[de link-object ()
(link-generic "object"
(link-generic '(json-object-check Name)
'(link-object)
"}"
'(link-object-value Name) ]

Expand Down
2 changes: 2 additions & 0 deletions test.l
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
(unless (= "false" (sys "PIL_NAMESPACES"))
(when symbols (symbols 'unit 'pico)) )

(when symbols (symbols 'json 'pico))

(load (pack (car (file)) ".modules/picolisp-unit/HEAD/unit.l"))

(chdir "test/"
Expand Down
3 changes: 0 additions & 3 deletions test/test_json.l
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

(prinl "^J Testing JSON encoder/decoder for PicoLisp^J")

(unless (= "false" (sys "PIL_NAMESPACES"))
(symbols 'json) )

(setq
*My_tests_are_order_dependent NIL
*Json_output '(("first" . "John")
Expand Down
10 changes: 9 additions & 1 deletion test/test_regressions.l
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,16 @@
(encode '(("test" . null)))
"Regression test GH issue #8 - Invalid encoding of null" ) ]

(unless symbols (from "######"))
[de test-gh-issue-9 ()
(assert-equal '(("Hello" . "World"))
(json~decode "{\"Hello\":\"World\"}")
"Regression test GH issue #9 - json~decode broken outside of 'json' namespace" ) ]
######

[execute
'(test-gh-issue-4)
'(test-gh-issue-5)
'(test-gh-issue-6)
'(test-gh-issue-8) ]
'(test-gh-issue-8)
(when symbols '(test-gh-issue-9) ]

0 comments on commit 459da5a

Please sign in to comment.