Elm Exactly
Results / elm-parser /

ParserHexIntTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Parser.number` configured for hexadecimal parses `0x` literals with hexadecimal digits in either letter case.

`"0xFF"` gives `Ok 255` and `"0xdeadbeef"` gives `Ok 3735928559`, a value
above the largest 32-bit signed integer.

Among what is not tested: the other number formats being rejected, and
`Parser.int` on hexadecimal input.

Results

elm-0.19.1

passran in 69 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
hex_ff: Ok 255
hex_deadbeef: Ok 3735928559

elm-0.19.2

passran in 50 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
hex_ff: Ok 255
hex_deadbeef: Ok 3735928559

elm-0.19.3

passran in 45 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
hex_ff: Ok 255
hex_deadbeef: Ok 3735928559

lamdera-1.5.0

passran in 37 ms
Output
hex_ff: Ok 255
hex_deadbeef: Ok 3735928559

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module ParserHexIntTest exposing (main)
{-| `Parser.number` configured for hexadecimal parses `0x` literals with hexadecimal digits in either letter case.
`"0xFF"` gives `Ok 255` and `"0xdeadbeef"` gives `Ok 3735928559`, a value
above the largest 32-bit signed integer.
Among what is not tested: the other number formats being rejected, and
`Parser.int` on hexadecimal input.
-}
-- CHECK: hex_ff: Ok 255
-- CHECK: hex_deadbeef: Ok 3735928559
import Html exposing (text)
import Parser
{-| Parses a hexadecimal literal and rejects every other number format.
-}
hexInt : Parser.Parser Int
hexInt =
Parser.number
{ int = Nothing
, hex = Just identity
, octal = Nothing
, binary = Nothing
, float = Nothing
}
main =
let
_ = Debug.log "hex_ff" (Parser.run hexInt "0xFF")
_ = Debug.log "hex_deadbeef" (Parser.run hexInt "0xdeadbeef")
in
text "done"