mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 01:13:30 +00:00
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.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
% vim: ft=mercury ts=4 sw=4 et
|
||||
%---------------------------------------------------------------------------%
|
||||
% Copyright (C) 1994-2006, 2009, 2011-2012 The University of Melbourne.
|
||||
% Copyright (C) 2014-2025 The Mercury team.
|
||||
% Copyright (C) 2014-2026 The Mercury team.
|
||||
% This file is distributed under the terms specified in COPYING.LIB.
|
||||
%---------------------------------------------------------------------------%
|
||||
%
|
||||
@@ -494,7 +494,7 @@ write_term_nl(OutStream, VarSet, Term, !IO) :-
|
||||
|
||||
format_term_nl(Stream, VarSet, Term, !State) :-
|
||||
OpTable = init_mercury_op_table,
|
||||
format_term_with_op_table(Stream, OpTable, VarSet, Term, !State).
|
||||
format_term_nl_with_op_table(Stream, OpTable, VarSet, Term, !State).
|
||||
|
||||
%---------------------%
|
||||
|
||||
|
||||
@@ -170,6 +170,7 @@ ORDINARY_PROGS = \
|
||||
foreign_type_1 \
|
||||
foreign_type_2 \
|
||||
foreign_type_3 \
|
||||
format_term_nl \
|
||||
frameopt_pragma_redirect \
|
||||
free_free_mode \
|
||||
from_ground_term_bug \
|
||||
|
||||
1
tests/hard_coded/format_term_nl.exp
Normal file
1
tests/hard_coded/format_term_nl.exp
Normal file
@@ -0,0 +1 @@
|
||||
PASSED
|
||||
56
tests/hard_coded/format_term_nl.m
Normal file
56
tests/hard_coded/format_term_nl.m
Normal file
@@ -0,0 +1,56 @@
|
||||
%---------------------------------------------------------------------------%
|
||||
% 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.
|
||||
%---------------------------------------------------------------------------%
|
||||
Reference in New Issue
Block a user