Elm Exactly
Results / elm-json /

JsonIssue18IndexNegativeTest

Tags:elm19-bug

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail

Issue: elm/json#18

`Json.Decode.index` checks for an index past the end but not for a negative one.

<https://github.com/elm/json/issues/18>

Elm 0.19.1 (elm/json 1.1.4) decodes `array[-1]`, which is `undefined`: `index -1 (succeed ())`
on `[1]` succeeds with `Ok ()`. An index outside the array must fail, as `index 1` does.

Results

elm-0.19.1

failran in 58 ms
Missing pattern: {{(^|\n)index -1: Err}}
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
index 1: Err (Failure "Expecting a LONGER array. Need index 1 but only see 1 entries" <internals>)
index -1: Ok ()

elm-0.19.2

failran in 57 ms
Missing pattern: {{(^|\n)index -1: Err}}
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
index 1: Err (Failure "Expecting a LONGER array. Need index 1 but only see 1 entries" <internals>)
index -1: Ok ()

elm-0.19.3

failran in 59 ms
Missing pattern: {{(^|\n)index -1: Err}}
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
index 1: Err (Failure "Expecting a LONGER array. Need index 1 but only see 1 entries" <internals>)
index -1: Ok ()

lamdera-1.5.0

failran in 50 ms
Missing pattern: {{(^|\n)index -1: Err}}
--- output ---
index 1: Err (Failure "Expecting a LONGER array. Need index 1 but only see 1 entries" <internals>)
index -1: Ok ()

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module JsonIssue18IndexNegativeTest exposing (main)
{-| `Json.Decode.index` checks for an index past the end but not for a negative one.
<https://github.com/elm/json/issues/18>
Elm 0.19.1 (elm/json 1.1.4) decodes `array[-1]`, which is `undefined`: `index -1 (succeed ())`
on `[1]` succeeds with `Ok ()`. An index outside the array must fail, as `index 1` does.
-}
-- TAGS: elm19-bug
-- CHECK: {{(^|\n)index 1: Err}}
-- CHECK: {{(^|\n)index -1: Err}}
import Html exposing (text)
import Json.Decode as JD
main =
let
_ =
Debug.log "index 1" (JD.decodeString (JD.index 1 (JD.succeed ())) "[1]")
_ =
Debug.log "index -1" (JD.decodeString (JD.index -1 (JD.succeed ())) "[1]")
in
text "done"