This commit is contained in:
2026-01-25 22:09:29 +01:00
parent 1ee28a1644
commit a59dbe1d55
27 changed files with 3435 additions and 2 deletions
+18
View File
@@ -0,0 +1,18 @@
// retoor <retoor@molodetz.nl>
import "yaml" for Yaml
var yaml = "
# This is a comment
name: test
# Another comment
value: 123
"
var data = Yaml.parse(yaml)
System.print(data["name"]) // expect: test
System.print(data["value"]) // expect: 123
var inlineComment = "name: test # inline comment"
var data2 = Yaml.parse(inlineComment)
System.print(data2["name"]) // expect: test
+25
View File
@@ -0,0 +1,25 @@
// retoor <retoor@molodetz.nl>
import "yaml" for Yaml
var yaml = "
sections:
- title: Getting Started
pages:
- file: index
title: Overview
- file: installation
title: Installation
- title: API Reference
pages:
- file: json
title: json
"
var nav = Yaml.parse(yaml)
System.print(nav["sections"][0]["title"]) // expect: Getting Started
System.print(nav["sections"][0]["pages"][0]["file"]) // expect: index
System.print(nav["sections"][0]["pages"][0]["title"]) // expect: Overview
System.print(nav["sections"][0]["pages"][1]["file"]) // expect: installation
System.print(nav["sections"][1]["title"]) // expect: API Reference
System.print(nav["sections"][1]["pages"][0]["file"]) // expect: json
+12
View File
@@ -0,0 +1,12 @@
// retoor <retoor@molodetz.nl>
import "yaml" for Yaml
var empty = Yaml.parse("")
System.print(empty) // expect: null
var nullInput = Yaml.parse(null)
System.print(nullInput) // expect: null
var whitespace = Yaml.parse(" \n \n ")
System.print(whitespace) // expect: null
+21
View File
@@ -0,0 +1,21 @@
// retoor <retoor@molodetz.nl>
import "yaml" for Yaml
var yaml = "items:\n - first\n - second\n - third"
var data = Yaml.parse(yaml)
System.print(data["items"][0]) // expect: first
System.print(data["items"][1]) // expect: second
System.print(data["items"][2]) // expect: third
System.print(data["items"].count) // expect: 3
var simple = "- one\n- two\n- three"
var list = Yaml.parse(simple)
System.print(list[0]) // expect: one
System.print(list[1]) // expect: two
System.print(list.count) // expect: 3
var numbers = "- 1\n- 2\n- 3"
var numList = Yaml.parse(numbers)
System.print(numList[0]) // expect: 1
System.print(numList[1]) // expect: 2
+17
View File
@@ -0,0 +1,17 @@
// retoor <retoor@molodetz.nl>
import "yaml" for Yaml
var yaml = "server:\n host: localhost\n port: 8080"
var config = Yaml.parse(yaml)
System.print(config["server"]["host"]) // expect: localhost
System.print(config["server"]["port"]) // expect: 8080
var deep = "
level1:
level2:
level3:
value: deep
"
var deepConfig = Yaml.parse(deep)
System.print(deepConfig["level1"]["level2"]["level3"]["value"]) // expect: deep
+27
View File
@@ -0,0 +1,27 @@
// retoor <retoor@molodetz.nl>
import "yaml" for Yaml
var simple = Yaml.parse("name: test")
System.print(simple["name"]) // expect: test
var num = Yaml.parse("count: 42")
System.print(num["count"]) // expect: 42
var float = Yaml.parse("value: 3.14")
System.print(float["value"]) // expect: 3.14
var bool = Yaml.parse("active: true")
System.print(bool["active"]) // expect: true
var boolFalse = Yaml.parse("active: false")
System.print(boolFalse["active"]) // expect: false
var nullVal = Yaml.parse("value: null")
System.print(nullVal["value"]) // expect: null
var quoted = Yaml.parse("name: \"hello world\"")
System.print(quoted["name"]) // expect: hello world
var singleQuoted = Yaml.parse("name: 'hello world'")
System.print(singleQuoted["name"]) // expect: hello world
+25
View File
@@ -0,0 +1,25 @@
// retoor <retoor@molodetz.nl>
import "yaml" for Yaml
var simple = {"name": "test", "value": 42}
var str = Yaml.stringify(simple)
System.print(str.contains("name: test")) // expect: true
System.print(str.contains("value: 42")) // expect: true
var withList = {"items": ["one", "two", "three"]}
var listStr = Yaml.stringify(withList)
System.print(listStr.contains("items:")) // expect: true
System.print(listStr.contains("- one")) // expect: true
System.print(listStr.contains("- two")) // expect: true
var nested = {"server": {"host": "localhost", "port": 8080}}
var nestedStr = Yaml.stringify(nested)
System.print(nestedStr.contains("server:")) // expect: true
System.print(nestedStr.contains("host: localhost")) // expect: true
System.print(Yaml.stringify(null)) // expect: null
System.print(Yaml.stringify(true)) // expect: true
System.print(Yaml.stringify(false)) // expect: false
System.print(Yaml.stringify(42)) // expect: 42
System.print(Yaml.stringify("hello")) // expect: hello