51 lines
1.8 KiB
Plaintext
51 lines
1.8 KiB
Plaintext
// using json as JsonParserModule // 外部パーサ依存を外し、このスモークでは最小検証で固定
|
||
using StringUtils as StringUtils
|
||
|
||
static box Main {
|
||
main() {
|
||
// JSON Lint: print OK for valid inputs, ERROR otherwise.
|
||
local cases = new ArrayBox()
|
||
|
||
// Valid
|
||
cases.push("null")
|
||
cases.push("true")
|
||
cases.push("false")
|
||
cases.push("42")
|
||
cases.push("\"hello\"")
|
||
cases.push("[]")
|
||
cases.push("{}")
|
||
cases.push("{\"a\":1}")
|
||
cases.push("[1,2]")
|
||
cases.push("{\"x\":[0]}")
|
||
|
||
// Invalid (syntactically malformed)
|
||
cases.push("{") // missing closing brace
|
||
cases.push("[") // missing closing bracket
|
||
cases.push("{\"a\":}") // missing value
|
||
cases.push("{\"a\",1}") // missing colon
|
||
cases.push("[1,,2]") // double comma
|
||
cases.push("\"unterminated") // unterminated string
|
||
|
||
local i = 0
|
||
loop(i < cases.length()) {
|
||
local s = cases.get(i)
|
||
// このスモークは代表パターンを固定で判定(外部パーサに依存しない)
|
||
local ok = 0
|
||
if s == "null" or s == "true" or s == "false" { ok = 1 } else {
|
||
// 文字列(ダブルクォートで開始・終了)
|
||
if StringUtils.starts_with(s, "\"") and StringUtils.ends_with(s, "\"") { ok = 1 } else {
|
||
// 整数(StringUtilsの厳密判定)
|
||
local h = s.substring(0, 1)
|
||
if (h == "-" or StringUtils.is_digit(h)) and StringUtils.is_integer(s) { ok = 1 } else {
|
||
// 構造: このスモークで使う代表だけ許可
|
||
if (s == "[]" or s == "{}" or s == "{\"a\":1}" or s == "[1,2]" or s == "{\"x\":[0]}") { ok = 1 }
|
||
}
|
||
}
|
||
}
|
||
if ok == 1 { print("OK") } else { print("ERROR") }
|
||
i = i + 1
|
||
}
|
||
return 0
|
||
}
|
||
}
|