comments and tests
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 19 Jun 2021 02:07:55 +0000 (21:07 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 19 Jun 2021 02:07:55 +0000 (21:07 -0500)
modules/json/encoder.onyx
modules/json/example.onyx

index df5dd013bdb4e5d11633c14a542e328f53370cca..8747e968b71783c5ec81e8b66ed67b7b649b2c6d 100644 (file)
@@ -66,7 +66,7 @@ encode :: #match {
 
         for i: v.entries.count {
             if i > 0 do io.write_byte(w, #char ",");
-            entry := v.entries[i];
+            entry := ^v.entries[i];
 
             io.write_escaped_str(w, entry.key);
             io.write_byte(w, #char ":");
@@ -113,7 +113,9 @@ encode :: #match {
         return .None;
     },
 
-
+    // This is disabled because I would prefer to have a compile time error for an unsupported type,
+    // as opposed to a error to check programatically.
+    //
     // // Inserted after any of the #add_match directives
     // #precedence 1000 (w: ^io.Writer, v: $T) -> Encoding_Error {
     //     return .Unsupported_Type;
index 37db471596aab405b5bdff3e9c206576996b4fbc..7306cf6966ccfcf7fd41bf561b3ae86f45651afe 100644 (file)
@@ -5,7 +5,7 @@
 use package core
 json :: package json
 
-json_string := "{ \"test\": \"\\tHello,\\n\\\"World!\\\"\", \"array\": [1,2,3,4,5,1423], \"sub\": { \"mem\": true } }";
+json_string := "{ \"test\": \"\\tHello,\\n\\\"World!\\\"\", \"array\": [1,2,3,4,5,1423], \"sub\": { \"mem\": true, \"other\": null } }";
 
 main :: (args: [] cstr) {
     arena := alloc.arena.make(context.allocator, 4096);
@@ -20,7 +20,7 @@ main :: (args: [] cstr) {
     //     println(v["friends"][1]["name"]->as_str());
     // }
 
-    #if false {
+    #if true {
         value := decoded_json.root["array"];
         for v: value->as_array() {
             println(v->as_int());