File: unmarshaler_test.go

package info (click to toggle)
golang-github-yudai-gojsondiff 1.0.0%2Bgit20180504.0525c87-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 220 kB
  • sloc: makefile: 13
file content (116 lines) | stat: -rw-r--r-- 1,870 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package gojsondiff_test

import (
	. "github.com/yudai/gojsondiff"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/yudai/gojsondiff/tests"

	"encoding/json"
	"fmt"
	"github.com/k0kubun/pp"
)

var _ = Describe("Gojsondiff", func() {
	Describe("Unmarshaller", func() {
		Describe("CompareObjects", func() {
			It("", func() {
				um := NewUnmarshaller()
				diff, err := um.UnmarshalString(`
{
  "summary": [
    "@@ -638,17 +638,17 @@\n via, Bra\n-z\n+s\n il,  %0ACh\n@@ -916,20 +916,13 @@\n re a\n-lso known as\n+.k.a.\n  Car\n",
    0,
    2
  ],
  "surface": [
    17840000,
    0,
    0
  ],
  "demographics": {
    "population": [
      385742554,
      385744896
    ]
  },
  "languages": {
    "2": [
      "inglés"
    ],
    "_t": "a",
    "_2": [
      "english",
      0,
      0
    ]
  },
  "countries": {
    "0": {
      "capital": [
        "Buenos Aires",
        "Rawson"
      ]
    },
    "9": [
      {
        "name": "Antártida",
        "unasur": false
      }
    ],
    "10": {
      "population": [
        42888594
      ]
    },
    "_t": "a",
    "_4": [
      "",
      10,
      3
    ],
    "_8": [
      "",
      2,
      3
    ],
    "_10": [
      {
        "name": "Uruguay",
        "capital": "Montevideo",
        "independence": "1825-08-25T07:00:00.000Z",
        "unasur": true
      },
      0,
      0
    ],
    "_11": [
      {
        "name": "Venezuela",
        "capital": "Caracas",
        "independence": "1811-07-05T07:00:00.000Z",
        "unasur": true
      },
      0,
      0
    ]
  },
  "spanishName": [
    "Sudamérica"
  ]
}
`)
				Expect(err).To(BeNil())
				pp.Print(diff)

				a := LoadFixture("FIXTURES/jsondiffpatch.json")
				differ := New()
				differ.ApplyPatch(a, diff)
				pp.Println(a)
				result, _ := json.Marshal(a)
				fmt.Println(string(result))
			})
		})
	})
})