Elm Exactly
Results / elm-parser /

ParserLoneLowSurrogateTest

Tags:elm-unspecced

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Parser.chompIf` on a string that starts with two low surrogates (U+DC00 U+DC01) hands its
predicate a `Char` whose code is 0xDC00 and consumes two UTF-16 code units.

The string is built with `Char.fromCode`. One predicate checks for the code 0xDC00, one for a
code above 0x10FFFF, which must never be seen, and the third test logs the length of the chomped
text.

A Standard Definition of Elm? does not decide this test: `Char.fromCode` of a surrogate gives a
character of the implementation's choosing (the basis entry Char.fromCode), and `elm/parser` and
`String.length` are library, outside the definition.
<https://elm-test-suite.netlify.app/standard/basis/Char/fromCode>

Results

elm-0.19.1

passran in 86 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
code is DC00: "Ok"
code above 10FFFF: "Err"
chomped length: "Ok 2"

elm-0.19.2

passran in 52 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
code is DC00: "Ok"
code above 10FFFF: "Err"
chomped length: "Ok 2"

elm-0.19.3

passran in 66 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
code is DC00: "Ok"
code above 10FFFF: "Err"
chomped length: "Ok 2"

lamdera-1.5.0

passran in 57 ms
Output
code is DC00: "Ok"
code above 10FFFF: "Err"
chomped length: "Ok 2"

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-parser/ParserLoneLowSurrogateTest] in its title.

Source

The -- CHECK: lines give the expected output.

module ParserLoneLowSurrogateTest exposing (main)
{-| `Parser.chompIf` on a string that starts with two low surrogates (U+DC00 U+DC01) hands its
predicate a `Char` whose code is 0xDC00 and consumes two UTF-16 code units.
The string is built with `Char.fromCode`. One predicate checks for the code 0xDC00, one for a
code above 0x10FFFF, which must never be seen, and the third test logs the length of the chomped
text.
A Standard Definition of Elm? does not decide this test: `Char.fromCode` of a surrogate gives a
character of the implementation's choosing (the basis entry Char.fromCode), and `elm/parser` and
`String.length` are library, outside the definition.
<https://elm-test-suite.netlify.app/standard/basis/Char/fromCode>
-}
-- TAGS: elm-unspecced
-- MODE-GUARD: a Char equality must give the same answer as under --optimize
-- NO-SKIP: an edge case every compiler must run
-- CHECK: code is DC00: "Ok"
-- CHECK: code above 10FFFF: "Err"
-- CHECK: chomped length: "Ok 2"
import ConformanceHelp exposing (logAll, worker)
import Parser exposing (Parser)
src : String
src =
String.fromList [ Char.fromCode 0xDC00, Char.fromCode 0xDC01 ]
okErr : Result x a -> String
okErr r =
case r of
Ok _ ->
"Ok"
Err _ ->
"Err"
lenResult : Result x Int -> String
lenResult r =
case r of
Ok n ->
"Ok " ++ String.fromInt n
Err _ ->
"Err"
chompedLength : Parser Int
chompedLength =
Parser.getChompedString (Parser.chompIf (\_ -> True))
|> Parser.map String.length
report : ()
report =
logAll
[ ( "code is DC00", okErr (Parser.run (Parser.chompIf (\c -> Char.toCode c == 0xDC00)) src) )
, ( "code above 10FFFF", okErr (Parser.run (Parser.chompIf (\c -> Char.toCode c > 0x0010FFFF)) src) )
, ( "chomped length", lenResult (Parser.run chompedLength src) )
]
main : Program () () ()
main =
worker report