-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathannotation_test.go
98 lines (95 loc) · 1.9 KB
/
annotation_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
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
package tl
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestParseAnnotation(t *testing.T) {
for _, tt := range []struct {
Case string
Input string
Result []Annotation
}{
{
Input: "//@name The name of the option @value The new value of the option",
Result: []Annotation{
{
Name: "name",
Value: "The name of the option",
},
{
Name: "value",
Value: "The new value of the option",
},
},
},
{
Case: "Slashes",
Input: "//@cwass StatisticsGraph@description /////@description t@description h",
Result: []Annotation{
{
Name: "cwass",
Value: "StatisticsGraph",
},
{
Name: "description",
Value: "/////",
},
{
Name: "description",
Value: "t",
},
{
Name: "description",
Value: "h",
},
},
},
} {
t.Run(tt.Case, func(t *testing.T) {
ann, err := parseAnnotation(tt.Input)
if err != nil {
t.Fatal(err)
}
require.Equal(t, tt.Result, ann, "result should be equal")
})
}
t.Run("String", func(t *testing.T) {
for _, input := range []string{
"//@foo bar",
"//@bar baz.",
} {
ann, err := parseAnnotation(input)
if err != nil {
t.Fatal(err)
}
t.Logf("%#v", ann)
if len(ann) != 1 {
t.Fatal("bad len")
}
if s := ann[0].String(); s != input {
t.Errorf("%q != %q", s, input)
}
}
})
t.Run("Error", func(t *testing.T) {
for _, input := range []string{
"//@{} test",
"//",
"1",
"//@\xef\f\f\f\f/@class StatisticsGraph@description /@r a@n a@a t@n h",
"//@0 0@0 @0 0",
} {
if _, err := parseAnnotation(input); err == nil {
t.Errorf("expected error on %q", input)
}
}
})
t.Run("SingleLine", func(t *testing.T) {
if str := singleLineAnnotations([]Annotation{
{Name: "class", Value: "foo"},
{Name: "desc", Value: "bar"},
}); str != "//@class foo @desc bar" {
t.Error(str)
}
})
}