mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
tests/hard_coded/*.m:
Rename modules as mentioned above.
In a few cases, where the main module's name itself had a suffix,
such as "_mod_a" or "_main", remove that suffix. This entails
renaming the .exp file as well. (In some cases, this meant that
the name of a helper module was "taken over" by the main module
of the test case.)
Update all references to the moved modules.
General updates to programming style, such as
- replacing DCG notation with state var notation
- replacing (C->T;E) with (if C then T else E)
- moving pred/func declarations to just before their code
- replacing io.write/io.nl sequences with io.write_line
- replacing io.print/io.nl sequences with io.print_line
- fixing too-long lines
- fixing grammar errors in comments
tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
Update all references to the moved modules.
Enable the constant_prop_int test case. The fact that it wasn't enabled
before is probably an accident. (When constant_prop_int.m was created,
the test case was added to a list in the Mmakefile, but that list
was later removed due to never being referenced.)
tests/hard_coded/constant_prop_int.{m,exp}:
Delete the calls to shift operations with negative shift amounts,
since we have added a compile-time error for these since the test
was originally created.
148 lines
4.9 KiB
Mathematica
148 lines
4.9 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% This test case is designed to test the correctness of the program
|
|
% transformation performed by compiler/format_call.m and the associated
|
|
% code in compiler/simplify.m.
|
|
|
|
:- module opt_format.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module char.
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module stream.
|
|
:- import_module stream.string_writer.
|
|
:- import_module string.
|
|
|
|
main(!IO) :-
|
|
io.write_string(test_string_format_1(42, 'x', "HAL", 1111i64, 2222u64),
|
|
!IO),
|
|
io.write_string(test_string_format_2(142, 'y', "IBM"), !IO),
|
|
io.write_string(test_string_format_2(242, 'z', "JCN"), !IO),
|
|
io.write_string(test_string_format_2(342, 'v', "KDO"), !IO),
|
|
io.nl(!IO),
|
|
test_io_format_1(42, 'a', "WHAL", 3333i64, 4444u64, !IO),
|
|
test_io_format_2(142, 'b', "WIBM", !IO),
|
|
test_io_format_2(242, 'c', "WJCN", !IO),
|
|
test_io_format_2(342, 'd', "WKDO", !IO),
|
|
io.nl(!IO),
|
|
io.output_stream(OutStream, !IO),
|
|
test_stream_writer_format_1(OutStream, 42, 'e', "XHAL", 5555i64, 6666u64,
|
|
!IO),
|
|
test_stream_writer_format_2(OutStream, 142, 'f', "XIBM", !IO),
|
|
test_stream_writer_format_2(OutStream, 242, 'g', "XJCN", !IO),
|
|
test_stream_writer_format_2(OutStream, 342, 'h', "XKDO", !IO).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- func test_string_format_1(int, char, string, int64, uint64) = string.
|
|
|
|
test_string_format_1(Int, Char, Str, Int64, UInt64) =
|
|
string.format("abc_%d_def_%%%c_ghi_%s_jkl_%d_mno_%u_pqr\\\n",
|
|
[i(Int), c(Char), s(Str), i64(Int64), u64(UInt64)]).
|
|
|
|
:- func test_string_format_2(int, char, string) = string.
|
|
|
|
test_string_format_2(Int, Char, Str) = Result :-
|
|
PolyStr = s(Str),
|
|
( if
|
|
Int > 300
|
|
then
|
|
Tail = [c(Char), PolyStr],
|
|
IntX = Int + 1,
|
|
Result = string.format("abc_%04d_def_%%%c_ghi_%s_jkl\\\n",
|
|
[i(IntX) | Tail])
|
|
else if
|
|
Int > 200,
|
|
IntY = Int - 1,
|
|
FmtStr = "cba_%s_fed_%%%c_ghi_%d_jkl\\\n",
|
|
Values = [PolyStr, c(Char), i(IntY)]
|
|
then
|
|
Result = string.format(FmtStr, Values)
|
|
else
|
|
IntX = Int + 1,
|
|
Tail = [PolyStr],
|
|
Result = string.format("cba_%c_def_%%%d_ghi_%-7s_jkl\\\n",
|
|
[c(Char), i(IntX) | Tail])
|
|
).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pred test_io_format_1(int::in, char::in, string::in, int64::in, uint64::in,
|
|
io::di, io::uo) is det.
|
|
|
|
test_io_format_1(Int, Char, Str, Int64, UInt64, !IO) :-
|
|
io.format("abc_%d_def_%%%c_ghi_%s_jkl_%d_mno_%u_pqr\\\n",
|
|
[i(Int), c(Char), s(Str), i64(Int64), u64(UInt64)], !IO).
|
|
|
|
:- pred test_io_format_2(int::in, char::in, string::in, io::di, io::uo) is det.
|
|
|
|
test_io_format_2(Int, Char, Str, !IO) :-
|
|
PolyStr = s(Str),
|
|
io.output_stream(OutStream, !IO),
|
|
( if
|
|
Int > 300
|
|
then
|
|
Tail = [c(Char), PolyStr],
|
|
IntX = Int + 1,
|
|
io.format("abc_%05.3d_def_%%%c_ghi_%5s_jkl\\\n", [i(IntX) | Tail], !IO)
|
|
else if
|
|
Int > 200,
|
|
IntY = Int - 1,
|
|
FmtStr = "cba_%s_fed_%%%c_ghi_%d_jkl\\\n",
|
|
Values = [PolyStr, c(Char), i(IntY)]
|
|
then
|
|
io.format(FmtStr, Values, !IO)
|
|
else
|
|
IntX = Int + 1,
|
|
Tail = [PolyStr],
|
|
io.format(OutStream, "cba_%c_def_%%%d_ghi_%s_jkl\\\n",
|
|
[c(Char), i(IntX) | Tail], !IO)
|
|
).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- pred test_stream_writer_format_1(Stream::in, int::in, char::in, string::in,
|
|
int64::in, uint64::in, State::di, State::uo) is det
|
|
<= stream.writer(Stream, string, State).
|
|
|
|
test_stream_writer_format_1(Stream, Int, Char, Str, Int64, UInt64, !State) :-
|
|
stream.string_writer.format(Stream,
|
|
"abc_%d_def_%%%c_ghi_%s_jkl_%d_mno_%u_pqr\\\n",
|
|
[i(Int), c(Char), s(Str), i64(Int64), u64(UInt64)], !State).
|
|
|
|
:- pred test_stream_writer_format_2(Stream::in, int::in, char::in, string::in,
|
|
State::di, State::uo) is det <= stream.writer(Stream, string, State).
|
|
|
|
test_stream_writer_format_2(Stream, Int, Char, Str, !State) :-
|
|
PolyStr = s(Str),
|
|
( if
|
|
Int > 300
|
|
then
|
|
Tail = [c(Char), PolyStr],
|
|
IntX = Int + 1,
|
|
stream.string_writer.format(Stream,
|
|
"abc_%05.3d_def_%%%c_ghi_%5s_jkl\\\n", [i(IntX) | Tail], !State)
|
|
else if
|
|
Int > 200,
|
|
IntY = Int - 1,
|
|
FmtStr = "cba_%s_fed_%%%c_ghi_%d_jkl\\\n",
|
|
Values = [PolyStr, c(Char), i(IntY)]
|
|
then
|
|
stream.string_writer.format(Stream, FmtStr, Values, !State)
|
|
else
|
|
IntX = Int + 1,
|
|
Tail = [PolyStr],
|
|
stream.string_writer.format(Stream, "cba_%c_def_%%%d_ghi_%s_jkl\\\n",
|
|
[c(Char), i(IntX) | Tail], !State)
|
|
).
|