checker/same_test.go
2023-06-16 16:28:01 -07:00

72 lines
1 KiB
Go

package checker
import (
"reflect"
"testing"
)
func TestSameValid(t *testing.T) {
type User struct {
Password string
Confirm string `checkers:"same:Password"`
}
user := &User{
Password: "1234",
Confirm: "1234",
}
_, valid := Check(user)
if !valid {
t.Fail()
}
}
func TestSameInvalid(t *testing.T) {
type User struct {
Password string
Confirm string `checkers:"same:Password"`
}
user := &User{
Password: "1234",
Confirm: "12",
}
_, valid := Check(user)
if valid {
t.Fail()
}
}
func TestSameWithoutParent(t *testing.T) {
defer FailIfNoPanic(t)
type User struct {
Password string
Confirm string `checkers:"same:Password"`
}
user := &User{
Password: "1234",
Confirm: "12",
}
checkSame(reflect.ValueOf(user.Confirm), reflect.ValueOf(nil), "Password")
}
func TestSameInvalidName(t *testing.T) {
defer FailIfNoPanic(t)
type User struct {
Password string
Confirm string `checkers:"same:Unknown"`
}
user := &User{
Password: "1234",
Confirm: "1234",
}
Check(user)
}