mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-19 03:13:40 +00:00
tests/accumulator/*.m:
tests/analysis_*/*.m:
tests/benchmarks*/*.m:
tests/debugger*/*.{m,exp,inp}:
tests/declarative_debugger*/*.{m,exp,inp}:
tests/dppd*/*.m:
tests/exceptions*/*.m:
tests/general*/*.m:
tests/grade_subdirs*/*.m:
tests/hard_coded*/*.m:
Make these tests use four-space indentation, and ensure that
each module is imported on its own line. (I intend to use the latter
to figure out which subdirectories' tests can be executed in parallel.)
These changes usually move code to different lines. For the debugger tests,
specify the new line numbers in .inp files and expect them in .exp files.
181 lines
4.7 KiB
Mathematica
181 lines
4.7 KiB
Mathematica
% vim: ft=mercury ts=4 sw=4 et
|
|
% Test case for io.write (and io.write_line).
|
|
%
|
|
% Author: trd
|
|
|
|
:- module write.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module array.
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module map.
|
|
:- import_module term.
|
|
:- import_module univ.
|
|
:- import_module version_array.
|
|
|
|
:- pred test_ops(io::di, io::uo) is det.
|
|
:- pred test_builtins(io::di, io::uo) is det.
|
|
:- pred test_discriminated(io::di, io::uo) is det.
|
|
:- pred test_polymorphism(io::di, io::uo) is det.
|
|
:- pred test_other(io::di, io::uo) is det.
|
|
:- pred newline(io::di, io::uo) is det.
|
|
|
|
:- type enum
|
|
---> one
|
|
; two
|
|
; three.
|
|
|
|
:- type fruit
|
|
---> apple(list(int))
|
|
; banana(list(enum)).
|
|
|
|
:- type thingie
|
|
---> foo
|
|
; bar(int)
|
|
; bar(int, int)
|
|
; qux(int)
|
|
; quux(int)
|
|
; quuux(int, int)
|
|
; wombat
|
|
; zoom(int)
|
|
; zap(int, float)
|
|
; zip(int, int)
|
|
; zop(float, float).
|
|
|
|
:- type poly(A, B)
|
|
---> poly_one(A)
|
|
; poly_two(B)
|
|
; poly_three(B, A, poly(B, A)).
|
|
|
|
:- type no_tag
|
|
---> qwerty(int).
|
|
|
|
:- type expr
|
|
---> var(string)
|
|
; int(int)
|
|
; expr + expr
|
|
; expr - expr
|
|
; expr * expr
|
|
; (expr, expr)
|
|
; {expr; expr}
|
|
; {{expr}}
|
|
; (type)
|
|
; blah
|
|
; (:-).
|
|
|
|
main(!IO) :-
|
|
test_ops(!IO),
|
|
test_discriminated(!IO),
|
|
test_polymorphism(!IO),
|
|
test_builtins(!IO),
|
|
test_other(!IO).
|
|
|
|
test_ops(!IO) :-
|
|
io.write(var("X") + int(3) * var("X^2") ; (type), !IO), newline(!IO),
|
|
io.write(write.{type}, !IO), newline(!IO),
|
|
io.write(write.{:-}, !IO), newline(!IO),
|
|
io.write((:-), !IO), newline(!IO),
|
|
io.write(write.{blah}, !IO), newline(!IO),
|
|
io.write((blah ; (type), (type) * blah ; (type)), !IO), newline(!IO),
|
|
io.write(((blah ; blah), blah) * blah ; blah, !IO), newline(!IO),
|
|
io.write((type) * blah ; (type), !IO), newline(!IO).
|
|
|
|
test_discriminated(!IO) :-
|
|
io.write_string("TESTING DISCRIMINATED UNIONS\n", !IO),
|
|
|
|
% Test enumerations.
|
|
io.write_line(one, !IO),
|
|
io.write_line(two, !IO),
|
|
io.write_line(three, !IO),
|
|
|
|
% Test simple tags.
|
|
io.write(apple([9, 5, 1]), !IO), newline(!IO),
|
|
io.write(banana([three, one, two]), !IO), newline(!IO),
|
|
|
|
% Test complicated tags.
|
|
io.write(zop(3.3, 2.03), !IO), newline(!IO),
|
|
io.write(zip(3, 2), !IO), newline(!IO),
|
|
io.write(zap(3, -2.111), !IO), newline(!IO),
|
|
|
|
% Test complicated constant.
|
|
io.write(wombat, !IO), newline(!IO),
|
|
io.write(foo, !IO), newline(!IO),
|
|
|
|
newline(!IO).
|
|
|
|
test_polymorphism(!IO) :-
|
|
io.write_string("TESTING POLYMORPHISM\n", !IO),
|
|
io.write(poly_one([2399.3]), !IO), newline(!IO),
|
|
io.write(poly_two(3), !IO), newline(!IO),
|
|
io.write(poly_three(3.33, 4, poly_one(9.11)), !IO), newline(!IO),
|
|
|
|
newline(!IO).
|
|
|
|
test_builtins(!IO) :-
|
|
io.write_string("TESTING BUILTINS\n", !IO),
|
|
|
|
% Test strings.
|
|
io.write("", !IO), newline(!IO),
|
|
io.write("Hello, world\n", !IO), newline(!IO),
|
|
io.write("Foo%sFoo", !IO), newline(!IO),
|
|
io.write("""", !IO), newline(!IO), % interesting - prints """ of course
|
|
|
|
% Test characters.
|
|
io.write('a', !IO), newline(!IO),
|
|
io.write('&', !IO), newline(!IO),
|
|
|
|
% Test floats.
|
|
io.write(3.14159, !IO), newline(!IO),
|
|
io.write(11.28324983E-22, !IO), newline(!IO),
|
|
io.write(22.3954899E22, !IO), newline(!IO),
|
|
|
|
% Test integers.
|
|
io.write(-65, !IO), newline(!IO),
|
|
io.write(4, !IO), newline(!IO),
|
|
|
|
% Test univ.
|
|
type_to_univ(["hi! I'm a univ!"], Univ),
|
|
io.write(Univ, !IO), newline(!IO),
|
|
|
|
% Test predicates.
|
|
io.write(newline, !IO), newline(!IO),
|
|
|
|
newline(!IO).
|
|
|
|
% Note: testing abstract types is always going to have results
|
|
% that are dependent on the implementation. If someone changes
|
|
% the implementation, the results of this test can change.
|
|
%
|
|
test_other(!IO) :-
|
|
io.write_string("TESTING OTHER TYPES\n", !IO),
|
|
term.init_var_supply(VarSupply),
|
|
term.create_var(Var, VarSupply, NewVarSupply),
|
|
io.write(Var, !IO), newline(!IO),
|
|
io.write(VarSupply, !IO), newline(!IO),
|
|
io.write(NewVarSupply, !IO), newline(!IO),
|
|
|
|
% Presently, at least, map is an equivalence and
|
|
% an abstract type.
|
|
map.init(Map),
|
|
io.write(Map, !IO), newline(!IO),
|
|
|
|
% A no tag type.
|
|
io.write(qwerty(4), !IO), newline(!IO),
|
|
|
|
array.from_list([1, 2, 3, 4], Array),
|
|
io.write(Array, !IO), newline(!IO),
|
|
|
|
VersionArray = version_array.from_list([1, 2, 3, 4]),
|
|
io.write(VersionArray, !IO), newline(!IO),
|
|
|
|
newline(!IO).
|
|
|
|
newline(!IO) :-
|
|
io.write_char('\n', !IO).
|