EncodeDecodeStringAstralTest
A string containing a character outside the Basic Multilingual Plane survives a round trip through Bytes.Encode.string and Bytes.Decode.string. The string is `"a😀b"`. U+1F600 takes 4 bytes in UTF-8, so the logged width is 1 + 4 + 1 = 6. The decoded string is compared with the original, and the comparison is logged as `True` when they are equal.
Results
elm-0.19.1
passran in 73 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. width: 6 roundtrip_ok: True
elm-0.19.2
passran in 58 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. width: 6 roundtrip_ok: True
elm-0.19.3
passran in 43 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. width: 6 roundtrip_ok: True
lamdera-1.5.0
passran in 58 msOutput
width: 6 roundtrip_ok: True
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-bytes/EncodeDecodeStringAstralTest] in its title.
Source
The -- CHECK: lines give the expected output.
module EncodeDecodeStringAstralTest exposing (main)
{-| A string containing a character outside the Basic Multilingual Plane survives
a round trip through Bytes.Encode.string and Bytes.Decode.string.
The string is `"a😀b"`. U+1F600 takes 4 bytes in UTF-8, so the logged width is
1 + 4 + 1 = 6. The decoded string is compared with the original, and the
comparison is logged as `True` when they are equal.
-}
-- CHECK: width: 6
-- CHECK: roundtrip_ok: True
import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
original =
"a😀b"
bytes =
E.encode (E.string original)
decoded =
D.decode (D.string (Bytes.width bytes)) bytes
|> Maybe.withDefault "FAIL"
_ =
Debug.log "width" (Bytes.width bytes)
_ =
Debug.log "roundtrip_ok" (decoded == original)
in
text "done"