Files
mercury/tests/invalid/string_format_bad.m
Zoltan Somogyi f345d20e33 Rename X's aux modules as X_helper_N in invalid.
tests/invalid/*.m:
    Rename modules as mentioned above.

    In two cases where the main module name is a Mercury keyword (to the
    extent that Mercury has keywords), add a "test_" prefix to the
    module name.

    Reorganize the ho_default_func_2 test case. The original code
    of this test had three modules, a parent and two children,
    with the module being tested being one of the *child* modules
    (ho_default_func_2.sub). This does not work; the .log file
    from the successful execution of this test case showed that
    there was no actual compilation involved; the test stopped
    after invoking "mmc --generate-dependencies" on that child module.
    The new version of this test makes that child module the main module,
    and moves the relevant parts of the other two original modules
    into a single new child module.

    Rename ii_parent to instance_pc (pc being short for parent-child).
    This test case still has the child module listed as the target
    in Mmakefile, so it still does not progress past generating its
    dependencies.

    Rename the imported_mode test case as bad_exported_mode,
    because this is what it was testing.

    exported_mode.m was used both as the main module of a test,
    and as a helper module in the imported_mode test (now renamed
    to bad_exported_mode). Make a copy of it as a helper module
    for bad_exported_mode.

    Update all references to the moved modules.

    General updates to programming style, such as

    - replacing DCG notation with state var notation
    - adding lines around vim modelines
    - fixing indentation
    - fixing grammar errors in comments

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
    Update all references to the moved modules and/or moved lines.
2023-06-16 20:18:36 +02:00

75 lines
2.0 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 expandtab ft=mercury
%---------------------------------------------------------------------------%
:- module string_format_bad.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module bool.
:- import_module list.
:- import_module stream.
:- import_module stream.string_writer.
:- import_module string.
main(!IO) :-
S1 = string.format("", [s("x1")]),
io.write_string(S1, !IO),
S2 = string.format("%d", [s("x2")]),
io.write_string(S2, !IO),
io.stdout_stream(OutputStream, !IO),
io.format("%d", [s("x3")], !IO),
io.format(OutputStream, "%d", [s("x4")], !IO),
stream.string_writer.format(OutputStream, "%d", [s("x4")], !IO),
io.format("%w", [i(5)], !IO),
io.write_string(p(s("five")), !IO),
F6 = "%s %f",
make_bool(6, T6),
( if
T6 = yes,
V6A = i(6)
then
V6 = [s("six"), V6A],
io.format(OutputStream, F6, V6, !IO),
make_bool(7, T7),
F7 = "%d %s %d",
(
T7 = yes,
io.format(OutputStream, F7, [f(7.0) | V6], !IO)
;
T7 = no
)
else
true
).
:- pred make_bool(int::in, bool::out) is det.
make_bool(_, yes).
:- func t(string) = string.
t(S) = S.
:- func p(string.poly_type) = string.
p(s(S)) = t(string.format("%s", [s(S)])).
p(c(C)) = t(string.format("%c", [c(C)])).
p(i(I)) = t(string.format("%d", [i(I)])).
p(i8(I8)) = t(string.format("%d", [i8(I8)])).
p(i16(I16)) = t(string.format("%d", [i16(I16)])).
p(i32(I32)) = t(string.format("%d", [i32(I32)])).
p(i64(I64)) = t(string.format("%d", [i64(I64)])).
p(f(F)) = t(string.format("%f", [f(F)])).
p(u(U)) = t(string.format("%u", [u(U)])).
p(u8(U8)) = t(string.format("%u", [u8(U8)])).
p(u16(U16)) = t(string.format("%u", [u16(U16)])).
p(u32(U32)) = t(string.format("%u", [u32(U32)])).
p(u64(U64)) = t(string.format("%u", [u64(U64)])).