Skip to content

Commit

Permalink
Merge pull request #83 from rezakhademix/release-new-version-v2
Browse files Browse the repository at this point in the history
released: new version v2
  • Loading branch information
rezakhademix authored Apr 6, 2024
2 parents 2ae831e + df4682b commit 2674e07
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 91 deletions.
8 changes: 4 additions & 4 deletions after_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func Test_After(t *testing.T) {
value: "2022-01-01",
afterValue: "2022-02-01",
isPassed: false,
msg: "birth_date can't be after 2022-02-01.",
expectedMsg: "birth_date can't be after 2022-02-01.",
msg: "birth_date can't be before 2022-02-01.",
expectedMsg: "birth_date can't be before 2022-02-01.",
},
}

v := New()

for _, test := range tests {
v := New()

value, _ := time.Parse("2006-01-02", test.value)
afterValue, _ := time.Parse("2006-01-02", test.afterValue)

Expand Down
4 changes: 2 additions & 2 deletions before_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func Test_Before(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

value, _ := time.Parse("2006-01-02", test.value)
beforeValue, _ := time.Parse("2006-01-02", test.beforeValue)

Expand Down
8 changes: 4 additions & 4 deletions between_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func Test_BetweenInt(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.BetweenInt(test.value, test.min, test.max, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down Expand Up @@ -132,9 +132,9 @@ func Test_BetweenFloat(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.BetweenFloat(test.value, test.min, test.max, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down
4 changes: 2 additions & 2 deletions date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func Test_Date(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.Date(test.layout, test.value, test.field, test.msg)

if !test.isPassed {
Expand Down
4 changes: 2 additions & 2 deletions email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func Test_Email(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.Email(test.value, test.field, test.message)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down
6 changes: 3 additions & 3 deletions exists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ func TestValidator_Exists(t *testing.T) {
},
}

v := New().
WithRepo(repo{})

for _, test := range tests {
v := New().
WithRepo(repo{})

v.Exists(test.value, test.table, test.column, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down
4 changes: 2 additions & 2 deletions ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func Test_IP4(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.IP4(test.value, test.field, test.message)

assert.Equal(t, test.isPassed, v.IsPassed(), test.name)
Expand Down
12 changes: 6 additions & 6 deletions len_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func Test_LenString(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.LenString(test.value, test.len, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down Expand Up @@ -104,9 +104,9 @@ func Test_LenInt(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.LenInt(test.value, test.len, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down Expand Up @@ -163,9 +163,9 @@ func Test_LenSlice(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.LenSlice(test.value, test.len, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
default: help

test: ## run all tests
go test -v ./...
go test -v --race ./...

test-one: ## run only tests matching the passed regex as `name`
ifdef name
Expand Down
4 changes: 2 additions & 2 deletions max.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
// MaxMsg is the default error message format for fields with Max validation rule.
MaxMsg = "%s should be less than %v"
// MaxStringMsg is the default error message format for fields with MaxString validation rule.
MaxStringMsg = "%s should has less than %v characters"
MaxStringMsg = "%s should have less than %v characters"
)

// MaxInt checks if the integer value is less than or equal the given max value.
Expand Down Expand Up @@ -48,7 +48,7 @@ func (v *Validator) MaxFloat(f, max float64, field, msg string) *Validator {
// Example:
//
// v := validator.New()
// v.MaxString("rey", 5, "name", "name should has less than 5 characters.")
// v.MaxString("rey", 5, "name", "name should have less than 5 characters.")
// if v.IsFailed() {
// fmt.Printf("validation errors: %#v\n", v.Errors())
// }
Expand Down
18 changes: 9 additions & 9 deletions max_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func Test_MaxInt(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.MaxInt(test.value, test.max, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down Expand Up @@ -104,9 +104,9 @@ func Test_MaxFloat64(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.MaxFloat(test.value, test.max, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down Expand Up @@ -159,22 +159,22 @@ func Test_MaxString(t *testing.T) {
max: -1,
isPassed: false,
msg: "",
expectedMsg: "username should has less than -1 characters",
expectedMsg: "username should have less than -1 characters",
},
{
name: "test `abcd` won't pass validation when maximum valid length is 3",
field: "alphabet",
value: "abcd",
max: 3,
isPassed: false,
msg: "alphabet should has less than 3 characters",
expectedMsg: "alphabet should has less than 3 characters",
msg: "alphabet should have less than 3 characters",
expectedMsg: "alphabet should have less than 3 characters",
},
}

v := New()

for _, test := range tests {
v := New()

v.MaxString(test.value, test.max, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down
4 changes: 2 additions & 2 deletions min.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
// MinMsg is the default error message format for fields with Min validation rule.
MinMsg = "%s should be more than %v"
// MinStringMsg is the default error message format for fields with MinString validation rule.
MinStringMsg = "%s should has more than %v characters"
MinStringMsg = "%s should have more than %v characters"
)

// MinInt checks if the given integer value is greater than or equal the given min value.
Expand Down Expand Up @@ -48,7 +48,7 @@ func (v *Validator) MinFloat(f, min float64, field, msg string) *Validator {
// Example:
//
// v := validator.New()
// v.MinString("rey", 5, "name", "name should has more than 5 characters.")
// v.MinString("rey", 5, "name", "name should have more than 5 characters.")
// if v.IsFailed() {
// fmt.Printf("validation errors: %#v\n", v.Errors())
// }
Expand Down
20 changes: 10 additions & 10 deletions min_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func Test_MinInt(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.MinInt(test.value, test.min, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down Expand Up @@ -113,9 +113,9 @@ func Test_MinFloat(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.MinFloat(test.value, test.min, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down Expand Up @@ -159,7 +159,7 @@ func Test_MinString(t *testing.T) {
min: 5,
isPassed: false,
msg: "",
expectedMsg: "username should has more than 5 characters",
expectedMsg: "username should have more than 5 characters",
},
{
name: "test empty space string won't pass validation when minimum valid length is 2",
Expand All @@ -168,22 +168,22 @@ func Test_MinString(t *testing.T) {
min: 2,
isPassed: false,
msg: "",
expectedMsg: "username should has more than 2 characters",
expectedMsg: "username should have more than 2 characters",
},
{
name: "test `abcd` won't pass validation when minimum valid length is 7",
field: "alphabet",
value: "abcd",
min: 7,
isPassed: false,
msg: "alphabet should has more than 7 characters",
expectedMsg: "alphabet should has more than 7 characters",
msg: "alphabet should have more than 7 characters",
expectedMsg: "alphabet should have more than 7 characters",
},
}

v := New()

for _, test := range tests {
v := New()

v.MinString(test.value, test.min, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down
6 changes: 3 additions & 3 deletions notexists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ func Test_NotExists(t *testing.T) {
},
}

v := New().
WithRepo(repo{})

for _, test := range tests {
v := New().
WithRepo(repo{})

v.NotExists(test.value, test.table, test.column, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down
4 changes: 2 additions & 2 deletions regex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func Test_RegexMatches(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.RegexMatches(test.value, test.pattern, test.field, test.message)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down
16 changes: 8 additions & 8 deletions required_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func Test_RequiredInt(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.RequiredInt(test.value, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down Expand Up @@ -104,9 +104,9 @@ func Test_RequiredString(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.RequiredString(test.value, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down Expand Up @@ -159,9 +159,9 @@ func Test_RequiredFloat(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.RequiredFloat(test.value, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down Expand Up @@ -222,9 +222,9 @@ func Test_RequiredSlice(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.RequiredSlice(test.value, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down
4 changes: 2 additions & 2 deletions url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func Test_Url(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.URL(test.value, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed(), test.name)
Expand Down
4 changes: 2 additions & 2 deletions uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func Test_UUID(t *testing.T) {
},
}

v := New()

for _, test := range tests {
v := New()

v.UUID(test.value, test.field, test.msg)

assert.Equal(t, test.isPassed, v.IsPassed())
Expand Down
Loading

0 comments on commit 2674e07

Please sign in to comment.