-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tag_test.go
36 lines (29 loc) · 887 Bytes
/
tag_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
package googp
import (
"reflect"
"testing"
)
func Test_Tag(t *testing.T) {
var v struct {
A string `googp:"og:title,og:description"`
B string
C string `googp:"-"`
OGP
}
tag := newTag(reflect.TypeOf(v).Field(0))
assertEqual(t, tag.names, []string{"og:title", "og:description"})
assertEqual(t, tag.isContainsName("og:title"), true)
assertEqual(t, tag.isContainsName("og:description"), true)
assertEqual(t, tag.isContainsName("og"), false)
tag = newTag(reflect.TypeOf(v).Field(1))
assertEqual(t, tag.names, []string{"og:b"})
tag = newTag(reflect.TypeOf(v).Field(2))
assertEqual(t, tag.names, []string{})
tag = newTag(reflect.TypeOf(v).Field((3)))
assertEqual(t, tag.names, []string{""})
}
func TestToSnake(t *testing.T) {
assertEqual(t, toSnake("CreatedAt"), "created_at")
assertEqual(t, toSnake("ID"), "id")
assertEqual(t, toSnake("AbCdEf"), "ab_cd_ef")
}