Skip to content

Commit

Permalink
coveralls
Browse files Browse the repository at this point in the history
  • Loading branch information
celt237 committed Jun 30, 2024
1 parent 15def06 commit 362c392
Show file tree
Hide file tree
Showing 8 changed files with 812 additions and 31 deletions.
57 changes: 26 additions & 31 deletions internal/annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,57 @@ func TestAnnotation(t *testing.T) {
tests := []struct {
name string
fileName string
mode AnnotationMode
wantResult *FileDesc
wantErr bool
}{
{
name: "数组模式单接口测试",
fileName: "test/data/arraymode/arraymode_single_interface.go",
mode: AnnotationModeArray,
wantResult: get_arraymode_single_interface("test/data/arraymode/arraymode_single_interface.json"),
wantErr: false,
},
{
name: "数组模式单结构体测试",
fileName: "test/data/arraymode/arraymode_single_struct.go",
mode: AnnotationModeArray,
wantResult: get_arraymode_single_interface("test/data/arraymode/arraymode_single_struct.json"),
wantErr: false,
},
{
name: "数组模式混合测试",
fileName: "test/data/arraymode/arraymode_mult.go",
mode: AnnotationModeArray,
wantResult: get_arraymode_single_interface("test/data/arraymode/arraymode_mult.json"),
wantErr: false,
},
{
name: "map模式单接口测试",
fileName: "test/data/mapmode/mapmode_single_interface.go",
mode: AnnotationModeMap,
wantResult: get_arraymode_single_interface("test/data/mapmode/mapmode_single_interface.json"),
wantErr: false,
},
{
name: "map模式单结构体测试",
fileName: "test/data/mapmode/mapmode_single_struct.go",
mode: AnnotationModeMap,
wantResult: get_arraymode_single_interface("test/data/mapmode/mapmode_single_struct.json"),
wantErr: false,
},
{
name: "map模式混合测试",
fileName: "test/data/mapmode/mapmode_mult.go",
mode: AnnotationModeMap,
wantResult: get_arraymode_single_interface("test/data/mapmode/mapmode_mult.json"),
wantErr: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
CurrentAnnotationMode = tt.mode
fileParser := GetFileParser(tt.fileName)
fileDesc, err := fileParser.Parse()
if (err != nil) != tt.wantErr {
Expand Down Expand Up @@ -114,34 +140,3 @@ func deepCompare(a, b interface{}, fieldName string) bool {
}
return equal
}

//{
//name: "数组模式单结构体测试",
//fileName: "data/arraymode/arraymode_single_struct.go",
//wantResult: 1,
//wantErr: false,
//},
//{
//name: "数组模式混合测试",
//fileName: "data/arraymode/arraymode_mult.go",
//wantResult: 1,
//wantErr: false,
//},
//{
//name: "map模式单接口测试",
//fileName: "data/arraymode/mapmode_single_interface.go",
//wantResult: 1,
//wantErr: false,
//},
//{
//name: "map模式单结构体测试",
//fileName: "data/arraymode/mapmode_single_struct.go",
//wantResult: 1,
//wantErr: false,
//},
//{
//name: "map模式混合测试",
//fileName: "data/arraymode/mapmode_mult.go",
//wantResult: 1,
//wantErr: false,
//},
4 changes: 4 additions & 0 deletions internal/astParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func parseAnnotation(comments []string, mode AnnotationMode) (annotations map[st
}
attributeName := strings.TrimSpace(itemSlice[0])
attributeValue := strings.TrimSpace(itemSlice[1])
// attributeValue去掉引号
if strings.HasPrefix(attributeValue, "\"") && strings.HasSuffix(attributeValue, "\"") {
attributeValue = attributeValue[1 : len(attributeValue)-1]
}
attribute[attributeName] = attributeValue
}
if _, ok := annotations[name]; ok {
Expand Down
51 changes: 51 additions & 0 deletions internal/test/data/mapmode/mapmode_mult.go
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
package mapmode

import "github.com/celt237/go-annotation/internal/test/data"

// InterfaceTwo test
// @annotation(id="1", name="test")
type InterfaceTwo interface {
// Method1 test1
// @annotation
Method1(a1 *data.A1, a2 *data.A2, a3 *data.A3) error

// Method2 test2
// @annotation(name="test")
Method2(a2 data.A2) (a3 *data.A3, err error)

// Method3 test3
// @annotation(name="test")
Method3() (data.A1, error)

// Method4 test4
// @annotation(name="test", des="test2")
Method4(a3 *data.A3)
}

// StructTwo test
// @annotation(id="1", name="test")
type StructTwo struct {
}

// Method1 test1
// @annotation
func (s *StructTwo) Method1(a1 *data.A1, a2 *data.A2, a3 *data.A3) error {
return nil
}

// Method2 test2
// @annotation(name="test")
func (s *StructTwo) Method2(a2 data.A2) (a3 *data.A3, err error) {
return nil, nil
}

// Method3 test3
// @annotation(name="test")
func (s *StructTwo) Method3() (data.A1, error) {
return data.A1{}, nil
}

// Method4 test4
// @annotation(name="test", des="test2")
func (s *StructTwo) Method4(a3 *data.A3) {
return
}
Loading

0 comments on commit 362c392

Please sign in to comment.