diff --git a/alphanumeric_test.go b/alphanumeric_test.go index 82ee9c4..dfba213 100644 --- a/alphanumeric_test.go +++ b/alphanumeric_test.go @@ -1,21 +1,25 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsAlphanumericInvalid(t *testing.T) { - if IsAlphanumeric("-/") == ResultValid { + if checker.IsAlphanumeric("-/") == checker.ResultValid { t.Fail() } } func TestIsAlphanumericValid(t *testing.T) { - if IsAlphanumeric("ABcd1234") != ResultValid { + if checker.IsAlphanumeric("ABcd1234") != checker.ResultValid { t.Fail() } } func TestCheckAlphanumericNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { Username int `checkers:"alphanumeric"` @@ -23,7 +27,7 @@ func TestCheckAlphanumericNonString(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestCheckAlphanumericInvalid(t *testing.T) { @@ -35,7 +39,7 @@ func TestCheckAlphanumericInvalid(t *testing.T) { Username: "user-/", } - _, valid := Check(user) + _, valid := checker.Check(user) if valid { t.Fail() } @@ -50,7 +54,7 @@ func TestCheckAlphanumericValid(t *testing.T) { Username: "ABcd1234", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } diff --git a/ascii_test.go b/ascii_test.go index de2a9ea..61b0433 100644 --- a/ascii_test.go +++ b/ascii_test.go @@ -1,21 +1,25 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsASCIIInvalid(t *testing.T) { - if IsASCII("𝄞 Music!") == ResultValid { + if checker.IsASCII("𝄞 Music!") == checker.ResultValid { t.Fail() } } func TestIsASCIIValid(t *testing.T) { - if IsASCII("Checker") != ResultValid { + if checker.IsASCII("Checker") != checker.ResultValid { t.Fail() } } func TestCheckASCIINonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { Age int `checkers:"ascii"` @@ -23,7 +27,7 @@ func TestCheckASCIINonString(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestCheckASCIIInvalid(t *testing.T) { @@ -35,7 +39,7 @@ func TestCheckASCIIInvalid(t *testing.T) { Username: "𝄞 Music!", } - _, valid := Check(user) + _, valid := checker.Check(user) if valid { t.Fail() } @@ -50,7 +54,7 @@ func TestCheckASCIIValid(t *testing.T) { Username: "checker", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } diff --git a/cidr_test.go b/cidr_test.go index 6e77832..e93c564 100644 --- a/cidr_test.go +++ b/cidr_test.go @@ -1,21 +1,25 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsCidrInvalid(t *testing.T) { - if IsCidr("900.800.200.100//24") == ResultValid { + if checker.IsCidr("900.800.200.100//24") == checker.ResultValid { t.Fail() } } func TestIsCidrValid(t *testing.T) { - if IsCidr("2001:db8::/32") != ResultValid { + if checker.IsCidr("2001:db8::/32") != checker.ResultValid { t.Fail() } } func TestCheckCidrNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type Network struct { Subnet int `checkers:"cidr"` @@ -23,7 +27,7 @@ func TestCheckCidrNonString(t *testing.T) { network := &Network{} - Check(network) + checker.Check(network) } func TestCheckCidrInvalid(t *testing.T) { @@ -35,7 +39,7 @@ func TestCheckCidrInvalid(t *testing.T) { Subnet: "900.800.200.100//24", } - _, valid := Check(network) + _, valid := checker.Check(network) if valid { t.Fail() } @@ -50,7 +54,7 @@ func TestCheckCidrValid(t *testing.T) { Subnet: "192.0.2.0/24", } - _, valid := Check(network) + _, valid := checker.Check(network) if !valid { t.Fail() } diff --git a/credit_card_test.go b/credit_card_test.go index 1a35c16..d62e298 100644 --- a/credit_card_test.go +++ b/credit_card_test.go @@ -1,8 +1,10 @@ -package checker +package checker_test import ( "strconv" "testing" + + "github.com/cinar/checker" ) // Test numbers from https://stripe.com/docs/testing @@ -28,151 +30,151 @@ func changeToInvalidLuhn(number string) string { } func TestIsAnyCreditCardValid(t *testing.T) { - if IsAnyCreditCard(amexCard) != ResultValid { + if checker.IsAnyCreditCard(amexCard) != checker.ResultValid { t.Fail() } } func TestIsAnyCreditCardInvalidPattern(t *testing.T) { - if IsAnyCreditCard(invalidCard) == ResultValid { + if checker.IsAnyCreditCard(invalidCard) == checker.ResultValid { t.Fail() } } func TestIsAnyCreditCardInvalidLuhn(t *testing.T) { - if IsAnyCreditCard(changeToInvalidLuhn(amexCard)) == ResultValid { + if checker.IsAnyCreditCard(changeToInvalidLuhn(amexCard)) == checker.ResultValid { t.Fail() } } func TestIsAmexCreditCardValid(t *testing.T) { - if IsAmexCreditCard(amexCard) != ResultValid { + if checker.IsAmexCreditCard(amexCard) != checker.ResultValid { t.Fail() } } func TestIsAmexCreditCardInvalidPattern(t *testing.T) { - if IsAmexCreditCard(invalidCard) == ResultValid { + if checker.IsAmexCreditCard(invalidCard) == checker.ResultValid { t.Fail() } } func TestIsAmexCreditCardInvalidLuhn(t *testing.T) { - if IsAmexCreditCard(changeToInvalidLuhn(amexCard)) == ResultValid { + if checker.IsAmexCreditCard(changeToInvalidLuhn(amexCard)) == checker.ResultValid { t.Fail() } } func TestIsDinersCreditCardValid(t *testing.T) { - if IsDinersCreditCard(dinersCard) != ResultValid { + if checker.IsDinersCreditCard(dinersCard) != checker.ResultValid { t.Fail() } } func TestIsDinersCreditCardInvalidPattern(t *testing.T) { - if IsDinersCreditCard(invalidCard) == ResultValid { + if checker.IsDinersCreditCard(invalidCard) == checker.ResultValid { t.Fail() } } func TestIsDinersCreditCardInvalidLuhn(t *testing.T) { - if IsDinersCreditCard(changeToInvalidLuhn(dinersCard)) == ResultValid { + if checker.IsDinersCreditCard(changeToInvalidLuhn(dinersCard)) == checker.ResultValid { t.Fail() } } func TestIsDiscoverCreditCardValid(t *testing.T) { - if IsDiscoveryCreditCard(discoverCard) != ResultValid { + if checker.IsDiscoveryCreditCard(discoverCard) != checker.ResultValid { t.Fail() } } func TestIsDiscoverCreditCardInvalidPattern(t *testing.T) { - if IsDiscoveryCreditCard(invalidCard) == ResultValid { + if checker.IsDiscoveryCreditCard(invalidCard) == checker.ResultValid { t.Fail() } } func TestIsDiscoverCreditCardInvalidLuhn(t *testing.T) { - if IsDiscoveryCreditCard(changeToInvalidLuhn(discoverCard)) == ResultValid { + if checker.IsDiscoveryCreditCard(changeToInvalidLuhn(discoverCard)) == checker.ResultValid { t.Fail() } } func TestIsJcbCreditCardValid(t *testing.T) { - if IsJcbCreditCard(jcbCard) != ResultValid { + if checker.IsJcbCreditCard(jcbCard) != checker.ResultValid { t.Fail() } } func TestIsJcbCreditCardInvalidPattern(t *testing.T) { - if IsJcbCreditCard(invalidCard) == ResultValid { + if checker.IsJcbCreditCard(invalidCard) == checker.ResultValid { t.Fail() } } func TestIsJcbCreditCardInvalidLuhn(t *testing.T) { - if IsJcbCreditCard(changeToInvalidLuhn(jcbCard)) == ResultValid { + if checker.IsJcbCreditCard(changeToInvalidLuhn(jcbCard)) == checker.ResultValid { t.Fail() } } func TestIsMasterCardCreditCardValid(t *testing.T) { - if IsMasterCardCreditCard(masterCard) != ResultValid { + if checker.IsMasterCardCreditCard(masterCard) != checker.ResultValid { t.Fail() } } func TestIsMasterCardCreditCardInvalidPattern(t *testing.T) { - if IsMasterCardCreditCard(invalidCard) == ResultValid { + if checker.IsMasterCardCreditCard(invalidCard) == checker.ResultValid { t.Fail() } } func TestIsMasterCardCreditCardInvalidLuhn(t *testing.T) { - if IsMasterCardCreditCard(changeToInvalidLuhn(masterCard)) == ResultValid { + if checker.IsMasterCardCreditCard(changeToInvalidLuhn(masterCard)) == checker.ResultValid { t.Fail() } } func TestIsUnionPayCreditCardValid(t *testing.T) { - if IsUnionPayCreditCard(unionPayCard) != ResultValid { + if checker.IsUnionPayCreditCard(unionPayCard) != checker.ResultValid { t.Fail() } } func TestIsUnionPayCreditCardInvalidPattern(t *testing.T) { - if IsUnionPayCreditCard(invalidCard) == ResultValid { + if checker.IsUnionPayCreditCard(invalidCard) == checker.ResultValid { t.Fail() } } func TestIsUnionPayCreditCardInvalidLuhn(t *testing.T) { - if IsUnionPayCreditCard(changeToInvalidLuhn(unionPayCard)) == ResultValid { + if checker.IsUnionPayCreditCard(changeToInvalidLuhn(unionPayCard)) == checker.ResultValid { t.Fail() } } func TestIsVisaCreditCardValid(t *testing.T) { - if IsVisaCreditCard(visaCard) != ResultValid { + if checker.IsVisaCreditCard(visaCard) != checker.ResultValid { t.Fail() } } func TestIsVisaCreditCardInvalidPattern(t *testing.T) { - if IsVisaCreditCard(invalidCard) == ResultValid { + if checker.IsVisaCreditCard(invalidCard) == checker.ResultValid { t.Fail() } } func TestIsVisaCreditCardInvalidLuhn(t *testing.T) { - if IsVisaCreditCard(changeToInvalidLuhn(visaCard)) == ResultValid { + if checker.IsVisaCreditCard(changeToInvalidLuhn(visaCard)) == checker.ResultValid { t.Fail() } } func TestCheckCreditCardNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type Order struct { CreditCard int `checkers:"credit-card"` @@ -180,7 +182,7 @@ func TestCheckCreditCardNonString(t *testing.T) { order := &Order{} - Check(order) + checker.Check(order) } func TestCheckCreditCardValid(t *testing.T) { @@ -192,7 +194,7 @@ func TestCheckCreditCardValid(t *testing.T) { CreditCard: amexCard, } - _, valid := Check(order) + _, valid := checker.Check(order) if !valid { t.Fail() } @@ -207,14 +209,14 @@ func TestCheckCreditCardInvalid(t *testing.T) { CreditCard: invalidCard, } - _, valid := Check(order) + _, valid := checker.Check(order) if valid { t.Fail() } } func TestCheckCreditCardMultipleUnknown(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type Order struct { CreditCard string `checkers:"credit-card:amex,unknown"` @@ -224,7 +226,7 @@ func TestCheckCreditCardMultipleUnknown(t *testing.T) { CreditCard: amexCard, } - Check(order) + checker.Check(order) } func TestCheckCreditCardMultipleInvalid(t *testing.T) { @@ -236,7 +238,7 @@ func TestCheckCreditCardMultipleInvalid(t *testing.T) { CreditCard: discoverCard, } - _, valid := Check(order) + _, valid := checker.Check(order) if valid { t.Fail() } diff --git a/digits_test.go b/digits_test.go index af57cac..3dfd694 100644 --- a/digits_test.go +++ b/digits_test.go @@ -1,21 +1,25 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsDigitsInvalid(t *testing.T) { - if IsDigits("checker") == ResultValid { + if checker.IsDigits("checker") == checker.ResultValid { t.Fail() } } func TestIsDigitsValid(t *testing.T) { - if IsDigits("1234") != ResultValid { + if checker.IsDigits("1234") != checker.ResultValid { t.Fail() } } func TestCheckDigitsNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { ID int `checkers:"digits"` @@ -23,7 +27,7 @@ func TestCheckDigitsNonString(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestCheckDigitsInvalid(t *testing.T) { @@ -35,7 +39,7 @@ func TestCheckDigitsInvalid(t *testing.T) { ID: "checker", } - _, valid := Check(user) + _, valid := checker.Check(user) if valid { t.Fail() } @@ -50,7 +54,7 @@ func TestCheckDigitsValid(t *testing.T) { ID: "1234", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } diff --git a/doc/checkers/alphanumeric.md b/doc/checkers/alphanumeric.md index 2cb89b6..ace92b0 100644 --- a/doc/checkers/alphanumeric.md +++ b/doc/checkers/alphanumeric.md @@ -1,6 +1,6 @@ # Alphanumeric Checker -The ```alphanumeric``` checker checks if the given string consists of only alphanumeric characters. If the string contains non-alphanumeric characters, the checker will return the ```NOT_ALPHANUMERIC``` result. Here is an example: +The `alphanumeric` checker checks if the given string consists of only alphanumeric characters. If the string contains non-alphanumeric characters, the checker will return the `NOT_ALPHANUMERIC` result. Here is an example: ```golang type User struct { @@ -11,18 +11,18 @@ user := &User{ Username: "ABcd1234", } -_, valid := Check(user) +_, valid := checker.Check(user) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```alphanumeric``` checker function ```IsAlphanumeric``` to validate the user input. Here is an example: +In your custom checkers, you can call the `alphanumeric` checker function [`IsAlphanumeric`](https://pkg.go.dev/github.com/cinar/checker#IsAlphanumeric) to validate the user input. Here is an example: ```golang -result := IsAlphanumeric("ABcd1234") +result := checker.IsAlphanumeric("ABcd1234") -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/ascii.md b/doc/checkers/ascii.md index 8f7efe9..cb5b9f8 100644 --- a/doc/checkers/ascii.md +++ b/doc/checkers/ascii.md @@ -1,6 +1,6 @@ # ASCII Checker -The ```ascii``` checker checks if the given string consists of only ASCII characters. If the string contains non-ASCII characters, the checker will return the ```NOT_ASCII``` result. Here is an example: +The `ascii` checker checks if the given string consists of only ASCII characters. If the string contains non-ASCII characters, the checker will return the `NOT_ASCII` result. Here is an example: ```golang type User struct { @@ -11,18 +11,18 @@ user := &User{ Username: "checker", } -_, valid := Check(user) +_, valid := checker.Check(user) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```ascii``` checker function ```IsASCII``` to validate the user input. Here is an example: +In your custom checkers, you can call the `ascii` checker function [`IsASCII`](https://pkg.go.dev/github.com/cinar/checker#IsASCII) to validate the user input. Here is an example: ```golang -result := IsASCII("Checker") +result := checker.IsASCII("Checker") -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/cidr.md b/doc/checkers/cidr.md index 8e4f4ae..d496f29 100644 --- a/doc/checkers/cidr.md +++ b/doc/checkers/cidr.md @@ -1,6 +1,6 @@ # CIDR Checker -The ```cidr``` checker checks if the value is a valid CIDR notation IP address and prefix length, like "192.0.2.0/24" or "2001:db8::/32", as defined in [RFC 4632](https://rfc-editor.org/rfc/rfc4632.html) and [RFC 4291](https://rfc-editor.org/rfc/rfc4291.html). If the value is not a valid CIDR notation, the checker will return the ```NOT_CIDR``` result. Here is an example: +The `cidr` checker checks if the value is a valid CIDR notation IP address and prefix length, like `192.0.2.0/24` or `2001:db8::/32`, as defined in [RFC 4632](https://rfc-editor.org/rfc/rfc4632.html) and [RFC 4291](https://rfc-editor.org/rfc/rfc4291.html). If the value is not a valid CIDR notation, the checker will return the `NOT_CIDR` result. Here is an example: ```golang type Network struct { @@ -11,18 +11,18 @@ network := &Network{ Subnet: "192.0.2.0/24", } -_, valid := Check(network) +_, valid := checker.Check(network) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```cidr``` checker function ```IsCidr``` to validate the user input. Here is an example: +In your custom checkers, you can call the `cidr` checker function [`IsCidr`](https://pkg.go.dev/github.com/cinar/checker#IsASCII) to validate the user input. Here is an example: ```golang -result := IsCidr("2001:db8::/32") +result := checker.IsCidr("2001:db8::/32") -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/credit_card.md b/doc/checkers/credit_card.md index b5f47cd..19989d2 100644 --- a/doc/checkers/credit_card.md +++ b/doc/checkers/credit_card.md @@ -1,6 +1,6 @@ # Credit Card Checker -The ```credit-card``` checker checks if the given value is a valid credit card number. If the given value is not a valid credit card number, the checker will return the ```NOT_CREDIT_CARD``` result. +The `credit-card` checker checks if the given value is a valid credit card number. If the given value is not a valid credit card number, the checker will return the `NOT_CREDIT_CARD` result. Here is an example: @@ -13,7 +13,7 @@ order := &Order{ CreditCard: invalidCard, } -_, valid := Check(order) +_, valid := checker.Check(order) if valid { // Send the mistakes back to the user } @@ -32,7 +32,7 @@ order := &Order{ CreditCard: "6011111111111117", } -_, valid := Check(order) +_, valid := checker.Check(order) if valid { // Send the mistakes back to the user } @@ -40,23 +40,23 @@ if valid { If you would like to verify a credit card that is not listed here, please use the [luhn](luhn.md) checker to use the Luhn Algorithm to verify the check digit. -In your custom checkers, you can call the ```credit-card``` checker functions below to validate the user input. +In your custom checkers, you can call the `credit-card` checker functions below to validate the user input. -- IsAnyCreditCard: checks if the given value is a valid credit card number. -- IsAmexCreditCard: checks if the given value is a valid AMEX credit card number. -- IsDinersCreditCard: checks if the given value is a valid Diners credit card number. -- IsDiscoverCreditCard: checks if the given value is a valid Discover credit card number. -- IsJcbCreditCard: checks if the given value is a valid JCB credit card number. -- IsMasterCardCreditCard: checks if the given value is a valid MasterCard credit card number. -- IsUnionPayCreditCard: checks if the given value is a valid UnionPay credit card number. -- IsVisaCreditCard: checks if the given value is a valid VISA credit card number. +- [`IsAnyCreditCard`](https://pkg.go.dev/github.com/cinar/checker#IsAnyCreditCard): checks if the given value is a valid credit card number. +- [`IsAmexCreditCard`](https://pkg.go.dev/github.com/cinar/checker#IsAmexCreditCard): checks if the given value is a valid AMEX credit card number. +- [`IsDinersCreditCard`](https://pkg.go.dev/github.com/cinar/checker#IsDinersCreditCard): checks if the given value is a valid Diners credit card number. +- [`IsDiscoverCreditCard`](https://pkg.go.dev/github.com/cinar/checker#IsDiscoverCreditCard): checks if the given value is a valid Discover credit card number. +- [`IsJcbCreditCard`](https://pkg.go.dev/github.com/cinar/checker#IsJcbCreditCard): checks if the given value is a valid JCB credit card number. +- [`IsMasterCardCreditCard`](https://pkg.go.dev/github.com/cinar/checker#IsMasterCardCreditCard): checks if the given value is a valid MasterCard credit card number. +- [`IsUnionPayCreditCard`](https://pkg.go.dev/github.com/cinar/checker#IsUnionPayCreditCard): checks if the given value is a valid UnionPay credit card number. +- [`IsVisaCreditCard`](https://pkg.go.dev/github.com/cinar/checker#IsVisaCreditCard): checks if the given value is a valid VISA credit card number. Here is an example: ```golang -result := IsAnyCreditCard("6011111111111117") +result := checker.IsAnyCreditCard("6011111111111117") -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/digits.md b/doc/checkers/digits.md index d4999c3..03fb89a 100644 --- a/doc/checkers/digits.md +++ b/doc/checkers/digits.md @@ -1,6 +1,6 @@ # Digits Checker -The ```digits``` checker checks if the given string consists of only digit characters. If the string contains non-digit characters, the checker will return the ```NOT_DIGITS``` result. Here is an example: +The `digits` checker checks if the given string consists of only digit characters. If the string contains non-digit characters, the checker will return the `NOT_DIGITS` result. Here is an example: ```golang type User struct { @@ -11,18 +11,18 @@ user := &User{ Id: "1234", } -_, valid := Check(user) +_, valid := checker.Check(user) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```digits``` checker function ```IsDigits``` to validate the user input. Here is an example: +In your custom checkers, you can call the `digits` checker function [`IsDigits`](https://pkg.go.dev/github.com/cinar/checker#IsDigits) to validate the user input. Here is an example: ```golang -result := IsDigits("1234") +result := checker.IsDigits("1234") -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/email.md b/doc/checkers/email.md index d226b58..db41c6a 100644 --- a/doc/checkers/email.md +++ b/doc/checkers/email.md @@ -1,6 +1,6 @@ # Email Checker -The ```email``` checker checks if the given string is an email address. If the given string is not a valid email address, the checker will return the ```NOT_EMAIL``` result. Here is an example: +The `email` checker checks if the given string is an email address. If the given string is not a valid email address, the checker will return the `NOT_EMAIL` result. Here is an example: ```golang type User struct { @@ -11,18 +11,18 @@ user := &User{ Email: "user@zdo.com", } -_, valid := Check(user) +_, valid := checker.Check(user) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```email``` checker function ```IsEmail``` to validate the user input. Here is an example: +In your custom checkers, you can call the `email` checker function [`IsEmail`](https://pkg.go.dev/github.com/cinar/checker#IsEmail) to validate the user input. Here is an example: ```golang -result := IsEmail("user@zdo.com") +result := checker.IsEmail("user@zdo.com") -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/fqdn.md b/doc/checkers/fqdn.md index 4b1ece4..e63565f 100644 --- a/doc/checkers/fqdn.md +++ b/doc/checkers/fqdn.md @@ -1,6 +1,6 @@ # FQDN Checker -The Full Qualified Domain Name (FQDN) is the complete domain name for a computer or host on the internet. The ```fqdn``` checker checks if the given string consists of a FQDN. If the string is not a valid FQDN, the checker will return the ```NOT_FQDN``` result. Here is an example: +The Full Qualified Domain Name (FQDN) is the complete domain name for a computer or host on the internet. The `fqdn` checker checks if the given string consists of a FQDN. If the string is not a valid FQDN, the checker will return the `NOT_FQDN` result. Here is an example: ```golang type Request struct { @@ -11,18 +11,18 @@ request := &Request{ Domain: "zdo.com", } -_, valid := Check(request) +_, valid := checker.Check(request) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```fqdn``` checker function ```IsFqdn``` to validate the user input. Here is an example: +In your custom checkers, you can call the `fqdn` checker function [`IsFqdn`](https://pkg.go.dev/github.com/cinar/checker#IsFqdn) to validate the user input. Here is an example: ```golang -result := IsFqdn("zdo.com") +result := checker.IsFqdn("zdo.com") -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/ip.md b/doc/checkers/ip.md index 970b03a..4b01a51 100644 --- a/doc/checkers/ip.md +++ b/doc/checkers/ip.md @@ -1,6 +1,6 @@ # IP Checker -The ```ip``` checker checks if the value is an IP address. If the value is not an IP address, the checker will return the ```NOT_IP``` result. Here is an example: +The `ip` checker checks if the value is an IP address. If the value is not an IP address, the checker will return the `NOT_IP` result. Here is an example: ```golang type Request struct { @@ -11,18 +11,18 @@ request := &Request{ RemoteIP: "192.168.1.1", } -_, valid := Check(request) +_, valid := checker.Check(request) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```ip``` checker function ```IsIP``` to validate the user input. Here is an example: +In your custom checkers, you can call the `ip` checker function [`IsIP`](https://pkg.go.dev/github.com/cinar/checker#IsIP) to validate the user input. Here is an example: ```golang -result := IsIP("2001:db8::68") +result := checker.IsIP("2001:db8::68") -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/ipv4.md b/doc/checkers/ipv4.md index c6d8b99..d3ac8a5 100644 --- a/doc/checkers/ipv4.md +++ b/doc/checkers/ipv4.md @@ -1,6 +1,6 @@ # IPv4 Checker -The ```ipv4``` checker checks if the value is an IPv4 address. If the value is not an IPv4 address, the checker will return the ```NOT_IP_V4``` result. Here is an example: +The `ipv4` checker checks if the value is an IPv4 address. If the value is not an IPv4 address, the checker will return the `NOT_IP_V4` result. Here is an example: ```golang type Request struct { @@ -11,18 +11,18 @@ request := &Request{ RemoteIP: "192.168.1.1", } -_, valid := Check(request) +_, valid := checker.Check(request) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```ipv4``` checker function ```IsIPV4``` to validate the user input. Here is an example: +In your custom checkers, you can call the `ipv4` checker function [`IsIPV4`](https://pkg.go.dev/github.com/cinar/checker#IsIPV4) to validate the user input. Here is an example: ```golang -result := IsIPV4("192.168.1.1") +result := checker.IsIPV4("192.168.1.1") -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/ipv6.md b/doc/checkers/ipv6.md index 050f442..66626e2 100644 --- a/doc/checkers/ipv6.md +++ b/doc/checkers/ipv6.md @@ -1,6 +1,6 @@ # IPv6 Checker -The ```ipv6``` checker checks if the value is an IPv6 address. If the value is not an IPv6 address, the checker will return the ```NOT_IP_V6``` result. Here is an example: +The `ipv6` checker checks if the value is an IPv6 address. If the value is not an IPv6 address, the checker will return the `NOT_IP_V6` result. Here is an example: ```golang type Request struct { @@ -11,18 +11,18 @@ request := &Request{ RemoteIP: "2001:db8::68", } -_, valid := Check(request) +_, valid := checker.Check(request) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```ipv6``` checker function ```IsIPV6``` to validate the user input. Here is an example: +In your custom checkers, you can call the `ipv6` checker function [`IsIPV6`](https://pkg.go.dev/github.com/cinar/checker#IsIPV6) to validate the user input. Here is an example: ```golang -result := IsIPV6("2001:db8::68") +result := checker.IsIPV6("2001:db8::68") -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/luhn.md b/doc/checkers/luhn.md index d23ca5a..3148e43 100644 --- a/doc/checkers/luhn.md +++ b/doc/checkers/luhn.md @@ -1,6 +1,6 @@ # Luhn Checker -The ```luhn``` checker checks if the given number is valid based on the Luhn Algorithm. If the given number is not valid, it will return the ```NOT_LUHN``` result. Here is an example: +The `luhn` checker checks if the given number is valid based on the Luhn Algorithm. If the given number is not valid, it will return the `NOT_LUHN` result. Here is an example: ```golang type Order struct { @@ -11,18 +11,18 @@ order := &Order{ CreditCard: "4012888888881881", } -_, valid := Check(order) +_, valid := checker.Check(order) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```luhn``` checker function ```IsLuhn``` to validate the user input. Here is an example: +In your custom checkers, you can call the `luhn` checker function [`IsLuhn`](https://pkg.go.dev/github.com/cinar/checker#IsLuhn) to validate the user input. Here is an example: ```golang -result := IsLuhn("4012888888881881") +result := checker.IsLuhn("4012888888881881") -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/mac.md b/doc/checkers/mac.md index dfa8c11..ac50fdd 100644 --- a/doc/checkers/mac.md +++ b/doc/checkers/mac.md @@ -1,6 +1,6 @@ # MAC Checker -The ```mac``` checker checks if the value is a valid an IEEE 802 MAC-48, EUI-48, EUI-64, or a 20-octet IP over InfiniBand link-layer address. If the value is not a valid MAC address, the checker will return the ```NOT_MAC``` result. Here is an example: +The `mac` checker checks if the value is a valid an IEEE 802 MAC-48, EUI-48, EUI-64, or a 20-octet IP over InfiniBand link-layer address. If the value is not a valid MAC address, the checker will return the `NOT_MAC` result. Here is an example: ```golang type Network struct { @@ -11,18 +11,18 @@ network := &Network{ HardwareAddress: "00:00:5e:00:53:01", } -_, valid := Check(network) +_, valid := checker.Check(network) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```mac``` checker function ```IsMAc``` to validate the user input. Here is an example: +In your custom checkers, you can call the `mac` checker function [`IsMac`](https://pkg.go.dev/github.com/cinar/checker#IsMac) to validate the user input. Here is an example: ```golang -result := IsMac("00:00:5e:00:53:01") +result := checker.IsMac("00:00:5e:00:53:01") -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/max.md b/doc/checkers/max.md index e780768..b26e714 100644 --- a/doc/checkers/max.md +++ b/doc/checkers/max.md @@ -1,6 +1,6 @@ # Max Checker -The ```max``` checker checks if the given ```int``` or ```float``` value is less than the given maximum. If the value is above the maximum, the checker will return the ```NOT_MAX``` result. Here is an example: +The `max` checker checks if the given ```int``` or ```float``` value is less than the given maximum. If the value is above the maximum, the checker will return the `NOT_MAX` result. Here is an example: ```golang type Order struct { @@ -11,20 +11,20 @@ order := &Order{ Quantity: 5, } -mistakes, valid := Check(order) +mistakes, valid := checker.Check(order) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```max``` checker function ```IsMax``` to validate the user input. Here is an example: +In your custom checkers, you can call the `max` checker function [`IsMax`](https://pkg.go.dev/github.com/cinar/checker#IsMax) to validate the user input. Here is an example: ```golang quantity := 5 -result := IsMax(quantity, 10 ) +result := checker.IsMax(quantity, 10) -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/maxlength.md b/doc/checkers/maxlength.md index 340715b..af008aa 100644 --- a/doc/checkers/maxlength.md +++ b/doc/checkers/maxlength.md @@ -1,6 +1,6 @@ # Max Length Checker -The ```max-length``` checker checks if the length of the given value is less than the given maximum length. If the length of the value is above the maximum length, the checker will return the ```NOT_MAX_LENGTH``` result. Here is an example: +The `max-length` checker checks if the length of the given value is less than the given maximum length. If the length of the value is above the maximum length, the checker will return the `NOT_MAX_LENGTH` result. Here is an example: ```golang type User struct { @@ -11,7 +11,7 @@ user := &User{ Password: "1234", } -mistakes, valid := Check(user) +mistakes, valid := checker.Check(user) if !valid { // Send the mistakes back to the user } @@ -19,14 +19,14 @@ if !valid { The checker can be applied to all types that are supported by the [reflect.Value.Len()](https://pkg.go.dev/reflect#Value.Len) function. -If you do not want to validate user input stored in a struct, you can individually call the ```max-length``` checker function ```IsMaxLength``` to validate the user input. Here is an example: +If you do not want to validate user input stored in a struct, you can individually call the `max-length` checker function [`IsMaxLength`](https://pkg.go.dev/github.com/cinar/checker#IsMaxLength) to validate the user input. Here is an example: ```golang s := "1234" -result := IsMaxLength(s, 4) +result := checker.IsMaxLength(s, 4) -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/min.md b/doc/checkers/min.md index 0b05725..8520655 100644 --- a/doc/checkers/min.md +++ b/doc/checkers/min.md @@ -1,6 +1,6 @@ # Min Checker -The ```min``` checker checks if the given ```int``` or ```float``` value is greather than the given minimum. If the value is below the minimum, the checker will return the ```NOT_MIN``` result. Here is an example: +The `min` checker checks if the given ```int``` or ```float``` value is greather than the given minimum. If the value is below the minimum, the checker will return the `NOT_MIN` result. Here is an example: ```golang type User struct { @@ -11,20 +11,20 @@ user := &User{ Age: 45, } -mistakes, valid := Check(user) +mistakes, valid := checker.Check(user) if !valid { // Send the mistakes back to the user } ``` -In your custom checkers, you can call the ```min``` checker function ```IsMin``` to validate the user input. Here is an example: +In your custom checkers, you can call the `min` checker function [`IsMin`](https://pkg.go.dev/github.com/cinar/checker#IsMin) to validate the user input. Here is an example: ```golang age := 45 -result := IsMin(age, 21) +result := checker.IsMin(age, 21) -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/minlength.md b/doc/checkers/minlength.md index d50dd06..7a9a680 100644 --- a/doc/checkers/minlength.md +++ b/doc/checkers/minlength.md @@ -1,6 +1,6 @@ # Min Length Checker -The ```min-length``` checker checks if the length of the given value is greather than the given minimum length. If the length of the value is below the minimum length, the checker will return the ```NOT_MIN_LENGTH``` result. Here is an example: +The `min-length` checker checks if the length of the given value is greather than the given minimum length. If the length of the value is below the minimum length, the checker will return the `NOT_MIN_LENGTH` result. Here is an example: ```golang type User struct { @@ -11,7 +11,7 @@ user := &User{ Password: "1234", } -mistakes, valid := Check(user) +mistakes, valid := checker.Check(user) if !valid { // Send the mistakes back to the user } @@ -19,14 +19,14 @@ if !valid { The checker can be applied to all types that are supported by the [reflect.Value.Len()](https://pkg.go.dev/reflect#Value.Len) function. -If you do not want to validate user input stored in a struct, you can individually call the ```min-length``` checker function ```IsMinLength``` to validate the user input. Here is an example: +If you do not want to validate user input stored in a struct, you can individually call the `min-length` checker function [`IsMinLength`](https://pkg.go.dev/github.com/cinar/checker#IsMinLength) to validate the user input. Here is an example: ```golang s := "1234" -result := IsMinLength(s, 4) +result := checker.IsMinLength(s, 4) -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` diff --git a/doc/checkers/regexp.md b/doc/checkers/regexp.md index cf5d699..f97a4cb 100644 --- a/doc/checkers/regexp.md +++ b/doc/checkers/regexp.md @@ -1,6 +1,6 @@ # Regexp Checker -The ```regexp``` checker checks if the given string matches the given regexp. If the given string does not match, the checker will return the ```NOT_MATCH``` result. Here is an example: +The `regexp` checker checks if the given string matches the given regexp. If the given string does not match, the checker will return the `NOT_MATCH` result. Here is an example: ```golang type User struct { @@ -11,27 +11,27 @@ user := &User{ Username: "abcd", } -_, valid := Check(user) +_, valid := checker.Check(user) if !valid { // Send the mistakes back to the user } ``` -The ```regexp``` checker can be used to build other checkers for other regexp patterns. In order to do that, you can use the ```MakeRegexpChecker``` function. The function takes an expression and a result to return when the the given string is not a match. Here is an example: +The `regexp` checker can be used to build other checkers for other regexp patterns. In order to do that, you can use the [`MakeRegexpChecker`](https://pkg.go.dev/github.com/cinar/checker#MakeRegexpChecker) function. The function takes an expression and a result to return when the the given string is not a match. Here is an example: ```golang -checkHex := MakeRegexpChecker("^[A-Fa-f0-9]+$", "NOT_HEX") +checkHex := checker.MakeRegexpChecker("^[A-Fa-f0-9]+$", "NOT_HEX") result := checkHex(reflect.ValueOf("f0f0f0"), reflect.ValueOf(nil)) -if result != ResultValid { +if result != checker.ResultValid { // Send the mistakes back to the user } ``` -To register the new regexp checker to validate user input in struct, you ```MakeRegexpChecker``` function can be used. Here is an example: +To register the new regexp checker to validate user input in struct, [`Register`](https://pkg.go.dev/github.com/cinar/checker#Register) function can be used. Here is an example: ```golang -Register("hex", MakeRegexpMaker("^[A-Fa-f0-9]+$", "NOT_HEX")) +checker.Register("hex", checker.MakeRegexpMaker("^[A-Fa-f0-9]+$", "NOT_HEX")) type Theme struct { Color string `checkers:hex` @@ -41,7 +41,7 @@ theme := &Theme{ Color: "f0f0f0", } -_, valid := Check(theme) +_, valid := checker.Check(theme) if !valid { // Send the mistakes back to the user } diff --git a/doc/checkers/required.md b/doc/checkers/required.md index bac89d6..f59dad2 100644 --- a/doc/checkers/required.md +++ b/doc/checkers/required.md @@ -1,6 +1,6 @@ # Required Checker -The ```required``` checker checks for the presence of required input. If the input is not present, the checker will return the ```REQUIRED``` result. Here is an example: +The `required` checker checks for the presence of required input. If the input is not present, the checker will return the `REQUIRED` result. Here is an example: ```golang type Person struct { @@ -15,13 +15,13 @@ if !valid { } ``` -If you do not want to validate user input stored in a struct, you can individually call the ```required``` checker function ```IsRequired``` to validate the user input. Here is an example: +If you do not want to validate user input stored in a struct, you can individually call the `required` checker function [`IsRequired`](https://pkg.go.dev/github.com/cinar/checker#IsRequired) to validate the user input. Here is an example: ```golang var name result := checker.IsRequired(name) -if result != ResultValid { +if result != checker.ResultValid { // Send the result back to the user } ``` diff --git a/doc/checkers/same.md b/doc/checkers/same.md index 7ee6e22..f974dd1 100644 --- a/doc/checkers/same.md +++ b/doc/checkers/same.md @@ -1,6 +1,6 @@ # Same Checker -The ```same``` checker checks if the given value is equal to the value of the other field specified by its name. If they are not equal, the checker will return the ```NOT_SAME``` result. In the example below, the ```same``` checker ensures that the value in the ```Confirm``` field matches the value in the ```Password``` field. +The `same` checker checks if the given value is equal to the value of the other field specified by its name. If they are not equal, the checker will return the `NOT_SAME` result. In the example below, the `same` checker ensures that the value in the `Confirm` field matches the value in the `Password` field. ```golang type User struct { diff --git a/doc/normalizers/lower.md b/doc/normalizers/lower.md index fc0fcf5..0c8d041 100644 --- a/doc/normalizers/lower.md +++ b/doc/normalizers/lower.md @@ -1,6 +1,6 @@ # Lower Case Normalizer -The ```lower``` normalizer maps all Unicode letters in the given value to their lower case. It can be mixed with checkers and other normalizers when defining the validation steps for user data. +The `lower` normalizer maps all Unicode letters in the given value to their lower case. It can be mixed with checkers and other normalizers when defining the validation steps for user data. ```golang type User struct { @@ -11,7 +11,7 @@ user := &User{ Username: "chECker", } -Check(user) +checker.Check(user) fmt.Println(user.Username) // checker ``` diff --git a/doc/normalizers/title.md b/doc/normalizers/title.md index 04bdfc0..7eb4710 100644 --- a/doc/normalizers/title.md +++ b/doc/normalizers/title.md @@ -1,6 +1,6 @@ # Title Case Normalizer -The ```title``` normalizer maps the first letter of each word to their upper case. It can be mixed with checkers and other normalizers when defining the validation steps for user data. +The `title` normalizer maps the first letter of each word to their upper case. It can be mixed with checkers and other normalizers when defining the validation steps for user data. ```golang type Book struct { @@ -11,7 +11,7 @@ book := &Book{ Chapter: "THE checker", } -Check(book) +checker.Check(book) fmt.Println(book.Chapter) // The Checker ``` diff --git a/doc/normalizers/trim.md b/doc/normalizers/trim.md index bec939e..e99f112 100644 --- a/doc/normalizers/trim.md +++ b/doc/normalizers/trim.md @@ -1,6 +1,6 @@ # Trim Normalizer -The ```trim``` normalizer removes the whitespaces at the beginning and at the end of the given value. It can be mixed with checkers and other normalizers when defining the validation steps for user data. +The `trim` normalizer removes the whitespaces at the beginning and at the end of the given value. It can be mixed with checkers and other normalizers when defining the validation steps for user data. ```golang type User struct { @@ -11,7 +11,7 @@ user := &User{ Username: " normalizer ", } -Check(user) +checker.Check(user) fmt.Println(user.Username) // CHECKER ``` diff --git a/doc/normalizers/trim_left.md b/doc/normalizers/trim_left.md index 1e0e8ee..7c49338 100644 --- a/doc/normalizers/trim_left.md +++ b/doc/normalizers/trim_left.md @@ -1,6 +1,6 @@ # Trim Left Normalizer -The ```trim-left``` normalizer removes the whitespaces at the beginning of the given value. It can be mixed with checkers and other normalizers when defining the validation steps for user data. +The `trim-left` normalizer removes the whitespaces at the beginning of the given value. It can be mixed with checkers and other normalizers when defining the validation steps for user data. ```golang type User struct { @@ -11,7 +11,7 @@ user := &User{ Username: " normalizer", } -Check(user) +checker.Check(user) fmt.Println(user.Username) // normalizer ``` diff --git a/doc/normalizers/trim_right.md b/doc/normalizers/trim_right.md index e08a288..d2e0ca0 100644 --- a/doc/normalizers/trim_right.md +++ b/doc/normalizers/trim_right.md @@ -1,6 +1,6 @@ # Trim Right Normalizer -The ```trim-right``` normalizer removes the whitespaces at the end of the given value. It can be mixed with checkers and other normalizers when defining the validation steps for user data. +The `trim-right` normalizer removes the whitespaces at the end of the given value. It can be mixed with checkers and other normalizers when defining the validation steps for user data. ```golang type User struct { @@ -11,7 +11,7 @@ user := &User{ Username: "normalizer ", } -Check(user) +checker.Check(user) fmt.Println(user.Username) // CHECKER ``` diff --git a/doc/normalizers/upper.md b/doc/normalizers/upper.md index f802f4b..c57ed01 100644 --- a/doc/normalizers/upper.md +++ b/doc/normalizers/upper.md @@ -1,6 +1,6 @@ # Upper Case Normalizer -The ```upper``` normalizer maps all Unicode letters in the given value to their upper case. It can be mixed with checkers and other normalizers when defining the validation steps for user data. +The `upper` normalizer maps all Unicode letters in the given value to their upper case. It can be mixed with checkers and other normalizers when defining the validation steps for user data. ```golang type User struct { diff --git a/email_test.go b/email_test.go index e88530d..e1afe8e 100644 --- a/email_test.go +++ b/email_test.go @@ -1,9 +1,13 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestCheckEmailNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { Email int `checkers:"email"` @@ -11,7 +15,7 @@ func TestCheckEmailNonString(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestCheckEmailValid(t *testing.T) { @@ -23,7 +27,7 @@ func TestCheckEmailValid(t *testing.T) { Email: "user@zdo.com", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } @@ -52,7 +56,7 @@ func TestIsEmailValid(t *testing.T) { } for _, email := range validEmails { - if IsEmail(email) != ResultValid { + if checker.IsEmail(email) != checker.ResultValid { t.Fatal(email) } } @@ -76,7 +80,7 @@ func TestIsEmailInvalid(t *testing.T) { } for _, email := range validEmails { - if IsEmail(email) == ResultValid { + if checker.IsEmail(email) == checker.ResultValid { t.Fatal(email) } } diff --git a/fqdn_test.go b/fqdn_test.go index 2724ad6..fcf0a52 100644 --- a/fqdn_test.go +++ b/fqdn_test.go @@ -1,63 +1,67 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestCheckFdqnWithoutTld(t *testing.T) { - if IsFqdn("abcd") != ResultNotFqdn { + if checker.IsFqdn("abcd") != checker.ResultNotFqdn { t.Fail() } } func TestCheckFdqnShortTld(t *testing.T) { - if IsFqdn("abcd.c") != ResultNotFqdn { + if checker.IsFqdn("abcd.c") != checker.ResultNotFqdn { t.Fail() } } func TestCheckFdqnNumericTld(t *testing.T) { - if IsFqdn("abcd.1234") != ResultNotFqdn { + if checker.IsFqdn("abcd.1234") != checker.ResultNotFqdn { t.Fail() } } func TestCheckFdqnLong(t *testing.T) { - if IsFqdn("abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.com") != ResultNotFqdn { + if checker.IsFqdn("abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd.com") != checker.ResultNotFqdn { t.Fail() } } func TestCheckFdqnInvalidCharacters(t *testing.T) { - if IsFqdn("ab_cd.com") != ResultNotFqdn { + if checker.IsFqdn("ab_cd.com") != checker.ResultNotFqdn { t.Fail() } } func TestCheckFdqnStaringWithHyphen(t *testing.T) { - if IsFqdn("-abcd.com") != ResultNotFqdn { + if checker.IsFqdn("-abcd.com") != checker.ResultNotFqdn { t.Fail() } } func TestCheckFdqnStaringEndingWithHyphen(t *testing.T) { - if IsFqdn("abcd-.com") != ResultNotFqdn { + if checker.IsFqdn("abcd-.com") != checker.ResultNotFqdn { t.Fail() } } func TestCheckFdqnStartingWithDot(t *testing.T) { - if IsFqdn(".abcd.com") != ResultNotFqdn { + if checker.IsFqdn(".abcd.com") != checker.ResultNotFqdn { t.Fail() } } func TestCheckFdqnEndingWithDot(t *testing.T) { - if IsFqdn("abcd.com.") != ResultNotFqdn { + if checker.IsFqdn("abcd.com.") != checker.ResultNotFqdn { t.Fail() } } func TestCheckFqdnNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type Request struct { Domain int `checkers:"fqdn"` @@ -65,7 +69,7 @@ func TestCheckFqdnNonString(t *testing.T) { request := &Request{} - Check(request) + checker.Check(request) } func TestCheckFqdnValid(t *testing.T) { @@ -77,7 +81,7 @@ func TestCheckFqdnValid(t *testing.T) { Domain: "zdo.com", } - _, valid := Check(request) + _, valid := checker.Check(request) if !valid { t.Fail() } diff --git a/ip_test.go b/ip_test.go index add19eb..5035125 100644 --- a/ip_test.go +++ b/ip_test.go @@ -1,21 +1,25 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsIPInvalid(t *testing.T) { - if IsIP("900.800.200.100") == ResultValid { + if checker.IsIP("900.800.200.100") == checker.ResultValid { t.Fail() } } func TestIsIPValid(t *testing.T) { - if IsIP("2001:db8::68") != ResultValid { + if checker.IsIP("2001:db8::68") != checker.ResultValid { t.Fail() } } func TestCheckIpNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type Request struct { RemoteIP int `checkers:"ip"` @@ -23,7 +27,7 @@ func TestCheckIpNonString(t *testing.T) { request := &Request{} - Check(request) + checker.Check(request) } func TestCheckIpInvalid(t *testing.T) { @@ -35,7 +39,7 @@ func TestCheckIpInvalid(t *testing.T) { RemoteIP: "900.800.200.100", } - _, valid := Check(request) + _, valid := checker.Check(request) if valid { t.Fail() } @@ -50,7 +54,7 @@ func TestCheckIPValid(t *testing.T) { RemoteIP: "192.168.1.1", } - _, valid := Check(request) + _, valid := checker.Check(request) if !valid { t.Fail() } diff --git a/ipv4_test.go b/ipv4_test.go index 2548ee4..251a90a 100644 --- a/ipv4_test.go +++ b/ipv4_test.go @@ -1,27 +1,31 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsIPV4Invalid(t *testing.T) { - if IsIPV4("900.800.200.100") == ResultValid { + if checker.IsIPV4("900.800.200.100") == checker.ResultValid { t.Fail() } } func TestIsIPV4InvalidV6(t *testing.T) { - if IsIPV4("2001:db8::68") == ResultValid { + if checker.IsIPV4("2001:db8::68") == checker.ResultValid { t.Fail() } } func TestIsIPV4Valid(t *testing.T) { - if IsIPV4("192.168.1.1") != ResultValid { + if checker.IsIPV4("192.168.1.1") != checker.ResultValid { t.Fail() } } func TestCheckIPV4NonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type Request struct { RemoteIP int `checkers:"ipv4"` @@ -29,7 +33,7 @@ func TestCheckIPV4NonString(t *testing.T) { request := &Request{} - Check(request) + checker.Check(request) } func TestCheckIPV4Invalid(t *testing.T) { @@ -41,7 +45,7 @@ func TestCheckIPV4Invalid(t *testing.T) { RemoteIP: "900.800.200.100", } - _, valid := Check(request) + _, valid := checker.Check(request) if valid { t.Fail() } @@ -56,7 +60,7 @@ func TestCheckIPV4Valid(t *testing.T) { RemoteIP: "192.168.1.1", } - _, valid := Check(request) + _, valid := checker.Check(request) if !valid { t.Fail() } diff --git a/ipv6_test.go b/ipv6_test.go index 55e72c3..9fccdca 100644 --- a/ipv6_test.go +++ b/ipv6_test.go @@ -1,27 +1,31 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsIPV6Invalid(t *testing.T) { - if IsIPV6("900.800.200.100") == ResultValid { + if checker.IsIPV6("900.800.200.100") == checker.ResultValid { t.Fail() } } func TestIsIPV6InvalidV4(t *testing.T) { - if IsIPV6("192.168.1.1") == ResultValid { + if checker.IsIPV6("192.168.1.1") == checker.ResultValid { t.Fail() } } func TestIsIPV6Valid(t *testing.T) { - if IsIPV6("2001:db8::68") != ResultValid { + if checker.IsIPV6("2001:db8::68") != checker.ResultValid { t.Fail() } } func TestCheckIPV6NonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type Request struct { RemoteIP int `checkers:"ipv6"` @@ -29,7 +33,7 @@ func TestCheckIPV6NonString(t *testing.T) { request := &Request{} - Check(request) + checker.Check(request) } func TestCheckIPV6Invalid(t *testing.T) { @@ -41,7 +45,7 @@ func TestCheckIPV6Invalid(t *testing.T) { RemoteIP: "900.800.200.100", } - _, valid := Check(request) + _, valid := checker.Check(request) if valid { t.Fail() } @@ -56,7 +60,7 @@ func TestCheckIPV6Valid(t *testing.T) { RemoteIP: "2001:db8::68", } - _, valid := Check(request) + _, valid := checker.Check(request) if !valid { t.Fail() } diff --git a/lower_test.go b/lower_test.go index 7234d8f..8b68d46 100644 --- a/lower_test.go +++ b/lower_test.go @@ -1,9 +1,13 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestNormalizeLowerNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { Username int `checkers:"lower"` @@ -11,7 +15,7 @@ func TestNormalizeLowerNonString(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestNormalizeLowerResultValid(t *testing.T) { @@ -23,7 +27,7 @@ func TestNormalizeLowerResultValid(t *testing.T) { Username: "chECker", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } @@ -38,7 +42,7 @@ func TestNormalizeLower(t *testing.T) { Username: "chECker", } - Check(user) + checker.Check(user) if user.Username != "checker" { t.Fail() diff --git a/luhn_test.go b/luhn_test.go index c2ea724..646c248 100644 --- a/luhn_test.go +++ b/luhn_test.go @@ -1,6 +1,10 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsLuhnValid(t *testing.T) { numbers := []string{ @@ -11,14 +15,14 @@ func TestIsLuhnValid(t *testing.T) { } for _, number := range numbers { - if IsLuhn(number) != ResultValid { + if checker.IsLuhn(number) != checker.ResultValid { t.Fail() } } } func TestCheckLuhnNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type Order struct { CreditCard int `checkers:"luhn"` @@ -26,7 +30,7 @@ func TestCheckLuhnNonString(t *testing.T) { order := &Order{} - Check(order) + checker.Check(order) } func TestCheckLuhnInvalid(t *testing.T) { @@ -38,7 +42,7 @@ func TestCheckLuhnInvalid(t *testing.T) { CreditCard: "4012888888881884", } - _, valid := Check(order) + _, valid := checker.Check(order) if valid { t.Fail() } @@ -53,7 +57,7 @@ func TestCheckLuhnValid(t *testing.T) { CreditCard: "4012888888881881", } - _, valid := Check(order) + _, valid := checker.Check(order) if !valid { t.Fail() } diff --git a/mac_test.go b/mac_test.go index b636567..60f0cfd 100644 --- a/mac_test.go +++ b/mac_test.go @@ -1,21 +1,25 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsMacInvalid(t *testing.T) { - if IsMac("1234") == ResultValid { + if checker.IsMac("1234") == checker.ResultValid { t.Fail() } } func TestIsMacValid(t *testing.T) { - if IsMac("00:00:5e:00:53:01") != ResultValid { + if checker.IsMac("00:00:5e:00:53:01") != checker.ResultValid { t.Fail() } } func TestCheckMacNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type Network struct { HardwareAddress int `checkers:"mac"` @@ -23,7 +27,7 @@ func TestCheckMacNonString(t *testing.T) { network := &Network{} - Check(network) + checker.Check(network) } func TestCheckMacInvalid(t *testing.T) { @@ -35,7 +39,7 @@ func TestCheckMacInvalid(t *testing.T) { HardwareAddress: "1234", } - _, valid := Check(network) + _, valid := checker.Check(network) if valid { t.Fail() } @@ -50,7 +54,7 @@ func TestCheckMacValid(t *testing.T) { HardwareAddress: "00:00:5e:00:53:01", } - _, valid := Check(network) + _, valid := checker.Check(network) if !valid { t.Fail() } diff --git a/max_test.go b/max_test.go index af1f4a4..bc7833e 100644 --- a/max_test.go +++ b/max_test.go @@ -1,17 +1,21 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsMaxValid(t *testing.T) { n := 5 - if IsMax(n, 10) != ResultValid { + if checker.IsMax(n, 10) != checker.ResultValid { t.Fail() } } func TestCheckMaxInvalidConfig(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type Order struct { Quantity int `checkers:"max:AB"` @@ -19,7 +23,7 @@ func TestCheckMaxInvalidConfig(t *testing.T) { order := &Order{} - Check(order) + checker.Check(order) } func TestCheckMaxValid(t *testing.T) { @@ -31,7 +35,7 @@ func TestCheckMaxValid(t *testing.T) { Quantity: 5, } - _, valid := Check(order) + _, valid := checker.Check(order) if !valid { t.Fail() } @@ -46,7 +50,7 @@ func TestCheckMaxInvalid(t *testing.T) { Quantity: 20, } - _, valid := Check(order) + _, valid := checker.Check(order) if valid { t.Fail() } diff --git a/maxlength_test.go b/maxlength_test.go index 12529cc..551f12a 100644 --- a/maxlength_test.go +++ b/maxlength_test.go @@ -1,17 +1,21 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsMaxLengthValid(t *testing.T) { s := "1234" - if IsMaxLength(s, 4) != ResultValid { + if checker.IsMaxLength(s, 4) != checker.ResultValid { t.Fail() } } func TestCheckMaxLengthInvalidConfig(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { Password string `checkers:"max-length:AB"` @@ -19,7 +23,7 @@ func TestCheckMaxLengthInvalidConfig(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestCheckMaxLengthValid(t *testing.T) { @@ -31,7 +35,7 @@ func TestCheckMaxLengthValid(t *testing.T) { Password: "1234", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } @@ -46,7 +50,7 @@ func TestCheckMaxLengthInvalid(t *testing.T) { Password: "123456", } - _, valid := Check(user) + _, valid := checker.Check(user) if valid { t.Fail() } diff --git a/min_test.go b/min_test.go index d3a4adc..9f6738a 100644 --- a/min_test.go +++ b/min_test.go @@ -1,17 +1,21 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsMinValid(t *testing.T) { n := 45 - if IsMin(n, 21) != ResultValid { + if checker.IsMin(n, 21) != checker.ResultValid { t.Fail() } } func TestCheckMinInvalidConfig(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { Age int `checkers:"min:AB"` @@ -19,7 +23,7 @@ func TestCheckMinInvalidConfig(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestCheckMinValid(t *testing.T) { @@ -31,7 +35,7 @@ func TestCheckMinValid(t *testing.T) { Age: 45, } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } @@ -46,7 +50,7 @@ func TestCheckMinInvalid(t *testing.T) { Age: 18, } - _, valid := Check(user) + _, valid := checker.Check(user) if valid { t.Fail() } diff --git a/minlength_test.go b/minlength_test.go index e5b2cf8..7389700 100644 --- a/minlength_test.go +++ b/minlength_test.go @@ -1,17 +1,21 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestIsMinLengthValid(t *testing.T) { s := "1234" - if IsMinLength(s, 4) != ResultValid { + if checker.IsMinLength(s, 4) != checker.ResultValid { t.Fail() } } func TestCheckMinLengthInvalidConfig(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { Password string `checkers:"min-length:AB"` @@ -19,7 +23,7 @@ func TestCheckMinLengthInvalidConfig(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestCheckMinLengthValid(t *testing.T) { @@ -31,7 +35,7 @@ func TestCheckMinLengthValid(t *testing.T) { Password: "1234", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } @@ -46,7 +50,7 @@ func TestCheckMinLengthInvalid(t *testing.T) { Password: "12", } - _, valid := Check(user) + _, valid := checker.Check(user) if valid { t.Fail() } diff --git a/regexp_test.go b/regexp_test.go index 8a8c768..99cee62 100644 --- a/regexp_test.go +++ b/regexp_test.go @@ -1,12 +1,14 @@ -package checker +package checker_test import ( "reflect" "testing" + + "github.com/cinar/checker" ) func TestCheckRegexpNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { Username int `checkers:"regexp:^[A-Za-z]$"` @@ -14,7 +16,7 @@ func TestCheckRegexpNonString(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestCheckRegexpInvalid(t *testing.T) { @@ -26,7 +28,7 @@ func TestCheckRegexpInvalid(t *testing.T) { Username: "abcd1234", } - _, valid := Check(user) + _, valid := checker.Check(user) if valid { t.Fail() } @@ -41,23 +43,23 @@ func TestCheckRegexpValid(t *testing.T) { Username: "abcd", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } } func TestMakeRegexpChecker(t *testing.T) { - checkHex := MakeRegexpChecker("^[A-Fa-f0-9]+$", "NOT_HEX") + checkHex := checker.MakeRegexpChecker("^[A-Fa-f0-9]+$", "NOT_HEX") result := checkHex(reflect.ValueOf("f0f0f0"), reflect.ValueOf(nil)) - if result != ResultValid { + if result != checker.ResultValid { t.Fail() } } func TestMakeRegexpMaker(t *testing.T) { - Register("hex", MakeRegexpMaker("^[A-Fa-f0-9]+$", "NOT_HEX")) + checker.Register("hex", checker.MakeRegexpMaker("^[A-Fa-f0-9]+$", "NOT_HEX")) type Theme struct { Color string `checkers:"hex"` @@ -67,7 +69,7 @@ func TestMakeRegexpMaker(t *testing.T) { Color: "f0f0f0", } - _, valid := Check(theme) + _, valid := checker.Check(theme) if !valid { t.Fail() } diff --git a/required_test.go b/required_test.go index 3b689e2..d25eafd 100644 --- a/required_test.go +++ b/required_test.go @@ -1,104 +1,97 @@ -package checker +package checker_test import ( - "reflect" "testing" + + "github.com/cinar/checker" ) func TestIsRequired(t *testing.T) { s := "valid" - if IsRequired(s) != ResultValid { + if checker.IsRequired(s) != checker.ResultValid { t.Fail() } } -func TestCheckRequiredValidString(t *testing.T) { - s := "valid" - - if checkRequired(reflect.ValueOf(s), reflect.ValueOf(nil)) != ResultValid { - t.Fail() - } -} - -func TestCheckRequiredUninitializedString(t *testing.T) { +func TestIsRequiredUninitializedString(t *testing.T) { var s string - if checkRequired(reflect.ValueOf(s), reflect.ValueOf(nil)) != ResultRequired { + if checker.IsRequired(s) != checker.ResultRequired { t.Fail() } } -func TestCheckRequiredEmptyString(t *testing.T) { +func TestIsRequiredEmptyString(t *testing.T) { s := "" - if checkRequired(reflect.ValueOf(s), reflect.ValueOf(nil)) != ResultRequired { + if checker.IsRequired(s) == checker.ResultValid { t.Fail() } } -func TestCheckRequiredUninitializedNumber(t *testing.T) { +func TestIsRequiredUninitializedNumber(t *testing.T) { var n int - if checkRequired(reflect.ValueOf(n), reflect.ValueOf(nil)) != ResultRequired { + if checker.IsRequired(n) != checker.ResultRequired { t.Fail() } } -func TestCheckRequiredValidSlice(t *testing.T) { +func TestIsRequiredValidSlice(t *testing.T) { s := []int{1} - if checkRequired(reflect.ValueOf(s), reflect.ValueOf(nil)) != ResultValid { + if checker.IsRequired(s) != checker.ResultValid { t.Fail() } } -func TestCheckRequiredUninitializedSlice(t *testing.T) { +func TestIsRequiredUninitializedSlice(t *testing.T) { var s []int - if checkRequired(reflect.ValueOf(s), reflect.ValueOf(nil)) != ResultRequired { + if checker.IsRequired(s) != checker.ResultRequired { t.Fail() } } -func TestCheckRequiredEmptySlice(t *testing.T) { +func TestIsRequiredEmptySlice(t *testing.T) { s := make([]int, 0) - if checkRequired(reflect.ValueOf(s), reflect.ValueOf(nil)) != ResultRequired { + if checker.IsRequired(s) != checker.ResultRequired { t.Fail() } } -func TestCheckRequiredValidArray(t *testing.T) { +func TestIsRequiredValidArray(t *testing.T) { s := [1]int{1} - if checkRequired(reflect.ValueOf(s), reflect.ValueOf(nil)) != ResultValid { + if checker.IsRequired(s) != checker.ResultValid { t.Fail() } } -func TestCheckRequiredEmptyArray(t *testing.T) { +func TestIsRequiredEmptyArray(t *testing.T) { s := [1]int{} - if checkRequired(reflect.ValueOf(s), reflect.ValueOf(nil)) != ResultRequired { + if checker.IsRequired(s) != checker.ResultRequired { t.Fail() } } -func TestCheckRequiredValidMap(t *testing.T) { +func TestIsRequiredValidMap(t *testing.T) { m := map[string]string{ "a": "b", } - if checkRequired(reflect.ValueOf(m), reflect.ValueOf(nil)) != ResultValid { + if checker.IsRequired(m) != checker.ResultValid { t.Fail() } } -func TestCheckRequiredUninitializedMap(t *testing.T) { +func TestIsRequiredUninitializedMap(t *testing.T) { var m map[string]string - if checkRequired(reflect.ValueOf(m), reflect.ValueOf(nil)) != ResultRequired { + if checker.IsRequired(m) != checker.ResultRequired { t.Fail() } } @@ -106,17 +99,35 @@ func TestCheckRequiredUninitializedMap(t *testing.T) { func TestCheckRequiredEmptyMap(t *testing.T) { m := map[string]string{} - if checkRequired(reflect.ValueOf(m), reflect.ValueOf(nil)) != ResultRequired { + if checker.IsRequired(m) != checker.ResultRequired { t.Fail() } } -func TestMakeRequired(t *testing.T) { - check := makeRequired("") +func TestCheckRequiredValid(t *testing.T) { + type User struct { + Username string `checkers:"required"` + } - s := "valid" + user := &User{ + Username: "checker", + } + + _, valid := checker.Check(user) + if !valid { + t.Fail() + } +} + +func TestCheckRequiredInvalid(t *testing.T) { + type User struct { + Username string `checkers:"required"` + } + + user := &User{} - if check(reflect.ValueOf(s), reflect.ValueOf(nil)) != ResultValid { + _, valid := checker.Check(user) + if valid { t.Fail() } } diff --git a/same_test.go b/same_test.go index 657f3b9..54e7f09 100644 --- a/same_test.go +++ b/same_test.go @@ -1,8 +1,9 @@ -package checker +package checker_test import ( - "reflect" "testing" + + "github.com/cinar/checker" ) func TestSameValid(t *testing.T) { @@ -16,7 +17,7 @@ func TestSameValid(t *testing.T) { Confirm: "1234", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } @@ -33,30 +34,14 @@ func TestSameInvalid(t *testing.T) { Confirm: "12", } - _, valid := Check(user) + _, valid := checker.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) + defer checker.FailIfNoPanic(t) type User struct { Password string @@ -68,5 +53,5 @@ func TestSameInvalidName(t *testing.T) { Confirm: "1234", } - Check(user) + checker.Check(user) } diff --git a/test_helper_test.go b/test_helper_test.go index e5e5d11..a093409 100644 --- a/test_helper_test.go +++ b/test_helper_test.go @@ -1,13 +1,17 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestFailIfNoPanicValid(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) panic("") } func TestFailIfNoPanicInvalid(t *testing.T) { - defer FailIfNoPanic(t) - defer FailIfNoPanic(nil) + defer checker.FailIfNoPanic(t) + defer checker.FailIfNoPanic(nil) } diff --git a/title_test.go b/title_test.go index 078e3ab..acad9d1 100644 --- a/title_test.go +++ b/title_test.go @@ -1,9 +1,13 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestNormalizeTitleNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type Book struct { Chapter int `checkers:"title"` @@ -11,7 +15,7 @@ func TestNormalizeTitleNonString(t *testing.T) { book := &Book{} - Check(book) + checker.Check(book) } func TestNormalizeTitleResultValid(t *testing.T) { @@ -23,7 +27,7 @@ func TestNormalizeTitleResultValid(t *testing.T) { Chapter: "THE checker", } - _, valid := Check(book) + _, valid := checker.Check(book) if !valid { t.Fail() } @@ -38,7 +42,7 @@ func TestNormalizeTitle(t *testing.T) { Chapter: "THE checker", } - Check(book) + checker.Check(book) if book.Chapter != "The Checker" { t.Fail() diff --git a/trim_left_test.go b/trim_left_test.go index 96ba8dc..181bdb1 100644 --- a/trim_left_test.go +++ b/trim_left_test.go @@ -1,9 +1,13 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestNormalizeTrimLeftNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { Username int `checkers:"trim-left"` @@ -11,7 +15,7 @@ func TestNormalizeTrimLeftNonString(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestNormalizeTrimLeftResultValid(t *testing.T) { @@ -23,7 +27,7 @@ func TestNormalizeTrimLeftResultValid(t *testing.T) { Username: " normalizer ", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } @@ -38,7 +42,7 @@ func TestNormalizeTrimLeft(t *testing.T) { Username: " normalizer ", } - Check(user) + checker.Check(user) if user.Username != "normalizer " { t.Fail() diff --git a/trim_right_test.go b/trim_right_test.go index ed87f56..da3b114 100644 --- a/trim_right_test.go +++ b/trim_right_test.go @@ -1,9 +1,13 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestNormalizeTrimRightNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { Username int `checkers:"trim-right"` @@ -11,7 +15,7 @@ func TestNormalizeTrimRightNonString(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestNormalizeTrimRightResultValid(t *testing.T) { @@ -23,7 +27,7 @@ func TestNormalizeTrimRightResultValid(t *testing.T) { Username: " normalizer ", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } @@ -38,7 +42,7 @@ func TestNormalizeTrimRight(t *testing.T) { Username: " normalizer ", } - Check(user) + checker.Check(user) if user.Username != " normalizer" { t.Fail() diff --git a/trim_test.go b/trim_test.go index fce2305..2e58fb3 100644 --- a/trim_test.go +++ b/trim_test.go @@ -1,9 +1,13 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestNormalizeTrimNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { Username int `checkers:"trim"` @@ -11,7 +15,7 @@ func TestNormalizeTrimNonString(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestNormalizeTrimResultValid(t *testing.T) { @@ -23,7 +27,7 @@ func TestNormalizeTrimResultValid(t *testing.T) { Username: " normalizer ", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } @@ -38,7 +42,7 @@ func TestNormalizeTrim(t *testing.T) { Username: " normalizer ", } - Check(user) + checker.Check(user) if user.Username != "normalizer" { t.Fail() diff --git a/upper_test.go b/upper_test.go index 36cba9e..fedd20b 100644 --- a/upper_test.go +++ b/upper_test.go @@ -1,9 +1,13 @@ -package checker +package checker_test -import "testing" +import ( + "testing" + + "github.com/cinar/checker" +) func TestNormalizeUpperNonString(t *testing.T) { - defer FailIfNoPanic(t) + defer checker.FailIfNoPanic(t) type User struct { Username int `checkers:"upper"` @@ -11,7 +15,7 @@ func TestNormalizeUpperNonString(t *testing.T) { user := &User{} - Check(user) + checker.Check(user) } func TestNormalizeUpperResultValid(t *testing.T) { @@ -23,7 +27,7 @@ func TestNormalizeUpperResultValid(t *testing.T) { Username: "chECker", } - _, valid := Check(user) + _, valid := checker.Check(user) if !valid { t.Fail() } @@ -38,7 +42,7 @@ func TestNormalizeUpper(t *testing.T) { Username: "chECker", } - Check(user) + checker.Check(user) if user.Username != "CHECKER" { t.Fail()