Files
mercury/tests/hard_coded/format_term_nl.m
Julien Fischer e3cc72cb0b Fix bug in term_io.format_term_nl/5.
library/term_io.m:
     foramt_term_nl/5 should call format_term_nl_with_op_table/6, *not*
     format_term_with_op_table/6, otherwise the terminating ".\n" will
     not be written.

tests/hard_coded/Mmakefile:
tests/hard_coded/format_term_nl.{exp,m}:
     Add a regression test.
2026-02-20 16:03:18 +11:00

57 lines
1.8 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
% Regression test for bug with term_io.format_term_nl/5 in rotd-2026-02-19
% and before where the terminating ".\n" was not being appended to the term.
%---------------------------------------------------------------------------%
:- module format_term_nl.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module bool.
:- import_module integer.
:- import_module list.
:- import_module string.
:- import_module string.builder.
:- import_module term.
:- import_module term_context.
:- import_module term_int.
:- import_module term_io.
:- import_module varset.
%---------------------------------------------------------------------------%
main(!IO) :-
varset.init(VarSet : varset(generic)),
Args = [
term.functor(term.atom("bar"), [], dummy_context),
term_int.int_to_decimal_term(42, dummy_context)
],
Term = term.functor(term.atom("foo"), Args, dummy_context),
State0 = string.builder.init,
term_io.format_term_nl(string.builder.handle, VarSet, Term,
State0, State),
String = string.builder.to_string(State),
( if string.suffix(String, ".\n") then
io.print_line("PASSED", !IO)
else
io.print_line("FAILED", !IO),
io.print_line(String, !IO),
io.nl(!IO)
).
%---------------------------------------------------------------------------%
:- end_module format_term_nl.
%---------------------------------------------------------------------------%