From d3be2ddb2d0ea2e7557babc7a335d6f6167987fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 1 Nov 2024 18:32:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0atring=20trim/convert=20?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run_test.go | 69 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/run_test.go b/run_test.go index 2419bdb..b78e031 100644 --- a/run_test.go +++ b/run_test.go @@ -106,20 +106,16 @@ func TestRunRequired(t *testing.T) { } ruleListForDisableAutoConvert := []*define.FieldRule{ &define.FieldRule{ - Path: "name", - Type: "string", - DisableRewrite: false, - DefaultValue: nil, - IsRequired: true, - AllowEmpty: false, - AllowZero: false, - AllowNil: false, - DisableAutoTrimSpace: false, - DisableAutoConvert: true, - RequiredConditionGroup: nil, - ValueLimit: nil, - SliceConfig: nil, - MapConfig: nil, + Path: "name", + Type: "string", + DisableRewrite: false, + DefaultValue: nil, + IsRequired: true, + AllowEmpty: false, + AllowZero: false, + AllowNil: false, + DisableAutoTrimSpace: false, + DisableAutoConvert: true, }, } err = Run(sourceData, ruleListForDisableAutoConvert, nil) @@ -127,4 +123,49 @@ func TestRunRequired(t *testing.T) { fmt.Println(err.Error()) } assert.Error(t, err) + + sourceData = map[string]interface{}{ + "name": " ", + } + ruleListForAllowTrim := []*define.FieldRule{ + &define.FieldRule{ + Path: "name", + Type: "string", + DisableRewrite: false, + DefaultValue: nil, + IsRequired: true, + AllowEmpty: false, + AllowZero: false, + AllowNil: false, + DisableAutoTrimSpace: false, + DisableAutoConvert: true, + }, + } + err = Run(sourceData, ruleListForAllowTrim, nil) + if nil != err { + fmt.Println(err.Error()) + } + assert.Error(t, err) + + sourceData = map[string]interface{}{ + "name": " ", + } + ruleListForDisableTrim := []*define.FieldRule{ + &define.FieldRule{ + Path: "name", + Type: "string", + DisableRewrite: false, + DefaultValue: nil, + IsRequired: true, + AllowEmpty: false, + AllowZero: false, + AllowNil: false, + DisableAutoTrimSpace: true, + DisableAutoConvert: true, + }, + } + err = Run(sourceData, ruleListForDisableTrim, nil) + if nil != err { + fmt.Println(err.Error()) + } }