Prolog "markup"
Admin User, created Apr 06. 2025
/**
* 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(common, markup, 'XLOG 2.3 markup streams').
/****************************************************************/
/* Stream Formatter */
/****************************************************************/
/* format(X, Y) */
runner_pred(format, 2, common, markup, 'XLOG 2.3.1').
runner_case(format, 2, common, markup, 'XLOG 2.3.1, XLOG 1') :-
with_text_to(X, format('abc ~4e', [0.499999])),
X == 'abc 5.0000e-1'.
runner_case(format, 2, common, markup, 'XLOG 2.3.1, XLOG 2') :-
with_text_to(X, format('~4f def', [49.9999])),
X == '49.9999 def'.
runner_case(format, 2, common, markup, 'XLOG 2.3.1, XLOG 3') :-
with_text_to(X, format('abc ~4g def', [4.99999E10])),
X == 'abc 5e10 def'.
runner_case(format, 2, common, markup, 'XLOG 2.3.1, XLOG 4') :-
with_text_to(X, format('abc ~~ ~f def', [49.9999])),
X == 'abc ~ 49.999900 def'.
runner_case(format, 2, common, markup, 'XLOG 2.3.1, XLOG 5') :-
with_text_to(X, format('abc ~w def ~q', ['X','Y'])),
X == 'abc X def 'Y''.
runner_case(format, 2, common, markup, 'XLOG 2.3.1, XLOG 6') :-
with_text_to(X, format('foo?bar=~c', ['1=2'])),
X == 'foo?bar=1%3D2'.
runner_case(format, 2, common, markup, 'XLOG 2.3.1, XLOG 7') :-
catch(with_text_to(_, format('~y', [123.456])), error(E,_), true),
E == existence_error(format_character, y).
runner_case(format, 2, common, markup, 'XLOG 2.3.1, XLOG 8') :-
with_text_to(X, format('tag ~a header level 1', ['<h1>'])),
X == 'tag <h1> header level 1'.
runner_case(format, 2, common, markup, 'XLOG 2.3.1, XLOG 9') :-
catch(with_text_to(_, format('abc ~w def', [a,b])), error(E,_), true),
E == syntax_error(aguments_mismatch).
runner_case(format, 2, common, markup, 'XLOG 2.3.1, XLOG 10') :-
with_text_to(X, format('abc ~4f def~n', [2*pi])),
X == 'abc 6.2832 def\n'.
runner_case(format, 2, common, markup, 'XLOG 2.3.1, XLOG 11') :-
catch(with_text_to(_, format('abc ~d def', [1.2])), error(E,_), true),
E == type_error(integer, 1.2).
/* format_atom(X, Y, Z) */
runner_pred(format_atom, 3, common, markup, 'XLOG 2.3.2').
runner_case(format_atom, 3, common, markup, 'XLOG 2.3.2, XLOG 1') :-
format_atom('abc ~w def', [1+2], X),
X == 'abc 1+2 def'.
runner_case(format_atom, 3, common, markup, 'XLOG 2.3.2, XLOG 2') :-
format_atom('abc ~k def ~2r', [1+2,7], X),
X == 'abc +(1, 2) def 111'.
runner_case(format_atom, 3, common, markup, 'XLOG 2.3.2, XLOG 3') :-
format_atom('~0f ~0f def', [1.5, 2.5], X),
X == '2 2 def'.
runner_case(format_atom, 3, common, markup, 'XLOG 2.3.2, XLOG 4') :-
catch(format_atom(_, [1+2], 'abc 1+2 def'), error(E,_), true),
E == instantiation_error.
runner_case(format_atom, 3, common, markup, 'XLOG 2.3.2, XLOG 5') :-
catch(format_atom('abc ~w def', [], _), error(E,_), true),
E == syntax_error(aguments_mismatch).
/****************************************************************/
/* Ascii Sink */
/****************************************************************/
/* tag(A) */
runner_pred(tag,1, common, markup, 'XLOG 2.3.3').
runner_case(tag,1, common, markup, 'XLOG 2.3.3, XLOG 1') :-
with_text_to(X, (tag('<span style="color: red">'),
write('foo'), tag('</span>'))),
X == '\33\[31mfoo\33\[39m'.
runner_case(tag,1, common, markup, 'XLOG 2.3.3, XLOG 2') :-
with_text_to(X, tag('&')),
X == '&' .
runner_case(tag,1, common, markup, 'XLOG 2.3.3, XLOG 3') :-
with_text_to(X, tag('John <i>Doe</i>')),
X == 'John \33\[3mDoe\33\[23m'.
runner_case(tag,1, common, markup, 'XLOG 2.3.3, XLOG 4') :-
catch(with_text_to(_, tag('<foo')), error(E,_), true),
E == syntax_error(missing_angle).
/****************************************************************/
/* XML Sink */
/****************************************************************/
/* dom_output_new(S, W) */
runner_pred(dom_output_new,2, common, markup, 'XLOG 2.3.4').
runner_case(dom_output_new,2, common, markup, 'XLOG 2.3.4, XLOG 1') :-
with_text_to(X, (current_output(S), dom_output_new(S, W),
write(W, 'foo<bar>baz'), flush_output(W))),
X == 'foo<bar>baz'.
runner_case(dom_output_new,2, common, markup, 'XLOG 2.3.4, XLOG 2') :-
with_text_to(X, (current_output(S), dom_output_new(S, W), tag(W, '<p>'),
write(W, 'foo'), tag(W, '</p>'), flush_output(W))),
X == '<p>foo</p>\n'.
/* dom_error_new(S, W) */
runner_pred(dom_error_new,2, common, markup, 'XLOG 2.3.5').
runner_case(dom_error_new,2, common, markup, 'XLOG 2.3.5, XLOG 1') :-
with_text_to(X, (current_output(S), dom_error_new(S, W),
write(W, 'foo'), flush_output(W))),
X == '<span style=\'color: #A52A2A\'>foo</span>'.