This data structure is used to return information on decoding
errors from the decoding functions.
- .. member:: const char *text
+ .. member:: char text[]
The error message (in UTF-8), or an empty string if a message is
not available.
+ .. member:: char source[]
+
+ Source of the error. This is (a part of) the file name when
+ using :func:`json_load_file()`, or a special identifier in angle
+ brackets otherwise (e.g. ``<string>``).
+
.. member:: int line
- The line number on which the error occurred, or -1 if this
- information is not available.
+ The line number on which the error occurred.
.. member:: int column
- The character column on which the error occurred, or -1 if this
- information is not available.
+ The character column on which the error occurred. Note that this
+ is the *character column*, not the byte column, i.e. a non-ASCII
+ UTF-8 character counts as one column.
- .. member:: const char *source
+ .. member:: size_t position
- Source of the error. This is (a part of) the file name when
- using :func:`json_load_file()`, or a special identifier in angle
- brackets otherwise (e.g. ``<string>``).
+ The position in bytes from the start of the input. This is
+ useful for debugging Unicode encoding problems.
The normal use of :type:`json_error_t` is to allocate it on the
stack, and pass a pointer to a decoding function. Example::
error->text[0] = '\0';
error->line = -1;
error->column = -1;
+ error->position = 0;
strncpy(error->source, source, JSON_ERROR_SOURCE_LENGTH);
error->source[JSON_ERROR_SOURCE_LENGTH - 1] = '\0';
}
void jsonp_error_set(json_error_t *error, int line, int column,
- const char *msg, ...)
+ size_t position, const char *msg, ...)
{
va_list ap;
va_start(ap, msg);
- jsonp_error_vset(error, line, column, msg, ap);
+ jsonp_error_vset(error, line, column, position, msg, ap);
va_end(ap);
}
void jsonp_error_vset(json_error_t *error, int line, int column,
- const char *msg, va_list ap)
+ size_t position, const char *msg, va_list ap)
{
if(!error)
return;
error->line = line;
error->column = column;
+ error->position = position;
vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH, msg, ap);
}
#define JSON_ERROR_SOURCE_LENGTH 80
typedef struct {
- char text[JSON_ERROR_TEXT_LENGTH];
int line;
int column;
+ int position;
char source[JSON_ERROR_SOURCE_LENGTH];
+ char text[JSON_ERROR_TEXT_LENGTH];
} json_error_t;
void jsonp_error_init(json_error_t *error, const char *source);
void jsonp_error_set(json_error_t *error, int line, int column,
- const char *msg, ...);
+ size_t position, const char *msg, ...);
void jsonp_error_vset(json_error_t *error, int line, int column,
- const char *msg, va_list ap);
+ size_t position, const char *msg, va_list ap);
/* Wrappers for custom memory functions */
void* jsonp_malloc(size_t size);
#include "strbuffer.h"
#include "utf.h"
+#define STREAM_STATE_OK 0
+#define STREAM_STATE_EOF -1
+#define STREAM_STATE_ERROR -2
+
#define TOKEN_INVALID -1
#define TOKEN_EOF 0
#define TOKEN_STRING 256
#define TOKEN_FALSE 260
#define TOKEN_NULL 261
-/* read one byte from stream, return EOF on end of file */
+/* Read one byte from stream, convert to unsigned char, then int, and
+ return. return EOF on end of file. This corresponds to the
+ behaviour of fgetc(). */
typedef int (*get_func)(void *data);
-/* return non-zero if end of file has been reached */
-typedef int (*eof_func)(void *data);
-
typedef struct {
get_func get;
- eof_func eof;
void *data;
- int stream_pos;
char buffer[5];
int buffer_pos;
+ int state;
+ int line;
+ int column, last_column;
+ size_t position;
} stream_t;
-
typedef struct {
stream_t stream;
strbuffer_t saved_text;
int token;
- int line, column;
union {
char *string;
json_int_t integer;
} value;
} lex_t;
+#define stream_to_lex(stream) container_of(stream, lex_t, stream)
+
/*** error reporting ***/
char msg_text[JSON_ERROR_TEXT_LENGTH];
int line = -1, col = -1;
+ size_t pos = 0;
const char *result = msg_text;
if(!error)
const char *saved_text = strbuffer_value(&lex->saved_text);
char msg_with_context[JSON_ERROR_TEXT_LENGTH];
- line = lex->line;
+ line = lex->stream.line;
+ col = lex->stream.column;
+ pos = lex->stream.position;
if(saved_text && saved_text[0])
{
}
else
{
- snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH,
- "%s near end of file", msg_text);
- result = msg_with_context;
+ if(lex->stream.state == STREAM_STATE_ERROR) {
+ /* No context for UTF-8 decoding errors */
+ result = msg_text;
+ }
+ else {
+ snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH,
+ "%s near end of file", msg_text);
+ result = msg_with_context;
+ }
}
}
- jsonp_error_set(error, line, col, "%s", result);
+ jsonp_error_set(error, line, col, pos, "%s", result);
}
/*** lexical analyzer ***/
static void
-stream_init(stream_t *stream, get_func get, eof_func eof, void *data)
+stream_init(stream_t *stream, get_func get, void *data)
{
stream->get = get;
- stream->eof = eof;
stream->data = data;
- stream->stream_pos = 0;
stream->buffer[0] = '\0';
stream->buffer_pos = 0;
+
+ stream->state = STREAM_STATE_OK;
+ stream->line = 1;
+ stream->column = 0;
+ stream->position = 0;
}
-static char stream_get(stream_t *stream, json_error_t *error)
+static int stream_get(stream_t *stream, json_error_t *error)
{
- char c;
+ int c;
+
+ if(stream->state != STREAM_STATE_OK)
+ return stream->state;
if(!stream->buffer[stream->buffer_pos])
{
- stream->buffer[0] = stream->get(stream->data);
- stream->buffer_pos = 0;
+ c = stream->get(stream->data);
+ if(c == EOF) {
+ stream->state = STREAM_STATE_EOF;
+ return STREAM_STATE_EOF;
+ }
- c = stream->buffer[0];
+ stream->buffer[0] = c;
+ stream->buffer_pos = 0;
- if((unsigned char)c >= 0x80 && c != (char)EOF)
+ if(0x80 <= c && c <= 0xFF)
{
/* multi-byte UTF-8 sequence */
int i, count;
if(!utf8_check_full(stream->buffer, count, NULL))
goto out;
- stream->stream_pos += count;
stream->buffer[count] = '\0';
}
- else {
+ else
stream->buffer[1] = '\0';
- stream->stream_pos++;
- }
}
- return stream->buffer[stream->buffer_pos++];
+ c = stream->buffer[stream->buffer_pos++];
-out:
- error_set(error, NULL, "unable to decode byte 0x%x at position %d",
- (unsigned char)c, stream->stream_pos);
+ stream->position++;
+ if(c == '\n') {
+ stream->line++;
+ stream->last_column = stream->column;
+ stream->column = 0;
+ }
+ else if(utf8_check_first(c)) {
+ /* track the Unicode character column, so increment only if
+ this is the first character of a UTF-8 sequence */
+ stream->column++;
+ }
- stream->buffer[0] = EOF;
- stream->buffer[1] = '\0';
- stream->buffer_pos = 1;
+ return c;
- return EOF;
+out:
+ stream->state = STREAM_STATE_ERROR;
+ error_set(error, stream_to_lex(stream), "unable to decode byte 0x%x", c);
+ return STREAM_STATE_ERROR;
}
-static void stream_unget(stream_t *stream, char c)
+static void stream_unget(stream_t *stream, int c)
{
+ if(c == STREAM_STATE_EOF || c == STREAM_STATE_ERROR)
+ return;
+
+ stream->position--;
+ if(c == '\n') {
+ stream->line--;
+ stream->column = stream->last_column;
+ }
+ else if(utf8_check_first(c))
+ stream->column--;
+
assert(stream->buffer_pos > 0);
stream->buffer_pos--;
assert(stream->buffer[stream->buffer_pos] == c);
return stream_get(&lex->stream, error);
}
-static int lex_eof(lex_t *lex)
-{
- return lex->stream.eof(lex->stream.data);
-}
-
-static void lex_save(lex_t *lex, char c)
+static void lex_save(lex_t *lex, int c)
{
strbuffer_append_byte(&lex->saved_text, c);
}
static int lex_get_save(lex_t *lex, json_error_t *error)
{
- char c = stream_get(&lex->stream, error);
- lex_save(lex, c);
+ int c = stream_get(&lex->stream, error);
+ if(c != STREAM_STATE_EOF && c != STREAM_STATE_ERROR)
+ lex_save(lex, c);
return c;
}
-static void lex_unget_unsave(lex_t *lex, char c)
+static void lex_unget(lex_t *lex, int c)
{
- char d;
stream_unget(&lex->stream, c);
- d = strbuffer_pop(&lex->saved_text);
- assert(c == d);
+}
+
+static void lex_unget_unsave(lex_t *lex, int c)
+{
+ if(c != STREAM_STATE_EOF && c != STREAM_STATE_ERROR) {
+ char d;
+ stream_unget(&lex->stream, c);
+ d = strbuffer_pop(&lex->saved_text);
+ assert(c == d);
+ }
}
static void lex_save_cached(lex_t *lex)
{
lex_save(lex, lex->stream.buffer[lex->stream.buffer_pos]);
lex->stream.buffer_pos++;
+ lex->stream.position++;
}
}
static void lex_scan_string(lex_t *lex, json_error_t *error)
{
- char c;
+ int c;
const char *p;
char *t;
int i;
c = lex_get_save(lex, error);
while(c != '"') {
- if(c == (char)EOF) {
- lex_unget_unsave(lex, c);
- if(lex_eof(lex))
- error_set(error, lex, "premature end of input");
+ if(c == STREAM_STATE_ERROR)
+ goto out;
+
+ else if(c == STREAM_STATE_EOF) {
+ error_set(error, lex, "premature end of input");
goto out;
}
- else if((unsigned char)c <= 0x1F) {
+ else if(0 <= c && c <= 0x1F) {
/* control character */
lex_unget_unsave(lex, c);
if(c == '\n')
c = lex_get_save(lex, error);
for(i = 0; i < 4; i++) {
if(!isxdigit(c)) {
- lex_unget_unsave(lex, c);
error_set(error, lex, "invalid escape");
goto out;
}
c == 'f' || c == 'n' || c == 'r' || c == 't')
c = lex_get_save(lex, error);
else {
- lex_unget_unsave(lex, c);
error_set(error, lex, "invalid escape");
goto out;
}
#define json_strtoint strtol
#endif
-static int lex_scan_number(lex_t *lex, char c, json_error_t *error)
+static int lex_scan_number(lex_t *lex, int c, json_error_t *error)
{
const char *saved_text;
char *end;
c = lex_get_save(lex, error);
}
else {
- lex_unget_unsave(lex, c);
- goto out;
+ lex_unget_unsave(lex, c);
+ goto out;
}
if(c != '.' && c != 'E' && c != 'e') {
if(c == '.') {
c = lex_get(lex, error);
- if(!isdigit(c))
+ if(!isdigit(c)) {
+ lex_unget(lex, c);
goto out;
+ }
lex_save(lex, c);
c = lex_get_save(lex, error);
static int lex_scan(lex_t *lex, json_error_t *error)
{
- char c;
+ int c;
strbuffer_clear(&lex->saved_text);
c = lex_get(lex, error);
while(c == ' ' || c == '\t' || c == '\n' || c == '\r')
- {
- if(c == '\n')
- lex->line++;
-
c = lex_get(lex, error);
+
+ if(c == STREAM_STATE_EOF) {
+ lex->token = TOKEN_EOF;
+ goto out;
}
- if(c == (char)EOF) {
- if(lex_eof(lex))
- lex->token = TOKEN_EOF;
- else
- lex->token = TOKEN_INVALID;
+ if(c == STREAM_STATE_ERROR) {
+ lex->token = TOKEN_INVALID;
goto out;
}
return result;
}
-static int lex_init(lex_t *lex, get_func get, eof_func eof, void *data)
+static int lex_init(lex_t *lex, get_func get, void *data)
{
- stream_init(&lex->stream, get, eof, data);
+ stream_init(&lex->stream, get, data);
if(strbuffer_init(&lex->saved_text))
return -1;
lex->token = TOKEN_INVALID;
- lex->line = 1;
-
return 0;
}
else
{
stream->pos++;
- return c;
+ return (unsigned char)c;
}
}
-static int string_eof(void *data)
-{
- string_data_t *stream = (string_data_t *)data;
- return (stream->data[stream->pos] == '\0');
-}
-
json_t *json_loads(const char *string, size_t flags, json_error_t *error)
{
lex_t lex;
(void)flags; /* unused */
- if(lex_init(&lex, string_get, string_eof, (void *)&stream_data))
+ if(lex_init(&lex, string_get, (void *)&stream_data))
return NULL;
jsonp_error_init(error, "<string>");
json_t *result;
(void)flags; /* unused */
- if(lex_init(&lex, (get_func)fgetc, (eof_func)feof, input))
+ if(lex_init(&lex, (get_func)fgetc, input))
return NULL;
if(input == stdin)
#include "jansson_private.h"
typedef struct {
+ const char *start;
const char *fmt;
char token;
json_error_t *error;
static void set_error(scanner_t *s, const char *fmt, ...)
{
va_list ap;
+ size_t pos;
va_start(ap, fmt);
- jsonp_error_vset(s->error, s->line, s->column, fmt, ap);
+
+ pos = (size_t)(s->fmt - s->start);
+ jsonp_error_vset(s->error, s->line, s->column, pos, fmt, ap);
+
va_end(ap);
}
jsonp_error_init(error, "");
if(!fmt || !*fmt) {
- jsonp_error_set(error, 1, 1, "Null or empty format string");
+ jsonp_error_set(error, -1, -1, 0, "Null or empty format string");
return NULL;
}
s.error = error;
s.flags = flags;
- s.fmt = fmt;
+ s.fmt = s.start = fmt;
s.line = 1;
s.column = 0;
jsonp_error_init(error, "");
if(!fmt || !*fmt) {
- jsonp_error_set(error, 1, 1, "Null or empty format string");
+ jsonp_error_set(error, -1, -1, 0, "Null or empty format string");
return -1;
}
s.error = error;
s.flags = flags;
- s.fmt = fmt;
+ s.fmt = s.start = fmt;
s.line = 1;
s.column = 0;
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
#include <jansson.h>
static int getenv_int(const char *name)
return (int)result;
}
+/* Return a pointer to the first non-whitespace character of str.
+ Modifies str so that all trailing whitespace characters are
+ replaced by '\0'. */
+static const char *strip(char *str)
+{
+ size_t length;
+ char *result = str;
+ while(*result && isspace(*result))
+ result++;
+
+ length = strlen(result);
+ if(length == 0)
+ return result;
+
+ while(isspace(result[length - 1]))
+ result[--length] = '\0';
+
+ return result;
+}
+
int main(int argc, char *argv[])
{
int indent = 0;
if(getenv_int("JSON_SORT_KEYS"))
flags |= JSON_SORT_KEYS;
- json = json_loadf(stdin, 0, &error);
+ if(getenv_int("STRIP")) {
+ /* Load to memory, strip leading and trailing whitespace */
+ size_t size = 0, used = 0;
+ char *buffer = NULL;
+
+ while(1) {
+ int count;
+
+ size = (size == 0 ? 128 : size * 2);
+ buffer = realloc(buffer, size);
+ if(!buffer) {
+ fprintf(stderr, "Unable to allocate %d bytes\n", (int)size);
+ return 1;
+ }
+
+ count = fread(buffer + used, 1, size - used, stdin);
+ if(count < size - used) {
+ buffer[used + count] = '\0';
+ break;
+ }
+ used += count;
+ }
+
+ json = json_loads(strip(buffer), 0, &error);
+ free(buffer);
+ }
+ else
+ json = json_loadf(stdin, 0, &error);
+
if(!json) {
- fprintf(stderr, "%d\n%s\n", error.line, error.text);
+ fprintf(stderr, "%d %d %d\n%s\n",
+ error.line, error.column, error.position,
+ error.text);
return 1;
}
/* NULL format */
if(json_pack_ex(&error, 0, NULL))
fail("json_pack failed to catch NULL format string");
- if(error.line != 1 || error.column != 1)
+ if(error.line != -1 || error.column != -1)
fail("json_pack didn't get the error coordinates right!");
/* More complicated checks for row/columns */
+++ /dev/null
-1
-invalid token near '''
+++ /dev/null
-['
\ No newline at end of file
+++ /dev/null
-1
-'[' or '{' expected near 'a'
+++ /dev/null
-aå
\ No newline at end of file
+++ /dev/null
-1
-string or '}' expected near ','
+++ /dev/null
-{,
\ No newline at end of file
+++ /dev/null
-1
-unexpected token near ','
+++ /dev/null
-[,
\ No newline at end of file
+++ /dev/null
-[1,
\ No newline at end of file
+++ /dev/null
-1
-'[' or '{' expected near end of file
+++ /dev/null
-1
-\u0000 is not allowed
+++ /dev/null
-["\u0000 (null byte not allowed)"]
\ No newline at end of file
+++ /dev/null
-[1,]
\ No newline at end of file
+++ /dev/null
-6
-unexpected token near ']'
+++ /dev/null
-[1,
-2,
-3,
-4,
-5,
-]
\ No newline at end of file
+++ /dev/null
-2
-end of file expected near 'foo'
+++ /dev/null
-[1,2,3]
-foo
+++ /dev/null
-1
-end of file expected near 'foo'
+++ /dev/null
-[1,2,3]foo
\ No newline at end of file
+++ /dev/null
-1
-invalid token near '0'
+++ /dev/null
-[012]
\ No newline at end of file
+++ /dev/null
-1
-invalid escape near '"\'
+++ /dev/null
-["\a <-- invalid escape"]
\ No newline at end of file
+++ /dev/null
-1
-invalid token near 'troo'
+++ /dev/null
-[troo
\ No newline at end of file
+++ /dev/null
-[-123foo]
\ No newline at end of file
+++ /dev/null
-1
-']' expected near 'foo'
+++ /dev/null
-[-123.123foo]
\ No newline at end of file
+++ /dev/null
-1
-invalid Unicode '\uD888\u3210'
+++ /dev/null
-["\uD888\u3210 (first surrogate and invalid second surrogate)"]
\ No newline at end of file
+++ /dev/null
-{
\ No newline at end of file
+++ /dev/null
-[
\ No newline at end of file
+++ /dev/null
-1
-invalid Unicode '\uDFAA'
+++ /dev/null
-["\uDFAA (second surrogate on it's own)"]
\ No newline at end of file
+++ /dev/null
-1
-invalid token near '-'
+++ /dev/null
-[-foo]
\ No newline at end of file
+++ /dev/null
-1
-invalid token near '-0'
+++ /dev/null
-[-012]
\ No newline at end of file
+++ /dev/null
-1
-control character 0x0 near '"null byte '
+++ /dev/null
-1
-invalid token near end of file
+++ /dev/null
-1
-'[' or '{' expected near 'null'
+++ /dev/null
-null
\ No newline at end of file
+++ /dev/null
-1
-string or '}' expected near '''
+++ /dev/null
-{'a'
\ No newline at end of file
+++ /dev/null
-1
-'}' expected near '123'
+++ /dev/null
-{"a":"a" 123}
\ No newline at end of file
+++ /dev/null
-[{}
\ No newline at end of file
+++ /dev/null
-{"a"
\ No newline at end of file
+++ /dev/null
-{"a":
\ No newline at end of file
+++ /dev/null
-{"a":"a
\ No newline at end of file
+++ /dev/null
-1
-invalid token near '1e'
+++ /dev/null
-[1ea]
\ No newline at end of file
+++ /dev/null
-1
-real number overflow near '-123123e100000'
+++ /dev/null
-[-123123e100000]
\ No newline at end of file
+++ /dev/null
-1
-real number overflow near '123123e100000'
+++ /dev/null
-[123123e100000]
\ No newline at end of file
+++ /dev/null
-1
-invalid token near '1e'
+++ /dev/null
-[1e]
\ No newline at end of file
+++ /dev/null
-1
-invalid token near '1.'
+++ /dev/null
-[1.]
\ No newline at end of file
+++ /dev/null
-#!/bin/sh
-#
-# Copyright (c) 2009-2011 Petri Lehtinen <petri@digip.org>
-#
-# Jansson is free software; you can redistribute it and/or modify
-# it under the terms of the MIT license. See LICENSE for details.
-
-is_test() {
- test -d $test_path
-}
-
-run_test() {
- $json_process <$test_path/input >$test_log/stdout 2>$test_log/stderr
- valgrind_check $test_log/stderr || return 1
- cmp -s $test_path/error $test_log/stderr
-}
-
-show_error() {
- valgrind_show_error && return
-
- echo "EXPECTED ERROR:"
- nl -bn $test_path/error
- echo "ACTUAL ERROR:"
- nl -bn $test_log/stderr
-}
-
-. $top_srcdir/test/scripts/run-tests.sh
+++ /dev/null
-1
-control character 0x9 near '"'
+++ /dev/null
-[" <-- tab character"]
\ No newline at end of file
+++ /dev/null
-1
-too big negative integer
+++ /dev/null
-[-123123123123123123123123123123]
\ No newline at end of file
+++ /dev/null
-1
-too big integer
+++ /dev/null
-[123123123123123123123123123123]
\ No newline at end of file
+++ /dev/null
-1
-invalid Unicode '\uDADA'
+++ /dev/null
-["\uDADA (first surrogate without the second)"]
\ No newline at end of file
+++ /dev/null
-1
-'[' or '{' expected near 'å'
+++ /dev/null
-å
\ No newline at end of file
+++ /dev/null
-[{
\ No newline at end of file
+++ /dev/null
-["a"
\ No newline at end of file
+++ /dev/null
-{"
\ No newline at end of file
+++ /dev/null
-{"a
\ No newline at end of file
+++ /dev/null
-1
-string or '}' expected near '['
+++ /dev/null
-{[
\ No newline at end of file
+++ /dev/null
-["a
\ No newline at end of file
--1
-unable to decode byte 0xed at position 2
+1 2 2
+unable to decode byte 0xed near '"'
--1
-unable to decode byte 0xe5 at position 3
+1 3 3
+unable to decode byte 0xe5 near '"\'
--1
-unable to decode byte 0xe5 at position 1
+1 1 1
+unable to decode byte 0xe5
--1
-unable to decode byte 0xe5 at position 4
+1 4 4
+unable to decode byte 0xe5 near '123'
--1
-unable to decode byte 0xe5 at position 4
+1 4 4
+unable to decode byte 0xe5 near '"\u'
--1
-unable to decode byte 0xe5 at position 4
+1 4 4
+unable to decode byte 0xe5 near '1e1'
--1
-unable to decode byte 0xe5 at position 2
+1 2 2
+unable to decode byte 0xe5 near 'a'
--1
-unable to decode byte 0xe5 at position 2
+1 2 2
+unable to decode byte 0xe5 near '0'
--1
-unable to decode byte 0xe5 at position 3
+1 3 3
+unable to decode byte 0xe5 near '1e'
--1
-unable to decode byte 0xe5 at position 2
+1 2 2
+unable to decode byte 0xe5 near '"'
--1
-unable to decode byte 0xe5 at position 0
+1 0 0
+unable to decode byte 0xe5
--1
-unable to decode byte 0x81 at position 2
+1 2 2
+unable to decode byte 0x81 near '"'
--1
-unable to decode byte 0xf4 at position 2
+1 2 2
+unable to decode byte 0xf4 near '"'
--1
-unable to decode byte 0xe0 at position 2
+1 2 2
+unable to decode byte 0xe0 near '"'
--1
-unable to decode byte 0xf0 at position 2
+1 2 2
+unable to decode byte 0xf0 near '"'
--1
-unable to decode byte 0xc1 at position 2
+1 2 2
+unable to decode byte 0xc1 near '"'
--1
-unable to decode byte 0xfd at position 2
+1 2 2
+unable to decode byte 0xfd near '"'
--1
-unable to decode byte 0xe0 at position 2
+1 2 2
+unable to decode byte 0xe0 near '"'
-1
+1 2 2
invalid token near '''
-1
+1 1 1
'[' or '{' expected near 'a'
-1
+1 2 2
string or '}' expected near ','
-1
+1 2 2
unexpected token near ','
+++ /dev/null
-2
-']' expected near end of file
-1
+2 0 4
']' expected near end of file
-1
+1 3 3
']' expected near end of file
-1
+1 0 0
'[' or '{' expected near end of file
-1
+1 33 33
\u0000 is not allowed
-1
+1 4 4
unexpected token near ']'
-1
+6 1 17
unexpected token near ']'
+++ /dev/null
-6
-unexpected token near ']'
-2
+2 3 11
end of file expected near 'foo'
-1
+1 10 10
end of file expected near 'foo'
-1
+1 2 2
invalid token near '0'
-1
-invalid escape near '"\'
+1 4 4
+invalid escape near '"\a'
-1
+1 5 5
invalid token near 'troo'
-1
+1 8 8
']' expected near 'foo'
+++ /dev/null
-1
-']' expected near 'foo'
-1
+1 12 12
']' expected near 'foo'
-1
+1 62 62
invalid Unicode '\uD888\u3210'
-1
+2 0 2
string or '}' expected near end of file
-1
+1 1 1
string or '}' expected near end of file
+++ /dev/null
-2
-']' expected near end of file
-1
+2 0 2
']' expected near end of file
-1
+1 1 1
']' expected near end of file
-1
+1 40 40
invalid Unicode '\uDFAA'
-1
+1 2 2
invalid token near '-'
-1
+1 3 3
invalid token near '-0'
-1
+1 12 12
control character 0x0 near '"null byte '
--- /dev/null
+The embedded NULL byte breaks json_loads(), which is used instead of
+json_loadf() in the stripped tests.
-1
+1 2 2
invalid token near end of file
--- /dev/null
+The embedded NULL byte breaks json_loads(), which is used instead of
+json_loadf() in the stripped tests.
-1
+1 4 4
'[' or '{' expected near 'null'
-1
+1 2 2
string or '}' expected near '''
-1
+1 12 12
'}' expected near '123'
+++ /dev/null
-2
-']' expected near end of file
--- /dev/null
+2 0 4
+']' expected near end of file
--- /dev/null
+1 3 3
+']' expected near end of file
-1
+2 0 5
':' expected near end of file
-2
+1 4 4
':' expected near end of file
-1
+2 0 6
unexpected token near end of file
-2
+1 5 5
unexpected token near end of file
-1
+1 7 7
unexpected newline near '"a'
-1
+1 7 7
premature end of input near '"a'
-1
+1 3 3
invalid token near '1e'
-1
+1 15 15
real number overflow near '-123123e100000'
-1
+1 14 14
real number overflow near '123123e100000'
-1
+1 3 3
invalid token near '1e'
-1
+1 3 3
invalid token near '1.'
test -d $test_path
}
+do_run() {
+ variant=$1
+ s=".$1"
+
+ strip=0
+ if [ "$variant" = "strip" ]; then
+ # This test should not be stripped
+ [ -f $test_path/nostrip ] && return
+ strip=1
+ fi
+
+ STRIP=$strip $json_process \
+ <$test_path/input >$test_log/stdout$s 2>$test_log/stderr$s
+ valgrind_check $test_log/stderr$s || return 1
+
+ ref=error
+ [ -f $test_path/error$s ] && ref=error$s
+
+ if ! cmp -s $test_path/$ref $test_log/stderr$s; then
+ echo $variant > $test_log/variant
+ return 1
+ fi
+}
+
run_test() {
- $json_process <$test_path/input >$test_log/stdout 2>$test_log/stderr
- valgrind_check $test_log/stderr || return 1
- cmp -s $test_path/error $test_log/stderr
+ do_run normal && do_run strip
}
show_error() {
valgrind_show_error && return
+ read variant < $test_log/variant
+ s=".$variant"
+
+ echo "VARIANT: $variant"
+
echo "EXPECTED ERROR:"
- nl -bn $test_path/error
+ ref=error
+ [ -f $test_path/error$s ] && ref=error$s
+ nl -bn $test_path/$ref
+
echo "ACTUAL ERROR:"
- nl -bn $test_log/stderr
+ nl -bn $test_log/stderr$s
}
. $top_srcdir/test/scripts/run-tests.sh
-1
+1 2 2
control character 0x9 near '"'
-1
+1 32 32
too big negative integer
-1
+1 31 31
too big integer
-1
+1 46 46
invalid Unicode '\uDADA'
-1
+1 1 2
'[' or '{' expected near 'å'
-2
+2 0 3
string or '}' expected near end of file
-2
+1 2 2
string or '}' expected near end of file
+++ /dev/null
-2
-']' expected near end of file
--- /dev/null
+2 0 5
+']' expected near end of file
--- /dev/null
+1 4 4
+']' expected near end of file
-1
+1 2 2
unexpected newline near '"'
-1
+1 2 2
premature end of input near '"'
-1
+1 3 3
unexpected newline near '"a'
-1
+1 3 3
premature end of input near '"a'
-1
+1 2 2
string or '}' expected near '['
-1
+1 3 3
unexpected newline near '"a'
-1
+1 3 3
premature end of input near '"a'
+++ /dev/null
-[1,2,3,4,
-"a", "b", "c",
-{"foo": "bar", "core": "dump"},
-true, false, true, true, null, false
-]
\ No newline at end of file
+++ /dev/null
-[1, 2, 3, 4, "a", "b", "c", {"core": "dump", "foo": "bar"}, true, false, true, true, null, false]
\ No newline at end of file
+++ /dev/null
-[]
\ No newline at end of file
+++ /dev/null
-[]
\ No newline at end of file
+++ /dev/null
-[{}]
\ No newline at end of file
+++ /dev/null
-[{}]
\ No newline at end of file
+++ /dev/null
-{}
\ No newline at end of file
+++ /dev/null
-{}
\ No newline at end of file
+++ /dev/null
-[""]
\ No newline at end of file
+++ /dev/null
-[""]
\ No newline at end of file
+++ /dev/null
-["\u0012 escaped control character"]
\ No newline at end of file
+++ /dev/null
-["\u0012 escaped control character"]
\ No newline at end of file
+++ /dev/null
-[false]
\ No newline at end of file
+++ /dev/null
-[false]
\ No newline at end of file
+++ /dev/null
-[-123]
\ No newline at end of file
+++ /dev/null
-[-123]
\ No newline at end of file
+++ /dev/null
-[-1]
\ No newline at end of file
+++ /dev/null
-[-1]
\ No newline at end of file
+++ /dev/null
-[-0]
\ No newline at end of file
+++ /dev/null
-[0]
\ No newline at end of file
+++ /dev/null
-[null]
\ No newline at end of file
+++ /dev/null
-[null]
\ No newline at end of file
+++ /dev/null
-["\u002c one-byte UTF-8"]
\ No newline at end of file
+++ /dev/null
-[", one-byte UTF-8"]
\ No newline at end of file
+++ /dev/null
-[1E-2]
\ No newline at end of file
+++ /dev/null
-[0.01]
\ No newline at end of file
+++ /dev/null
-[1E+2]
\ No newline at end of file
+++ /dev/null
-[100.0]
\ No newline at end of file
+++ /dev/null
-[1E22]
\ No newline at end of file
+++ /dev/null
-[1e+22]
\ No newline at end of file
+++ /dev/null
-[123e45]
\ No newline at end of file
+++ /dev/null
-[1.2299999999999999e+47]
\ No newline at end of file
+++ /dev/null
-[123.456e78]
\ No newline at end of file
+++ /dev/null
-[1.23456e+80]
\ No newline at end of file
+++ /dev/null
-[1e-2]
\ No newline at end of file
+++ /dev/null
-[0.01]
\ No newline at end of file
+++ /dev/null
-[1e+2]
\ No newline at end of file
+++ /dev/null
-[100.0]
\ No newline at end of file
+++ /dev/null
-[123e-10000000]
\ No newline at end of file
+++ /dev/null
-[0.0]
\ No newline at end of file
+++ /dev/null
-#!/bin/sh
-#
-# Copyright (c) 2009-2011 Petri Lehtinen <petri@digip.org>
-#
-# Jansson is free software; you can redistribute it and/or modify
-# it under the terms of the MIT license. See LICENSE for details.
-
-export JSON_SORT_KEYS=1
-
-is_test() {
- test -d $test_path
-}
-
-run_test() {
- $json_process <$test_path/input >$test_log/stdout 2>$test_log/stderr
- valgrind_check $test_log/stderr || return 1
- cmp -s $test_path/output $test_log/stdout
-}
-
-show_error() {
- valgrind_show_error && return
-
- echo "EXPECTED OUTPUT:"
- nl -bn $test_path/output
- echo "ACTUAL OUTPUT:"
- nl -bn $test_log/stdout
-}
-
-. $top_srcdir/test/scripts/run-tests.sh
+++ /dev/null
-["a"]
\ No newline at end of file
+++ /dev/null
-["a"]
\ No newline at end of file
+++ /dev/null
-["abcdefghijklmnopqrstuvwxyz1234567890 "]
\ No newline at end of file
+++ /dev/null
-["abcdefghijklmnopqrstuvwxyz1234567890 "]
\ No newline at end of file
+++ /dev/null
-[0]
\ No newline at end of file
+++ /dev/null
-[0]
\ No newline at end of file
+++ /dev/null
-[1]
\ No newline at end of file
+++ /dev/null
-[1]
\ No newline at end of file
+++ /dev/null
-[123]
\ No newline at end of file
+++ /dev/null
-[123]
\ No newline at end of file
+++ /dev/null
-{"a": []}
\ No newline at end of file
+++ /dev/null
-[123.456789]
\ No newline at end of file
+++ /dev/null
-[123.456789]
\ No newline at end of file
+++ /dev/null
-["\"\\\/\b\f\n\r\t"]
\ No newline at end of file
+++ /dev/null
-["\"\\/\b\f\n\r\t"]
\ No newline at end of file
+++ /dev/null
-["\u0821 three-byte UTF-8"]
\ No newline at end of file
+++ /dev/null
-["ࠡ three-byte UTF-8"]
\ No newline at end of file
+++ /dev/null
-[true]
\ No newline at end of file
+++ /dev/null
-[true]
\ No newline at end of file
+++ /dev/null
-["\u0123 two-byte UTF-8"]
\ No newline at end of file
+++ /dev/null
-["ģ two-byte UTF-8"]
\ No newline at end of file
+++ /dev/null
-["€þıœəßð some utf-8 ĸʒ×ŋµåäö𝄞"]
\ No newline at end of file
+++ /dev/null
-["€þıœəßð some utf-8 ĸʒ×ŋµåäö𝄞"]
\ No newline at end of file
+++ /dev/null
-["\uD834\uDD1E surrogate, four-byte UTF-8"]
\ No newline at end of file
+++ /dev/null
-["𝄞 surrogate, four-byte UTF-8"]
\ No newline at end of file
test -d $test_path
}
+do_run() {
+ variant=$1
+ s=".$1"
+
+ strip=0
+ [ "$variant" = "strip" ] && strip=1
+
+ STRIP=$strip $json_process \
+ <$test_path/input >$test_log/stdout$s 2>$test_log/stderr$s
+ valgrind_check $test_log/stderr$s || return 1
+
+ ref=output
+ [ -f $test_path/output$s ] && ref=output$s
+
+ if ! cmp -s $test_path/$ref $test_log/stdout$s; then
+ echo $variant > $test_log/variant
+ return 1
+ fi
+}
+
run_test() {
- $json_process <$test_path/input >$test_log/stdout 2>$test_log/stderr
- valgrind_check $test_log/stderr || return 1
- cmp -s $test_path/output $test_log/stdout
+ do_run normal && do_run strip
}
show_error() {
valgrind_show_error && return
+ read variant < $test_log/variant
+ s=".$variant"
+
+ echo "VARIANT: $variant"
+
echo "EXPECTED OUTPUT:"
- nl -bn $test_path/output
+ ref=output
+ [ -f $test_path/output$s ] && ref=output$s
+ nl -bn $test_path/$ref
+
echo "ACTUAL OUTPUT:"
- nl -bn $test_log/stdout
+ nl -bn $test_log/stdout$s
}
. $top_srcdir/test/scripts/run-tests.sh