增加指针 nil 验证
This commit is contained in:
		
							
								
								
									
										5
									
								
								run.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								run.go
									
									
									
									
									
								
							@ -153,6 +153,11 @@ func getDataStatus(val gjson.Result, dataType string) string {
 | 
			
		||||
			if len(val.Map()) == 0 {
 | 
			
		||||
				return consts.DataStatusIsEmpty
 | 
			
		||||
			}
 | 
			
		||||
		} else if strings.HasPrefix(dataType, "*") {
 | 
			
		||||
			// 指针类型
 | 
			
		||||
			if nil == val.Value() {
 | 
			
		||||
				return consts.DataStatusIsNil
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return ""
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										21
									
								
								run_test.go
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								run_test.go
									
									
									
									
									
								
							@ -10,6 +10,8 @@ package validator
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
	"github.com/tidwall/gjson"
 | 
			
		||||
	"testing"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@ -21,3 +23,22 @@ func TestRun(t *testing.T) {
 | 
			
		||||
	byteData, _ := json.Marshal(sourceData)
 | 
			
		||||
	fmt.Println(string(byteData))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Test_getDataStatus(t *testing.T) {
 | 
			
		||||
	type args struct {
 | 
			
		||||
		val      gjson.Result
 | 
			
		||||
		dataType string
 | 
			
		||||
	}
 | 
			
		||||
	tests := []struct {
 | 
			
		||||
		name string
 | 
			
		||||
		args args
 | 
			
		||||
		want string
 | 
			
		||||
	}{
 | 
			
		||||
		// TODO: Add test cases.
 | 
			
		||||
	}
 | 
			
		||||
	for _, tt := range tests {
 | 
			
		||||
		t.Run(tt.name, func(t *testing.T) {
 | 
			
		||||
			assert.Equalf(t, tt.want, getDataStatus(tt.args.val, tt.args.dataType), "getDataStatus(%v, %v)", tt.args.val, tt.args.dataType)
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user