Files
mercury/tests/hard_coded/string_contains_char.exp
Peter Wang 2ff6b119ef Fix some handling of ill-formed sequences in string module.
library/string.m:
    Fix string.all_match to fail if the string being tested contains
    any ill-formed code unit sequences.

    Fix the Mercury implementation of string.contains_char to continue
    searching for the character past any ill-formed code unit sequences.
    The foreign code implementations already did so.

    Fix unsafe_index_next_repl and unsafe_prev_index_repl in C grades.
    We indexed the C string with `ReplacedCodeUnit = Str[Index]' but
    since Mercury strings have the C type `char *', ReplacedCodeUnit
    could take on a negative value. When ReplacedCodeUnit == -1,
    the caller would assume there is a valid encoding of a code point
    beginning at Index, and therefore return `not_replaced' instead of
    `replaced_code_unit(255)'.

    Add casts to `unsigned char' in other places where we index C
    strings.

    Clarify documentation.

    Document that string.duplicate_char may throw an exception.

tests/hard_coded/string_all_match.m:
tests/hard_coded/string_all_match.exp:
tests/hard_coded/string_all_match.exp2:
    Add test for string.all_match.

tests/hard_coded/contains_char_2.m:
tests/hard_coded/contains_char_2.exp:
    Delete older test case for string.contains_char.

tests/hard_coded/string_contains_char.m:
tests/hard_coded/string_contains_char.exp:
tests/hard_coded/string_contains_char.exp2:
    Add better test for string.contains_char.

tests/hard_coded/Mmakefile:
    Enable the tests.

NEWS:
    Announce the changes.
2022-07-27 14:56:49 +10:00

16 lines
629 B
Plaintext
Raw Blame History

contains_char("", 'X') ==> false.
contains_char("abc", 'X') ==> false.
contains_char("abc", 'a') ==> true.
contains_char("abc", 'b') ==> true.
contains_char("abc", 'c') ==> true.
contains_char("aßξ啕𐀀.", 'ß') ==> true.
contains_char("aßξ啕𐀀.", 'ξ') ==> true.
contains_char("aßξ啕𐀀.", '啕') ==> true.
contains_char("aßξ啕𐀀.", '.') ==> true.
contains_char("aßξ啕𐀀.", '☿') ==> false.
contains_char("abc<62>123", 'c') ==> true.
contains_char("abc<62>123", '1') ==> true.
contains_char("abc<62>123", '2') ==> true.
contains_char("abc<62>123", '3') ==> true.
contains_char("abc<62>123", '<27>') ==> false.