JsonMap and JsonableArray

This commit is contained in:
2023-03-28 03:47:37 -06:00
parent 12db1cffd6
commit b32ffe7ec9
13 changed files with 134 additions and 18 deletions

13
src/test/Main.hx Normal file
View File

@@ -0,0 +1,13 @@
package test;
import kiss.Kiss;
import kiss.Prelude;
import kiss.List;
import sys.io.File;
import sys.FileSystem;
import kiss_tools.JsonMap;
import kiss_tools.JsonableArray;
@:build(kiss.Kiss.build())
class Main {}

38
src/test/Main.kiss Normal file
View File

@@ -0,0 +1,38 @@
// Test FuzzyJson
(loadFrom "kiss-tools" "src/kiss_tools/FuzzyJson.kiss")
(loadFuzzyJson "dogs" "test/fuzzy.json")
(loadFuzzyJson "dogs" "test/fuzzy2.json")
(assert (= "is a very good dog" (getFuzzyJson "dogs" "Albort")))
// 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"))
// Test JsonMap<JsonableArray>
(var TEST_JSON_FILE "testJsonFile.json")
(File.saveContent TEST_JSON_FILE (File.getContent "test/map-start.json"))
(let [jsonMap (new JsonMap<JsonableArray<TestJsonable>> TEST_JSON_FILE (new JsonableArray<TestJsonable>> [] (new TestJsonable "")))
a (jsonMap.get "a")
aString (a.elements.toString)
b (jsonMap.get "b")
bString (b.elements.toString)]
(assert (contains aString "abc"))
(assert (contains aString "def"))
(assert (contains bString "ghi"))
(assert (contains bString "jkl"))
(a.elements.push (new TestJsonable "mno"))
(jsonMap.put "a" a)
(let [c (jsonMap.get "c")]
(assertEquals 0 c.elements.length)))
// Uncomment this line when expanding the test:
// (File.saveContent "test/map-end.json" (File.getContent TEST_JSON_FILE))
(assertEquals (File.getContent "test/map-end.json") (File.getContent TEST_JSON_FILE))
(FileSystem.deleteFile TEST_JSON_FILE)

7
src/test/TestJsonable.hx Normal file
View File

@@ -0,0 +1,7 @@
package test;
import kiss.Prelude;
import kiss.List;
@:build(kiss.Kiss.build())
class TestJsonable {}

View File

@@ -0,0 +1,5 @@
(defNew [&prop :String s])
(method parse [:String s] (new TestJsonable s))
(method stringify [] s)
(method toString [] s)