-
Notifications
You must be signed in to change notification settings - Fork 60
/
annotation_test.go
44 lines (39 loc) · 992 Bytes
/
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
package main
import (
"testing"
"github.com/dave/dst"
"github.com/stretchr/testify/assert"
)
func TestAnnotationStrings(t *testing.T) {
assert.Equal(t, "// __golines:shorten:5", CreateAnnotation(5))
assert.Equal(t, 5, ParseAnnotation("// __golines:shorten:5"))
assert.Equal(t, -1, ParseAnnotation("// __golines:shorten:not_a_number"))
assert.Equal(t, -1, ParseAnnotation("// not an annotation"))
assert.True(t, IsAnnotation("// __golines:shorten:5"))
assert.False(t, IsAnnotation("// not an annotation"))
}
func TestHasAnnotation(t *testing.T) {
node1 := &dst.Ident{
Name: "x",
Decs: dst.IdentDecorations{
NodeDecs: dst.NodeDecs{
Start: []string{
"// not an annotation",
CreateAnnotation(55),
},
},
},
}
assert.True(t, HasAnnotation(node1))
node2 := &dst.Ident{
Name: "x",
Decs: dst.IdentDecorations{
NodeDecs: dst.NodeDecs{
Start: []string{
"// not an annotation",
},
},
},
}
assert.False(t, HasAnnotation(node2))
}