Passed
Push — main ( 815f74...226e09 )
by Rushan
02:04 queued 12s
created

examples_constraint_test.go   A

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validation_test.ExampleNewCustomStringConstraint 0 15 2
1
package validation_test
2
3
import (
4
	"fmt"
5
6
	"github.com/muonsoft/validation"
7
	"github.com/muonsoft/validation/validator"
8
)
9
10
func ExampleNewCustomStringConstraint() {
11
	validate := func(s string) bool {
12
		return s == "valid"
13
	}
14
	constraint := validation.NewCustomStringConstraint(
15
		validate,
16
		"ExampleConstraint", // constraint name
17
		"exampleCode",       // violation code
18
		"Unexpected value.", // violation message template
19
	)
20
21
	s := "foo"
22
	err := validator.ValidateString(&s, constraint)
23
24
	fmt.Println(err)
25
	// Output:
26
	// violation: Unexpected value.
27
}
28