Files
mercury/tests/hard_coded/string_strip.m
Julien Fischer 459847a064 Move the univ, maybe, pair and unit types from std_util into their own
Estimated hours taken: 18
Branches: main

Move the univ, maybe, pair and unit types from std_util into their own
modules.  std_util still contains the general purpose higher-order programming
constructs.

library/std_util.m:
	Move univ, maybe, pair and unit (plus any other related types
	and procedures) into their own modules.

library/maybe.m:
	New module.  This contains the maybe and maybe_error types and
	the associated procedures.

library/pair.m:
	New module.  This contains the pair type and associated procedures.

library/unit.m:
	New module. This contains the types unit/0 and unit/1.

library/univ.m:
	New module. This contains the univ type and associated procedures.

library/library.m:
	Add the new modules.

library/private_builtin.m:
	Update the declaration of the type_ctor_info struct for univ.

runtime/mercury.h:
	Update the declaration for the type_ctor_info struct for univ.

runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
	Update the definition of MR_Univ.

runtime/mercury_init.h:
	Fix a comment: ML_type_name is now exported from type_desc.m.

compiler/mlds_to_il.m:
	Update the the name of the module that defines univs (which are
	handled specially by the il code generator.)

library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
	Conform to the above changes.  Import the new modules where they
	are needed; don't import std_util where it isn't needed.

	Fix formatting in lots of modules.  Delete duplicate module
	imports.

tests/*:
	Update the test suite to confrom to the above changes.
2006-03-29 08:09:58 +00:00

122 lines
2.9 KiB
Mathematica

%-----------------------------------------------------------------------------%
% string_strip.m
% Ralph Becket <rafe@cs.mu.oz.au>
% Wed Feb 12 17:10:49 EST 2003
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
%
% Test the string strip type functions.
%
%-----------------------------------------------------------------------------%
:- module string_strip.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module string, int, list, pair, char, solutions.
:- pred space(char, char).
:- mode space(in, out ) is semidet.
:- mode space(out, out ) is multi.
space(' ', ' ').
space('\t', 't').
space('\n', 'n').
%-----------------------------------------------------------------------------%
main(!IO) :-
Strings =
condense(
map(func(Spaces) = ["foo", Spaces ++ "foo", "foo" ++ Spaces,
Spaces ++ "foo" ++ Spaces],
condense(
map(func(Length) = solutions(mk_spaces(Length)),
1`..`2
)
)
)
),
Tests = [
"chomp" -
chomp,
"lstrip" -
lstrip,
"rstrip" -
rstrip,
"strip" -
strip,
"lstrip(is_alpha)" -
lstrip(char.is_alpha),
"rstrip(is_alpha)" -
rstrip(char.is_alpha),
"prefix_length(is_whitespace)" -
( func(S) = format("%d", [i(prefix_length(char.is_whitespace, S))]) ),
"suffix_length(is_whitespace)" -
( func(S) = format("%d", [i(suffix_length(char.is_whitespace, S))]) )
],
Results =
condense(
map(func(Name - Test) =
map(func(String) =
format("%s(\"%s\") = \"%s\"",
[s(Name), s(quote(String)), s(quote(Test(String)))]),
Strings
),
Tests
)
),
io.write_list(Results, "\n", io.write_string, !IO),
io.nl(!IO).
%-----------------------------------------------------------------------------%
:- func quote(string) = string.
quote(S) =
string.from_char_list(
foldr(
func(C, Cs) = ( if space(C, X) then ['\\', X | Cs] else [C | Cs] ),
string.to_char_list(S),
[]
)
).
%-----------------------------------------------------------------------------%
:- pred mk_spaces(int, string).
:- mode mk_spaces(in, out ) is multi.
mk_spaces(N, S) :-
map((pred(_::in, C::out) is multi :- space(C, _)), 1`..`N, Cs),
S = string.from_char_list(Cs).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%