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

validation_test.ExampleNewCustomStringConstraint   A

Complexity

Conditions 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nop 0
dl 0
loc 15
rs 9.85
c 0
b 0
f 0
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