File: reflect_test.go

package info (click to toggle)
golang-github-blevesearch-bleve 0.5.0%2Bgit20170912.278.6eea5b78-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,764 kB
  • sloc: yacc: 311; sh: 51; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 742 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
package mapping

import (
	"reflect"
	"testing"
)

func TestLookupPropertyPath(t *testing.T) {
	tests := []struct {
		input  interface{}
		path   string
		output interface{}
	}{
		{
			input: map[string]interface{}{
				"Type": "a",
			},
			path:   "Type",
			output: "a",
		},
		{
			input: struct {
				Type string
			}{
				Type: "b",
			},
			path:   "Type",
			output: "b",
		},
		{
			input: &struct {
				Type string
			}{
				Type: "b",
			},
			path:   "Type",
			output: "b",
		},
	}

	for _, test := range tests {
		actual := lookupPropertyPath(test.input, test.path)
		if !reflect.DeepEqual(actual, test.output) {
			t.Fatalf("expected '%v', got '%v', for path '%s' in  %+v", test.output, actual, test.path, test.input)
		}
	}
}