@port-labs/jq-node-bindings 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +5 -0
- package/.jshintignore +1 -0
- package/.jshintrc +23 -0
- package/binding.gyp +56 -0
- package/configure +26 -0
- package/deps/jq/.gitattributes +2 -0
- package/deps/jq/.travis.yml +53 -0
- package/deps/jq/AUTHORS +73 -0
- package/deps/jq/COPYING +70 -0
- package/deps/jq/ChangeLog +1349 -0
- package/deps/jq/Makefile.am +198 -0
- package/deps/jq/NEWS +88 -0
- package/deps/jq/README.md +64 -0
- package/deps/jq/builtin.c +1684 -0
- package/deps/jq/builtin.h +10 -0
- package/deps/jq/bytecode.c +161 -0
- package/deps/jq/bytecode.h +92 -0
- package/deps/jq/compile-ios.sh +102 -0
- package/deps/jq/compile.c +1210 -0
- package/deps/jq/compile.h +101 -0
- package/deps/jq/config/m4/check-math-func.m4 +4 -0
- package/deps/jq/config/m4/find-func-no-libs.m4 +8 -0
- package/deps/jq/config/m4/find-func-no-libs2.m4 +62 -0
- package/deps/jq/config/m4/find-func.m4 +9 -0
- package/deps/jq/config/m4/misc.m4 +3 -0
- package/deps/jq/configure.ac +221 -0
- package/deps/jq/docs/Gemfile +7 -0
- package/deps/jq/docs/Gemfile.lock +63 -0
- package/deps/jq/docs/README.md +25 -0
- package/deps/jq/docs/Rakefile +145 -0
- package/deps/jq/docs/content/1.tutorial/default.yml +327 -0
- package/deps/jq/docs/content/2.download/default.yml +117 -0
- package/deps/jq/docs/content/3.manual/manual.yml +2878 -0
- package/deps/jq/docs/content/3.manual/v1.3/manual.yml +1270 -0
- package/deps/jq/docs/content/3.manual/v1.4/manual.yml +1672 -0
- package/deps/jq/docs/content/index/index.yml +51 -0
- package/deps/jq/docs/default_manpage.md +22 -0
- package/deps/jq/docs/public/.htaccess +28 -0
- package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.css +1058 -0
- package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.min.css +9 -0
- package/deps/jq/docs/public/bootstrap/css/bootstrap.css +5224 -0
- package/deps/jq/docs/public/bootstrap/css/bootstrap.min.css +9 -0
- package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings-white.png +0 -0
- package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings.png +0 -0
- package/deps/jq/docs/public/bootstrap/js/bootstrap.js +2027 -0
- package/deps/jq/docs/public/bootstrap/js/bootstrap.min.js +6 -0
- package/deps/jq/docs/public/css/base.scss +99 -0
- package/deps/jq/docs/public/jq.png +0 -0
- package/deps/jq/docs/public/robots.txt +2 -0
- package/deps/jq/docs/site.yml +18 -0
- package/deps/jq/docs/templates/default.liquid +34 -0
- package/deps/jq/docs/templates/index.liquid +60 -0
- package/deps/jq/docs/templates/manual.liquid +122 -0
- package/deps/jq/docs/templates/shared/_footer.liquid +5 -0
- package/deps/jq/docs/templates/shared/_head.liquid +12 -0
- package/deps/jq/docs/templates/shared/_header.liquid +26 -0
- package/deps/jq/exec_stack.h +112 -0
- package/deps/jq/execute.c +1155 -0
- package/deps/jq/inject_errors.c +112 -0
- package/deps/jq/jq.1.default +39 -0
- package/deps/jq/jq.1.prebuilt +3075 -0
- package/deps/jq/jq.h +60 -0
- package/deps/jq/jq.spec +70 -0
- package/deps/jq/jq_parser.h +9 -0
- package/deps/jq/jq_test.c +346 -0
- package/deps/jq/jv.c +1333 -0
- package/deps/jq/jv.h +240 -0
- package/deps/jq/jv_alloc.c +179 -0
- package/deps/jq/jv_alloc.h +27 -0
- package/deps/jq/jv_aux.c +619 -0
- package/deps/jq/jv_dtoa.c +4275 -0
- package/deps/jq/jv_dtoa.h +22 -0
- package/deps/jq/jv_file.c +49 -0
- package/deps/jq/jv_parse.c +852 -0
- package/deps/jq/jv_print.c +348 -0
- package/deps/jq/jv_unicode.c +96 -0
- package/deps/jq/jv_unicode.h +11 -0
- package/deps/jq/jv_utf8_tables.h +37 -0
- package/deps/jq/lexer.c +2442 -0
- package/deps/jq/lexer.h +362 -0
- package/deps/jq/lexer.l +184 -0
- package/deps/jq/libm.h +160 -0
- package/deps/jq/linker.c +393 -0
- package/deps/jq/linker.h +7 -0
- package/deps/jq/locfile.c +91 -0
- package/deps/jq/locfile.h +29 -0
- package/deps/jq/m4/ax_compare_version.m4 +177 -0
- package/deps/jq/m4/ax_prog_bison_version.m4 +68 -0
- package/deps/jq/main.c +566 -0
- package/deps/jq/opcode_list.h +44 -0
- package/deps/jq/parser.c +3914 -0
- package/deps/jq/parser.h +193 -0
- package/deps/jq/parser.y +923 -0
- package/deps/jq/scripts/crosscompile +42 -0
- package/deps/jq/scripts/gen_utf8_tables.py +32 -0
- package/deps/jq/scripts/version +5 -0
- package/deps/jq/setup.sh +33 -0
- package/deps/jq/tests/jq.test +1235 -0
- package/deps/jq/tests/jqtest +5 -0
- package/deps/jq/tests/mantest +7 -0
- package/deps/jq/tests/modules/.jq +5 -0
- package/deps/jq/tests/modules/a.jq +2 -0
- package/deps/jq/tests/modules/b/b.jq +2 -0
- package/deps/jq/tests/modules/c/c.jq +16 -0
- package/deps/jq/tests/modules/c/d.jq +1 -0
- package/deps/jq/tests/modules/data.json +4 -0
- package/deps/jq/tests/modules/lib/jq/e/e.jq +1 -0
- package/deps/jq/tests/modules/lib/jq/f.jq +1 -0
- package/deps/jq/tests/modules/syntaxerror/syntaxerror.jq +1 -0
- package/deps/jq/tests/modules/test_bind_order.jq +4 -0
- package/deps/jq/tests/modules/test_bind_order0.jq +1 -0
- package/deps/jq/tests/modules/test_bind_order1.jq +2 -0
- package/deps/jq/tests/modules/test_bind_order2.jq +2 -0
- package/deps/jq/tests/onig.supp +21 -0
- package/deps/jq/tests/onig.test +85 -0
- package/deps/jq/tests/onigtest +5 -0
- package/deps/jq/tests/setup +36 -0
- package/deps/jq/tests/shtest +205 -0
- package/deps/jq/tests/torture/input0.json +7 -0
- package/deps/jq/util.c +462 -0
- package/deps/jq/util.h +64 -0
- package/deps/jq.gyp +35 -0
- package/index.d.ts +3 -0
- package/jest.config.js +10 -0
- package/lib/index.js +14 -0
- package/package.json +48 -0
- package/reports/jest-port-api.xml +35 -0
- package/src/binding.cc +177 -0
- package/src/binding.h +13 -0
- package/test/santiy.test.js +122 -0
- package/util/configure.js +27 -0
package/deps/jq/jq.h
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#ifndef JQ_H
|
|
2
|
+
#define JQ_H
|
|
3
|
+
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
#include <jv.h>
|
|
6
|
+
|
|
7
|
+
enum {JQ_DEBUG_TRACE = 1};
|
|
8
|
+
|
|
9
|
+
typedef struct jq_state jq_state;
|
|
10
|
+
typedef void (*jq_msg_cb)(void *, jv);
|
|
11
|
+
|
|
12
|
+
jq_state *jq_init(void);
|
|
13
|
+
void jq_set_error_cb(jq_state *, jq_msg_cb, void *);
|
|
14
|
+
void jq_get_error_cb(jq_state *, jq_msg_cb *, void **);
|
|
15
|
+
void jq_set_nomem_handler(jq_state *, void (*)(void *), void *);
|
|
16
|
+
jv jq_format_error(jv msg);
|
|
17
|
+
void jq_report_error(jq_state *, jv);
|
|
18
|
+
int jq_compile(jq_state *, const char*);
|
|
19
|
+
int jq_compile_args(jq_state *, const char*, jv);
|
|
20
|
+
void jq_dump_disassembly(jq_state *, int);
|
|
21
|
+
void jq_start(jq_state *, jv value, int);
|
|
22
|
+
jv jq_next(jq_state *);
|
|
23
|
+
void jq_teardown(jq_state **);
|
|
24
|
+
|
|
25
|
+
typedef jv (*jq_input_cb)(jq_state *, void *);
|
|
26
|
+
void jq_set_input_cb(jq_state *, jq_input_cb, void *);
|
|
27
|
+
void jq_get_input_cb(jq_state *, jq_input_cb *, void **);
|
|
28
|
+
|
|
29
|
+
void jq_set_debug_cb(jq_state *, jq_msg_cb, void *);
|
|
30
|
+
void jq_get_debug_cb(jq_state *, jq_msg_cb *, void **);
|
|
31
|
+
|
|
32
|
+
void jq_set_attrs(jq_state *, jv);
|
|
33
|
+
jv jq_get_attrs(jq_state *);
|
|
34
|
+
jv jq_get_jq_origin(jq_state *);
|
|
35
|
+
jv jq_get_prog_origin(jq_state *);
|
|
36
|
+
jv jq_get_lib_dirs(jq_state *);
|
|
37
|
+
void jq_set_attr(jq_state *, jv, jv);
|
|
38
|
+
jv jq_get_attr(jq_state *, jv);
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* We use char * instead of jf for filenames here because filenames
|
|
42
|
+
* should be in the process' locale's codeset, which may not be UTF-8,
|
|
43
|
+
* whereas jv string values must be in UTF-8. This way the caller
|
|
44
|
+
* doesn't have to perform any codeset conversions.
|
|
45
|
+
*/
|
|
46
|
+
typedef struct jq_util_input_state jq_util_input_state;
|
|
47
|
+
typedef void (*jq_util_msg_cb)(void *, const char *);
|
|
48
|
+
|
|
49
|
+
jq_util_input_state *jq_util_input_init(jq_util_msg_cb, void *);
|
|
50
|
+
void jq_util_input_set_parser(jq_util_input_state *, jv_parser *, int);
|
|
51
|
+
void jq_util_input_free(jq_util_input_state **);
|
|
52
|
+
void jq_util_input_add_input(jq_util_input_state *, const char *);
|
|
53
|
+
int jq_util_input_errors(jq_util_input_state *);
|
|
54
|
+
jv jq_util_input_next_input(jq_util_input_state *);
|
|
55
|
+
jv jq_util_input_next_input_cb(jq_state *, void *);
|
|
56
|
+
jv jq_util_input_get_position(jq_state*);
|
|
57
|
+
jv jq_util_input_get_current_filename(jq_state*);
|
|
58
|
+
jv jq_util_input_get_current_line(jq_state*);
|
|
59
|
+
|
|
60
|
+
#endif /* !JQ_H */
|
package/deps/jq/jq.spec
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# This is spec file maintained by developers of JQ, not by a OS distro.
|
|
2
|
+
# Your OS of choice will likely ignore this RPM spec file.
|
|
3
|
+
Summary: Command-line JSON processor
|
|
4
|
+
Name: jq
|
|
5
|
+
Version: %{myver}
|
|
6
|
+
Release: %{myrel}%{?dist}
|
|
7
|
+
Source0: jq-%{myver}.tar.gz
|
|
8
|
+
URL: https://stedolan.github.io/jq
|
|
9
|
+
License: BSD
|
|
10
|
+
AutoReqProv: no
|
|
11
|
+
#BuildPrereq: autoconf, libtool, automake, flex, bison, python
|
|
12
|
+
|
|
13
|
+
Group: Applications/System
|
|
14
|
+
# Requires:
|
|
15
|
+
|
|
16
|
+
# Disables debug packages and stripping of binaries:
|
|
17
|
+
%global _enable_debug_package 0
|
|
18
|
+
%global debug_package %{nil}
|
|
19
|
+
%global __os_install_post %{nil}
|
|
20
|
+
|
|
21
|
+
# Crank up the compression
|
|
22
|
+
%define _binary_payload w7.lzdio
|
|
23
|
+
|
|
24
|
+
%description
|
|
25
|
+
jq is a command-line JSON processor
|
|
26
|
+
|
|
27
|
+
%prep
|
|
28
|
+
%setup
|
|
29
|
+
|
|
30
|
+
%build
|
|
31
|
+
echo "Building in: \"$(pwd)\""
|
|
32
|
+
%if "%{devbuild}" == "yes"
|
|
33
|
+
./configure --prefix=%{_prefix} --enable-devel
|
|
34
|
+
%else
|
|
35
|
+
./configure --prefix=%{_prefix}
|
|
36
|
+
%endif
|
|
37
|
+
make
|
|
38
|
+
|
|
39
|
+
%install
|
|
40
|
+
echo "Installing to: \"%{buildroot}\""
|
|
41
|
+
make install DESTDIR=%{buildroot}
|
|
42
|
+
|
|
43
|
+
%clean
|
|
44
|
+
rm -rf %{buildroot}
|
|
45
|
+
|
|
46
|
+
%files
|
|
47
|
+
%defattr(-,root,root)
|
|
48
|
+
%{_bindir}/jq
|
|
49
|
+
%if "%{devbuild}" == "yes"
|
|
50
|
+
%{_libexecdir}/%{name}/jq_test
|
|
51
|
+
%{_libexecdir}/%{name}/testdata
|
|
52
|
+
%endif
|
|
53
|
+
%{_datadir}/doc/%{name}/AUTHORS
|
|
54
|
+
%{_datadir}/doc/%{name}/COPYING
|
|
55
|
+
%{_datadir}/doc/%{name}/README
|
|
56
|
+
%{_datadir}/doc/%{name}/README.md
|
|
57
|
+
%{_datadir}/man/man1/jq.1
|
|
58
|
+
%{_includedir}/jq.h
|
|
59
|
+
%{_includedir}/jv.h
|
|
60
|
+
%{_prefix}/lib/libjq.a
|
|
61
|
+
%{_prefix}/lib/libjq.la
|
|
62
|
+
%{_prefix}/lib/libjq.so
|
|
63
|
+
%{_prefix}/lib/libjq.so.1
|
|
64
|
+
%{_prefix}/lib/libjq.so.1.0.4
|
|
65
|
+
|
|
66
|
+
%changelog
|
|
67
|
+
|
|
68
|
+
%pre
|
|
69
|
+
|
|
70
|
+
%post
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
#include <assert.h>
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <string.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
#include "jv.h"
|
|
6
|
+
#include "jq.h"
|
|
7
|
+
|
|
8
|
+
static void jv_test();
|
|
9
|
+
static void run_jq_tests(jv, int, FILE *);
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
int jq_testsuite(jv libdirs, int verbose, int argc, char* argv[]) {
|
|
13
|
+
FILE *testdata = stdin;
|
|
14
|
+
jv_test();
|
|
15
|
+
if (argc > 0) {
|
|
16
|
+
testdata = fopen(argv[0], "r");
|
|
17
|
+
if (!testdata) {
|
|
18
|
+
perror("fopen");
|
|
19
|
+
exit(1);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
run_jq_tests(libdirs, verbose, testdata);
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static int skipline(const char* buf) {
|
|
27
|
+
int p = 0;
|
|
28
|
+
while (buf[p] == ' ' || buf[p] == '\t') p++;
|
|
29
|
+
if (buf[p] == '#' || buf[p] == '\n' || buf[p] == 0) return 1;
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static int checkerrormsg(const char* buf) {
|
|
34
|
+
return strcmp(buf, "%%FAIL\n") == 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static int checkfail(const char* buf) {
|
|
38
|
+
return strcmp(buf, "%%FAIL\n") == 0 || strcmp(buf, "%%FAIL IGNORE MSG\n") == 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
struct err_data {
|
|
42
|
+
char buf[4096];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
static void test_err_cb(void *data, jv e) {
|
|
46
|
+
struct err_data *err_data = data;
|
|
47
|
+
if (jv_get_kind(e) != JV_KIND_STRING)
|
|
48
|
+
e = jv_dump_string(e, JV_PRINT_INVALID);
|
|
49
|
+
if (!strncmp(jv_string_value(e), "jq: error", sizeof("jq: error") - 1))
|
|
50
|
+
snprintf(err_data->buf, sizeof(err_data->buf), "%s", jv_string_value(e));
|
|
51
|
+
if (strchr(err_data->buf, '\n'))
|
|
52
|
+
*(strchr(err_data->buf, '\n')) = '\0';
|
|
53
|
+
jv_free(e);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata) {
|
|
57
|
+
char prog[4096];
|
|
58
|
+
char buf[4096];
|
|
59
|
+
struct err_data err_msg;
|
|
60
|
+
int tests = 0, passed = 0, invalid = 0;
|
|
61
|
+
unsigned int lineno = 0;
|
|
62
|
+
int must_fail = 0;
|
|
63
|
+
int check_msg = 0;
|
|
64
|
+
jq_state *jq = NULL;
|
|
65
|
+
|
|
66
|
+
jq = jq_init();
|
|
67
|
+
assert(jq);
|
|
68
|
+
if (jv_get_kind(lib_dirs) == JV_KIND_NULL)
|
|
69
|
+
lib_dirs = jv_array();
|
|
70
|
+
jq_set_attr(jq, jv_string("JQ_LIBRARY_PATH"), lib_dirs);
|
|
71
|
+
|
|
72
|
+
while (1) {
|
|
73
|
+
if (!fgets(prog, sizeof(prog), testdata)) break;
|
|
74
|
+
lineno++;
|
|
75
|
+
if (skipline(prog)) continue;
|
|
76
|
+
if (checkfail(prog)) {
|
|
77
|
+
must_fail = 1;
|
|
78
|
+
check_msg = checkerrormsg(prog);
|
|
79
|
+
jq_set_error_cb(jq, test_err_cb, &err_msg);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (prog[strlen(prog)-1] == '\n') prog[strlen(prog)-1] = 0;
|
|
83
|
+
printf("Testing '%s' at line number %u\n", prog, lineno);
|
|
84
|
+
int pass = 1;
|
|
85
|
+
tests++;
|
|
86
|
+
int compiled = jq_compile(jq, prog);
|
|
87
|
+
|
|
88
|
+
if (must_fail) {
|
|
89
|
+
jq_set_error_cb(jq, NULL, NULL);
|
|
90
|
+
if (!fgets(buf, sizeof(buf), testdata)) { invalid++; break; }
|
|
91
|
+
lineno++;
|
|
92
|
+
if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
|
|
93
|
+
if (compiled) {
|
|
94
|
+
printf("*** Test program compiled that should not have at line %u: %s\n", lineno, prog);
|
|
95
|
+
must_fail = 0;
|
|
96
|
+
check_msg = 0;
|
|
97
|
+
invalid++;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (check_msg && strcmp(buf, err_msg.buf) != 0) {
|
|
101
|
+
printf("*** Erroneous test program failed with wrong message (%s) at line %u: %s\n", err_msg.buf, lineno, prog);
|
|
102
|
+
invalid++;
|
|
103
|
+
} else {
|
|
104
|
+
passed++;
|
|
105
|
+
}
|
|
106
|
+
must_fail = 0;
|
|
107
|
+
check_msg = 0;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!compiled) {
|
|
112
|
+
printf("*** Test program failed to compile at line %u: %s\n", lineno, prog);
|
|
113
|
+
invalid++;
|
|
114
|
+
// skip past test data
|
|
115
|
+
while (fgets(buf, sizeof(buf), testdata)) {
|
|
116
|
+
lineno++;
|
|
117
|
+
if (buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n'))
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (verbose) {
|
|
123
|
+
printf("Disassembly:\n");
|
|
124
|
+
jq_dump_disassembly(jq, 2);
|
|
125
|
+
printf("\n");
|
|
126
|
+
}
|
|
127
|
+
if (!fgets(buf, sizeof(buf), testdata)) { invalid++; break; }
|
|
128
|
+
lineno++;
|
|
129
|
+
jv input = jv_parse(buf);
|
|
130
|
+
if (!jv_is_valid(input)) {
|
|
131
|
+
printf("*** Input is invalid on line %u: %s\n", lineno, buf);
|
|
132
|
+
invalid++;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
jq_start(jq, input, verbose ? JQ_DEBUG_TRACE : 0);
|
|
136
|
+
|
|
137
|
+
while (fgets(buf, sizeof(buf), testdata)) {
|
|
138
|
+
lineno++;
|
|
139
|
+
if (skipline(buf)) break;
|
|
140
|
+
jv expected = jv_parse(buf);
|
|
141
|
+
if (!jv_is_valid(expected)) {
|
|
142
|
+
printf("*** Expected result is invalid on line %u: %s\n", lineno, buf);
|
|
143
|
+
invalid++;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
jv actual = jq_next(jq);
|
|
147
|
+
if (!jv_is_valid(actual)) {
|
|
148
|
+
jv_free(actual);
|
|
149
|
+
printf("*** Insufficient results for test at line number %u: %s\n", lineno, prog);
|
|
150
|
+
pass = 0;
|
|
151
|
+
break;
|
|
152
|
+
} else if (!jv_equal(jv_copy(expected), jv_copy(actual))) {
|
|
153
|
+
printf("*** Expected ");
|
|
154
|
+
jv_dump(jv_copy(expected), 0);
|
|
155
|
+
printf(", but got ");
|
|
156
|
+
jv_dump(jv_copy(actual), 0);
|
|
157
|
+
printf(" for test at line number %u: %s\n", lineno, prog);
|
|
158
|
+
pass = 0;
|
|
159
|
+
}
|
|
160
|
+
jv as_string = jv_dump_string(jv_copy(expected), rand() & ~(JV_PRINT_COLOUR|JV_PRINT_REFCOUNT));
|
|
161
|
+
jv reparsed = jv_parse_sized(jv_string_value(as_string), jv_string_length_bytes(jv_copy(as_string)));
|
|
162
|
+
assert(jv_equal(jv_copy(expected), jv_copy(reparsed)));
|
|
163
|
+
jv_free(as_string);
|
|
164
|
+
jv_free(reparsed);
|
|
165
|
+
jv_free(expected);
|
|
166
|
+
jv_free(actual);
|
|
167
|
+
}
|
|
168
|
+
if (pass) {
|
|
169
|
+
jv extra = jq_next(jq);
|
|
170
|
+
if (jv_is_valid(extra)) {
|
|
171
|
+
printf("*** Superfluous result: ");
|
|
172
|
+
jv_dump(extra, 0);
|
|
173
|
+
printf(" for test at line number %u, %s\n", lineno, prog);
|
|
174
|
+
pass = 0;
|
|
175
|
+
} else {
|
|
176
|
+
jv_free(extra);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
passed+=pass;
|
|
180
|
+
}
|
|
181
|
+
jq_teardown(&jq);
|
|
182
|
+
printf("%d of %d tests passed (%d malformed)\n", passed,tests,invalid);
|
|
183
|
+
if (passed != tests) exit(1);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
static void jv_test() {
|
|
188
|
+
/// JSON parser regression tests
|
|
189
|
+
{
|
|
190
|
+
jv v = jv_parse("{\"a':\"12\"}");
|
|
191
|
+
assert(jv_get_kind(v) == JV_KIND_INVALID);
|
|
192
|
+
v = jv_invalid_get_msg(v);
|
|
193
|
+
assert(strcmp(jv_string_value(v), "Expected separator between values at line 1, column 9 (while parsing '{\"a':\"12\"}')") == 0);
|
|
194
|
+
jv_free(v);
|
|
195
|
+
}
|
|
196
|
+
/// Arrays and numbers
|
|
197
|
+
{
|
|
198
|
+
jv a = jv_array();
|
|
199
|
+
assert(jv_get_kind(a) == JV_KIND_ARRAY);
|
|
200
|
+
assert(jv_array_length(jv_copy(a)) == 0);
|
|
201
|
+
assert(jv_array_length(jv_copy(a)) == 0);
|
|
202
|
+
|
|
203
|
+
a = jv_array_append(a, jv_number(42));
|
|
204
|
+
assert(jv_array_length(jv_copy(a)) == 1);
|
|
205
|
+
assert(jv_number_value(jv_array_get(jv_copy(a), 0)) == 42);
|
|
206
|
+
|
|
207
|
+
jv a2 = jv_array_append(jv_array(), jv_number(42));
|
|
208
|
+
assert(jv_equal(jv_copy(a), jv_copy(a)));
|
|
209
|
+
assert(jv_equal(jv_copy(a2), jv_copy(a2)));
|
|
210
|
+
assert(jv_equal(jv_copy(a), jv_copy(a2)));
|
|
211
|
+
assert(jv_equal(jv_copy(a2), jv_copy(a)));
|
|
212
|
+
jv_free(a2);
|
|
213
|
+
|
|
214
|
+
a2 = jv_array_append(jv_array(), jv_number(19));
|
|
215
|
+
assert(!jv_equal(jv_copy(a), jv_copy(a2)));
|
|
216
|
+
assert(!jv_equal(jv_copy(a2), jv_copy(a)));
|
|
217
|
+
jv_free(a2);
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
assert(jv_get_refcnt(a) == 1);
|
|
221
|
+
a = jv_array_append(a, jv_copy(a));
|
|
222
|
+
assert(jv_get_refcnt(a) == 1);
|
|
223
|
+
|
|
224
|
+
assert(jv_array_length(jv_copy(a)) == 2);
|
|
225
|
+
assert(jv_number_value(jv_array_get(jv_copy(a), 0)) == 42);
|
|
226
|
+
|
|
227
|
+
for (int i=0; i<10; i++) {
|
|
228
|
+
jv subarray = jv_array_get(jv_copy(a), 1);
|
|
229
|
+
assert(jv_get_kind(subarray) == JV_KIND_ARRAY);
|
|
230
|
+
assert(jv_array_length(jv_copy(subarray)) == 1);
|
|
231
|
+
assert(jv_number_value(jv_array_get(jv_copy(subarray), 0)) == 42);
|
|
232
|
+
jv_free(subarray);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
jv subarray = jv_array_get(jv_copy(a), 1);
|
|
237
|
+
assert(jv_get_kind(subarray) == JV_KIND_ARRAY);
|
|
238
|
+
assert(jv_array_length(jv_copy(subarray)) == 1);
|
|
239
|
+
assert(jv_number_value(jv_array_get(jv_copy(subarray), 0)) == 42);
|
|
240
|
+
|
|
241
|
+
jv sub2 = jv_copy(subarray);
|
|
242
|
+
sub2 = jv_array_append(sub2, jv_number(19));
|
|
243
|
+
|
|
244
|
+
assert(jv_get_kind(sub2) == JV_KIND_ARRAY);
|
|
245
|
+
assert(jv_array_length(jv_copy(sub2)) == 2);
|
|
246
|
+
assert(jv_number_value(jv_array_get(jv_copy(sub2), 0)) == 42);
|
|
247
|
+
assert(jv_number_value(jv_array_get(jv_copy(sub2), 1)) == 19);
|
|
248
|
+
|
|
249
|
+
assert(jv_get_kind(subarray) == JV_KIND_ARRAY);
|
|
250
|
+
assert(jv_array_length(jv_copy(subarray)) == 1);
|
|
251
|
+
assert(jv_number_value(jv_array_get(jv_copy(subarray), 0)) == 42);
|
|
252
|
+
|
|
253
|
+
jv_free(subarray);
|
|
254
|
+
|
|
255
|
+
void* before = sub2.u.ptr;
|
|
256
|
+
sub2 = jv_array_append(sub2, jv_number(200));
|
|
257
|
+
void* after = sub2.u.ptr;
|
|
258
|
+
assert(before == after);
|
|
259
|
+
jv_free(sub2);
|
|
260
|
+
|
|
261
|
+
jv a3 = jv_array_append(jv_copy(a), jv_number(19));
|
|
262
|
+
assert(jv_array_length(jv_copy(a3)) == 3);
|
|
263
|
+
assert(jv_number_value(jv_array_get(jv_copy(a3), 0)) == 42);
|
|
264
|
+
assert(jv_array_length(jv_array_get(jv_copy(a3), 1)) == 1);
|
|
265
|
+
assert(jv_number_value(jv_array_get(jv_copy(a3), 2)) == 19);
|
|
266
|
+
jv_free(a3);
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
jv a4 = jv_array();
|
|
270
|
+
a4 = jv_array_append(a4, jv_number(1));
|
|
271
|
+
a4 = jv_array_append(a4, jv_number(2));
|
|
272
|
+
jv a5 = jv_copy(a4);
|
|
273
|
+
a4 = jv_array_append(a4, jv_number(3));
|
|
274
|
+
a4 = jv_array_slice(a4, 0, 1);
|
|
275
|
+
assert(jv_array_length(jv_copy(a4)) == 1);
|
|
276
|
+
a4 = jv_array_append(a4, jv_number(4));
|
|
277
|
+
assert(jv_array_length(jv_copy(a4)) == 2);
|
|
278
|
+
assert(jv_array_length(jv_copy(a5)) == 2);
|
|
279
|
+
jv_free(a4);
|
|
280
|
+
jv_free(a5);
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
assert(jv_array_length(jv_copy(a)) == 2);
|
|
284
|
+
assert(jv_number_value(jv_array_get(jv_copy(a), 0)) == 42);
|
|
285
|
+
assert(jv_array_length(jv_array_get(jv_copy(a), 1)) == 1);
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
//jv_dump(jv_copy(a), 0); printf("\n");
|
|
289
|
+
jv_free(a);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
/// Strings
|
|
294
|
+
{
|
|
295
|
+
assert(jv_equal(jv_string("foo"), jv_string_sized("foo", 3)));
|
|
296
|
+
char nasty[] = "foo\0";
|
|
297
|
+
jv shortstr = jv_string(nasty), longstr = jv_string_sized(nasty, sizeof(nasty));
|
|
298
|
+
assert(jv_string_length_bytes(jv_copy(shortstr)) == (int)strlen(nasty));
|
|
299
|
+
assert(jv_string_length_bytes(jv_copy(longstr)) == (int)sizeof(nasty));
|
|
300
|
+
jv_free(shortstr);
|
|
301
|
+
jv_free(longstr);
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
char a1s[] = "hello", a2s[] = "hello", bs[] = "goodbye";
|
|
305
|
+
jv a1 = jv_string(a1s), a2 = jv_string(a2s), b = jv_string(bs);
|
|
306
|
+
assert(jv_equal(jv_copy(a1), jv_copy(a2)));
|
|
307
|
+
assert(jv_equal(jv_copy(a2), jv_copy(a1)));
|
|
308
|
+
assert(!jv_equal(jv_copy(a1), jv_copy(b)));
|
|
309
|
+
|
|
310
|
+
assert(jv_string_hash(jv_copy(a1)) == jv_string_hash(jv_copy(a1)));
|
|
311
|
+
assert(jv_string_hash(jv_copy(a1)) == jv_string_hash(jv_copy(a2)));
|
|
312
|
+
assert(jv_string_hash(jv_copy(b)) != jv_string_hash(jv_copy(a1)));
|
|
313
|
+
jv_free(a1);
|
|
314
|
+
jv_free(a2);
|
|
315
|
+
jv_free(b);
|
|
316
|
+
|
|
317
|
+
assert(jv_equal(jv_string("hello42!"), jv_string_fmt("hello%d%s", 42, "!")));
|
|
318
|
+
char big[20000];
|
|
319
|
+
for (int i=0; i<(int)sizeof(big); i++) big[i] = 'a';
|
|
320
|
+
big[sizeof(big)-1] = 0;
|
|
321
|
+
jv str = jv_string_fmt("%s", big);
|
|
322
|
+
assert(jv_string_length_bytes(jv_copy(str)) == sizeof(big) - 1);
|
|
323
|
+
assert(!strcmp(big, jv_string_value(str)));
|
|
324
|
+
jv_free(str);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/// Objects
|
|
328
|
+
{
|
|
329
|
+
jv o1 = jv_object();
|
|
330
|
+
o1 = jv_object_set(o1, jv_string("foo"), jv_number(42));
|
|
331
|
+
o1 = jv_object_set(o1, jv_string("bar"), jv_number(24));
|
|
332
|
+
assert(jv_number_value(jv_object_get(jv_copy(o1), jv_string("foo"))) == 42);
|
|
333
|
+
assert(jv_number_value(jv_object_get(jv_copy(o1), jv_string("bar"))) == 24);
|
|
334
|
+
|
|
335
|
+
jv o2 = jv_object_set(jv_copy(o1), jv_string("foo"), jv_number(420));
|
|
336
|
+
o2 = jv_object_set(o2, jv_string("bar"), jv_number(240));
|
|
337
|
+
assert(jv_number_value(jv_object_get(jv_copy(o1), jv_string("foo"))) == 42);
|
|
338
|
+
assert(jv_number_value(jv_object_get(jv_copy(o1), jv_string("bar"))) == 24);
|
|
339
|
+
assert(jv_number_value(jv_object_get(jv_copy(o2), jv_string("foo"))) == 420);
|
|
340
|
+
jv_free(o1);
|
|
341
|
+
assert(jv_number_value(jv_object_get(jv_copy(o2), jv_string("bar"))) == 240);
|
|
342
|
+
|
|
343
|
+
//jv_dump(jv_copy(o2), 0); printf("\n");
|
|
344
|
+
jv_free(o2);
|
|
345
|
+
}
|
|
346
|
+
}
|