CharFromCodeLoneSurrogatePatternTest
A lone low surrogate made by `Char.fromCode`, `Char.fromCode 0xDE00`, does not match the
pattern `'\u{1F600}'`, of which it is the second UTF-16 code unit; the character
`Char.fromCode 0x1F600` does.
`Char.fromCode` is library, outside A Standard Definition of Elm?, and what it gives for a
surrogate code point is not a character the book knows (a surrogate escape is not a character,
ruling A8). Elm/JS represents a Char as a JavaScript string, so the check guards against a
pattern matching part of one: a lone surrogate is a different `Char` from the character it is
half of.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. lowSurrogate: "other" fromCode: "grin"
elm-0.19.2
passran in 56 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. lowSurrogate: "other" fromCode: "grin"
elm-0.19.3
passran in 61 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. lowSurrogate: "other" fromCode: "grin"
lamdera-1.5.0
passran in 84 msOutput
lowSurrogate: "other" fromCode: "grin"
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/CharFromCodeLoneSurrogatePatternTest] in its title.
Source
The -- CHECK: lines give the expected output.
module CharFromCodeLoneSurrogatePatternTest exposing (main)
{-| A lone low surrogate made by `Char.fromCode`, `Char.fromCode 0xDE00`, does not match the
pattern `'\u{1F600}'`, of which it is the second UTF-16 code unit; the character
`Char.fromCode 0x1F600` does.
`Char.fromCode` is library, outside A Standard Definition of Elm?, and what it gives for a
surrogate code point is not a character the book knows (a surrogate escape is not a character,
ruling A8). Elm/JS represents a Char as a JavaScript string, so the check guards against a
pattern matching part of one: a lone surrogate is a different `Char` from the character it is
half of.
-}
-- CHECK: lowSurrogate: "other"
-- CHECK: fromCode: "grin"
import Html exposing (text)
classify : Char -> String
classify c =
case c of
'\u{1F600}' ->
"grin"
_ ->
"other"
main =
let
_ =
Debug.log "lowSurrogate" (classify (Char.fromCode 0xDE00))
_ =
Debug.log "fromCode" (classify (Char.fromCode 0x0001F600))
in
text "done"