EncodeCharTest
A list of `Char` encodes to JSON as an array of their integer code points when each element is encoded with `Json.Encode.int` of `Char.toCode`. `Json.Encode` has no encoder for `Char`; here `[ 'a', 'b', 'c' ]` encodes to `[97,98,99]`.
Results
elm-0.19.1
passran in 53 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. char_codes: "[97,98,99]"
elm-0.19.2
passran in 72 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. char_codes: "[97,98,99]"
elm-0.19.3
passran in 54 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. char_codes: "[97,98,99]"
lamdera-1.5.0
passran in 69 msOutput
char_codes: "[97,98,99]"
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-json/EncodeCharTest] in its title.
Source
The -- CHECK: lines give the expected output.
module EncodeCharTest exposing (main)
{-| A list of `Char` encodes to JSON as an array of their integer code points when each element
is encoded with `Json.Encode.int` of `Char.toCode`.
`Json.Encode` has no encoder for `Char`; here `[ 'a', 'b', 'c' ]` encodes to `[97,98,99]`.
-}
-- CHECK: char_codes: "[97,98,99]"
import Char
import Html exposing (text)
import Json.Encode as Encode
main =
let
chars : List Char
chars =
[ 'a', 'b', 'c' ]
encoded =
Encode.list (\c -> Encode.int (Char.toCode c)) chars
_ =
Debug.log "char_codes" (Encode.encode 0 encoded)
in
text "done"