Files
mercury/tests/declarative_debugger/io_stream_test.m
Zoltan Somogyi 58ea6ffff2 Delete old obsolete predicates and functions.
library/*.m:
    Specifically, delete any predicates and functions whose `pragma obsolete'
    dates from 2018 or before. Keep the ones that were obsoleted
    only this year or last year.

NEWS:
    Announce the changes.

tests/debugger/io_tab_goto.m:
tests/debugger/tabled_read.m:
tests/declarative_debugger/io_stream_test.m:
tests/declarative_debugger/tabled_read_decl.m:
tests/declarative_debugger/tabled_read_decl_goto.m:
tests/general/array_test.m:
tests/hard_coded/mutable_init_impure.m:
tests/hard_coded/remove_file.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug2.m:
tests/valid/mercury_java_parser_follow_code_bug.m:
    Replace references to predicates and functions that this diff deletes
    with their suggested replacements.

    In several test cases, bring the programming style up to date.

tests/hard_coded/shift_test.{m,exp}:
    Most of this test case tested the now-deleted legacy shift operations.
    Replace these with tests of their non-legacy versions, including
    testing for the expected exceptions.

tests/hard_coded/shift_test.{m,exp}:
    Don't pass --no-warn-obsolete when compiling shift_test.m anymore.
2020-08-18 11:57:47 +10:00

66 lines
1.5 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% Test the declarative debugger's handling of I/O streams.
%
:- module io_stream_test.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module char.
:- import_module int.
:- import_module list.
main(!IO) :-
io.open_input("tabled_read_decl.data", Res, !IO),
(
Res = ok(Stream),
io_stream_test.part_1(Stream, !IO),
io_stream_test.part_2(Stream, !IO)
;
Res = error(_),
io.write_string("could not open tabled_read.data\n", !IO)
).
:- pred part_1(io.input_stream::in, io::di, io::uo) is det.
part_1(Stream, !IO) :-
test(Stream, A, !IO),
io.write_int(A, !IO),
io.nl(!IO).
:- pred part_2(io.input_stream::in, io::di, io::uo) is det.
part_2(Stream, !IO) :-
test(Stream, A, !IO),
io.write_int(A, !IO),
io.nl(!IO).
:- pred test(io.input_stream::in, int::out, io::di, io::uo) is det.
test(Stream, N, !IO) :-
% BUG: the 1 should be 0
test_2(Stream, 1, N, !IO).
:- pred test_2(io.input_stream::in, int::in, int::out, io::di, io::uo) is det.
test_2(Stream, SoFar, N, !IO) :-
io.read_char(Stream, Res, !IO),
( if
Res = ok(Char),
char.is_decimal_digit(Char),
char.decimal_digit_to_int(Char, CharInt)
then
test_2(Stream, SoFar * 10 + CharInt, N, !IO)
else
N = SoFar
).