Prolog "format"

         
/**
* 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.
*/
:- multifile(runner_case/5).
:- discontiguous(runner_case/5).
:- multifile(runner_pred/5).
:- discontiguous(runner_pred/5).
:- multifile(runner_file/3).
runner_file(adapter, format, 'XLOG 1.2 format').
/****************************************************************/
/* Web Specifiers */
/****************************************************************/
/* format_web(X, Y) */
runner_pred(format_web, 2, adapter, format, 'XLOG 1.2.1').
runner_case(format_web, 2, adapter, format, 'XLOG 1.2.1, XLOG 8') :-
open_output_atom_stream(S),
format(S, 'tag ~a header level 1', ['<h1>']),
close_output_atom_stream(S, X),
X == 'tag &lt;h1&gt; header level 1'.
runner_case(format_web, 2, adapter, format, 'XLOG 1.2.1, XLOG 6') :-
open_output_atom_stream(S),
format(S, 'foo?bar=~c', ['1=2']),
close_output_atom_stream(S, X),
X == 'foo?bar=1%3D2'.
/****************************************************************/
/* Stream Formatter */
/****************************************************************/
/* format(X, Y) */
runner_pred(format, 2, adapter, format, 'XLOG 1.2.2').
runner_case(format, 2, adapter, format, 'XLOG 1.2.2, XLOG 1') :-
open_output_atom_stream(S),
format(S, 'abc ~4e', [0.499999]),
close_output_atom_stream(S, X),
X == 'abc 5.0000e-01'.
runner_case(format, 2, adapter, format, 'XLOG 1.2.2, XLOG 2') :-
open_output_atom_stream(S),
format(S, '~4f def', [49.9999]),
close_output_atom_stream(S, X),
X == '49.9999 def'.
runner_case(format, 2, adapter, format, 'XLOG 1.2.2, XLOG 3') :-
open_output_atom_stream(S),
format(S, 'abc ~4g def', [4.99999E10]),
close_output_atom_stream(S, X),
X == 'abc 5e+10 def'.
runner_case(format, 2, adapter, format, 'XLOG 1.2.2, XLOG 4') :-
open_output_atom_stream(S),
format(S, 'abc ~4f def~n', [2*pi]),
close_output_atom_stream(S, X),
X == 'abc 6.2832 def\n'.
runner_case(format, 2, adapter, format, 'XLOG 1.2.2, XLOG 5') :-
open_output_atom_stream(S),
format(S, 'abc ~d def', [1.2]),
close_output_atom_stream(S, X),
X == 'abc 1.2 def'.
runner_case(format, 2, adapter, format, 'XLOG 1.2.2, XLOG 6') :-
open_output_atom_stream(S),
format(S, 'abc ~d~10|def', [1.2]),
close_output_atom_stream(S, X),
X == 'abc 1.2 def'.
runner_case(format, 2, adapter, format, 'XLOG 1.2.2, XLOG 7') :-
open_output_atom_stream(S),
format(S, 'foo ~3f ~3f bar', [27, 0rNaN]),
close_output_atom_stream(S, X),
X =='foo 27.000 NaN bar'.
runner_case(format, 2, adapter, format, 'XLOG 1.2.2, XLOG 8') :-
open_output_atom_stream(S),
format(S, 'foo ~3G bar', [0.0000027]),
close_output_atom_stream(S, X),
X == 'foo 2.7E-06 bar'.
runner_case(format, 2, adapter, format, 'XLOG 1.2.2, XLOG 9') :-
open_output_atom_stream(S),
format(S, 'baz ~3r 456', [nan]),
close_output_atom_stream(S, X),
X == 'baz NaN 456'.
runner_case(format, 2, adapter, format, 'XLOG 1.2.2, XLOG 10') :-
open_output_atom_stream(S),
catch(format(S, '~y', [123.456]), error(E,_), true),
E == existence_error(format_character, y).
runner_case(format, 2, adapter, format, 'XLOG 1.2.2, XLOG 11') :-
open_output_atom_stream(S),
catch(format(S, 'abc ~w def', [a,b]), error(E,_), true),
E == syntax_error(aguments_mismatch).
/****************************************************************/
/* Atom Formatter */
/****************************************************************/
/* format_atom(X, Y, Z) */
runner_pred(format_atom, 3, adapter, format, 'XLOG 1.2.3').
runner_case(format_atom, 3, adapter, format, 'XLOG 1.2.3, XLOG 1') :-
format_atom('abc ~w def', [1+2], X),
X == 'abc 1+2 def'.
runner_case(format_atom, 3, adapter, format, 'XLOG 1.2.3, XLOG 2') :-
format_atom('abc ~k def ~2r', [1+2,7], X),
X == 'abc +(1, 2) def 111'.
runner_case(format_atom, 3, adapter, format, 'XLOG 1.2.3, XLOG 3') :-
format_atom('~0f ~0f def', [1.5, 2.5], X),
X == '2 2 def'.
runner_case(format_atom, 3, adapter, format, 'XLOG 1.2.3, XLOG 4') :-
format_atom('abc ~w def ~q', ['X','Y'], X),
X == 'abc X def \'Y\''.
runner_case(format_atom, 3, adapter, format, 'XLOG 1.2.3, XLOG 5') :-
format_atom('abc ~~ ~f def', [49.9999], X),
X == 'abc ~ 49.999900 def'.
runner_case(format_atom, 3, adapter, format, 'XLOG 1.2.3, XLOG 6') :-
format_atom('abc~t~w~t~20|def', [1+2], X),
X == 'abc 1+2 def'.
runner_case(format_atom, 3, adapter, format, 'XLOG 1.2.3, XLOG 7') :-
format_atom('foo ~d bar', [inf], X),
X = 'foo Inf bar'.
runner_case(format_atom, 3, adapter, format, 'XLOG 1.2.3, XLOG 8') :-
format_atom('foo ~3E bar', [27], X),
X = 'foo 2.700E+01 bar'.
runner_case(format_atom, 3, adapter, format, 'XLOG 1.2.3, XLOG 9') :-
format_atom('baz ~27R 123', [-7625597484986], X),
X = 'baz -QQQQQQQQQ 123'.
runner_case(format_atom, 3, adapter, format, 'XLOG 1.2.3, XLOG 10') :-
catch(format_atom(_, [1+2], 'abc 1+2 def'), error(E,_), true),
E == instantiation_error.
runner_case(format_atom, 3, adapter, format, 'XLOG 1.2.3, XLOG 11') :-
catch(format_atom('abc ~w def', [], _), error(E,_), true),
E == syntax_error(aguments_mismatch).

Use Privacy (c) 2005-2026 XLOG Technologies AG