示例#1
0
func TestEmailInValid(t *testing.T) {
	v := struct {
		Email string `email:"-"`
	}{
		"fuga",
	}

	if err := gova.Validate(v); err == nil {
		t.Error("email validator doesn't work!")
	}
}
示例#2
0
func TestEmailValid(t *testing.T) {
	v := struct {
		Email string `email:"-"`
	}{
		"*****@*****.**",
	}

	if err := gova.Validate(v); err != nil {
		t.Error(err)
	}
}
示例#3
0
func TestPatternValid(t *testing.T) {
	v := struct {
		Num string `pattern:"[0-9]+"`
	}{
		"11111",
	}

	if err := gova.Validate(v); err != nil {
		t.Error(err)
	}
}
示例#4
0
func TestPatternInValid(t *testing.T) {
	v := struct {
		Num string `pattern:"[0-9]+"`
	}{
		"fuga",
	}

	if err := gova.Validate(v); err == nil {
		t.Error("pattern validator doesn't work!")
	}
}
示例#5
0
func TestLengthValid(t *testing.T) {
	v := struct {
		Str string `length:"10"`
	}{
		"1234567890",
	}

	if err := gova.Validate(v); err != nil {
		t.Error(err)
	}
}
示例#6
0
func TestLengthInValid(t *testing.T) {
	v := struct {
		Str string `length:"10"`
	}{
		"1234",
	}

	if err := gova.Validate(v); err == nil {
		t.Error("length validator doesn't work!")
	}
}
示例#7
0
func TestStructPointerResolutionValidation(t *testing.T) {
	// this test should not cause panic
	tmp := &Form{"alpha"}
	gova.Validate(tmp)
}