Another thorough rewrite of library(json) to better preserve the complete set of answers as much as possible and thereby write more elegant and simple code. Some performance gains too!
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
:- use_module(library(charsio)).
|
||||
:- use_module(library(dcgs)).
|
||||
:- use_module(library(format)).
|
||||
:- use_module(library(json)).
|
||||
:- use_module(library(lists)).
|
||||
:- use_module(library(os)).
|
||||
@@ -18,23 +19,31 @@ name_parse(Name, Json) :-
|
||||
once(phrase_from_file(json_chars(Json), Path)).
|
||||
|
||||
test_json_read :-
|
||||
name_parse("pass_null.json", _),
|
||||
name_parse("pass_alnum.json", _),
|
||||
name_parse("pass_special.json", _),
|
||||
name_parse("pass_mandatory_escapes.json", _),
|
||||
name_parse("pass_forward_slash.json", _),
|
||||
name_parse("pass_hex.json", _),
|
||||
name_parse("pass_smallfloat.json", _),
|
||||
name_parse("pass_bigfloat.json", _),
|
||||
name_parse("pass_null.json", null),
|
||||
name_parse("pass_alnum.json", string("ABCDEFGHIJKLMNOPQRSTUVWYZabcdefghijklmnopqrstuvwyz0123456789")),
|
||||
name_parse("pass_special.json", string("`1~!@#$%^&*()_+-={':[,]}|;.</>?")),
|
||||
name_parse("pass_mandatory_escapes.json", string(" \" \\ \b\f\n\r\t ")),
|
||||
name_parse("pass_forward_slash.json", string("/ & /")),
|
||||
name_parse("pass_hex.json", string("ģ\x4567\\x89ab\\xcdef\\xabcd\\xef4a\")),
|
||||
name_parse("pass_smallfloat.json", number(0.000000000000123456789)),
|
||||
name_parse("pass_bigfloat.json", number(12345678900000000000000000000000000.0)),
|
||||
time(name_parse("pass_everything.json", _)).
|
||||
|
||||
minify_sample_json :-
|
||||
name_parse("pass_everything.json", Json),
|
||||
time(once(phrase(json_chars(Json), MinChars))),
|
||||
test_path("pass_everything.min.json", MinPath),
|
||||
open(MinPath, write, Stream),
|
||||
format(Stream, "~s", [MinChars]),
|
||||
close(Stream).
|
||||
|
||||
test_json_minify :-
|
||||
test_path("pass_everything.min.json", MinPath),
|
||||
open(MinPath, read, RefMin),
|
||||
read_line_to_chars(RefMin, RefChars, []),
|
||||
close(RefMin),
|
||||
open(MinPath, read, Stream),
|
||||
read_line_to_chars(Stream, RefChars, []),
|
||||
close(Stream),
|
||||
name_parse("pass_everything.json", Json),
|
||||
time(phrase(json_chars(Json), MinChars)),
|
||||
time(once(phrase(json_chars(Json), MinChars))),
|
||||
RefChars = MinChars.
|
||||
|
||||
test_json_int_float :-
|
||||
|
||||
Reference in New Issue
Block a user