Skip to content

Commit

Permalink
improve example cases for package gi18n (#2970)
Browse files Browse the repository at this point in the history
  • Loading branch information
hailaz committed Sep 19, 2023
1 parent 395df94 commit 42de1c1
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 117 deletions.
14 changes: 7 additions & 7 deletions util/gvalid/gvalid_z_example_feature_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ func ExampleRule_Password2() {
}

// Output:
// The Password2 value `gofra` is not a valid password format
// The Password3 value `Goframe` is not a valid password format
// The Password4 value `goframe123` is not a valid password format
// The Password2 value `gofra` is not a valid password2 format
// The Password3 value `Goframe` is not a valid password2 format
// The Password4 value `goframe123` is not a valid password2 format
}

func ExampleRule_Password3() {
Expand All @@ -533,8 +533,8 @@ func ExampleRule_Password3() {
}

// Output:
// The Password2 value `gofra` is not a valid password format
// The Password3 value `Goframe123` is not a valid password format
// The Password2 value `gofra` is not a valid password3 format
// The Password3 value `Goframe123` is not a valid password3 format
}

func ExampleRule_Postcode() {
Expand Down Expand Up @@ -1040,7 +1040,7 @@ func ExampleRule_Same() {
}

// Output:
// The Password value `goframe.org` must be the same as field Password2
// The Password value `goframe.org` must be the same as field Password2 value `goframe.net`
}

func ExampleRule_Different() {
Expand All @@ -1062,7 +1062,7 @@ func ExampleRule_Different() {
}

// Output:
// The OtherMailAddr value `gf@goframe.org` must be different from field MailAddr
// The OtherMailAddr value `gf@goframe.org` must be different from field MailAddr value `gf@goframe.org`
}

func ExampleRule_In() {
Expand Down
10 changes: 5 additions & 5 deletions util/gvalid/gvalid_z_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/i18n/gi18n"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/gvalid"
)

func ExampleNew() {
validator := gvalid.New()
if err := validator.Data(16).Rules("min:18").Run(context.Background()); err != nil {
if err := g.Validator().Data(16).Rules("min:18").Run(context.Background()); err != nil {
fmt.Println(err)
}

Expand Down Expand Up @@ -91,7 +91,7 @@ func ExampleValidator_Clone() {

func ExampleValidator_I18n() {
var (
i18nManager = gi18n.New()
i18nManager = gi18n.New(gi18n.Options{Path: gtest.DataPath("i18n")})
ctxCn = gi18n.WithLanguage(context.Background(), "cn")
validator = gvalid.New()
)
Expand Down Expand Up @@ -138,7 +138,7 @@ func ExampleValidator_Bail() {

// output:
// Use Bail Error: The Account value `gf` length must be between 6 and 16
// Not Use Bail Error: The Account value `gf` length must be between 6 and 16; The Account value `gf` must be the same as field QQ
// Not Use Bail Error: The Account value `gf` length must be between 6 and 16; The Account value `gf` must be the same as field QQ value `123456`
}

func ExampleValidator_Ci() {
Expand All @@ -165,7 +165,7 @@ func ExampleValidator_Ci() {
}

// output:
// Not Use CI Error: The Password value `Goframe.org` must be the same as field Password2
// Not Use CI Error: The Password value `Goframe.org` must be the same as field Password2 value `goframe.org`
// Use CI Passed!
}

Expand Down
18 changes: 9 additions & 9 deletions util/gvalid/gvalid_z_unit_feature_recursive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func Test_CheckStruct_Recursive_Struct(t *testing.T) {
err := g.Validator().Data(user).Run(ctx)
t.AssertNE(err, nil)
t.Assert(err.Maps()["Name"], g.Map{"required": "The Name field is required"})
t.Assert(err.Maps()["Pass1"], g.Map{"same": "The Pass1 value `1` must be the same as field Pass2"})
t.Assert(err.Maps()["Pass2"], g.Map{"same": "The Pass2 value `2` must be the same as field Pass1"})
t.Assert(err.Maps()["Pass1"], g.Map{"same": "The Pass1 value `1` must be the same as field Pass2 value `2`"})
t.Assert(err.Maps()["Pass2"], g.Map{"same": "The Pass2 value `2` must be the same as field Pass1 value `1`"})
})
}

Expand All @@ -61,8 +61,8 @@ func Test_CheckStruct_Recursive_Struct_WithData(t *testing.T) {
err := g.Validator().Data(user).Assoc(data).Run(ctx)
t.AssertNE(err, nil)
t.Assert(err.Maps()["Name"], nil)
t.Assert(err.Maps()["Pass1"], g.Map{"same": "The Pass1 value `100` must be the same as field Pass2"})
t.Assert(err.Maps()["Pass2"], g.Map{"same": "The Pass2 value `200` must be the same as field Pass1"})
t.Assert(err.Maps()["Pass1"], g.Map{"same": "The Pass1 value `100` must be the same as field Pass2 value `200`"})
t.Assert(err.Maps()["Pass2"], g.Map{"same": "The Pass2 value `200` must be the same as field Pass1 value `100`"})
})
}

