Files
mercury/tests/hard_coded/string_switch_1.m
Zoltan Somogyi 2cec289e70 Use test case numbers according to our conventions ...
... in the general and hard_coded test case directories.

tests/general/Mercury.options:
tests/general/Mmakefile:
tests/general/commit_bug_1.exp:
tests/general/commit_bug_1.m:
    Rename the commit_bug test case as commit_bug_1, due to the existence
    of commit_bug_2.

tests/general/intermod_type.m:
tests/general/intermod_type_helper_1.m:
    Rename intermod_type2.m as intermod_type_helper_1.m.

tests/general/nondet_ite_1.exp:
tests/general/nondet_ite_1.m:
    Rename the nondet_ite test case as nondet_ite_1, due to the existence
    of nondet_ite_[234].

tests/general/string_format_test_1.exp:
tests/general/string_format_test_1.exp2:
tests/general/string_format_test_1.exp3:
tests/general/string_format_test_1.m:
    Rename the string_format_test test case as string_format_test_1,
    due to the existence of string_format_test_[23].

tests/general/string_test_1.exp:
tests/general/string_test_1.m:
    Rename the string_test test case as string_test_1,
    due to the existence of string_test_2.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/array_test_1.exp:
tests/hard_coded/array_test_1.m:
tests/hard_coded/array_test_2.exp:
tests/hard_coded/array_test_2.m:
    Rename the array_test and array_test2 test cases as
    array_test_1 and array_test_2.

tests/hard_coded/bad_indirect_reuse_1.exp:
tests/hard_coded/bad_indirect_reuse_1.m:
tests/hard_coded/bad_indirect_reuse_2.exp:
tests/hard_coded/bad_indirect_reuse_2.m:
tests/hard_coded/bad_indirect_reuse_3.exp:
tests/hard_coded/bad_indirect_reuse_3.m:
tests/hard_coded/bad_indirect_reuse_4.exp:
tests/hard_coded/bad_indirect_reuse_4.m:
    Rename the bad_indirect_reuse and bad_indirect_reuse[234] test cases
    as bad_indirect_reuse_[1234].

tests/hard_coded/copy_pred_1.exp:
tests/hard_coded/copy_pred_1.m:
    Rename the copy_pred test case as copy_pred_1, due to the existence
    of copy_pred_2.

tests/hard_coded/curry_1.exp:
tests/hard_coded/curry_1.m:
tests/hard_coded/curry_2.exp:
tests/hard_coded/curry_2.m:
tests/hard_coded/curry_2_helper_1.m:
    Rename the curry and curry2 test cases as curry_1 and curry_2,
    and rename the curry2_test module as curry_2_helper_1.

tests/hard_coded/cycles_1.exp:
tests/hard_coded/cycles_1.m:
tests/hard_coded/cycles_2.exp:
tests/hard_coded/cycles_2.m:
    Rename the cycles and cycles2 test cases as cycles_1 and cycles_2.

tests/hard_coded/delay_partial_test_1.exp:
tests/hard_coded/delay_partial_test_1.m:
tests/hard_coded/delay_partial_test_2.exp:
tests/hard_coded/delay_partial_test_2.m:
    Rename the delay_partial_test and delay_partial_test2 test cases
    as delay_partial_test_1 and delay_partial_test_2.

tests/hard_coded/dense_lookup_switch_1.exp:
tests/hard_coded/dense_lookup_switch_1.m:
tests/hard_coded/dense_lookup_switch_2.exp:
tests/hard_coded/dense_lookup_switch_2.m:
tests/hard_coded/dense_lookup_switch_3.exp:
tests/hard_coded/dense_lookup_switch_3.m:
tests/hard_coded/dense_lookup_switch_4.exp:
tests/hard_coded/dense_lookup_switch_4.m:
    Rename the dense_lookup_switch and dense_lookup_switch[234] test cases
    as dense_lookup_switch_[1234].

tests/hard_coded/dense_lookup_switch_non_1.exp:
tests/hard_coded/dense_lookup_switch_non_1.m:
tests/hard_coded/dense_lookup_switch_non_2.exp:
tests/hard_coded/dense_lookup_switch_non_2.m:
    Rename the dense_lookup_switch_non and dense_lookup_non2 test cases
    as dense_lookup_switch_non_[12].

