Merge branch 'master' into reflex-struct-field

pull/979/head
Just NON 2 years ago committed by GitHub
commit 32d22f5237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      README.md
  2. 7
      baked_in.go
  3. 37
      validator_test.go

@ -1,7 +1,7 @@
Package validator
=================
<img align="right" src="https://raw.githubusercontent.com/go-playground/validator/v9/logo.png">[![Join the chat at https://gitter.im/go-playground/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-playground/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
![Project status](https://img.shields.io/badge/version-10.11.0-green.svg)
![Project status](https://img.shields.io/badge/version-10.11.1-green.svg)
[![Build Status](https://travis-ci.org/go-playground/validator.svg?branch=master)](https://travis-ci.org/go-playground/validator)
[![Coverage Status](https://coveralls.io/repos/go-playground/validator/badge.svg?branch=master&service=github)](https://coveralls.io/github/go-playground/validator?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/validator)](https://goreportcard.com/report/github.com/go-playground/validator)

@ -1484,10 +1484,15 @@ func isAlphaUnicode(fl FieldLevel) bool {
return alphaUnicodeRegex.MatchString(fl.Field().String())
}
// isBoolean is the validation function for validating if the current field's value can be safely converted to a boolean.
// isBoolean is the validation function for validating if the current field's value is a valid boolean value or can be safely converted to a boolean value.
func isBoolean(fl FieldLevel) bool {
switch fl.Field().Kind() {
case reflect.Bool:
return true
default:
_, err := strconv.ParseBool(fl.Field().String())
return err == nil
}
}
// isDefault is the opposite of required aka hasValue

@ -8302,6 +8302,43 @@ func TestNumeric(t *testing.T) {
errs = validate.Var(i, "numeric")
Equal(t, errs, nil)
}
func TestBoolean(t *testing.T) {
validate := New()
b := true
errs := validate.Var(b, "boolean")
Equal(t, errs, nil)
b = false
errs = validate.Var(b, "boolean")
Equal(t, errs, nil)
s := "true"
errs = validate.Var(s, "boolean")
Equal(t, errs, nil)
s = "false"
errs = validate.Var(s, "boolean")
Equal(t, errs, nil)
s = "0"
errs = validate.Var(s, "boolean")
Equal(t, errs, nil)
s = "1"
errs = validate.Var(s, "boolean")
Equal(t, errs, nil)
s = "xyz"
errs = validate.Var(s, "boolean")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "", "", "boolean")
s = "1."
errs = validate.Var(s, "boolean")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "", "", "boolean")
}
func TestAlphaNumeric(t *testing.T) {
validate := New()

Loading…
Cancel
Save