(module main)

(import std.json (quote_string null_value bool_value i32_value u32_value i64_value u64_value f64_value field_string field_bool field_i32 field_u32 field_i64 field_u64 field_f64 field_null array0 array1 array2 array3 object0 object1 object2 object3))

(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_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_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 (field_string "name" "slovo")) "{\"name\":\"slovo\"}")
              (if (= (object2 (field_string "name" "slovo") (field_i32 "count" 3)) "{\"name\":\"slovo\",\"count\":3}")
                (= (object3 (field_string "name" "slovo") (field_i32 "count" 3) (field_bool "ok" true)) "{\"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_fields)
        (imported_json_arrays_objects)
        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 fields facade"
  (imported_json_fields))

(test "explicit std json arrays objects facade"
  (imported_json_arrays_objects))

(test "explicit std json facade all"
  (= (main) 42))
