Skip to content

cheapDiff produce a wrong patch when inverting values in list #2

@eniac314

Description

@eniac314

I may have found a bug. I tried replacing diff by cheapDiff for efficiency reasons but found out that the json output after applying the patch was not the same.

Here is an example of diverging results:

import Json.Diff as Diff exposing (..)
import Json.Patch.Invertible as Inv exposing (..)
import Json.Encode as E
import Json.Decode as D                                 
import Json.Patch as JP exposing (..)

doc1 = E.list E.int [1,2,3,4]
doc2 = E.list E.int [2,1,3,4]

patch = Diff.diff doc1 doc2
-- [Remove ["1"],Add ["0"] <internals>] : Patch

cheapPatch = Diff.cheapDiff doc1 doc2 |> Inv.toMinimalPatch
-- [Replace ["1"] <internals>] : Patch

JP.apply patch doc1 |> Result.toMaybe |> Maybe.map (D.decodeValue <| D.list D.int)
-- Just (Ok [2,1,3,4])

JP.apply cheapPatch doc1 |> Result.toMaybe |> Maybe.map (D.decodeValue <| D.list D.int)
-- Just (Ok [1,1,3,4]) : Maybe (Result D.Error (List Int))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions