From 21f01114b1d47e8c8fe6651d63b1d7a63c14143e Mon Sep 17 00:00:00 2001
From: David Trattnig <david@subsquare.at>
Date: Wed, 13 Jul 2022 11:50:10 +0200
Subject: [PATCH] Test: Null and optional values when parsing JSON

---
 tests/test_parse_json.liq | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/tests/test_parse_json.liq b/tests/test_parse_json.liq
index 36002e2..990a088 100755
--- a/tests/test_parse_json.liq
+++ b/tests/test_parse_json.liq
@@ -26,7 +26,6 @@
 let json.parse data = '{"show_id": "-1", "show_name": "Random Music"}'
 print("Set current show to '#{data.show_name}' (ID: #{data.show_id})")
 assertEquals("#{data.show_name}", "null")
-# > Set current show to 'null' (ID: null)
 
 # Scenario 2: Works, when data types of the JSON have been defined
 let json.parse (data : {
@@ -36,16 +35,12 @@ let json.parse (data : {
 print("Set current show to '#{data.show_name}' (ID: #{data.show_id})")
 assertEquals(data.show_name, "Random Music")
 assertEquals(data.show_id, "-1")
-# # > Set current show to 'Random Music' (ID: -1)
-
 
 # Scenario 3: Works, even when no data types have been defined
 let json.parse data = '{"show_id": "-1", "show_name": "Random Music"}'
 print("Set current show to '" ^ data.show_name ^ "' (ID: " ^ data.show_id ^ ")")
 assertEquals(data.show_name, "Random Music")
 assertEquals(data.show_id, "-1")
-# # > Set current show to 'Random Music' (ID: -1)
-
 
 # Scenario 4: Works, when variables have been accessed outside the string before
 let json.parse data = '{"show_id": "-1", "show_name": "Random Music"}'
@@ -55,5 +50,12 @@ assertEquals(data.show_id, "-1")
 print("Set current show to '#{data.show_name}' (ID: #{data.show_id})")
 assertEquals(data.show_name, "Random Music")
 assertEquals(data.show_id, "-1")
-# > Set current show to 'Random Music' (ID: -1)
-# > Set current show to 'Random Music' (ID: -1)
+
+# Scenario 5: Allow `null` and optional values
+let json.parse (data : {
+        show_id: string,
+        show_name: string?,
+        track_title: string?
+    }) = '{"show_id": "-1", "show_name": null}'
+print("Set current show to '#{data.show_name}' (ID: #{data.show_id})")
+assertEquals(data.show_id, "-1")
-- 
GitLab