Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]

Modules

ADT
Database
GTK2
GUI
IP
PiJAX
Public
Sql
Stdio
Subversion
System
Tools
Xosd
lua
v4l2
wx

Recent Changes

Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0

Popular Downloads

Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48


Module Information
Public.Parser.JSON2
Viewing contents of Public_Parser_JSON2-0.5/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(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.
test_do(string s = Public.Parser.JSON2.parse("\" It says little, does less, means nothing.\""); 
	return _refs(s) == 2;)
test_do(mapping m = Public.Parser.JSON2.parse(" { \"asd\" : 45 }  "); 
	return _refs(m) == 2;)
test_do(array a = Public.Parser.JSON2.parse(" [ 45, 34, 3, 4, 5 ] "); 
	return _refs(a) == 2;)
// test examples from json.org
test_do(
mixed o,a, s;
return equal(Public.Parser.JSON2.parse(s =
"{\
    \"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"
                ])
            ])
        ])
    ])
]))
&&
equal(Public.Parser.JSON2.parse(Public.Parser.JSON2.render(o)), a)
&&
equal(Public.Parser.JSON2.parse(Public.Parser.JSON2.render(o, HUMAN_READABLE)), a)
&&
equal(Public.Parser.JSON2.parse(Public.Parser.JSON2.render(o, ASCII_ONLY)), a);
&&
Public.Parser.JSON2.validate(s) == -1
)
test_do(
mixed o, a, s;
return equal(o = Public.Parser.JSON2.parse(s =
"    {	 \"menu\": 	{\
  \"id\": \"file\",\
  \"value\": \"File\",\
  \"popup\": {\
    \"menuitem\": [\
      {\"value\": \"New\", 	\"onclick\": \"CreateNewDoc()\"},\
      {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},\
      {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}\
    ]\	
  }\	
}	}\	
"), a = (["menu": ([
  "id": "file",
  "value": "File",
  "popup": ([
    "menuitem": ({
      (["value": "New", "onclick": "CreateNewDoc()"]),
      (["value": "Open", "onclick": "OpenDoc()"]),
      (["value": "Close", "onclick": "CloseDoc()"])
    })
  ])
])]))
&&
equal(Public.Parser.JSON2.parse(Public.Parser.JSON2.render(o)), a)
&&
equal(Public.Parser.JSON2.parse(Public.Parser.JSON2.render(o, HUMAN_READABLE)), a)
&&
equal(Public.Parser.JSON2.parse(Public.Parser.JSON2.render(o, ASCII_ONLY)), a);
&&
Public.Parser.JSON2.validate(s) == -1
)
test_do(
mixed o, a, s;
equal(o = Public.Parser.JSON2.parse(s =
"{\"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...\"}\
    ]\
}}\
"), a = (["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..."])
    })
])]) )
&&
equal(Public.Parser.JSON2.parse(Public.Parser.JSON2.render(o)), a)
&&
equal(Public.Parser.JSON2.parse(Public.Parser.JSON2.render(o, HUMAN_READABLE)), a)
&&
equal(Public.Parser.JSON2.parse(Public.Parser.JSON2.render(o, ASCII_ONLY)), a);
&&
Public.Parser.JSON2.validate(s) == -1
)


gotpike.org | Copyright © 2004 - 2019 | Pike is a trademark of Department of Computer and Information Science, Linköping University