mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-17 02:13:54 +00:00
tests/accumulator/*.m:
tests/analysis_*/*.m:
tests/benchmarks*/*.m:
tests/debugger*/*.{m,exp,inp}:
tests/declarative_debugger*/*.{m,exp,inp}:
tests/dppd*/*.m:
tests/exceptions*/*.m:
tests/general*/*.m:
tests/grade_subdirs*/*.m:
tests/hard_coded*/*.m:
Make these tests use four-space indentation, and ensure that
each module is imported on its own line. (I intend to use the latter
to figure out which subdirectories' tests can be executed in parallel.)
These changes usually move code to different lines. For the debugger tests,
specify the new line numbers in .inp files and expect them in .exp files.
67 lines
1.9 KiB
Mathematica
67 lines
1.9 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module string_replace.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module list.
|
|
:- import_module string.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
Str = "aaa bbbb ccccc aaa",
|
|
Str2 = "aßξ啕ßξ啕𐀀.",
|
|
Tests = [
|
|
{"", "a", "bc"},
|
|
|
|
{Str, "aab", "**"},
|
|
{Str, "aaaa", "**"},
|
|
{Str, "", "**"},
|
|
|
|
{Str, "aaa", ""},
|
|
{Str, "cc", "**"},
|
|
|
|
{Str2, "ßξ", "**"}, % decreased code units
|
|
{Str2, "ßξ", "★★"}, % increased code units
|
|
{Str2, "啕ßξ", "***"}
|
|
],
|
|
list__foldl(test_replace, Tests, !IO),
|
|
list__foldl(test_replace_all, Tests, !IO).
|
|
|
|
:- pred test_replace({string, string, string}::in, io::di, io::uo) is det.
|
|
|
|
test_replace({Str, Pat, Subst}, !IO) :-
|
|
io__write_string("string__replace(\"" ++ Str ++
|
|
"\", \"" ++ Pat ++
|
|
"\", \"" ++ Subst ++ "\", Result) \n\t", !IO),
|
|
( string__replace(Str, Pat, Subst, Result) ->
|
|
io__write(Result, !IO),
|
|
io__nl(!IO)
|
|
;
|
|
io__write_string("FAIL!\n", !IO)
|
|
).
|
|
|
|
:- pred test_replace_all({string, string, string}::in, io::di, io::uo) is det.
|
|
|
|
test_replace_all({Str, Pat, Subst}, !IO) :-
|
|
io__write_string("string__replace_all(\"" ++ Str ++
|
|
"\", \"" ++ Pat ++
|
|
"\", \"" ++ Subst ++ "\", Result) \n\t", !IO),
|
|
string__replace_all(Str, Pat, Subst, Result),
|
|
io__write(Result, !IO),
|
|
io__nl(!IO).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|