Module Information
Public.Parser.JSON2
Viewing contents of Public_Parser_JSON2-0.8/testsuite.in
// vim:syntax=lpc
// all examples are taken from www.json.org
//
test_true(programp(Public.Parser.JSON2.True))
test_true(programp(Public.Parser.JSON2.False))
test_true(programp(Public.Parser.JSON2.Null))
test_true(functionp(Public.Parser.JSON2.parse))
test_true(functionp(Public.Parser.JSON2.render))
test_true(functionp(Public.Parser.JSON2.validate))
// test the special types
test_true(objectp(Public.Parser.JSON2.Unicode))
test_true(Public.Parser.JSON2.true == Public.Parser.JSON2.parse("true"))
test_true(Public.Parser.JSON2.false == Public.Parser.JSON2.parse("false"))
test_true(Public.Parser.JSON2.null == Public.Parser.JSON2.parse("null"))
test_true(Public.Parser.JSON2.parse("true") == ~Public.Parser.JSON2.parse("false"))
// test numbers
test_true(Public.Parser.JSON2.parse("0E4") == 0.0)
// test reference counter.
// not sure how stable that is amoung pike versions....
test_true(_refs(Public.Parser.JSON2.parse("\" It says little, does less, means nothing.\"")) == 1)
test_true(_refs(Public.Parser.JSON2.parse(" { \"asd\" : 45 } ")) == 1)
test_true(_refs(Public.Parser.JSON2.parse(" [ 45, 34, 3, 4, 5 ] ")) == 1)
// testing if junk at the end breaks
test_true(-1 != Public.Parser.JSON2.validate_utf8("[ 32, 23, 43 , 54 ,45] uh"))
test_true(-1 == Public.Parser.JSON2.validate_utf8("[ 32, 23, 43 , 54 ,45] "))
test_true("\\/\"\"\\" == Public.Parser.JSON2.parse(Public.Parser.JSON2.render("\\/\"\"\\")))
test_true("\\/skjdhf\"sdf\"d\\" == Public.Parser.JSON2.parse(Public.Parser.JSON2.render("\\/skjdhf\"sdf\"d\\")))
test_true("\"\\\\\\\""*20 == Public.Parser.JSON2.parse_utf8(Public.Parser.JSON2.parse(Public.Parser.JSON2.parse_utf8(Public.Parser.JSON2.parse(Public.Parser.JSON2.render(Public.Parser.JSON2.render_utf8(Public.Parser.JSON2.render(Public.Parser.JSON2.render_utf8("\"\\\\\\\""*20), Public.Parser.JSON2.HUMAN_READABLE))))))))
// test examples from json.org
test_true(equal(Public.Parser.JSON2.parse(
"{\
\"glossary\": {\
\"title\": \"example glossary\",\
\"GlossDiv\": {\
\"title\": \"S\",\
\"GlossList\": {\
\"GlossEntry\": {\
\"ID\": \"SGML\",\
\"SortAs\": \"SGML\",\
\"GlossTerm\": \"Standard Generalized Markup Language\",\
\"Acronym\": \"SGML\",\
\"Abbrev\": \"ISO 8879:1986\",\
\"GlossDef\": {\
\"para\": \"A meta-markup language, used to create markup languages such as DocBook.\",\
\"GlossSeeAlso\": [\"GML\", \"XML\"]\
},\
\"GlossSee\": \"markup\"\
}\
}\
}\
}\
}\
"), ([
"glossary": ([
"title": "example glossary",
"GlossDiv": ([
"title": "S",
"GlossList": ([
"GlossEntry": ([
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": ([
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ({"GML", "XML"})
]),
"GlossSee": "markup"
])
])
])
])
])))
test_true(equal(Public.Parser.JSON2.parse(Public.Parser.JSON2.render(([
"glossary": ([
"title": "example glossary",
"GlossDiv": ([
"title": "S",
"GlossList": ([
"GlossEntry": ([
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": ([
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ({"GML", "XML"})
]),
"GlossSee": "markup"
])
])
])
])
]))), ([
"glossary": ([
"title": "example glossary",
"GlossDiv": ([
"title": "S",
"GlossList": ([
"GlossEntry": ([
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": ([
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ({"GML", "XML"})
]),
"GlossSee": "markup"
])
])
])
])
])))
test_true(equal(Public.Parser.JSON2.parse(" { \"menu\": {\
\"id\": \"file\",\
\"value\": \"File\",\
\"popup\": {\
\"menuitem\": [\
{\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"},\
{\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},\
{\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}\
]\
}\
} }\
"), (["menu": ([
"id": "file",
"value": "File",
"popup": ([
"menuitem": ({
(["value": "New", "onclick": "CreateNewDoc()"]),
(["value": "Open", "onclick": "OpenDoc()"]),
(["value": "Close", "onclick": "CloseDoc()"])
})
])
])])))
test_true(equal(Public.Parser.JSON2.parse("{\"menu\": {\
\"header\": \"SVG Viewer\",\
\"items\": [\
{\"id\": \"Open\"},\
{\"id\": \"OpenNew\", \"label\": \"Open New\"},\
null,\
{\"id\": \"ZoomIn\", \"label\": \"Zoom In\"},\
{\"id\": \"ZoomOut\", \"label\": \"Zoom Out\"},\
{\"id\": \"OriginalView\", \"label\": \"Original View\"},\
null,\
{\"id\": \"Quality\"},\
{\"id\": \"Pause\"},\
{\"id\": \"Mute\"},\
null,\
{\"id\": \"Find\", \"label\": \"Find...\"},\
{\"id\": \"FindAgain\", \"label\": \"Find Again\"},\
{\"id\": \"Copy\"},\
{\"id\": \"CopyAgain\", \"label\": \"Copy Again\"},\
{\"id\": \"CopySVG\", \"label\": \"Copy SVG\"},\
{\"id\": \"ViewSVG\", \"label\": \"View SVG\"},\
{\"id\": \"ViewSource\", \"label\": \"View Source\"},\
{\"id\": \"SaveAs\", \"label\": \"Save As\"},\
null,\
{\"id\": \"Help\"},\
{\"id\": \"About\", \"label\": \"About Adobe CVG Viewer...\"}\
]\
}}\
"), (["menu": ([
"header": "SVG Viewer",
"items": ({
(["id": "Open"]),
(["id": "OpenNew", "label": "Open New"]),
Public.Parser.JSON2.null,
(["id": "ZoomIn", "label": "Zoom In"]),
(["id": "ZoomOut", "label": "Zoom Out"]),
(["id": "OriginalView", "label": "Original View"]),
Public.Parser.JSON2.null,
(["id": "Quality"]),
(["id": "Pause"]),
(["id": "Mute"]),
Public.Parser.JSON2.null,
(["id": "Find", "label": "Find..."]),
(["id": "FindAgain", "label": "Find Again"]),
(["id": "Copy"]),
(["id": "CopyAgain", "label": "Copy Again"]),
(["id": "CopySVG", "label": "Copy SVG"]),
(["id": "ViewSVG", "label": "View SVG"]),
(["id": "ViewSource", "label": "View Source"]),
(["id": "SaveAs", "label": "Save As"]),
Public.Parser.JSON2.null,
(["id": "Help"]),
(["id": "About", "label": "About Adobe CVG Viewer..."])
})
])]) ))
test_true(
"" + String.int2char(76) + String.int2char(2000) + String.int2char(10000) + String.int2char(900000) + "" == Public.Parser.JSON2.parse_utf8(string_to_utf8("\"" + String.int2char(76) + String.int2char(2000) + String.int2char(10000) + String.int2char(900000) + "\"")))
test_true(Public.Parser.JSON2.validate("{\"menu\": {\
\"header\": \"SVG Viewer\",\
\"items\": [\
{\"id\": \"Open\"},\
{\"id\": \"OpenNew\", \"label\": \"Open New\"},\
null,\
{\"id\": \"ZoomIn\", \"label\": \"Zoom In\"},\
{\"id\": \"ZoomOut\", \"label\": \"Zoom Out\"},\
{\"id\": \"OriginalView\", \"label\": \"Original View\"},\
null,\
{\"id\": \"Quality\"},\
{\"id\": \"Pause\"},\
{\"id\": \"Mute\"},\
null,\
{\"id\": \"Find\", \"label\": \"Find...\"},\
{\"id\": \"FindAgain\", \"label\": \"Find Again\"},\
{\"id\": \"Copy\"},\
{\"id\": \"CopyAgain\", \"label\": \"Copy Again\"},\
{\"id\": \"CopySVG\", \"label\": \"Copy SVG\"},\
{\"id\": \"ViewSVG\", \"label\": \"View SVG\"},\
{\"id\": \"ViewSource\", \"label\": \"View Source\"},\
{\"id\": \"SaveAs\", \"label\": \"Save As\"},\
null,\
{\"id\": \"Help\"},\
{\"id\": \"About\", \"label\": \"About Adobe CVG Viewer...\"}\
]\
}}\
") == -1 )
test_true((string)(map(enumerate(4700, sizeof(Public.Parser.JSON2.Unicode)/4700, 0, `+) + ({sizeof(Public.Parser.JSON2.Unicode)-1}), Public.Parser.JSON2.Unicode->`[])) == Public.Parser.JSON2.parse_utf8(Public.Parser.JSON2.render_utf8((string)(map(enumerate(4700, sizeof(Public.Parser.JSON2.Unicode)/4700, 0, `+) + ({sizeof(Public.Parser.JSON2.Unicode)-1}), Public.Parser.JSON2.Unicode->`[])))))
test_true(8 == String.width(Public.Parser.JSON2.render_utf8((string)(map(enumerate(4700, sizeof(Public.Parser.JSON2.Unicode)/4700, 0, `+) + ({sizeof(Public.Parser.JSON2.Unicode)-1}), Public.Parser.JSON2.Unicode->`[])))))
test_true(equal(String.width(Public.Parser.JSON2.render_utf8(([
"glossary": ([
"title": (string)(map(enumerate(4700, sizeof(Public.Parser.JSON2.Unicode)/4700, 0, `+) + ({sizeof(Public.Parser.JSON2.Unicode)-1}), Public.Parser.JSON2.Unicode->`[])),
"GlossDiv": ([
"title": "S",
"GlossList": ([
"GlossEntry": ([
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": ([
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ({"GML", "XML"})
]),
"GlossSee": "markup"
])
])
])
])
]))), 8))
test_true(equal(Public.Parser.JSON2.parse_utf8(Public.Parser.JSON2.render_utf8(([
"glossary": ([
"title": (string)(map(enumerate(4700, sizeof(Public.Parser.JSON2.Unicode)/4700, 0, `+) + ({sizeof(Public.Parser.JSON2.Unicode)-1}), Public.Parser.JSON2.Unicode->`[])),
"GlossDiv": ([
"title": "S",
"GlossList": ([
"GlossEntry": ([
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": ([
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ({"GML", "XML"})
]),
"GlossSee": "markup"
])
])
])
])
]))), ([
"glossary": ([
"title": (string)(map(enumerate(4700, sizeof(Public.Parser.JSON2.Unicode)/4700, 0, `+) + ({sizeof(Public.Parser.JSON2.Unicode)-1}), Public.Parser.JSON2.Unicode->`[])),
"GlossDiv": ([
"title": "S",
"GlossList": ([
"GlossEntry": ([
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": ([
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ({"GML", "XML"})
]),
"GlossSee": "markup"
])
])
])
])
])))
|
|