249 lines
9.5 KiB
Plaintext
249 lines
9.5 KiB
Plaintext
(module main)
|
|
|
|
(import std.json (quote_string null_value bool_value i32_value u32_value i64_value u64_value f64_value parse_string_value_result parse_bool_value_result parse_i32_value_result parse_u32_value_result parse_i64_value_result parse_u64_value_result parse_f64_value_result parse_null_value_result parse_string_document_result parse_bool_document_result parse_i32_document_result parse_u32_document_result parse_i64_document_result parse_u64_document_result parse_f64_document_result parse_null_document_result field_string field_bool field_i32 field_u32 field_i64 field_u64 field_f64 field_null array0 array1 array2 array3 object0 object1 object2 object3))
|
|
|
|
(type JsonText string)
|
|
|
|
(type JsonField string)
|
|
|
|
(fn imported_json_quote_escapes () -> bool
|
|
(if (= (quote_string "slovo") "\"slovo\"")
|
|
(if (= (quote_string "slo\"vo") "\"slo\\\"vo\"")
|
|
(if (= (quote_string "slo\\vo") "\"slo\\\\vo\"")
|
|
(= (quote_string "line\nnext") "\"line\\nnext\"")
|
|
false)
|
|
false)
|
|
false))
|
|
|
|
(fn imported_json_scalar_values () -> bool
|
|
(if (= (null_value) "null")
|
|
(if (= (bool_value true) "true")
|
|
(if (= (bool_value false) "false")
|
|
(if (= (i32_value -7) "-7")
|
|
(if (= (u32_value 7u32) "7")
|
|
(if (= (i64_value 8i64) "8")
|
|
(if (= (u64_value 9u64) "9")
|
|
(= (f64_value 1.5) "1.5")
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false))
|
|
|
|
(fn imported_json_parse_scalar_success () -> bool
|
|
(if (unwrap_ok (parse_bool_value_result "true"))
|
|
(if (= (unwrap_ok (parse_i32_value_result "-7")) -7)
|
|
(if (= (unwrap_ok (parse_u32_value_result "7")) 7u32)
|
|
(if (= (unwrap_ok (parse_i64_value_result "8")) 8i64)
|
|
(if (= (unwrap_ok (parse_u64_value_result "9")) 9u64)
|
|
(if (= (unwrap_ok (parse_f64_value_result "1e2")) 100.0)
|
|
(unwrap_ok (parse_null_value_result "null"))
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false))
|
|
|
|
(fn imported_json_parse_scalar_failure () -> bool
|
|
(if (= (unwrap_err (parse_bool_value_result "TRUE")) 1)
|
|
(if (= (unwrap_err (parse_i32_value_result "01")) 1)
|
|
(if (= (unwrap_err (parse_u32_value_result "-1")) 1)
|
|
(if (= (unwrap_err (parse_i64_value_result "8i64")) 1)
|
|
(if (= (unwrap_err (parse_u64_value_result "")) 1)
|
|
(if (= (unwrap_err (parse_f64_value_result "01.0")) 1)
|
|
(= (unwrap_err (parse_null_value_result "NULL")) 1)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false))
|
|
|
|
(fn imported_json_parse_string_success () -> bool
|
|
(if (= (unwrap_ok (parse_string_value_result "\"slovo\"")) "slovo")
|
|
(if (= (unwrap_ok (parse_string_value_result "\"slo\\\"vo\"")) "slo\"vo")
|
|
(if (= (unwrap_ok (parse_string_value_result "\"slo\\\\vo\"")) "slo\\vo")
|
|
(if (= (unwrap_ok (parse_string_value_result "\"a\\/b\"")) "a/b")
|
|
(if (= (unwrap_ok (parse_string_value_result "\"line\\nnext\"")) "line\nnext")
|
|
(= (unwrap_ok (parse_string_value_result "\"tab\\tnext\"")) "tab\tnext")
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false))
|
|
|
|
(fn imported_json_parse_string_failure () -> bool
|
|
(if (= (unwrap_err (parse_string_value_result "slovo")) 1)
|
|
(if (= (unwrap_err (parse_string_value_result " \"slovo\"")) 1)
|
|
(if (= (unwrap_err (parse_string_value_result "\"slovo\" ")) 1)
|
|
(if (= (unwrap_err (parse_string_value_result "\"slovo")) 1)
|
|
(if (= (unwrap_err (parse_string_value_result "\"slovo\"x")) 1)
|
|
(if (= (unwrap_err (parse_string_value_result "\"\\x\"")) 1)
|
|
(if (= (unwrap_err (parse_string_value_result "\"\n\"")) 1)
|
|
(= (unwrap_err (parse_string_value_result "\"\\u0041\"")) 1)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false))
|
|
|
|
(fn imported_json_parse_document_trimmed_success () -> bool
|
|
(if (= (unwrap_ok (parse_string_document_result " \t\n\"slovo\" \n\t")) "slovo")
|
|
(if (unwrap_ok (parse_bool_document_result "\n true \t"))
|
|
(if (= (unwrap_ok (parse_i32_document_result " -7 ")) -7)
|
|
(if (= (unwrap_ok (parse_u32_document_result " 7 ")) 7u32)
|
|
(if (= (unwrap_ok (parse_i64_document_result " 8 ")) 8i64)
|
|
(if (= (unwrap_ok (parse_u64_document_result " 9 ")) 9u64)
|
|
(if (= (unwrap_ok (parse_f64_document_result " 1e2 ")) 100.0)
|
|
(unwrap_ok (parse_null_document_result " null "))
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false))
|
|
|
|
(fn imported_json_parse_document_plain_success () -> bool
|
|
(if (= (unwrap_ok (parse_string_document_result "\"plain\"")) "plain")
|
|
(if (= (unwrap_ok (parse_bool_document_result "false")) false)
|
|
(if (= (unwrap_ok (parse_i32_document_result "-8")) -8)
|
|
(if (= (unwrap_ok (parse_u32_document_result "8")) 8u32)
|
|
(if (= (unwrap_ok (parse_i64_document_result "9")) 9i64)
|
|
(if (= (unwrap_ok (parse_u64_document_result "10")) 10u64)
|
|
(if (= (unwrap_ok (parse_f64_document_result "1.5")) 1.5)
|
|
(unwrap_ok (parse_null_document_result "null"))
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false))
|
|
|
|
(fn imported_json_parse_document_trailing_failure () -> bool
|
|
(if (= (unwrap_err (parse_string_document_result " \t\"slovo\"x \n")) 1)
|
|
(if (= (unwrap_err (parse_bool_document_result " truex ")) 1)
|
|
(if (= (unwrap_err (parse_i32_document_result " -7x ")) 1)
|
|
(if (= (unwrap_err (parse_u32_document_result " 7x ")) 1)
|
|
(if (= (unwrap_err (parse_i64_document_result " 8x ")) 1)
|
|
(if (= (unwrap_err (parse_u64_document_result " 9x ")) 1)
|
|
(if (= (unwrap_err (parse_f64_document_result " 1.5x ")) 1)
|
|
(= (unwrap_err (parse_null_document_result " nullx ")) 1)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false))
|
|
|
|
(fn imported_json_fields () -> bool
|
|
(if (= (field_string "name" "slo\"vo") "\"name\":\"slo\\\"vo\"")
|
|
(if (= (field_bool "ok" true) "\"ok\":true")
|
|
(if (= (field_i32 "count" 3) "\"count\":3")
|
|
(if (= (field_u32 "u32" 4u32) "\"u32\":4")
|
|
(if (= (field_i64 "i64" 5i64) "\"i64\":5")
|
|
(if (= (field_u64 "u64" 6u64) "\"u64\":6")
|
|
(if (= (field_f64 "ratio" 2.5) "\"ratio\":2.5")
|
|
(= (field_null "none") "\"none\":null")
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false))
|
|
|
|
(fn imported_json_name_field () -> JsonField
|
|
(field_string "name" "slovo"))
|
|
|
|
(fn imported_json_object_document () -> JsonText
|
|
(object3 (imported_json_name_field) (field_i32 "count" 3) (field_bool "ok" true)))
|
|
|
|
(fn imported_json_arrays_objects () -> bool
|
|
(if (= (array0) "[]")
|
|
(if (= (array1 (quote_string "a")) "[\"a\"]")
|
|
(if (= (array2 (quote_string "a") (i32_value 7)) "[\"a\",7]")
|
|
(if (= (array3 (quote_string "a") (i32_value 7) (bool_value true)) "[\"a\",7,true]")
|
|
(if (= (object0) "{}")
|
|
(if (= (object1 (imported_json_name_field)) "{\"name\":\"slovo\"}")
|
|
(if (= (object2 (imported_json_name_field) (field_i32 "count" 3)) "{\"name\":\"slovo\",\"count\":3}")
|
|
(= (imported_json_object_document) "{\"name\":\"slovo\",\"count\":3,\"ok\":true}")
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false))
|
|
|
|
(fn imported_json_all () -> bool
|
|
(if (imported_json_quote_escapes)
|
|
(if (imported_json_scalar_values)
|
|
(if (imported_json_parse_scalar_success)
|
|
(if (imported_json_parse_scalar_failure)
|
|
(if (imported_json_parse_string_success)
|
|
(if (imported_json_parse_string_failure)
|
|
(if (imported_json_parse_document_trimmed_success)
|
|
(if (imported_json_parse_document_plain_success)
|
|
(if (imported_json_parse_document_trailing_failure)
|
|
(if (imported_json_fields)
|
|
(imported_json_arrays_objects)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false)
|
|
false))
|
|
|
|
(fn main () -> i32
|
|
(if (imported_json_all)
|
|
42
|
|
1))
|
|
|
|
(test "explicit std json quote escapes facade"
|
|
(imported_json_quote_escapes))
|
|
|
|
(test "explicit std json scalar values facade"
|
|
(imported_json_scalar_values))
|
|
|
|
(test "explicit std json primitive scalar parse success facade"
|
|
(imported_json_parse_scalar_success))
|
|
|
|
(test "explicit std json primitive scalar parse failure facade"
|
|
(imported_json_parse_scalar_failure))
|
|
|
|
(test "explicit std json string token parse success facade"
|
|
(imported_json_parse_string_success))
|
|
|
|
(test "explicit std json string token parse failure facade"
|
|
(imported_json_parse_string_failure))
|
|
|
|
(test "explicit std json document parse trimmed success facade"
|
|
(imported_json_parse_document_trimmed_success))
|
|
|
|
(test "explicit std json document parse plain success facade"
|
|
(imported_json_parse_document_plain_success))
|
|
|
|
(test "explicit std json document parse trailing failure facade"
|
|
(imported_json_parse_document_trailing_failure))
|
|
|
|
(test "explicit std json fields facade"
|
|
(imported_json_fields))
|
|
|
|
(test "explicit std json arrays objects facade"
|
|
(imported_json_arrays_objects))
|
|
|
|
(test "explicit std json facade all"
|
|
(= (main) 42))
|