mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
JSON-input string-preserve iterate
This commit is contained in:
parent
5999572f9f
commit
1b5307c9a2
6 changed files with 139 additions and 23 deletions
45
.gitignore
vendored
45
.gitignore
vendored
|
|
@ -2,20 +2,32 @@ mlr
|
|||
mlrd
|
||||
mlrg
|
||||
mlrp
|
||||
mlr-unit-tester
|
||||
test-argparse
|
||||
test-mlrutil
|
||||
test-mlrregex
|
||||
test-string-builder
|
||||
test-byte-readers
|
||||
test-peek-file-reader
|
||||
test-parse-trie
|
||||
test-lrec
|
||||
test-multiple-containers
|
||||
test-mlhmmv
|
||||
test-lrec-evaluators
|
||||
test_lrec_evaluators
|
||||
test-join-bucket-keeper
|
||||
test-json-parser
|
||||
test-lrec
|
||||
test-lrec-evaluators
|
||||
test-mlhmmv
|
||||
test-mlrregex
|
||||
test-mlrutil
|
||||
test-multiple-containers
|
||||
test-parse-trie
|
||||
test-peek-file-reader
|
||||
test-string-builder
|
||||
test_lrec_evaluators
|
||||
test_argparse
|
||||
test_byte_readers
|
||||
test_join_bucket_keeper
|
||||
test_json_parser
|
||||
test_lrec
|
||||
test_mlhmmv
|
||||
test_mlrregex
|
||||
test_mlrutil
|
||||
test_multiple_containers
|
||||
test_parse_trie
|
||||
test_peek_file_reader
|
||||
test_string_builder
|
||||
termcvt
|
||||
a.out
|
||||
*.dSYM
|
||||
|
|
@ -62,14 +74,3 @@ getl
|
|||
lemon_prepared
|
||||
lrim
|
||||
mlr-[0-9.]*.tar.*
|
||||
test_argparse
|
||||
test_byte_readers
|
||||
test_join_bucket_keeper
|
||||
test_lrec
|
||||
test_mlrutil
|
||||
test_mlrregex
|
||||
test_multiple_containers
|
||||
test_mlhmmv
|
||||
test_parse_trie
|
||||
test_peek_file_reader
|
||||
test_string_builder
|
||||
|
|
|
|||
|
|
@ -247,6 +247,12 @@ TEST_JOIN_BUCKET_KEEPER_SRCS = \
|
|||
input/peek_file_reader.c \
|
||||
unit_test/test_join_bucket_keeper.c
|
||||
|
||||
TEST_JSON_PARSER_SRCS = \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_globals.c \
|
||||
input/json_parser.c \
|
||||
unit_test/test_json_parser.c
|
||||
|
||||
EXPERIMENTAL_READER_SRCS = \
|
||||
lib/mlrutil.c \
|
||||
lib/mlrregex.c \
|
||||
|
|
@ -367,6 +373,9 @@ test-lrec-evaluators: .always
|
|||
test-join-bucket-keeper: .always
|
||||
$(CCDEBUG) $(TEST_JOIN_BUCKET_KEEPER_SRCS) -o test-join-bucket-keeper -lm
|
||||
|
||||
test-json-parser: .always
|
||||
$(CCDEBUG) $(TEST_JSON_PARSER_SRCS) -o test-json-parser -lm
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# Standalone mains
|
||||
|
||||
|
|
|
|||
|
|
@ -583,6 +583,8 @@ json_value_t * json_parse(
|
|||
b = 0;
|
||||
break;
|
||||
}
|
||||
// xxx temp. needs json_value restructure w/ single sval&length.
|
||||
integer_sval_add(&state, ptop, b);
|
||||
|
||||
b = *state.ptr;
|
||||
}
|
||||
|
|
@ -857,6 +859,14 @@ e_failed:
|
|||
return 0;
|
||||
}
|
||||
|
||||
json_value_t * json_parse_for_unit_test(
|
||||
const json_char * json,
|
||||
json_char** ppend_of_item)
|
||||
{
|
||||
json_char error_buf[JSON_ERROR_MAX];
|
||||
return json_parse(json, strlen(json), error_buf, ppend_of_item);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
void json_value_free(json_value_t * pvalue) {
|
||||
json_value_t * cur_value;
|
||||
|
|
|
|||
|
|
@ -148,6 +148,10 @@ json_value_t * json_parse(
|
|||
char * error_buf,
|
||||
json_char** ppend_of_item);
|
||||
|
||||
json_value_t * json_parse_for_unit_test(
|
||||
const json_char * json,
|
||||
json_char** ppend_of_item);
|
||||
|
||||
void json_value_free(json_value_t *);
|
||||
|
||||
char* json_describe_type(json_type_t type);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
// ================================================================
|
||||
// xxx clean up these comments
|
||||
// mmap: easy pointer math
|
||||
// stdio from file: stat, alloc, read. libify this.
|
||||
// stdio from stdin: realloc w/ page-size fread. libify this.
|
||||
|
||||
// note @ mlr -h: no streaing for JSON input. No records are processed until EOF is seen.
|
||||
// note @ mlr -h: no streaming for JSON input. No records are processed until EOF is seen.
|
||||
|
||||
// paginated:
|
||||
// json parse || error msg
|
||||
|
|
|
|||
91
c/unit_test/test_json_parser.c
Normal file
91
c/unit_test/test_json_parser.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "lib/minunit.h"
|
||||
#include "lib/mlrutil.h"
|
||||
#include "input/json_parser.h"
|
||||
|
||||
int tests_run = 0;
|
||||
int tests_failed = 0;
|
||||
int assertions_run = 0;
|
||||
int assertions_failed = 0;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
static char * test_numbers_only() {
|
||||
json_char* input = "123";
|
||||
json_char* end = NULL;
|
||||
json_value_t* pvalue = json_parse_for_unit_test(input, &end);
|
||||
mu_assert_lf(pvalue != NULL);
|
||||
mu_assert_lf(pvalue->type == JSON_INTEGER);
|
||||
printf("sval: [%s]\n", pvalue->u.integer.sval);
|
||||
// xxx make a dump-node method: non-recursive version
|
||||
// xxx make an argv-option :)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//typedef struct _json_value_t {
|
||||
// struct _json_value_t * parent;
|
||||
// json_type_t type;
|
||||
// union {
|
||||
// struct {
|
||||
// int nval;
|
||||
// unsigned int length;
|
||||
// char* sval;
|
||||
// } boolean;
|
||||
// struct {
|
||||
// json_int_t nval;
|
||||
// unsigned int length;
|
||||
// char* sval;
|
||||
// } integer;
|
||||
// struct {
|
||||
// double nval;
|
||||
// unsigned int length;
|
||||
// char* sval;
|
||||
// } dbl;
|
||||
// struct {
|
||||
// unsigned int length;
|
||||
// json_char * ptr; /* null-terminated */
|
||||
// } string;
|
||||
// struct {
|
||||
// unsigned int length;
|
||||
// union {
|
||||
// json_object_entry_t * values;
|
||||
// char* mem;
|
||||
// } p;
|
||||
// } object;
|
||||
// struct {
|
||||
// unsigned int length;
|
||||
// struct _json_value_t ** values;
|
||||
// } array;
|
||||
// } u;
|
||||
// union {
|
||||
// struct _json_value_t * next_alloc;
|
||||
// union {
|
||||
// void * pvobject_mem;
|
||||
// char * pobject_mem;
|
||||
// } p;
|
||||
// } _reserved;
|
||||
// unsigned int line, col;
|
||||
//} json_value_t;
|
||||
|
||||
// ================================================================
|
||||
static char * all_tests() {
|
||||
mu_run_test(test_numbers_only);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("TEST_JSON_PARSER ENTER\n");
|
||||
char *result = all_tests();
|
||||
printf("\n");
|
||||
if (result != 0) {
|
||||
printf("Not all unit tests passed\n");
|
||||
}
|
||||
else {
|
||||
printf("TEST_JSON_PARSER: ALL UNIT TESTS PASSED\n");
|
||||
}
|
||||
printf("Tests passed: %d of %d\n", tests_run - tests_failed, tests_run);
|
||||
printf("Assertions passed: %d of %d\n", assertions_run - assertions_failed, assertions_run);
|
||||
|
||||
return result != 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue