bee/parser/annotator_test.go

78 lines
1.4 KiB
Go
Raw Normal View History

2021-05-23 12:16:20 +00:00
package beeParser
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
var BeeAnnotator Annotator
2021-05-23 12:16:20 +00:00
const (
Annotation1 = `
@Name Field1
@Type string
@Path https://github.com/beego/bee
https://github.com/beego
`
Annotation2 = `
@Number 2
@Projects https://github.com/beego/bee
https://github.com/beego
`
)
func TestMain(m *testing.M) {
BeeAnnotator = &Annotation{}
2021-05-23 12:16:20 +00:00
retCode := m.Run() //run test
os.Exit(retCode)
}
func TestAnnotate(t *testing.T) {
2021-05-25 02:53:12 +00:00
expect1 := map[string]interface{}{
"Name": []string{"Field1"},
"Type": []string{"string"},
"Path": []string{"https://github.com/beego/bee", "https://github.com/beego"},
2021-05-23 12:16:20 +00:00
}
2021-05-25 02:53:12 +00:00
expect2 := map[string]interface{}{
"Number": []string{"2"},
"Projects": []string{"https://github.com/beego/bee", "", "https://github.com/beego"},
2021-05-23 12:16:20 +00:00
}
actual := BeeAnnotator.Annotate(Annotation1)
actual2 := BeeAnnotator.Annotate(Annotation2)
assert.Equal(t, expect1, actual)
assert.Equal(t, expect2, actual2)
}
func TestHandleWhitespaceValues(t *testing.T) {
src := []string{
" beego",
"",
" bee ",
" bee beego ",
}
expect := []string{
"beego",
"",
"bee",
"bee beego",
}
actual := handleWhitespaceValues(src)
assert.Equal(t, expect, actual)
}
//benchmark test
func BenchmarkAnnotate(b *testing.B) {
for i := 0; i < b.N; i++ {
BeeAnnotator.Annotate(Annotation1)
}
}