Skip to content
Snippets Groups Projects
Commit 21f01114 authored by David Trattnig's avatar David Trattnig
Browse files

Test: Null and optional values when parsing JSON

parent f0a71a06
No related branches found
No related tags found
1 merge request!3Liquidsoap 2 migration
......@@ -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")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment