remove math.blas.syntax and merge parsing words into math.blas.vectors/matrices
[factor/jcg.git] / basis / html / forms / forms-tests.factor
blobd2dc3ed3a3d541cc16becb7ce43c528578a3c633
1 IN: html.forms.tests
2 USING: kernel sequences tools.test assocs html.forms validators accessors
3 namespaces ;
5 : with-validation ( quot -- messages )
6     [
7         begin-form
8         call
9     ] with-scope ; inline
11 [ 14 ] [
12     [
13         "14" [ v-number 13 v-min-value 100 v-max-value ] validate
14     ] with-validation
15 ] unit-test
17 [ t ] [
18     [
19         "140" [ v-number 13 v-min-value 100 v-max-value ] validate
20         [ validation-error? ]
21         [ value>> "140" = ]
22         bi and
23     ] with-validation
24 ] unit-test
26 TUPLE: person name age ;
28 person {
29     { "name" [ ] }
30     { "age" [ v-number 13 v-min-value 100 v-max-value ] }
31 } define-validators
33 [ t t ] [
34     [
35         { { "age" "" } }
36         { { "age" [ v-required ] } }
37         validate-values
38         validation-failed?
39         "age" value
40         [ validation-error? ]
41         [ message>> "required" = ]
42         bi and
43     ] with-validation
44 ] unit-test
46 [ H{ { "a" 123 } } f ] [
47     [
48         H{
49             { "a" "123" }
50             { "b" "c" }
51             { "c" "d" }
52         }
53         H{
54             { "a" [ v-integer ] }
55         } validate-values
56         values
57         validation-failed?
58     ] with-validation
59 ] unit-test
61 [ t "foo" ] [
62     [
63         "foo" validation-error
64         validation-failed?
65         form get errors>> first
66     ] with-validation
67 ] unit-test