File: mutations_test.go

package info (click to toggle)
golang-objx 0.0~git20150928.0.1a9d0bb-1~bpo8+1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 324 kB
  • sloc: makefile: 5
file content (77 lines) | stat: -rw-r--r-- 1,652 bytes parent folder | download | duplicates (3)
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
package objx

import (
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestExclude(t *testing.T) {

	d := make(Map)
	d["name"] = "Mat"
	d["age"] = 29
	d["secret"] = "ABC"

	excluded := d.Exclude([]string{"secret"})

	assert.Equal(t, d["name"], excluded["name"])
	assert.Equal(t, d["age"], excluded["age"])
	assert.False(t, excluded.Has("secret"), "secret should be excluded")

}

func TestCopy(t *testing.T) {

	d1 := make(map[string]interface{})
	d1["name"] = "Tyler"
	d1["location"] = "UT"

	d1Obj := New(d1)
	d2Obj := d1Obj.Copy()

	d2Obj["name"] = "Mat"

	assert.Equal(t, d1Obj.Get("name").Str(), "Tyler")
	assert.Equal(t, d2Obj.Get("name").Str(), "Mat")

}

func TestMerge(t *testing.T) {

	d := make(map[string]interface{})
	d["name"] = "Mat"

	d1 := make(map[string]interface{})
	d1["name"] = "Tyler"
	d1["location"] = "UT"

	dObj := New(d)
	d1Obj := New(d1)

	merged := dObj.Merge(d1Obj)

	assert.Equal(t, merged.Get("name").Str(), d1Obj.Get("name").Str())
	assert.Equal(t, merged.Get("location").Str(), d1Obj.Get("location").Str())
	assert.Empty(t, dObj.Get("location").Str())

}

func TestMergeHere(t *testing.T) {

	d := make(map[string]interface{})
	d["name"] = "Mat"

	d1 := make(map[string]interface{})
	d1["name"] = "Tyler"
	d1["location"] = "UT"

	dObj := New(d)
	d1Obj := New(d1)

	merged := dObj.MergeHere(d1Obj)

	assert.Equal(t, dObj, merged, "With MergeHere, it should return the first modified map")
	assert.Equal(t, merged.Get("name").Str(), d1Obj.Get("name").Str())
	assert.Equal(t, merged.Get("location").Str(), d1Obj.Get("location").Str())
	assert.Equal(t, merged.Get("location").Str(), dObj.Get("location").Str())
}