Files
hakorune/json_minimal_test.nyash

77 lines
1.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// JSONライブラリの最小機能テスト
static box JsonMinimalTest {
main() {
print("🧪 JSON Minimal Test")
// 基本的なJSONードを手動作成
local null_node = this.create_node("null", null)
print("null node: " + null_node.stringify())
local bool_node = this.create_node("bool", true)
print("bool node: " + bool_node.stringify())
local int_node = this.create_node("int", 42)
print("int node: " + int_node.stringify())
local str_node = this.create_node("string", "hello")
print("string node: " + str_node.stringify())
print("✅ Minimal test complete")
return 0
}
// シンプルなJSONード作成
create_node(kind, value) {
local node = new MinimalJsonNode()
node.set_kind(kind)
node.set_value(value)
return node
}
}
// 最小限のJSONード
box MinimalJsonNode {
kind: StringBox
value: Box
birth() {
me.kind = "null"
me.value = null
}
set_kind(k) {
me.kind = k
}
set_value(v) {
me.value = v
}
get_kind() {
return me.kind
}
stringify() {
if me.kind == "null" {
return "null"
} else {
if me.kind == "bool" {
if me.value {
return "true"
} else {
return "false"
}
} else {
if me.kind == "int" {
return "" + me.value
} else {
if me.kind == "string" {
return "\"" + me.value + "\""
} else {
return "null"
}
}
}
}
}
}