Elm Exactly
Results / elm-core /

StringAstralAnyAllFilterTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`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 ms
Output
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 ms
Output
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 ms
Output
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 ms
Output
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"