Changeset

7238:7df4e385b248

Merge 0.10->trunk
author Matthew Wild <mwild1@gmail.com>
date Sat, 05 Mar 2016 20:50:17 +0000
parents 7236:3304a04281d6 (current diff) 7237:472736b583fb (diff)
children 7239:c9af793b2d8f
files
diffstat 38 files changed, 140 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Fri Mar 04 22:28:15 2016 +0000
+++ b/Makefile	Sat Mar 05 20:50:17 2016 +0000
@@ -54,6 +54,7 @@
 
 test:
 	cd tests && $(RUNWITH) test.lua 0
+	# Skipping: cd tests && RUNWITH=$(RUNWITH) ./test_util_json.sh
 
 util/%.so:
 	$(MAKE) install -C util-src
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail1.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+"A JSON payload should be an object or array, not a string."
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail10.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+{"Extra value after close": true} "misplaced quoted value"
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail11.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+{"Illegal expression": 1 + 2}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail12.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+{"Illegal invocation": alert()}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail13.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+{"Numbers cannot have leading zeroes": 013}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail14.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+{"Numbers cannot be hex": 0x14}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail15.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+["Illegal backslash escape: \x15"]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail16.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+[\naked]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail17.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+["Illegal backslash escape: \017"]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail18.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail19.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+{"Missing colon" null}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail2.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+["Unclosed array"
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail20.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+{"Double colon":: null}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail21.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+{"Comma instead of colon", null}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail22.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+["Colon instead of comma": false]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail23.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+["Bad value", truth]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail24.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+['single quote']
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail25.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+["	tab	character	in	string	"]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail26.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+["tab\   character\   in\  string\  "]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail27.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,2 @@
+["line
+break"]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail28.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,2 @@
+["line\
+break"]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail29.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+[0e]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail3.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+{unquoted_key: "keys must be quoted"}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail30.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+[0e+]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail31.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+[0e+-1]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail32.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+{"Comma instead if closing brace": true,
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail33.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+["mismatch"}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail4.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+["extra comma",]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail5.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+["double extra comma",,]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail6.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+[   , "<-- missing value"]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail7.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+["Comma after the close"],
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail8.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+["Extra close"]]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/fail9.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+{"Extra comma": true,}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/pass1.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,58 @@
+[
+    "JSON Test Pattern pass1",
+    {"object with 1 member":["array with 1 element"]},
+    {},
+    [],
+    -42,
+    true,
+    false,
+    null,
+    {
+        "integer": 1234567890,
+        "real": -9876.543210,
+        "e": 0.123456789e-12,
+        "E": 1.234567890E+34,
+        "":  23456789012E66,
+        "zero": 0,
+        "one": 1,
+        "space": " ",
+        "quote": "\"",
+        "backslash": "\\",
+        "controls": "\b\f\n\r\t",
+        "slash": "/ & \/",
+        "alpha": "abcdefghijklmnopqrstuvwyz",
+        "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
+        "digit": "0123456789",
+        "0123456789": "digit",
+        "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
+        "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
+        "true": true,
+        "false": false,
+        "null": null,
+        "array":[  ],
+        "object":{  },
+        "address": "50 St. James Street",
+        "url": "http://www.JSON.org/",
+        "comment": "// /* <!-- --",
+        "# -- --> */": " ",
+        " s p a c e d " :[1,2 , 3
+
+,
+
+4 , 5        ,          6           ,7        ],"compact":[1,2,3,4,5,6,7],
+        "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
+        "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
+        "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
+: "A key can be any string"
+    },
+    0.5 ,98.6
+,
+99.44
+,
+
+1066,
+1e1,
+0.1e1,
+1e-1,
+1e00,2e+00,2e-00
+,"rosebud"]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/pass2.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,1 @@
+[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/json/pass3.json	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,6 @@
+{
+    "JSON Test Pattern pass3": {
+        "The outermost value": "must be an object or array.",
+        "In this test": "It is an object."
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_util_json.sh	Sat Mar 05 20:50:17 2016 +0000
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+export LUA_PATH="../?.lua;;"
+export LUA_CPATH="../?.so;;"
+
+#set -x
+
+if ! which "$RUNWITH"; then
+	echo "Unable to find interpreter $RUNWITH";
+	exit 1;
+fi
+
+if ! $RUNWITH -e 'assert(require"util.json")' 2>/dev/null; then
+	echo "Unable to find util.json";
+	exit 1;
+fi
+
+FAIL=0
+
+for f in json/pass*.json; do
+	if ! $RUNWITH -e 'local j=require"util.json" assert(j.decode(io.read("*a"))~=nil)' <"$f" 2>/dev/null; then
+		echo "Failed to decode valid JSON: $f";
+		FAIL=1
+	fi
+done
+
+for f in json/fail*.json; do
+	if ! $RUNWITH -e 'local j=require"util.json" assert(j.decode(io.read("*a"))==nil)' <"$f" 2>/dev/null; then
+		echo "Invalid JSON decoded without error: $f";
+		FAIL=1
+	fi
+done
+
+if [ "$FAIL" == "1" ]; then
+	echo "JSON tests failed"
+	exit 1;
+fi
+
+exit 0;