Prolog "json"
Admin User, created Oct 29. 2024
/**
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
runner_file(extend, json, 'XLOG 3.4 json').
/* write_json(T) */
runner_pred(write_json, 1, extend, json, 'XLOG 3.4.1').
runner_case(write_json, 1, extend, json, 'XLOG 3.4.1, XLOG 1') :-
with_text_to(X, write_json(['abc\x12\def',null,5.0E7])),
X == '[\"abc\\u0012def\", \"null\", 50000000.0]'.
runner_case(write_json, 1, extend, json, 'XLOG 3.4.1, XLOG 2') :-
with_text_to(X, write_json({foo: @(null),baz:'</script>'})),
X == '{\"foo\": null, \"baz\": \"<\\/script>\"}'.
runner_case(write_json, 1, extend, json, 'XLOG 3.4.1, XLOG 3') :-
with_text_to(X, write_json('two 💕 hearts')),
X == '\"two 💕 hearts\"'.
runner_case(write_json, 1, extend, json, 'XLOG 3.4.1, XLOG 4') :-
catch(with_text_to(_, write_json(_)), error(E,_), true),
E == instantiation_error.
runner_case(write_json, 1, extend, json, 'XLOG 3.4.1, XLOG 5') :-
catch(with_text_to(_, write_json(1+2)), error(E,_), true),
E == type_error(json, 1+2).
/* read_json(T) */
runner_pred(read_json, 1, extend, json, 'XLOG 3.4.2').
runner_case(read_json, 1, extend, json, 'XLOG 3.4.2, XLOG 1') :-
with_text_from('[\"abc\\u0012def\", \"null\", 50000000.0]', read_json(X)),
X == ['abc\x12\def', null, 50000000.0].
runner_case(read_json, 1, extend, json, 'XLOG 3.4.2, XLOG 2') :-
with_text_from('{\"foo\": null, \"baz\": \"<\\/script>\"}', read_json(X)),
X == {foo: @(null), baz:'</script>'}.
runner_case(read_json, 1, extend, json, 'XLOG 3.4.2, XLOG 3') :-
with_text_from('\"two 💕 hearts\"', read_json(X)),
X == 'two 💕 hearts'.
runner_case(read_json, 1, extend, json, 'XLOG 3.4.2, XLOG 4') :-
catch(with_text_from('{"foo":bar}', read_json(_)), error(E,_), true),
E == type_error(ident, bar).
runner_case(read_json, 1, extend, json, 'XLOG 3.4.2, XLOG 5') :-
catch(with_text_from('("foo")', read_json(_)), error(E,_), true),
E == syntax_error(illegal_token).
/* json_atom(T, A) */
runner_pred(json_atom, 2, extend, json, 'XLOG 3.4.3').
runner_case(json_atom, 2, extend, json, 'XLOG 3.4.3, XLOG 1') :-
json_atom({foo:123, bar:baz}, A),
A == '{\"foo\": 123, \"bar\": \"baz\"}'.
runner_case(json_atom, 2, extend, json, 'XLOG 3.4.3, XLOG 2') :-
json_atom(X, '{"result":true, "count":42}'),
X == {result: @(true), count:42}.
runner_case(json_atom, 2, extend, json, 'XLOG 3.4.3, XLOG 3') :-
catch(json_atom(f(g), _), error(E,_), true),
E == type_error(json, f(g)).
runner_case(json_atom, 2, extend, json, 'XLOG 3.4.3, XLOG 4') :-
json_atom(X, '["foo",\r\n"bar"]'),
X == [foo, bar].
runner_case(json_atom, 2, extend, json, 'XLOG 3.4.3, XLOG 5') :-
catch(json_atom(_, '{"result":true, "count":42} "foo"'), error(E,_), true),
E == syntax_error(missing_eof).
runner_case(json_atom, 2, extend, json, 'XLOG 3.4.3, XLOG 6') :-
catch(json_atom(_, ' '), error(E,_), true),
E == syntax_error(illegal_eof).