github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/validate/test/isUnBlank_test.go (about) 1 package main 2 3 import ( 4 "testing" 5 6 "github.com/isyscore/isc-gobase/validate" 7 ) 8 9 type IsUnBlankEntity1 struct { 10 Name string `match:"isUnBlank"` 11 Age int 12 } 13 14 type IsUnBlankEntity2 struct { 15 Name string `match:"isUnBlank=true"` 16 Age int 17 } 18 19 type IsUnBlankEntity3 struct { 20 Name string `match:"isUnBlank=false"` 21 Age int 22 } 23 24 type IsUnBlankInnerEntity struct { 25 InnerName string `match:"isUnBlank"` 26 InnerAge int 27 } 28 29 type IsUnBlankEntity4 struct { 30 IsUnBlankInnerEntity `match:"check"` 31 Name string `match:"isUnBlank"` 32 } 33 34 type IsUnBlankEntity5 struct { 35 *IsUnBlankInnerEntity `match:"check"` 36 Name string `match:"isUnBlank"` 37 } 38 39 // 测试基本类型:简化版 40 func TestIsUnBlank1(t *testing.T) { 41 var value IsUnBlankEntity1 42 var result bool 43 var err string 44 45 //测试 正常情况 46 value = IsUnBlankEntity1{Name: "zhou"} 47 result, err = validate.Check(value, "name") 48 TrueErr(t, result, err) 49 50 // 测试 正常情况 51 value = IsUnBlankEntity1{Name: ""} 52 result, err = validate.Check(value, "name") 53 Equal(t, err, "属性 Name 的值为非空字符", result, false) 54 } 55 56 func TestIsUnBlank2(t *testing.T) { 57 var value IsUnBlankEntity1 58 var result bool 59 var err string 60 61 //测试 正常情况 62 value = IsUnBlankEntity1{Name: "zhou"} 63 result, err = validate.Check(value, "name") 64 TrueErr(t, result, err) 65 66 // 测试 正常情况 67 value = IsUnBlankEntity1{Name: ""} 68 result, err = validate.Check(value, "name") 69 Equal(t, err, "属性 Name 的值为非空字符", result, false) 70 } 71 72 // 测试基本类型 73 func TestIsUnBlank3(t *testing.T) { 74 var value IsUnBlankEntity3 75 var result bool 76 var err string 77 78 //测试 正常情况 79 value = IsUnBlankEntity3{Name: ""} 80 result, err = validate.Check(value, "name") 81 TrueErr(t, result, err) 82 83 // 测试 正常情况 84 value = IsUnBlankEntity3{Name: "zhou"} 85 result, err = validate.Check(value, "name") 86 Equal(t, err, "属性 Name 的值为空字符", result, false) 87 } 88 89 // 测试基本类型 90 func TestIsUnBlank4(t *testing.T) { 91 var value IsUnBlankEntity4 92 var result bool 93 var err string 94 95 // 测试 正常情况 96 value = IsUnBlankEntity4{IsUnBlankInnerEntity: IsUnBlankInnerEntity{InnerName: "", InnerAge: 12}, Name: "zhou"} 97 result, err = validate.Check(value) 98 Equal(t, err, "属性 InnerName 的值为非空字符", result, false) 99 } 100 101 func TestIsUnBlank5(t *testing.T) { 102 var value IsUnBlankEntity5 103 var result bool 104 var err string 105 106 // 测试 正常情况 107 value = IsUnBlankEntity5{Name: "zhou"} 108 result, err = validate.Check(value) 109 TrueErr(t, result, err) 110 111 value = IsUnBlankEntity5{Name: ""} 112 result, err = validate.Check(value, "name") 113 Equal(t, err, "属性 Name 的值为非空字符", result, false) 114 }