tests/hard_coded/direct_arg_partial_inst_1.exp:
tests/hard_coded/direct_arg_partial_inst_1.m:
tests/hard_coded/direct_arg_partial_inst_2.exp:
tests/hard_coded/direct_arg_partial_inst_2.m:
    Rename the direct_arg_partial_inst and direct_arg_partial_inst2 test cases
    as direct_arg_partial_inst_[12].

tests/hard_coded/direct_arg_tags_1.exp:
tests/hard_coded/direct_arg_tags_1.m:
    Rename the direct_arg_tags test case as direct_arg_tags_1, due to
    the existence of direct_arg_tags_2.

tests/hard_coded/export_test_1.exp:
tests/hard_coded/export_test_1.m:
tests/hard_coded/export_test_2.exp:
tests/hard_coded/export_test_2.m:
    Rename the export_test and export_test2 test cases as export_test_[12].

tests/hard_coded/follow_code_bug_1.exp:
tests/hard_coded/follow_code_bug_1.m:
    Rename the follow_code_bug test case as follow_code_bug_1, due to
    the existence of follow_code_bug_2.

tests/hard_coded/foreign_type_1.exp:
tests/hard_coded/foreign_type_1.m:
tests/hard_coded/foreign_type_2.exp:
tests/hard_coded/foreign_type_2.m:
tests/hard_coded/foreign_type_3.exp:
tests/hard_coded/foreign_type_3.m:
    Rename the foreign_type and foreign_type[23] test cases
    as foreign_type_[123].

tests/hard_coded/functor_ho_inst_1.exp:
tests/hard_coded/functor_ho_inst_1.m:
    Rename the functor_ho_inst test case as functor_ho_inst_1, due to
    the existence of functor_ho_inst_2.

tests/hard_coded/functor_ho_inst_excp_1.exp:
tests/hard_coded/functor_ho_inst_excp_1.m:
    Rename the functor_ho_inst_excp test case as functor_ho_inst_excp_1,
    due to the existence of functor_ho_inst_excp_2.

tests/hard_coded/higher_order_syntax_1.exp:
tests/hard_coded/higher_order_syntax_1.m:
tests/hard_coded/higher_order_syntax_2.exp:
tests/hard_coded/higher_order_syntax_2.m:
    Rename the higher_order_syntax and higher_order_syntax2 test cases
    as higher_order_syntax_[12].

tests/hard_coded/ho_order_1.exp:
tests/hard_coded/ho_order_1.m:
tests/hard_coded/ho_order_2.exp:
tests/hard_coded/ho_order_2.m:
    Rename the ho_order and ho_order2 test cases as ho_order_[12].

tests/hard_coded/lco_pack_args_1.exp:
tests/hard_coded/lco_pack_args_1.m:
    Rename the lco_pack_args test case as lco_pack_args_1, due to
    the existence of lco_pack_args_[23].

tests/hard_coded/loop_inv_extra_test_1.inp:
tests/hard_coded/loop_inv_extra_test_1.m:
tests/hard_coded/loop_inv_extra_test_2.inp:
tests/hard_coded/loop_inv_extra_test_2.m:
    Rename the loop_inv_test0 and loop_inv_test2 test cases as
    loop_inv_extra_test_1 and loop_inv_extra_test_2 respectively.
    Both these test cases test "extra" functionality that the compiler
    does not currently have, and thus neither is currently enabled.

tests/hard_coded/loop_inv_test_2.exp:
tests/hard_coded/loop_inv_test_2.inp:
tests/hard_coded/loop_inv_test_2.m:
    Rename the loop_inv_test test case as loop_inv_test_2,
    because loop_inv_test_1 was already taken (see below).

tests/hard_coded/loop_inv_test_1.exp:
tests/hard_coded/loop_inv_test_1.inp:
tests/hard_coded/loop_inv_test_1.m:
tests/hard_coded/loop_inv_test_3.exp:
tests/hard_coded/loop_inv_test_3.m:
tests/hard_coded/loop_inv_test_4.exp:
tests/hard_coded/loop_inv_test_4.m:
    Rename the loop_inv_test[134] test cases as loop_inv_test_[134].

