Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
engine-core
Commits
21f01114
Commit
21f01114
authored
2 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Test: Null and optional values when parsing JSON
parent
f0a71a06
No related branches found
No related tags found
1 merge request
!3
Liquidsoap 2 migration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_parse_json.liq
+9
-7
9 additions, 7 deletions
tests/test_parse_json.liq
with
9 additions
and
7 deletions
tests/test_parse_json.liq
+
9
−
7
View file @
21f01114
...
...
@@ -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")
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment