Files
mercury/tests/hard_coded/string_set_char.m
Zoltan Somogyi 38f1f5faf2 Shut up many warnings in executable test dirs.
tests/hard_coded/bitmap_test_helper_1.m:
tests/hard_coded/curry_2_helper_1.m:
tests/hard_coded/deep_copy_bug.m:
tests/hard_coded/erroneous_liveness.m:
tests/hard_coded/foreign_type_1.m:
tests/hard_coded/hash_table_test.m:
tests/hard_coded/ho_float_reg.m:
tests/hard_coded/impl_def_lex_string.m:
tests/hard_coded/impure_foreign.m:
tests/hard_coded/intermod_multimode_helper_1.m:
tests/hard_coded/multimode.m:
tests/hard_coded/qual_is_test.m:
tests/hard_coded/string_codepoint.m:
tests/hard_coded/string_codepoint_offset_ilseq.m:
tests/hard_coded/string_count_codepoints_ilseq.m:
tests/hard_coded/string_set_char.m:
tests/hard_coded/version_hash_table_test_2.m:
tests/submodules/parent_t2.m:
tests/typeclasses/arbitrary_constraint_pred_1.m:
tests/typeclasses/arbitrary_constraint_pred_2.m:
tests/typeclasses/instance_unconstrained_tvar_type_spec.m:
tests/typeclasses/typeclass_order_bug_1.m:
    Change code to avoid compiler warnings where this is (a) possible,
    and (b) does not interfere with the purpose of the test.

tests/hard_coded/string_codepoint.exp:
tests/hard_coded/string_codepoint_offset_ilseq.exp:
tests/hard_coded/string_codepoint_offset_ilseq.exp2:
    The changes to the source files of these tests changed all references
    to "codepoint" to "code_point", including in the text they output.
    Expect the updated output.

tests/general/Mercury.options:
tests/hard_coded/Mercury.options:
tests/typeclasses/Mercury.options:
tests/submodules/Mercury.options:
    Disable many of the remaining warnings.
2025-02-20 23:11:53 +11:00

129 lines
3.8 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module string_set_char.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module char.
:- import_module list.
:- import_module require.
:- import_module string.
%---------------------------------------------------------------------------%
main(!IO) :-
( if string.set_char('x', -1, "", _) then
error("test failed")
else
true
),
( if string.set_char('x', 0, "", _) then
error("test failed")
else
true
),
( if string.set_char('x', 1, "", _) then
error("test failed")
else
true
),
( if string.set_char('m', 0, "cat", "mat") then
true
else
error("test failed")
),
( if string.set_char('u', 1, "cat", "cut") then
true
else
error("test failed")
),
( if string.set_char('b', 2, "cat", "cab") then
true
else
error("test failed")
),
( if string.set_char('x', 3, "cat", _) then
error("test failed")
else
true
),
% Test variable-width characters.
% In UTF-8:
% y 1 code unit
% ý 2 code units
% 3 code units
% U+10000 4 code units
( if
set_char_by_cp(".aßξ啕𐀀.", 1, 'y', ".yßξ啕𐀀."),
set_char_by_cp(".aßξ啕𐀀.", 1, 'ý', ".ýßξ啕𐀀."),
set_char_by_cp(".aßξ啕𐀀.", 1, '', ".ẏßξ啕𐀀."),
set_char_by_cp(".aßξ啕𐀀.", 1, '𐀀', ".𐀀ßξ啕𐀀.")
then
true
else
io.write_string("variable-width set_char failed (1)\n", !IO)
),
( if
set_char_by_cp(".aßξ啕𐀀.", 2, 'y', ".ayξ啕𐀀."),
set_char_by_cp(".aßξ啕𐀀.", 2, 'ý', ".aýξ啕𐀀."),
set_char_by_cp(".aßξ啕𐀀.", 2, '', ".aẏξ啕𐀀."),
set_char_by_cp(".aßξ啕𐀀.", 2, '𐀀', ".a𐀀ξ啕𐀀.")
then
true
else
io.write_string("variable-width set_char failed (2)\n", !IO)
),
( if
set_char_by_cp(".aßξ啕𐀀.", 3, 'y', ".aßy啕𐀀."),
set_char_by_cp(".aßξ啕𐀀.", 3, 'ý', ".aßý啕𐀀."),
set_char_by_cp(".aßξ啕𐀀.", 3, '', ".aßẏ啕𐀀."),
set_char_by_cp(".aßξ啕𐀀.", 3, '𐀀', ".aß𐀀啕𐀀.")
then
true
else
io.write_string("variable-width set_char failed (3)\n", !IO)
),
( if
set_char_by_cp(".aßξ啕𐀀.", 4, 'y', ".aßξy𐀀."),
set_char_by_cp(".aßξ啕𐀀.", 4, 'ý', ".aßξý𐀀."),
set_char_by_cp(".aßξ啕𐀀.", 4, '', ".aßξẏ𐀀."),
set_char_by_cp(".aßξ啕𐀀.", 4, '𐀀', ".aßξ𐀀𐀀.")
then
true
else
io.write_string("variable-width set_char failed (4)\n", !IO)
),
( if
set_char_by_cp(".aßξ啕𐀀.", 5, 'y', ".aßξ啕y."),
set_char_by_cp(".aßξ啕𐀀.", 5, 'ý', ".aßξ啕ý."),
set_char_by_cp(".aßξ啕𐀀.", 5, '', ".aßξ啕ẏ."),
set_char_by_cp(".aßξ啕𐀀.", 5, '𐀀', ".aßξ啕𐀀.")
then
true
else
io.write_string("variable-width set_char failed (5)\n", !IO)
),
io.write_string("test finished\n", !IO).
:- pred set_char_by_cp(string::in, int::in, char::in, string::out) is semidet.
set_char_by_cp(Str0, CodePoint, Char, Str) :-
string.code_point_offset(Str0, CodePoint, Offset),
string.set_char(Char, Offset, Str0, Str),
trace [io(!IO), runtime(env("DEBUG"))] (
io.format("%s\n", [s(Str)], !IO)
).