tests/hard_coded/pprint_test_1.exp:
tests/hard_coded/pprint_test_1.m:
tests/hard_coded/pprint_test_2.exp:
tests/hard_coded/pprint_test_2.m:
    Rename the pprint_test and pprint_test2 test cases as pprint_test_[12].

tests/hard_coded/quantifier_1.exp:
tests/hard_coded/quantifier_1.m:
tests/hard_coded/quantifier_2.exp:
tests/hard_coded/quantifier_2.m:
    Rename the quantifier and quantifier2 test cases as quantifier_[12].

tests/hard_coded/random_1.exp:
tests/hard_coded/random_1.m:
tests/hard_coded/random_2.exp:
tests/hard_coded/random_2.m:
tests/hard_coded/random_3.exp:
tests/hard_coded/random_3.m:
    Rename the random[123] test cases as random_[123].

tests/hard_coded/random_shuffle_1.exp:
tests/hard_coded/random_shuffle_1.m:
tests/hard_coded/random_shuffle_2.exp:
tests/hard_coded/random_shuffle_2.m:
    Rename the random_shuffle[12] test cases as random_shuffle_[12].

tests/hard_coded/string_split_1.exp:
tests/hard_coded/string_split_1.m:
    Rename the string_split test case as string_split_1, due to
    the existence of string_split_2.

tests/hard_coded/string_switch_1.exp:
tests/hard_coded/string_switch_1.m:
tests/hard_coded/string_switch_2.exp:
tests/hard_coded/string_switch_2.m:
tests/hard_coded/string_switch_3.exp:
tests/hard_coded/string_switch_3.m:
tests/hard_coded/string_switch_4.exp:
tests/hard_coded/string_switch_4.m:
    Rename the string_switch and string_switch[233] test cases
    as string_switch_[1234].

tests/hard_coded/test_cord_1.exp:
tests/hard_coded/test_cord_1.m:
tests/hard_coded/test_cord_2.exp:
tests/hard_coded/test_cord_2.m:
tests/hard_coded/test_cord_3.exp:
tests/hard_coded/test_cord_3.m:
    Rename the test_cord and test_cord[23] test cases as test_cord_[123].

tests/hard_coded/trace_goal_opt.m:
tests/hard_coded/trace_goal_opt_helper_1.m:
    Rename the trace_goal_opt_2 module as trace_goal_opt_helper_1.

tests/hard_coded/tuple_test_1.exp:
tests/hard_coded/tuple_test_1.m:
tests/hard_coded/tuple_test_2.exp:
tests/hard_coded/tuple_test_2.m:
    Rename the tuple_test and tuple_test2 test cases as tuple_test_[12].

tests/hard_coded/version_hash_table_test_1.exp:
tests/hard_coded/version_hash_table_test_1.m:
tests/hard_coded/version_hash_table_test_2.exp:
tests/hard_coded/version_hash_table_test_2.m:
    Rename the version_hash_table_test and version_hash_table_test2
    test cases as version_hash_table_test_[12].

tests/hard_coded/write_reg_1.exp:
tests/hard_coded/write_reg_1.m:
tests/hard_coded/write_reg_2.exp:
tests/hard_coded/write_reg_2.m:
    Rename the write_reg[12] test cases as write_reg_[12].
2024-08-05 15:09:33 +02:00

