EncodeDecodeStringUnicodeContentTest
A string with two- and three-byte UTF-8 characters survives a round trip through `Bytes.Encode.string` and `Bytes.Decode.string`. The string `"café €λ"` is encoded, then decoded with `Bytes.Decode.string` given the encoded byte width. The test logs whether the decoded string equals the original, so the expected output is `True`; comparing in Elm avoids depending on how `Debug.log` escapes non-ASCII characters.
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. unicode_ok: True
elm-0.19.2
passran in 62 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. unicode_ok: True
elm-0.19.3
passran in 69 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. unicode_ok: True
lamdera-1.5.0
passran in 46 msOutput
unicode_ok: True
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-bytes/EncodeDecodeStringUnicodeContentTest] in its title.
Source
The -- CHECK: lines give the expected output.
module EncodeDecodeStringUnicodeContentTest exposing (main)
{-| A string with two- and three-byte UTF-8 characters survives a round trip through
`Bytes.Encode.string` and `Bytes.Decode.string`.
The string `"café €λ"` is encoded, then decoded with `Bytes.Decode.string` given the
encoded byte width. The test logs whether the decoded string equals the original, so the
expected output is `True`; comparing in Elm avoids depending on how `Debug.log` escapes
non-ASCII characters.
-}
-- CHECK: unicode_ok: True
import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
original =
"café €λ"
bytes =
E.encode (E.string original)
decoded =
D.decode (D.string (Bytes.width bytes)) bytes
|> Maybe.withDefault "FAIL"
_ =
Debug.log "unicode_ok" (decoded == original)
in
text "done"