Skip to content

Commit

Permalink
Make all test code to use test package. Fixes #98
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Jun 24, 2023
1 parent 8537d66 commit fd57223
Show file tree
Hide file tree
Showing 51 changed files with 462 additions and 374 deletions.
20 changes: 12 additions & 8 deletions alphanumeric_test.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
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"`
}

user := &User{}

Check(user)
checker.Check(user)
}

func TestCheckAlphanumericInvalid(t *testing.T) {
Expand All @@ -35,7 +39,7 @@ func TestCheckAlphanumericInvalid(t *testing.T) {
Username: "user-/",
}

_, valid := Check(user)
_, valid := checker.Check(user)
if valid {
t.Fail()
}
Expand All @@ -50,7 +54,7 @@ func TestCheckAlphanumericValid(t *testing.T) {
Username: "ABcd1234",
}

_, valid := Check(user)
_, valid := checker.Check(user)
if !valid {
t.Fail()
}
Expand Down
20 changes: 12 additions & 8 deletions ascii_test.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
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"`
}

user := &User{}

Check(user)
checker.Check(user)
}

func TestCheckASCIIInvalid(t *testing.T) {
Expand All @@ -35,7 +39,7 @@ func TestCheckASCIIInvalid(t *testing.T) {
Username: "𝄞 Music!",
}

_, valid := Check(user)
_, valid := checker.Check(user)
if valid {
t.Fail()
}
Expand All @@ -50,7 +54,7 @@ func TestCheckASCIIValid(t *testing.T) {
Username: "checker",
}

_, valid := Check(user)
_, valid := checker.Check(user)
if !valid {
t.Fail()
}
Expand Down
20 changes: 12 additions & 8 deletions cidr_test.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
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"`
}

network := &Network{}

Check(network)
checker.Check(network)
}

func TestCheckCidrInvalid(t *testing.T) {
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand Down
Loading

0 comments on commit fd57223

Please sign in to comment.