489 lines
9.1 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
%
% The codes of the tests
%
% string_switch_1.m
% string_switch_2.m
% string_switch_2.m
% string_switch_4.m
%
% are all identical, but we compile them with different compilation options.
%
:- module string_switch_1.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
:- implementation.
:- import_module int.
:- import_module list.
:- import_module solutions.
:- import_module string.
main(!IO) :-
TestStrs = [
"a", "b", "c",
"aa", "ab", "ac",
"ba", "bb", "bc",
"ca", "cb", "cc", "cf",
"xxx", "xxxxxxΓ", "xxxxxxx",
"Γ", "Δ", "Θ", "Σ", "Σζ"
],
% Test jump tables.
list.foldl(test_jump, TestStrs, !IO),
% Test semidet and det lookup tables.
list.foldl(test_one, TestStrs, !IO),
list.foldl(test_one_known, TestStrs, !IO),
% Test nondet and multi lookup tables.
list.foldl(test_several, TestStrs, !IO),
list.foldl(test_several_known, TestStrs, !IO),
list.foldl(test_several_nested, TestStrs, !IO).
%---------------------------------------------------------------------------%
:- pred test_jump(string::in, io::di, io::uo) is det.
test_jump(S, !IO) :-
( if jump(S, 50, N) then
io.format("jump %s -> %d\n", [s(S), i(N)], !IO)
else
io.format("jump %s failed\n", [s(S)], !IO)
).
:- pred test_one(string::in, io::di, io::uo) is det.
test_one(S, !IO) :-
( if one(S, N) then
io.format("one %s -> %d\n", [s(S), i(N)], !IO)
else
io.format("one %s failed\n", [s(S)], !IO)
).
:- pred test_one_known(string::in, io::di, io::uo) is det.
test_one_known(S, !IO) :-
( if
( S = "aa"
; S = "bb"
),
one(S, N)
then
io.format("one known %s -> %d\n", [s(S), i(N)], !IO)
else
io.format("one known %s failed\n", [s(S)], !IO)
).
:- pred test_several(string::in, io::di, io::uo) is det.
test_several(S, !IO) :-
solutions(several_unknown(S), Solns),
io.format("several %s -> ", [s(S)], !IO),
io.write_line(Solns, !IO).
:- pred test_several_known(string::in, io::di, io::uo) is det.
test_several_known(S, !IO) :-
solutions(several_known(S), Solns),
io.format("several known %s -> ", [s(S)], !IO),
io.write_line(Solns, !IO).
:- pred test_several_nested(string::in, io::di, io::uo) is det.
test_several_nested(S, !IO) :-
solutions(several_nested(S), Solns),
io.format("several nested %s -> ", [s(S)], !IO),
io.write_line(Solns, !IO).
%---------------------------------------------------------------------------%
:- pred jump(string::in, int::in, int::out) is semidet.
jump(S, N0, N) :-
(
S = "a",
N = N0 + 1
;
S = "b",
N = N0 + 2
;
( S = "aa"
; S = "ab"
),
N = 11
;
( S = "ba"
; S = "bb"
),
N = N0 + 12
;
( S = "ca"
; S = "cd"
; S = "ce"
),
N = 13
;
( S = "cb"
; S = "cg"
; S = "ch"
),
N = 14
;
( S = "cf"
; S = "ci"
),
N = 15
;
S = "xxx",
N = 21
;
S = "xxy",
N = 22
;
S = "xxz",
N = 23
;
S = "xyx",
N = 24
;
% The next two arms test the treatment of sticks by trie switches.
% The stick ends in the *middle* of the last code point, since
%
% - the last code point of each string has two UTF-8 code units, and
% - the first of those code units is the same in the two arms.
S = "xxxxxxΓ",
N = 25
;
S = "xxxxxxΔ",
N = 26
;
S = "Γ", % greek capital gamma, UC+0393
N = 27
;
S = "Δ", % greek capital delta, UC+0394
N = 28
;
( S = "Θ" % greek capital theta, UC+0398
; S = "Σ" % greek capital sigma, UC+03A3
),
N = 29
).
%---------------------------------------------------------------------------%
:- inst aa_bb
---> "aa"
; "bb".
:- pred one(string, int).
:- mode one(in(aa_bb), out) is det.
:- mode one(in, out) is semidet.
one(S, N) :-
(
S = "a",
N = 1
;
S = "b",
N = 2
;
( S = "aa"
; S = "ab"
),
N = 11
;
( S = "ba"
; S = "bb"
),
N = 12
;
( S = "ca"
; S = "cd"
; S = "ce"
),
N = 13
;
( S = "cb"
; S = "cg"
; S = "ch"
),
N = 14
;
( S = "cf"
; S = "ci"
),
N = 15
;
S = "xxx",
N = 21
;
S = "xxy",
N = 22
;
S = "xxz",
N = 23
;
S = "xyx",
N = 24
;
S = "xxxxxxΓ",
N = 25
;
S = "xxxxxxΔ",
N = 26
;
S = "Γ", % greek capital gamma, UC+0393
N = 27
;
S = "Δ", % greek capital delta, UC+0394
N = 28
;
( S = "Θ" % greek capital theta, UC+0398
; S = "Σ" % greek capital sigma, UC+03A3
),
N = 29
).
%---------------------------------------------------------------------------%
:- pred several_unknown(string::in, int::out) is nondet.
several_unknown(S, N) :-
several(S, N).
:- pred several_known(string::in, int::out) is nondet.
several_known(S, N) :-
( S = "aa"
; S = "bb"
),
several(S, N).
:- pred several(string, int).
:- mode several(in(aa_bb), out) is multi.
:- mode several(in, out) is nondet.
several(S, N) :-
(
S = "a",
N = 1
;
S = "b",
N = 2
;
( S = "aa"
; S = "ab"
),
( N = 11
; N = 12
)
;
( S = "ba"
; S = "bb"
),
( N = 13
; N = 14
; N = 15
)
;
( S = "ca"
; S = "cb"
; S = "cd"
; S = "ce"
),
N = 16
;
( S = "cg"
; S = "ch"
),
N = 17
;
( S = "cf"
; S = "ci"
),
( N = 18
; N = 19
)
;
S = "xxx",
N = 21
;
S = "xxy",
N = 22
;
S = "xxz",
N = 23
;
S = "xyx",
( N = 24
; N = 25
; N = 26
)
;
S = "xxxxxxΓ",
N = 25
;
S = "xxxxxxΔ",
( N = 26
; N = 27
)
;
S = "Γ", % greek capital gamma, UC+0393
N = 27
;
S = "Δ", % greek capital delta, UC+0394
N = 28
;
( S = "Θ" % greek capital theta, UC+0398
; S = "Σ" % greek capital sigma, UC+03A3
),
( N = 29
; N = 30
)
).
%---------------------------------------------------------------------------%
:- pred several_nested(string::in, int::out) is nondet.
several_nested(S0, R) :-
(
S = S0
;
S = "a" ++ S0
),
(
S = "a",
N = 1
;
S = "b",
N = 2
;
( S = "aa"
; S = "ab"
),
( N = 11
; N = 12
)
;
( S = "ba"
; S = "bb"
),
( N = 13
; N = 14
; N = 15
)
;
( S = "ca"
; S = "cb"
; S = "cd"
; S = "ce"
),
N = 16
;
S = "xxx",
N = 21
;
S = "xxy",
N = 22
;
S = "xxz",
N = 23
;
S = "xyx",
( N = 24
; N = 25
; N = 26
)
;
S = "axxxxxxΓ",
N = 25
;
S = "xxxxxxΔ",
N = 26
;
S = "aΓ", % greek capital gamma, UC+0393
N = 27
;
S = "Δ", % greek capital delta, UC+0394
N = 28
;
( S = "aΘ" % greek capital theta, UC+0398
; S = "Σ" % greek capital sigma, UC+03A3
),
N = 29
),
(
S0 = "a",
M = 1
;
S0 = "b",
M = 2
;
( S0 = "aa"
; S0 = "ab"
),
( M = 11
; M = 12
)
;
( S0 = "ba"
; S0 = "bb"
),
( M = 13
; M = 14
; M = 15
)
;
( S0 = "ca"
; S0 = "cb"
; S0 = "cd"
; S0 = "ce"
),
M = 16
;
S0 = "xxx",
M = 21
;
S0 = "xxy",
M = 22
;
S0 = "xxz",
M = 23
;
S0 = "xyx",
( M = 24
; M = 25
; M = 26
)
;
S0 = "axxxxxxΓ",
M = 25
;
S0 = "xxxxxxΔ",
M = 26
;
S0 = "Γ", % greek capital gamma, UC+0393
M = 27
;
S0 = "Δ", % greek capital delta, UC+0394
M = 28
;
( S0 = "xΘ" % greek capital theta, UC+0398
; S0 = "Σ" % greek capital sigma, UC+03A3
),
M = 29
),
R = 1000 * N + M.