takeFuzzyJson
This commit is contained in:
@@ -16,13 +16,18 @@
|
||||
(_loadFuzzyJson (eval key) (eval file))
|
||||
`{})
|
||||
|
||||
(defMacroFunction _getFuzzyJson [whichJson key]
|
||||
(defMacroFunction _getFuzzyJson [whichJson key take]
|
||||
(let [json (dictGet fuzzyJsons whichJson)
|
||||
bm (FuzzyMapTools.bestMatch json key)]
|
||||
(dictGet json bm)))
|
||||
bm (FuzzyMapTools.bestMatch json key)
|
||||
val (dictGet json bm)]
|
||||
(when take (json.remove bm))
|
||||
val))
|
||||
|
||||
(defMacro getFuzzyJson [whichJson key &builder b]
|
||||
(let [value (_getFuzzyJson (eval whichJson) (eval key))]
|
||||
(defMacro getFuzzyJson [whichJson key &opt take &builder b]
|
||||
(let [value (_getFuzzyJson (eval whichJson) (eval key) take)]
|
||||
(if !(= null value)
|
||||
`(haxe.Json.parse ,(Json.stringify value))
|
||||
`(throw (+ ,key " has a duplicate definition between multiple files of fuzzy json " ,whichJson)))))
|
||||
(throw (+ (eval key) " has a duplicate definition between multiple files of fuzzy json " (eval whichJson))))))
|
||||
|
||||
(defMacro takeFuzzyJson [whichJson key]
|
||||
`(getFuzzyJson ,whichJson ,key true))
|
@@ -5,5 +5,9 @@
|
||||
(loadFuzzyJson "dogs" "test/fuzzy2.json")
|
||||
|
||||
(assert (= "is a very good dog" (getFuzzyJson "dogs" "Albort")))
|
||||
// duplicate definitions throw an error
|
||||
(assertThrows (getFuzzyJson "dogs" "Rangie"))
|
||||
// takeFuzzyJson removes the match to make following fuzzyJson retrievals save time:
|
||||
(assert (= "is a very good dog" (takeFuzzyJson "dogs" "Albort")))
|
||||
// No good match will cause crash at compile time:
|
||||
(assertThrowsAtCompileTime (getFuzzyJson "dogs" "Albort"))
|
||||
// duplicate definitions throw an error at compile time:
|
||||
(assertThrowsAtCompileTime (getFuzzyJson "dogs" "Rangie"))
|
Reference in New Issue
Block a user