josephburnett / jd

JSON diff and patch
MIT License
1.62k stars 48 forks source link

Null becomes empty object #21

Closed kevburnsjr closed 4 years ago

kevburnsjr commented 4 years ago

See https://github.com/josephburnett/jd/issues/20

Fixes bug in test helper to expose 5 failing tests

$ go test
--- FAIL: TestArrayDiff (0.00s)
    common_test.go:120: [1 2 3].Diff([1 {} 3]) =
        @ [1]
        - 2
        + {}
        . Want @ [1]
        - 2
        + null
        .
--- FAIL: TestNullDiff (0.00s)
    common_test.go:120: {}.Diff({}) =
        @ []
        - {}
        . Want @ []
        - null
        .
    common_test.go:120: {}.Diff({}) =
        @ []
        + {}
        . Want @ []
        + null
        .
--- FAIL: TestObjectDiff (0.00s)
    common_test.go:120: {map[a:1] map[]}.Diff({map[a:{}] map[]}) =
        @ ["a"]
        - 1
        + {}
        . Want @ ["a"]
        - 1
        + null
        .
--- FAIL: TestStringDiff (0.00s)
    common_test.go:120: {}.Diff(abc) =
        @ []
        - {}
        + "abc"
        . Want @ []
        - null
        + "abc"
        .
FAIL
exit status 1
FAIL    github.com/josephburnett/jd/lib 0.026s

Changes jsonNull into a type that marshals cleanly to null

-type jsonNull struct{}
+type jsonNull []byte
josephburnett commented 4 years ago

Thanks for the pull request!