StringAstralAnyAllFilterTest
`String.any`, `String.all`, `String.filter` and `String.foldr` see a
character outside the Basic Multilingual Plane, such as an emoji, as one
`Char`.
Such a character has a code point above `0xFFFF` and takes two UTF-16 units,
a surrogate pair, in a string. The test establishes:
- `any` finds ๐ by its code point in `"a๐b"`, and no character of
`"a๐b๐"` has a surrogate code point;
- `all` with a code-point-above-`0xFFFF` predicate is `True` for `"๐๐๐"`
and `False` for `"๐a"`;
- `filter` keeping those characters of `"a๐b๐c"` gives `"๐๐"`, whose
`String.length` is 4, and dropping them gives `"abc"`;
- `foldr String.cons ""` rebuilds `"x๐y๐"` unchanged.Results
elm-0.19.1
passran in 45 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. any_emoji: True any_half: False all_astral: True all_bmp: False filter_keep_ok: True filter_keep_len: 4 filter_drop_ok: True foldr_string_ok: True
elm-0.19.2
passran in 41 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. any_emoji: True any_half: False all_astral: True all_bmp: False filter_keep_ok: True filter_keep_len: 4 filter_drop_ok: True foldr_string_ok: True
elm-0.19.3
passran in 38 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. any_emoji: True any_half: False all_astral: True all_bmp: False filter_keep_ok: True filter_keep_len: 4 filter_drop_ok: True foldr_string_ok: True
lamdera-1.5.0
passran in 66 msOutput
any_emoji: True any_half: False all_astral: True all_bmp: False filter_keep_ok: True filter_keep_len: 4 filter_drop_ok: True foldr_string_ok: True
Discussions
Discuss this testยทSearch the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/StringAstralAnyAllFilterTest] in its title.
Source
The -- CHECK: lines give the expected output.
module StringAstralAnyAllFilterTest exposing (main)
{-| `String.any`, `String.all`, `String.filter` and `String.foldr` see a
character outside the Basic Multilingual Plane, such as an emoji, as one
`Char`.
Such a character has a code point above `0xFFFF` and takes two UTF-16 units,
a surrogate pair, in a string. The test establishes:
- `any` finds ๐ by its code point in `"a๐b"`, and no character of
`"a๐b๐"` has a surrogate code point;
- `all` with a code-point-above-`0xFFFF` predicate is `True` for `"๐๐๐"`
and `False` for `"๐a"`;
- `filter` keeping those characters of `"a๐b๐c"` gives `"๐๐"`, whose
`String.length` is 4, and dropping them gives `"abc"`;
- `foldr String.cons ""` rebuilds `"x๐y๐"` unchanged.
-}
-- CHECK: any_emoji: True
-- CHECK: any_half: False
-- CHECK: all_astral: True
-- CHECK: all_bmp: False
-- CHECK: filter_keep_ok: True
-- CHECK: filter_keep_len: 4
-- CHECK: filter_drop_ok: True
-- CHECK: foldr_string_ok: True
import Html exposing (text)
isEmoji : Char -> Bool
isEmoji c =
Char.toCode c == 0x0001F600
isSurrogate : Char -> Bool
isSurrogate c =
let
n =
Char.toCode c
in
n >= 0xD800 && n <= 0xDFFF
isAstral : Char -> Bool
isAstral c =
Char.toCode c > 0xFFFF
main =
let
_ =
Debug.log "any_emoji" (String.any isEmoji "a๐b")
_ =
Debug.log "any_half" (String.any isSurrogate "a๐b๐")
_ =
Debug.log "all_astral" (String.all isAstral "๐๐๐")
_ =
Debug.log "all_bmp" (String.all isAstral "๐a")
_ =
Debug.log "filter_keep_ok" (String.filter isAstral "a๐b๐c" == "๐๐")
_ =
Debug.log "filter_keep_len" (String.length (String.filter isAstral "a๐b๐c"))
_ =
Debug.log "filter_drop_ok" (String.filter (not << isAstral) "a๐b๐c" == "abc")
_ =
Debug.log "foldr_string_ok" (String.foldr String.cons "" "x๐y๐" == "x๐y๐")
in
text "done"