1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
-- numbers
assert Equation(toJSON 1, "1")
assert Equation(toJSON 3.14159, "3.14159")
assert Equation(toJSON pi, "3.14159265358979")
assert Equation(toJSON(1/2), ".5")
-- strings
assert Equation(toJSON "Hello, world!", "\"Hello, world!\"")
assert Equation(toJSON "¡pʃɹoʍ 'oʃʃǝH", "\"¡pʃɹoʍ 'oʃʃǝH\"")
-- true/false/null
assert Equation(toJSON true, "true")
assert Equation(toJSON false, "false")
assert Equation(toJSON null, "null")
assert Equation(toJSON nil, "null")
-- arrays
assert Equation(toJSON {1, 2, 3}, "[1, 2, 3]")
assert Equation(toJSON [1, 2, 3], "[1, 2, 3]")
assert Equation(toJSON <|1, 2, 3|>, "[1, 2, 3]")
assert Equation(toJSON({1, 2, 3}, ValueSeparator => " , "), "[1 , 2 , 3]")
assert Equation(toJSON({1, 2, 3, {4, 5}}, Indent => 0), ///[
1,
2,
3,
[
4,
5
]
]///)
assert Equation(toJSON({1, 2, 3, {4, 5}}, Indent => 2), ///[
1,
2,
3,
[
4,
5
]
]///)
assert Equation(toJSON({1, 2, 3, {4, 5}}, Indent => " "), ///[
1,
2,
3,
[
4,
5
]
]///)
assert Equation(toJSON({}, Indent => 2), "[]")
assert Equation(toJSON({{}}, Indent => 2), ///[
[]
]///)
-- objects
assert Equation(toJSON(hashTable{"a" => 1, "b" => 2, "c" => 3}, Sort => true),
"{\"a\": 1, \"b\": 2, \"c\": 3}")
assert Equation(toJSON(hashTable{"a" => 1, "b" => 2, "c" => 3}, Sort => true,
ValueSeparator => " , "), "{\"a\": 1 , \"b\": 2 , \"c\": 3}")
assert Equation(toJSON(hashTable{"a" => 1, "b" => 2, "c" => 3}, Sort => true,
NameSeparator => " : "), "{\"a\" : 1, \"b\" : 2, \"c\" : 3}")
|