[m-rev.] for review: Test string case folding and case-insensitive comparison.
Julien Fischer
jfischer at opturion.com
Mon Jun 20 15:15:34 AEST 2016
On Mon, 20 Jun 2016, Peter Wang wrote:
> tests/hard_coded/Mmakefile:
> tests/hard_coded/string_case.m:
> tests/hard_coded/string_case.exp:
> Add tests string.to_lower, string.to_upper and string.compare_ci_ascii.
...
> diff --git a/tests/hard_coded/string_case.exp b/tests/hard_coded/string_case.exp
> new file mode 100644
> index 0000000..2070beb
> --- /dev/null
> +++ b/tests/hard_coded/string_case.exp
> @@ -0,0 +1,6 @@
> +testing string.to_lower(in, out)
> +testing string.to_upper(in, out)
> +testing string.to_lower(in, in)
> +testing string.to_upper(in, in)
> +testing string.compare_ci_ascii
> +done.
> diff --git a/tests/hard_coded/string_case.m b/tests/hard_coded/string_case.m
> new file mode 100644
> index 0000000..b338d30
> --- /dev/null
> +++ b/tests/hard_coded/string_case.m
> @@ -0,0 +1,111 @@
> +%---------------------------------------------------------------------------%
> +% vim: ts=4 sw=4 et ft=mercury
> +%---------------------------------------------------------------------------%
> +
> +:- module string_case.
> +:- interface.
> +
> +:- import_module io.
> +
> +:- pred main(io::di, io::uo) is cc_multi.
> +
> +%---------------------------------------------------------------------------%
> +%---------------------------------------------------------------------------%
> +
> +:- implementation.
> +
> +:- import_module char.
> +:- import_module list.
> +:- import_module require.
> +:- import_module solutions.
> +:- import_module string.
> +
> +%---------------------------------------------------------------------------%
> +
> +main(!IO) :-
> + write_string("testing string.to_lower(in, out)\n", !IO),
> + foldl(test_to_lower_in_out, strings, !IO),
> +
> + write_string("testing string.to_upper(in, out)\n", !IO),
> + foldl(test_to_upper_in_out, strings, !IO),
> +
> + write_string("testing string.to_lower(in, in)\n", !IO),
> + unsorted_aggregate(string_pairs, test_to_lower_in_in, !IO),
> +
> + write_string("testing string.to_upper(in, in)\n", !IO),
> + unsorted_aggregate(string_pairs, test_to_upper_in_in, !IO),
> +
> + write_string("testing string.compare_ci_ascii\n", !IO),
> + aggregate(string_pairs, test_compare_ci_ascii, !IO),
> +
> + write_string("done.\n", !IO).
> +
> +:- func strings = list(string).
> +
> +strings = [
> + "",
> + "0123456789",
I would extend that with the punctuation leading up to 'A', e.g.
"0123456789:;<=?@"
> + "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
> + "abcdefghijklmnopqrstuvwxyz",
Likewise, you should have characters immediately following 'z',
"{|}?~"
> + "Dog",
> + "DOGgie",
> + "็ไป\U0001F415dog",
> + "็ไป\U0001F415DOG"
> +].
The test strings should also contain some accented Latin characters.
Looks fine otherwise.
Julien.
More information about the reviews
mailing list