Expand Down Expand Up @@ -94,8 +94,8 @@ func Test_CheckStruct_Recursive_SliceStruct(t *testing.T) {
g.Dump(err.Items())
t.AssertNE(err, nil)
t.Assert(err.Maps()["Name"], g.Map{"required": "The Name field is required"})
t.Assert(err.Maps()["Pass1"], g.Map{"same": "The Pass1 value `3` must be the same as field Pass2"})
t.Assert(err.Maps()["Pass2"], g.Map{"same": "The Pass2 value `4` must be the same as field Pass1"})
t.Assert(err.Maps()["Pass1"], g.Map{"same": "The Pass1 value `3` must be the same as field Pass2 value `4`"})
t.Assert(err.Maps()["Pass2"], g.Map{"same": "The Pass2 value `4` must be the same as field Pass1 value `3`"})
})
}

Expand Down Expand Up @@ -127,7 +127,7 @@ func Test_CheckStruct_Recursive_SliceStruct_Bail(t *testing.T) {
g.Dump(err.Items())
t.AssertNE(err, nil)
t.Assert(err.Maps()["Name"], nil)
t.Assert(err.Maps()["Pass1"], g.Map{"same": "The Pass1 value `1` must be the same as field Pass2"})
t.Assert(err.Maps()["Pass1"], g.Map{"same": "The Pass1 value `1` must be the same as field Pass2 value `2`"})
t.Assert(err.Maps()["Pass2"], nil)
})
}
Expand Down Expand Up @@ -209,8 +209,8 @@ func Test_CheckMap_Recursive_SliceStruct(t *testing.T) {
g.Dump(err.Items())
t.AssertNE(err, nil)
t.Assert(err.Maps()["Name"], nil)
t.Assert(err.Maps()["Pass1"], g.Map{"same": "The Pass1 value `3` must be the same as field Pass2"})
t.Assert(err.Maps()["Pass2"], g.Map{"same": "The Pass2 value `4` must be the same as field Pass1"})
t.Assert(err.Maps()["Pass1"], g.Map{"same": "The Pass1 value `3` must be the same as field Pass2 value `4`"})
t.Assert(err.Maps()["Pass2"], g.Map{"same": "The Pass2 value `4` must be the same as field Pass1 value `3`"})
})
}

Expand Down
48 changes: 0 additions & 48 deletions util/gvalid/i18n/cn/validation.toml

This file was deleted.

45 changes: 0 additions & 45 deletions util/gvalid/i18n/en/validation.toml

This file was deleted.

2 changes: 1 addition & 1 deletion util/gvalid/internal/builtin/builtin_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (r RulePassword) Name() string {
}

func (r RulePassword) Message() string {
return "The {field} value `{value}` is not a valid passport format"
return "The {field} value `{value}` is not a valid password format"
}

func (r RulePassword) Run(in RunInput) error {
Expand Down
2 changes: 1 addition & 1 deletion util/gvalid/internal/builtin/builtin_password2.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (r RulePassword2) Name() string {
}

func (r RulePassword2) Message() string {
return "The {field} value `{value}` is not a valid passport format"
return "The {field} value `{value}` is not a valid password2 format"
}

func (r RulePassword2) Run(in RunInput) error {
Expand Down
2 changes: 1 addition & 1 deletion util/gvalid/internal/builtin/builtin_password3.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (r RulePassword3) Name() string {
}

func (r RulePassword3) Message() string {
return "The {field} value `{value}` is not a valid passport format"
return "The {field} value `{value}` is not a valid password3 format"
}

func (r RulePassword3) Run(in RunInput) error {
Expand Down

0 comments on commit 42de1c1

Please sign in to comment.