StringAstralUnconsTest
`String.uncons` splits a whole character outside the Basic Multilingual Plane, such as an emoji, off the front of a string, and `String.cons` puts it back. For `"๐b"` the head has code 128512 (`0x1F600`) and the rest is `"b"`, of length 1. `String.cons` of the head and the rest gives `"๐b"` again, and `String.cons '๐' "b"` has `String.length` 3, since `String.length` counts UTF-16 units and the emoji takes two.
Results
elm-0.19.1
passran in 67 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. uncons_code: 128512 uncons_rest_len: 1 uncons_rest_ok: True cons_roundtrip: True cons_len: 3
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. uncons_code: 128512 uncons_rest_len: 1 uncons_rest_ok: True cons_roundtrip: True cons_len: 3
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. uncons_code: 128512 uncons_rest_len: 1 uncons_rest_ok: True cons_roundtrip: True cons_len: 3
lamdera-1.5.0
passran in 41 msOutput
uncons_code: 128512 uncons_rest_len: 1 uncons_rest_ok: True cons_roundtrip: True cons_len: 3
Discussions
Discuss this testยทSearch the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/StringAstralUnconsTest] in its title.
Source
The -- CHECK: lines give the expected output.
module StringAstralUnconsTest exposing (main)
{-| `String.uncons` splits a whole character outside the Basic Multilingual
Plane, such as an emoji, off the front of a string, and `String.cons` puts it
back.
For `"๐b"` the head has code 128512 (`0x1F600`) and the rest is `"b"`, of
length 1. `String.cons` of the head and the rest gives `"๐b"` again, and
`String.cons '๐' "b"` has `String.length` 3, since `String.length` counts
UTF-16 units and the emoji takes two.
-}
-- CHECK: uncons_code: 128512
-- CHECK: uncons_rest_len: 1
-- CHECK: uncons_rest_ok: True
-- CHECK: cons_roundtrip: True
-- CHECK: cons_len: 3
import Html exposing (text)
main =
let
result =
String.uncons "๐b"
code =
case result of
Just ( c, _ ) ->
Char.toCode c
Nothing ->
-1
restLen =
case result of
Just ( _, r ) ->
String.length r
Nothing ->
-1
roundTrip =
case result of
Just ( c, r ) ->
String.cons c r == "๐b"
Nothing ->
False
_ =
Debug.log "uncons_code" code
_ =
Debug.log "uncons_rest_len" restLen
_ =
Debug.log "uncons_rest_ok" (Maybe.map Tuple.second result == Just "b")
_ =
Debug.log "cons_roundtrip" roundTrip
_ =
Debug.log "cons_len" (String.length (String.cons '๐' "b"))
in
text "done"