Total Lines | 39 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package validation_test |
||
2 | |||
3 | import ( |
||
4 | "fmt" |
||
5 | |||
6 | "github.com/muonsoft/validation" |
||
7 | "github.com/muonsoft/validation/it" |
||
8 | "github.com/muonsoft/validation/validator" |
||
9 | |||
10 | "regexp" |
||
11 | ) |
||
12 | |||
13 | func ExampleConditionalConstraint_Then() { |
||
14 | v := "foo" |
||
15 | err := validator.ValidateString( |
||
16 | &v, |
||
17 | validation.When(true). |
||
18 | Then( |
||
19 | it.Matches(regexp.MustCompile(`^\w+$`)), |
||
20 | ), |
||
21 | ) |
||
22 | fmt.Println(err) |
||
23 | // Output: |
||
24 | // <nil> |
||
25 | } |
||
26 | |||
27 | func ExampleConditionalConstraint_Else() { |
||
28 | v := "123" |
||
29 | err := validator.ValidateString( |
||
30 | &v, |
||
31 | validation.When(false). |
||
32 | Then( |
||
33 | it.Matches(regexp.MustCompile(`^\w+$`)), |
||
34 | ). |
||
35 | Else( |
||
36 | it.Matches(regexp.MustCompile(`^\d+$`)), |
||
37 | ), |
||
38 | ) |
||
39 | fmt.Println(err) |
||
40 | // Output: |
||
43 |