99 . "github.com/onsi/ginkgo/v2"
1010 . "github.com/onsi/gomega"
1111
12+ jsonpatch2 "github.com/evanphx/json-patch/v5"
1213 "github.com/go-faker/faker/v4"
13- jsonpatch2 "github.com/evanphx/json-patch"
1414
1515 "github.com/snorwin/jsonpatch"
1616)
@@ -34,6 +34,8 @@ type B struct {
3434 Uint32 uint32 `json:"uint32"`
3535 Uint64 uint64 `json:"uint64"`
3636 UintPtr uintptr `json:"ptr" faker:"-"`
37+ Float32 float32 `json:"float32"`
38+ Float64 float64 `json:"float64"`
3739 Time time.Time `json:"time"`
3840}
3941
@@ -47,12 +49,13 @@ type C struct {
4749}
4850
4951type D struct {
50- PtrSlice []* B `json:"ptr"`
51- StructSlice []C `json:"structs"`
52- StringSlice []string `json:"strs"`
53- IntSlice []int `json:"ints"`
54- StructSliceWithKey []C `json:"structsWithKey"`
55- PtrSliceWithKey []* B `json:"ptrWithKey"`
52+ PtrSlice []* B `json:"ptr"`
53+ StructSlice []C `json:"structs"`
54+ StringSlice []string `json:"strs"`
55+ IntSlice []int `json:"ints"`
56+ FloatSlice []float64 `json:"floats"`
57+ StructSliceWithKey []C `json:"structsWithKey"`
58+ PtrSliceWithKey []* B `json:"ptrWithKey"`
5659}
5760
5861type E struct {
@@ -158,6 +161,19 @@ var _ = Describe("JSONPatch", func() {
158161 // no change
159162 testPatch (B {Uint : 1 , Uint8 : 1 , Uint16 : 1 , Uint32 : 1 , Uint64 : 1 }, B {Uint : 1 , Uint8 : 1 , Uint16 : 1 , Uint32 : 1 , Uint64 : 1 })
160163 })
164+ It ("float" , func () {
165+ // add
166+ testPatch (B {Float32 : 1.1 , Float64 : 2.2 }, B {})
167+ // remove
168+ testPatch (B {}, B {Float32 : 1.1 , Float64 : 2.2 })
169+ // replace
170+ testPatch (B {Float32 : 1.1 , Float64 : 2.2 }, B {Float32 : 1.12 , Float64 : 2.22 })
171+ // mixed
172+ testPatch (B {Float32 : 1.1 }, B {Float64 : 2.2 })
173+ testPatch (B {Float32 : 1.0 , Float64 : 2.0 }, B {Float64 : 2.2 })
174+ // no change
175+ testPatch (B {Float32 : 1.1 , Float64 : 2.2 }, B {Float32 : 1.1 , Float64 : 2.2 })
176+ })
161177 It ("time" , func () {
162178 now := time .Now ()
163179 // add
@@ -227,6 +243,17 @@ var _ = Describe("JSONPatch", func() {
227243 testPatchWithExpected ([]int {3 , 1 }, []int {1 , 2 , 3 }, []int {1 , 3 }, jsonpatch .IgnoreSliceOrder ())
228244 testPatchWithExpected ([]int {3 , 2 }, []int {1 , 2 , 3 }, []int {2 , 3 }, jsonpatch .IgnoreSliceOrder ())
229245 })
246+ It ("float slice ignore order" , func () {
247+ // add
248+ testPatchWithExpected ([]float32 {1.1 , 2.1 , 3.1 }, []float32 {1.1 , 3.1 }, []float32 {1.1 , 3.1 , 2.1 }, jsonpatch .IgnoreSliceOrder ())
249+ testPatchWithExpected ([]float64 {1.1 , 2.1 , 3.1 }, []float64 {1.1 , 2.1 }, []float64 {1.1 , 2.1 , 3.1 }, jsonpatch .IgnoreSliceOrder ())
250+ // no change
251+ testPatchWithExpected ([]float32 {3.1 , 2.1 , 1.1 }, []float32 {1.1 , 2.1 , 3.1 }, []float32 {1.1 , 2.1 , 3.1 }, jsonpatch .IgnoreSliceOrder ())
252+ testPatchWithExpected ([]float64 {1.1 , 2.1 , 3.1 }, []float64 {3.1 , 2.1 , 1.1 }, []float64 {3.1 , 2.1 , 1.1 }, jsonpatch .IgnoreSliceOrder ())
253+ // remove
254+ testPatchWithExpected ([]float32 {3.1 , 1.1 }, []float32 {1.1 , 2.1 , 3.1 }, []float32 {1.1 , 3.1 }, jsonpatch .IgnoreSliceOrder ())
255+ testPatchWithExpected ([]float64 {3.1 , 2.1 }, []float64 {1.1 , 2.1 , 3.1 }, []float64 {2.1 , 3.1 }, jsonpatch .IgnoreSliceOrder ())
256+ })
230257 It ("uint slice ignore order" , func () {
231258 // add
232259 testPatchWithExpected ([]uint {1 , 2 , 3 }, []uint {1 , 3 }, []uint {1 , 3 , 2 }, jsonpatch .IgnoreSliceOrder ())
@@ -315,19 +342,17 @@ var _ = Describe("JSONPatch", func() {
315342 })
316343 })
317344 Context ("CreateJsonPatch_with_predicates" , func () {
318- var (
319- predicate jsonpatch.Predicate
320- )
345+ var predicate jsonpatch.Predicate
321346 BeforeEach (func () {
322347 predicate = jsonpatch.Funcs {
323- AddFunc : func (path jsonpatch.JSONPointer , modified interface {}) bool {
348+ AddFunc : func (_ jsonpatch.JSONPointer , modified interface {}) bool {
324349 if b , ok := modified .(B ); ok {
325350 return b .Bool || b .Int > 2
326351 }
327352
328353 return true
329354 },
330- ReplaceFunc : func (path jsonpatch.JSONPointer , modified , current interface {}) bool {
355+ ReplaceFunc : func (_ jsonpatch.JSONPointer , modified , current interface {}) bool {
331356 if modifiedC , ok := modified .(C ); ok {
332357 if currentC , ok := current .(C ); ok {
333358 return len (modifiedC .StrMap ) > len (currentC .StrMap )
@@ -336,7 +361,7 @@ var _ = Describe("JSONPatch", func() {
336361
337362 return true
338363 },
339- RemoveFunc : func (path jsonpatch.JSONPointer , current interface {}) bool {
364+ RemoveFunc : func (_ jsonpatch.JSONPointer , current interface {}) bool {
340365 if b , ok := current .(B ); ok {
341366 return b .Str != "don't remove me"
342367 }
0 commit comments