mirror of
https://github.com/beego/bee.git
synced 2024-11-21 23:50:54 +00:00
fix annotate to json with empty comment
This commit is contained in:
parent
8401b2200b
commit
1658822bf3
@ -57,7 +57,13 @@ func (a *Annotator) Annotate(comment string) []map[string]interface{} {
|
|||||||
|
|
||||||
//parse annotation to json
|
//parse annotation to json
|
||||||
func (a *Annotator) AnnotateToJson(comment string) (string, error) {
|
func (a *Annotator) AnnotateToJson(comment string) (string, error) {
|
||||||
|
if comment == "" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
annotate := a.Annotate(comment)
|
annotate := a.Annotate(comment)
|
||||||
|
if len(annotate) == 0 {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
result, err := json.MarshalIndent(annotate, "", " ")
|
result, err := json.MarshalIndent(annotate, "", " ")
|
||||||
return string(result), err
|
return string(result), err
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func TestAnnotate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAnnotateToJson(t *testing.T) {
|
func TestAnnotateToJson(t *testing.T) {
|
||||||
expect := `[
|
expect1 := `[
|
||||||
{
|
{
|
||||||
"Name": [
|
"Name": [
|
||||||
"Field1"
|
"Field1"
|
||||||
@ -69,9 +69,11 @@ func TestAnnotateToJson(t *testing.T) {
|
|||||||
}
|
}
|
||||||
]`
|
]`
|
||||||
|
|
||||||
actual, _ := BeeAnnotator.AnnotateToJson(Annotation1)
|
actual1, _ := BeeAnnotator.AnnotateToJson(Annotation1)
|
||||||
|
actual2, _ := BeeAnnotator.AnnotateToJson("")
|
||||||
|
|
||||||
assert.Equal(t, expect, actual)
|
assert.Equal(t, expect1, actual1)
|
||||||
|
assert.Equal(t, "", actual2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHandleWhitespaceValues(t *testing.T) {
|
func TestHandleWhitespaceValues(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user