Skip to content

Commit

Permalink
add tags test
Browse files Browse the repository at this point in the history
  • Loading branch information
Bedroome committed Mar 25, 2024
1 parent 402c497 commit 7f1d4ae
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tags.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// @Since 2024-03-23.
// @Author Fury, All rights Reserved.

package validator

type Fn func(value string, allowEmpty bool) bool

// TagMap: tags map, when you want to add a new validation to the validator
// TagMap tags map, when you want to add a new validation to the validator
// you can range this map to get the tag and valid function
var TagMap = map[string]Fn{
"email": IsValidEmail,
Expand Down
40 changes: 40 additions & 0 deletions tags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package validator

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestTagMap(t *testing.T) {
t.Helper()

assert.True(t, TagMap["email"](
"[email protected]",
true,
))

assert.True(t, TagMap["http_url"](
"https://example.org",
true,
))

assert.True(t, TagMap["id_card"](
"510212197002066715",
true,
))

assert.True(t, TagMap["identifier"](
"idA099",
true,
))

assert.True(t, TagMap["money"](
"123,233.1",
true,
))

assert.True(t, TagMap["phone_number"](
"18157610011",
true,
))
}

0 comments on commit 7f1d4ae

Please sign in to comment.