CharGetCharWidthTest
A width function comparing `Char.toCode` against `0xFFFF` gives 1 for an ASCII character taken from a string with `String.uncons`. `getCharWidth` returns 2 for a character above `0xFFFF` and 1 otherwise. The first character of `"abc"` is `'a'`, so the logged width is 1.
Results
elm-0.19.1
passran in 83 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. width: 1
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: 1
elm-0.19.3
passran in 62 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. width: 1
lamdera-1.5.0
passran in 66 msOutput
width: 1
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/CharGetCharWidthTest] in its title.
Source
The -- CHECK: lines give the expected output.
module CharGetCharWidthTest exposing (main)
{-| A width function comparing `Char.toCode` against `0xFFFF` gives 1 for an
ASCII character taken from a string with `String.uncons`.
`getCharWidth` returns 2 for a character above `0xFFFF` and 1 otherwise. The
first character of `"abc"` is `'a'`, so the logged width is 1.
-}
-- CHECK: width: 1
import Char
import Html exposing (text)
getCharWidth : Char -> Int
getCharWidth c =
if Char.toCode c > 0xFFFF then
2
else
1
main =
let
src =
"abc"
width =
case String.uncons src of
Just ( c, _ ) ->
getCharWidth c
Nothing ->
-1
_ =
Debug.log "width" width
in
text "done"