1
0
mirror of https://github.com/beego/bee.git synced 2024-11-14 22:10:55 +00:00
bee/parser/annotator_test.go

82 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{}{
2021-06-25 15:15:46 +00:00
"Name": "Field1",
"Type": "string",
"Path": []interface{}{"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{}{
2021-06-25 15:15:46 +00:00
"Number": 2,
"Projects": []interface{}{"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 ",
2021-06-25 15:15:46 +00:00
" 1 ",
" false ",
2021-05-23 12:16:20 +00:00
}
2021-06-25 15:15:46 +00:00
expect := []interface{}{
2021-05-23 12:16:20 +00:00
"beego",
"",
"bee",
"bee beego",
2021-06-25 15:15:46 +00:00
1,
false,
2021-05-23 12:16:20 +00:00
}
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)
}
}