StringAstralLengthTest
`String.length` counts UTF-16 code units, so a character outside the Basic Multilingual Plane counts as 2. U+1F600 (๐) is encoded as a surrogate pair. `String.length "๐"` is 2, and `String.length "a๐b"` is 4. The test also requires such a character to survive inside a string literal.
Results
elm-0.19.1
passran in 43 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. len_astral: 2 len_mixed: 4
elm-0.19.2
passran in 35 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. len_astral: 2 len_mixed: 4
elm-0.19.3
passran in 61 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. len_astral: 2 len_mixed: 4
lamdera-1.5.0
passran in 38 msOutput
len_astral: 2 len_mixed: 4
Discussions
Discuss this testยทSearch the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/StringAstralLengthTest] in its title.
Source
The -- CHECK: lines give the expected output.
module StringAstralLengthTest exposing (main)
{-| `String.length` counts UTF-16 code units, so a character outside the Basic Multilingual Plane counts as 2.
U+1F600 (๐) is encoded as a surrogate pair. `String.length "๐"` is 2, and
`String.length "a๐b"` is 4. The test also requires such a character to survive
inside a string literal.
-}
-- CHECK: len_astral: 2
-- CHECK: len_mixed: 4
import Html exposing (text)
main =
let
_ =
Debug.log "len_astral" (String.length "๐")
_ =
Debug.log "len_mixed" (String.length "a๐b")
in
text "done"