Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
98be9d5e
Commit
98be9d5e
authored
May 24, 2017
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Run Nicolas Seriot's JSON test-cases.
parent
4b78318d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
441 additions
and
88 deletions
+441
-88
Makefile.am
lib/libvarnishapi/Makefile.am
+8
-0
flint.lnt
lib/libvarnishapi/flint.lnt
+3
-0
vjsn.c
lib/libvarnishapi/vjsn.c
+430
-88
No files found.
lib/libvarnishapi/Makefile.am
View file @
98be9d5e
...
...
@@ -104,3 +104,11 @@ vsl_glob_test_SOURCES = \
vsl_glob_test_LDADD
=
@PCRE_LIBS@
${
RT_LIBS
}
${
LIBM
}
libvarnishapi.la
vsl_glob_test_CFLAGS
=
-I
$(top_srcdir)
/include
TESTS
=
vjsn_test
noinst_PROGRAMS
+=
${
TESTS
}
vjsn_test_SOURCES
=
vjsn.c
vjsn_test_CFLAGS
=
-DVJSN_TEST
vjsn_test_LDADD
=
libvarnishapi.la
lib/libvarnishapi/flint.lnt
View file @
98be9d5e
...
...
@@ -2,6 +2,9 @@
-esym(759, VJSN_*) // could be moved hdr->mod
-esym(765, VJSN_*) // could be made static
-esym(759, vjsn_dump) // could be moved hdr->mod
-esym(765, vjsn_dump) // could be made static
-esym(714, vjsn_dump) // not ref
-esym(788, vex_rhs_e::*)
-esym(788, VSL_transaction_e::*)
-esym(769, vex_rhs_e::VEX__UNSET)
...
...
lib/libvarnishapi/vjsn.c
View file @
98be9d5e
...
...
@@ -26,6 +26,8 @@
* SUCH DAMAGE.
*/
#include "config.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
...
...
@@ -455,106 +457,446 @@ vjsn_dump(const struct vjsn *js, FILE *fo)
#ifdef VJSN_TEST
static
struct
vjsn
*
vjsn_file
(
const
char
*
fn
,
const
char
**
err
)
/*
* Test-cases by Nicolas Seriot
*
* See: http://seriot.ch/parsing_json.php
*
* MIT License
*
* Copyright (c) 2016 Nicolas Seriot
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* We skip tests containing NUL, because we're lazy (The code will actually
* pass these tests if you provide for a way to pass the true length of the
* input to it, and we skip really huge tests, because we are only limited
* by available memory.
*
* To produce the C-data-structures:
*
* Clone https://github.com/nst/JSONTestSuite.git
*
* And run this python in test_parsing:
import glob
def emit(fin):
if fin in skip:
return
x = bytearray(open(fin).read())
if 0 in x:
return
if len(x) > 1000:
return
t = '\t"'
for i in x:
t += "\\x%02x" % i
if len(t) > 64:
print(t + '"')
t = '\t"'
print(t + '",')
print("const char *good[] = {")
for f in glob.glob("y_*"):
emit(f)
print("\tNULL")
print("};")
print("const char *bad[] = {")
for f in glob.glob("n_*"):
emit(f)
print("\tNULL")
print("};")
*/
const
char
*
good
[]
=
{
"
\x5b\x31\x32\x33\x65\x36\x35\x5d
"
,
"
\x5b\x5b\x5d\x20\x20\x20\x5d
"
,
"
\x5b\x22\x22\x5d
"
,
"
\x5b\x5d
"
,
"
\x5b\x22\x61\x22\x5d
"
,
"
\x5b\x66\x61\x6c\x73\x65\x5d
"
,
"
\x5b\x6e\x75\x6c\x6c\x2c\x20\x31\x2c\x20\x22\x31\x22\x2c\x20\x7b
"
"
\x7d\x5d
"
,
"
\x5b\x6e\x75\x6c\x6c\x5d
"
,
"
\x5b\x31\x0a\x5d
"
,
"
\x20\x5b\x31\x5d
"
,
"
\x5b\x31\x2c\x6e\x75\x6c\x6c\x2c\x6e\x75\x6c\x6c\x2c\x6e\x75\x6c
"
"
\x6c\x2c\x32\x5d
"
,
"
\x5b\x32\x5d\x20
"
,
"
\x5b\x30\x65\x2b\x31\x5d
"
,
"
\x5b\x30\x65\x31\x5d
"
,
"
\x5b\x20\x34\x5d
"
,
"
\x5b\x2d\x30\x2e\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30
"
"
\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30
"
"
\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30
"
"
\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30
"
"
\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30
"
"
\x30\x31\x5d\x0a
"
,
"
\x5b\x32\x30\x65\x31\x5d
"
,
"
\x5b\x2d\x30\x5d
"
,
"
\x5b\x2d\x31\x32\x33\x5d
"
,
"
\x5b\x2d\x31\x5d
"
,
"
\x5b\x2d\x30\x5d
"
,
"
\x5b\x31\x45\x32\x32\x5d
"
,
"
\x5b\x31\x45\x2d\x32\x5d
"
,
"
\x5b\x31\x45\x2b\x32\x5d
"
,
"
\x5b\x31\x32\x33\x65\x34\x35\x5d
"
,
"
\x5b\x31\x32\x33\x2e\x34\x35\x36\x65\x37\x38\x5d
"
,
"
\x5b\x31\x65\x2d\x32\x5d
"
,
"
\x5b\x31\x65\x2b\x32\x5d
"
,
"
\x5b\x31\x32\x33\x5d
"
,
"
\x5b\x31\x32\x33\x2e\x34\x35\x36\x37\x38\x39\x5d
"
,
"
\x7b\x22\x61\x73\x64\x22\x3a\x22\x73\x64\x66\x22\x2c\x20\x22\x64
"
"
\x66\x67\x22\x3a\x22\x66\x67\x68\x22\x7d
"
,
"
\x7b\x22\x61\x73\x64\x22\x3a\x22\x73\x64\x66\x22\x7d
"
,
"
\x7b\x22\x61\x22\x3a\x22\x62\x22\x2c\x22\x61\x22\x3a\x22\x63\x22
"
"
\x7d
"
,
"
\x7b\x22\x61\x22\x3a\x22\x62\x22\x2c\x22\x61\x22\x3a\x22\x62\x22
"
"
\x7d
"
,
"
\x7b\x7d
"
,
"
\x7b\x22\x22\x3a\x30\x7d
"
,
"
\x7b\x22\x66\x6f\x6f\x5c\x75\x30\x30\x30\x30\x62\x61\x72\x22\x3a
"
"
\x20\x34\x32\x7d
"
,
"
\x7b\x20\x22\x6d\x69\x6e\x22\x3a\x20\x2d\x31\x2e\x30\x65\x2b\x32
"
"
\x38\x2c\x20\x22\x6d\x61\x78\x22\x3a\x20\x31\x2e\x30\x65\x2b\x32
"
"
\x38\x20\x7d
"
,
"
\x7b\x22\x78\x22\x3a\x5b\x7b\x22\x69\x64\x22\x3a\x20\x22\x78\x78
"
"
\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78
"
"
\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78
"
"
\x78\x78\x78\x78\x78\x78\x22\x7d\x5d\x2c\x20\x22\x69\x64\x22\x3a
"
"
\x20\x22\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78
"
"
\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78
"
"
\x78\x78\x78\x78\x78\x78\x78\x78\x78\x78\x22\x7d
"
,
"
\x7b\x22\x61\x22\x3a\x5b\x5d\x7d
"
,
"
\x7b\x22\x74\x69\x74\x6c\x65\x22\x3a\x22\x5c\x75\x30\x34\x31\x66
"
"
\x5c\x75\x30\x34\x33\x65\x5c\x75\x30\x34\x33\x62\x5c\x75\x30\x34
"
"
\x34\x32\x5c\x75\x30\x34\x33\x65\x5c\x75\x30\x34\x34\x30\x5c\x75
"
"
\x30\x34\x33\x30\x20\x5c\x75\x30\x34\x31\x37\x5c\x75\x30\x34\x33
"
"
\x35\x5c\x75\x30\x34\x33\x63\x5c\x75\x30\x34\x33\x62\x5c\x75\x30
"
"
\x34\x33\x35\x5c\x75\x30\x34\x33\x61\x5c\x75\x30\x34\x33\x65\x5c
"
"
\x75\x30\x34\x33\x66\x5c\x75\x30\x34\x33\x30\x22\x20\x7d
"
,
"
\x7b\x0a\x22\x61\x22\x3a\x20\x22\x62\x22\x0a\x7d
"
,
"
\x5b\x22\x5c\x75\x44\x38\x30\x31\x5c\x75\x64\x63\x33\x37\x22\x5d
"
""
,
"
\x5b\x22\x5c\x75\x30\x30\x36\x30\x5c\x75\x30\x31\x32\x61\x5c\x75
"
"
\x31\x32\x41\x42\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x64\x38\x33\x64\x5c\x75\x64\x65\x33\x39\x5c\x75
"
"
\x64\x38\x33\x64\x5c\x75\x64\x63\x38\x64\x22\x5d
"
,
"
\x5b\x22\x5c\x22\x5c\x5c\x5c\x2f\x5c\x62\x5c\x66\x5c\x6e\x5c\x72
"
"
\x5c\x74\x22\x5d
"
,
"
\x5b\x22\x5c\x5c\x75\x30\x30\x30\x30\x22\x5d
"
,
"
\x5b\x22\x5c\x22\x22\x5d
"
,
"
\x5b\x22\x61\x2f\x2a\x62\x2a\x2f\x63\x2f\x2a\x64\x2f\x2f\x65\x22
"
"
\x5d
"
,
"
\x5b\x22\x5c\x5c\x61\x22\x5d
"
,
"
\x5b\x22\x5c\x5c\x6e\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x30\x30\x31\x32\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x46\x46\x46\x46\x22\x5d
"
,
"
\x5b\x22\x61\x73\x64\x22\x5d
"
,
"
\x5b\x22\x6e\x65\x77\x5c\x75\x30\x30\x41\x30\x6c\x69\x6e\x65\x22
"
"
\x5d
"
,
"
\x5b\x20\x22\x61\x73\x64\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x44\x42\x46\x46\x5c\x75\x44\x46\x46\x46\x22\x5d
"
""
,
"
\x5b\x22\xf4\x8f\xbf\xbf\x22\x5d
"
,
"
\x5b\x22\xf0\x9b\xbf\xbf\x22\x5d
"
,
"
\x5b\x22\xef\xbf\xbf\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x30\x30\x30\x30\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x30\x30\x32\x63\x22\x5d
"
,
"
\x5b\x22\xcf\x80\x22\x5d
"
,
"
\x5b\x22\x61\x73\x64\x20\x22\x5d
"
,
"
\x22\x20\x22
"
,
"
\x5b\x22\x5c\x75\x44\x38\x33\x34\x5c\x75\x44\x64\x31\x65\x22\x5d
"
""
,
"
\x5b\x22\x5c\x75\x30\x38\x32\x31\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x30\x31\x32\x33\x22\x5d
"
,
"
\x5b\x22\xe2\x80\xa8\x22\x5d
"
,
"
\x5b\x22\xe2\x80\xa9\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x30\x30\x36\x31\x5c\x75\x33\x30\x61\x66\x5c\x75
"
"
\x33\x30\x45\x41\x5c\x75\x33\x30\x62\x39\x22\x5d
"
,
"
\x5b\x22\x6e\x65\x77\x5c\x75\x30\x30\x30\x41\x6c\x69\x6e\x65\x22
"
"
\x5d
"
,
"
\x5b\x22\x7f\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x41\x36\x36\x44\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x30\x30\x35\x43\x22\x5d
"
,
"
\x5b\x22\xe2\x8d\x82\xe3\x88\xb4\xe2\x8d\x82\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x44\x42\x46\x46\x5c\x75\x44\x46\x46\x45\x22\x5d
"
""
,
"
\x5b\x22\x5c\x75\x44\x38\x33\x46\x5c\x75\x44\x46\x46\x45\x22\x5d
"
""
,
"
\x5b\x22\xe2\x82\xac\xf0\x9d\x84\x9e\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x32\x30\x30\x42\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x32\x30\x36\x34\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x46\x44\x44\x30\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x46\x46\x46\x45\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x30\x30\x32\x32\x22\x5d
"
,
"
\x5b\x22\x61\x7f\x61\x22\x5d
"
,
"
\x66\x61\x6c\x73\x65
"
,
"
\x34\x32
"
,
"
\x2d\x30\x2e\x31
"
,
"
\x6e\x75\x6c\x6c
"
,
"
\x22\x61\x73\x64\x22
"
,
"
\x74\x72\x75\x65
"
,
"
\x22\x22
"
,
"
\x5b\x22\x61\x22\x5d\x0a
"
,
"
\x5b\x74\x72\x75\x65\x5d
"
,
"
\x20\x5b\x5d\x20
"
,
NULL
};
const
char
*
bad
[]
=
{
"
\x5b\x31\x20\x74\x72\x75\x65\x5d
"
,
"
\x5b\x61\xe5\x5d
"
,
"
\x5b\x22\x22\x3a\x20\x31\x5d
"
,
"
\x5b\x22\x22\x5d\x2c
"
,
"
\x5b\x2c\x31\x5d
"
,
"
\x5b\x31\x2c\x2c\x32\x5d
"
,
"
\x5b\x22\x78\x22\x2c\x2c\x5d
"
,
"
\x5b\x22\x78\x22\x5d\x5d
"
,
"
\x5b\x22\x22\x2c\x5d
"
,
"
\x5b\x22\x78\x22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31\x2e\x30\x65\x5d
"
,
"
\x5b\x31\x20\x30\x30\x30\x2e\x30\x5d
"
,
"
\x5b\x31\x65\x45\x32\x5d
"
,
"
\x5b\x32\x2e\x65\x2b\x33\x5d
"
,
"
\x5b\x32\x2e\x65\x2d\x33\x5d
"
,
"
\x5b\x32\x2e\x65\x33\x5d
"
,
"
\x5b\x39\x2e\x65\x2b\x5d
"
,
"
\x5b\x49\x6e\x66\x5d
"
,
"
\x5b\x4e\x61\x4e\x5d
"
,
"
\x5b\xef\xbc\x91\x5d
"
,
"
\x5b\x31\x2b\x32\x5d
"
,
"
\x5b\x30\x78\x31\x5d
"
,
"
\x5b\x30\x78\x34\x32\x5d
"
,
"
\x5b\x49\x6e\x66\x69\x6e\x69\x74\x79\x5d
"
,
"
\x5b\x30\x65\x2b\x2d\x31\x5d
"
,
"
\x5b\x2d\x31\x32\x33\x2e\x31\x32\x33\x66\x6f\x6f\x5d
"
,
"
\x5b\x31\x32\x33\xe5\x5d
"
,
"
\x5b\x31\x65\x31\xe5\x5d
"
,
"
\x5b\x30\xe5\x5d\x0a
"
,
"
\x5b\x2d\x49\x6e\x66\x69\x6e\x69\x74\x79\x5d
"
,
"
\x5b\x2d\x66\x6f\x6f\x5d
"
,
"
\x5b\x2d\x20\x31\x5d
"
,
"
\x5b\x2d\x30\x31\x32\x5d
"
,
"
\x5b\x2d\x2e\x31\x32\x33\x5d
"
,
"
\x5b\x2d\x31\x78\x5d
"
,
"
\x5b\x31\x65\x61\x5d
"
,
"
\x5b\x31\x65\xe5\x5d
"
,
"
\x5b\x31\x2e\x5d
"
,
"
\x5b\x2e\x31\x32\x33\x5d
"
,
"
\x5b\x31\x2e\x32\x61\x2d\x33\x5d
"
,
"
\x5b\x31\x2e\x38\x30\x31\x31\x36\x37\x30\x30\x33\x33\x33\x37\x36
"
"
\x35\x31\x34\x48\x2d\x33\x30\x38\x5d
"
,
"
\x5b\x30\x31\x32\x5d
"
,
"
\x5b\x22\x78\x22\x2c\x20\x74\x72\x75\x74\x68\x5d
"
,
"
\x7b\x5b\x3a\x20\x22\x78\x22\x7d\x0a
"
,
"
\x7b\x22\x78\x22\x2c\x20\x6e\x75\x6c\x6c\x7d
"
,
"
\x7b\x22\x78\x22\x3a\x3a\x22\x62\x22\x7d
"
,
"
\x7b\xf0\x9f\x87\xa8\xf0\x9f\x87\xad\x7d
"
,
"
\x7b\x22\x61\x22\x3a\x22\x61\x22\x20\x31\x32\x33\x7d
"
,
"
\x7b\x6b\x65\x79\x3a\x20\x27\x76\x61\x6c\x75\x65\x27\x7d
"
,
"
\x7b\x22\x61\x22\x20\x62\x7d
"
,
"
\x7b\x3a\x22\x62\x22\x7d
"
,
"
\x7b\x22\x61\x22\x20\x22\x62\x22\x7d
"
,
"
\x7b\x22\x61\x22\x3a
"
,
"
\x7b\x22\x61\x22
"
,
"
\x7b\x31\x3a\x31\x7d
"
,
"
\x7b\x39\x39\x39\x39\x45\x39\x39\x39\x39\x3a\x31\x7d
"
,
"
\x7b\x22\xb9\x22\x3a\x22\x30\x22\x2c\x7d
"
,
"
\x7b\x6e\x75\x6c\x6c\x3a\x6e\x75\x6c\x6c\x2c\x6e\x75\x6c\x6c\x3a
"
"
\x6e\x75\x6c\x6c\x7d
"
,
"
\x7b\x22\x69\x64\x22\x3a\x30\x2c\x2c\x2c\x2c\x2c\x7d
"
,
"
\x7b\x27\x61\x27\x3a\x30\x7d
"
,
"
\x7b\x22\x69\x64\x22\x3a\x30\x2c\x7d
"
,
"
\x7b\x22\x61\x22\x3a\x22\x62\x22\x7d\x2f\x2a\x2a\x2f
"
,
"
\x7b\x22\x61\x22\x3a\x22\x62\x22\x7d\x2f\x2a\x2a\x2f\x2f
"
,
"
\x7b\x22\x61\x22\x3a\x22\x62\x22\x7d\x2f\x2f
"
,
"
\x7b\x22\x61\x22\x3a\x22\x62\x22\x7d\x2f
"
,
"
\x7b\x22\x61\x22\x3a\x22\x62\x22\x2c\x2c\x22\x63\x22\x3a\x22\x64
"
"
\x22\x7d
"
,
"
\x7b\x61\x3a\x20\x22\x62\x22\x7d
"
,
"
\x7b\x22\x61\x22\x3a\x22\x61
"
,
"
\x7b\x20\x22\x66\x6f\x6f\x22\x20\x3a\x20\x22\x62\x61\x72\x22\x2c
"
"
\x20\x22\x61\x22\x20\x7d
"
,
"
\x7b\x22\x61\x22\x3a\x22\x62\x22\x7d\x23
"
,
"
\x20
"
,
"
\x5b\x22\x5c\x75\x44\x38\x30\x30\x5c\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x44\x38\x30\x30\x5c\x75\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x44\x38\x30\x30\x5c\x75\x31\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x44\x38\x30\x30\x5c\x75\x31\x78\x22\x5d
"
,
"
\x5b\xc3\xa9\x5d
"
,
"
\x5b\x22\x5c\x78\x30\x30\x22\x5d
"
,
"
\x5b\x22\x5c\x5c\x5c\x22\x5d
"
,
"
\x5b\x22\x5c\x09\x22\x5d
"
,
"
\x5b\x22\x5c\xf0\x9f\x8c\x80\x22\x5d
"
,
"
\x5b\x22\x5c\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x30\x30\x41\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x44\x38\x33\x34\x5c\x75\x44\x64\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x44\x38\x30\x30\x5c\x75\x44\x38\x30\x30\x5c\x78
"
"
\x22\x5d
"
,
"
\x5b\x22\x5c\x75\xe5\x22\x5d
"
,
"
\x5b\x22\x5c\x61\x22\x5d
"
,
"
\x5b\x22\x5c\x75\x71\x71\x71\x71\x22\x5d
"
,
"
\x5b\x22\x5c\xe5\x22\x5d
"
,
"
\x5b\x5c\x75\x30\x30\x32\x30\x22\x61\x73\x64\x22\x5d
"
,
"
\x5b\x5c\x6e\x5d
"
,
"
\x22
"
,
"
\x5b\x27\x73\x69\x6e\x67\x6c\x65\x20\x71\x75\x6f\x74\x65\x27\x5d
"
""
,
"
\x61\x62\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\x30\x41\x22\x22\x5d
"
,
"
\x5b\x31
"
,
"
\x5b\x20\x66\x61\x6c\x73\x65\x2c\x20\x6e\x75\x6c
"
,
"
\x5b\x20\x74\x72\x75\x65\x2c\x20\x66\x61\x6c\x73
"
,
"
\x5b\x20\x66\x61\x6c\x73\x65\x2c\x20\x74\x72\x75
"
,
"
\x7b\x22\x61\x73\x64\x22\x3a\x22\x61\x73\x64\x22
"
,
"
\xc3\xa5
"
,
"
\x5b\xe2\x81\xa0\x5d
"
,
"
\x5b\x0c\x5d
"
,
NULL
};
static
void
test_good
(
const
char
*
j
)
{
int
fd
;
struct
stat
st
;
char
*
p
,
*
e
;
ssize_t
sz
;
struct
vjsn
*
js
;
const
char
*
err
;
AN
(
fn
);
AN
(
err
);
*
err
=
NULL
;
fd
=
open
(
fn
,
O_RDONLY
);
if
(
fd
<
0
)
{
*
err
=
strerror
(
errno
);
return
(
NULL
);
}
AZ
(
fstat
(
fd
,
&
st
));
if
(
!
S_ISREG
(
st
.
st_mode
))
{
AZ
(
close
(
fd
));
*
err
=
"Not a regular file"
;
return
(
NULL
);
}
if
(
st
.
st_size
==
0
)
{
AZ
(
close
(
fd
));
*
err
=
"Empty file"
;
return
(
NULL
);
}
p
=
malloc
(
st
.
st_size
+
1
);
AN
(
p
);
sz
=
read
(
fd
,
p
,
st
.
st_size
+
1
);
if
(
sz
<
0
)
{
*
err
=
strerror
(
errno
);
AZ
(
close
(
fd
));
free
(
p
);
return
(
NULL
);
}
AZ
(
close
(
fd
));
if
(
sz
<
st
.
st_size
)
{
free
(
p
);
*
err
=
"Short read"
;
return
(
NULL
);
js
=
vjsn_parse
(
j
,
&
err
);
if
(
js
==
NULL
||
err
!=
NULL
)
{
fprintf
(
stderr
,
"Parse error: %s
\n
%s
\n
"
,
err
,
j
);
exit
(
1
);
}
printf
(
"GOOD: %s
\n
"
,
j
);
vjsn_dump
(
js
,
stdout
);
vjsn_delete
(
&
js
);
}
if
(
sz
>
st
.
st_size
)
{
free
(
p
);
*
err
=
"Long read"
;
return
(
NULL
);
}
p
[
sz
]
=
'\0'
;
e
=
p
+
sz
;
ALLOC_OBJ
(
js
,
VJSN_MAGIC
);
AN
(
js
);
js
->
raw
=
p
;
js
->
ptr
=
p
;
js
->
value
=
vjsn_value
(
js
);
if
(
js
->
err
!=
NULL
)
{
*
err
=
js
->
err
;
vjsn_delete
(
&
js
);
return
(
NULL
);
}
static
void
test_bad
(
const
char
*
j
)
{
struct
vjsn
*
js
;
const
char
*
err
;
vjsn_skip_ws
(
js
);
if
(
js
->
ptr
!=
e
)
{
*
err
=
"Garbage after value"
;
vjsn_delete
(
&
js
);
return
(
NULL
);
js
=
vjsn_parse
(
j
,
&
err
);
if
(
js
!=
NULL
||
err
==
NULL
)
{
fprintf
(
stderr
,
"Parse succeeded %s
\n
"
,
j
);
exit
(
1
);
}
return
(
js
);
printf
(
"BAD: %s %s
\n
"
,
err
,
j
);
}
static
const
char
*
const
fnx
=
"tst.vjsn"
;
int
main
(
int
argc
,
char
**
argv
)
{
struct
vjsn
*
js
;
const
char
*
err
;
if
(
argc
==
1
)
js
=
vjsn_file
(
fnx
,
&
err
);
else
js
=
vjsn_file
(
argv
[
1
],
&
err
);
if
(
err
!=
NULL
)
{
fprintf
(
stderr
,
"ERROR: %s
\n
"
,
err
);
AZ
(
js
);
return
(
1
);
}
else
{
if
(
0
)
vjsn_dump
(
js
,
stdout
);
vjsn_delete
(
&
js
);
}
const
char
**
s
;
(
void
)
argc
;
(
void
)
argv
;
for
(
s
=
good
;
*
s
!=
NULL
;
s
++
)
test_good
(
*
s
);
for
(
s
=
bad
;
*
s
!=
NULL
;
s
++
)
test_bad
(
*
s
);
return
(
0
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment