]> gitweb.factorcode.org Git - factor.git/blob - basis/html/forms/forms-tests.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / basis / html / forms / forms-tests.factor
1 USING: kernel sequences tools.test assocs html.forms validators accessors
2 namespaces ;
3 FROM: html.forms => values ;
4 IN: html.forms.tests
5
6 : with-validation ( quot -- messages )
7     [
8         begin-form
9         call
10     ] with-scope ; inline
11
12 [ 14 ] [
13     [
14         "14" [ v-number 13 v-min-value 100 v-max-value ] validate
15     ] with-validation
16 ] unit-test
17
18 [ t ] [
19     [
20         "140" [ v-number 13 v-min-value 100 v-max-value ] validate
21         [ validation-error? ]
22         [ value>> "140" = ]
23         bi and
24     ] with-validation
25 ] unit-test
26
27 TUPLE: person name age ;
28
29 person {
30     { "name" [ ] }
31     { "age" [ v-number 13 v-min-value 100 v-max-value ] }
32 } define-validators
33
34 [ t t ] [
35     [
36         { { "age" "" } }
37         { { "age" [ v-required ] } }
38         validate-values
39         validation-failed?
40         "age" value
41         [ validation-error? ]
42         [ message>> "required" = ]
43         bi and
44     ] with-validation
45 ] unit-test
46
47 [ H{ { "a" 123 } } f ] [
48     [
49         H{
50             { "a" "123" }
51             { "b" "c" }
52             { "c" "d" }
53         }
54         H{
55             { "a" [ v-integer ] }
56         } validate-values
57         values
58         validation-failed?
59     ] with-validation
60 ] unit-test
61
62 [ t "foo" ] [
63     [
64         "foo" validation-error
65         validation-failed?
66         form get errors>> first
67     ] with-validation
68 ] unit-test