This repository has been archived by the owner on May 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialiser_test.go
61 lines (55 loc) · 1.59 KB
/
initialiser_test.go
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
package opal
import (
"reflect"
"testing"
)
func TestExtractOpalTags(t *testing.T) {
var tagOpalTests = []struct {
Tag reflect.StructTag
Value Tag
}{
{`||`, ``},
{`|something|`, `something`},
{`json:"value"|with normal|`, `with normal`},
}
for _, tt := range tagOpalTests {
if v := ExtractOpalTags(tt.Tag); v != tt.Value {
t.Errorf("ExtractOpalTags(%#q) = %#q, want %#q", tt.Tag, v, tt.Value)
}
}
}
func TestTagGet(t *testing.T) {
// Credit to Go
var tagGetTests = []struct {
Tag Tag
Key string
Value string
}{
{`protobuf:"PB(12)"`, `protobuf`, `"PB(12)"`},
{`protobuf:"PB(12)"`, `foo`, ``},
{`protobuf:"PB(12)"`, `rotobuf`, ``},
{`protobuf:"PB(12)" json:"name"`, `json`, `"name"`},
{`protobuf:"PB(12)" json:"name"`, `protobuf`, `"PB(12)"`},
{`protobuf: "PB(12)" json: "name"`, `json`, `"name"`},
{`protobuf: "PB(12)" json: "name"`, `protobuf`, `"PB(12)"`},
{`protobuf: "PB(12)", json: "name"`, `json`, `"name"`},
{`protobuf: "PB(12)", json: "name"`, `protobuf`, `"PB(12)"`},
{`protobuf: "PB(12)",json: "name"`, `json`, `"name"`},
{`protobuf: "PB(12)",json: "name"`, `protobuf`, `"PB(12)"`},
{`protobuf:"PB(12)",json:"name"`, `json`, `"name"`},
{`protobuf:"PB(12)", json:"name"`, `protobuf`, `"PB(12)"`},
}
for _, tt := range tagGetTests {
if v := tt.Tag.Get(tt.Key); v != tt.Value {
t.Errorf("Tag(%#q).Get(%#q) = %#q, want %#q", tt.Tag, tt.Key, v, tt.Value)
}
}
}
func TestImportName(t *testing.T) {
type T struct{}
r := reflect.TypeOf(T{})
s := importName(r)
if s != "opal.T" {
t.Errorf("importName(%#q) = %#q, want %#q", r, s, "opal.T")
}
}