validators: fix v-default (reported by Niklas Waern)
parent
000c21fc66
commit
26c4aec91a
|
@ -2,17 +2,12 @@ IN: validators.tests
|
||||||
USING: kernel sequences tools.test validators accessors
|
USING: kernel sequences tools.test validators accessors
|
||||||
namespaces assocs ;
|
namespaces assocs ;
|
||||||
|
|
||||||
[ "" v-one-line ] must-fail
|
|
||||||
[ "hello world" ] [ "hello world" v-one-line ] unit-test
|
|
||||||
[ "hello\nworld" v-one-line ] must-fail
|
|
||||||
|
|
||||||
[ "" v-one-word ] must-fail
|
|
||||||
[ "hello" ] [ "hello" v-one-word ] unit-test
|
|
||||||
[ "hello world" v-one-word ] must-fail
|
|
||||||
|
|
||||||
[ t ] [ "on" v-checkbox ] unit-test
|
[ t ] [ "on" v-checkbox ] unit-test
|
||||||
[ f ] [ "off" v-checkbox ] unit-test
|
[ f ] [ "off" v-checkbox ] unit-test
|
||||||
|
|
||||||
|
[ "default test" ] [ "" "default test" v-default ] unit-test
|
||||||
|
[ "blah" ] [ "blah" "default test" v-default ] unit-test
|
||||||
|
|
||||||
[ "foo" v-number ] must-fail
|
[ "foo" v-number ] must-fail
|
||||||
[ 123 ] [ "123" v-number ] unit-test
|
[ 123 ] [ "123" v-number ] unit-test
|
||||||
[ 123 ] [ "123" v-integer ] unit-test
|
[ 123 ] [ "123" v-integer ] unit-test
|
||||||
|
@ -42,6 +37,14 @@ namespaces assocs ;
|
||||||
[ "http:/www.factorcode.org" v-url ]
|
[ "http:/www.factorcode.org" v-url ]
|
||||||
[ "invalid URL" = ] must-fail-with
|
[ "invalid URL" = ] must-fail-with
|
||||||
|
|
||||||
|
[ "" v-one-line ] must-fail
|
||||||
|
[ "hello world" ] [ "hello world" v-one-line ] unit-test
|
||||||
|
[ "hello\nworld" v-one-line ] must-fail
|
||||||
|
|
||||||
|
[ "" v-one-word ] must-fail
|
||||||
|
[ "hello" ] [ "hello" v-one-word ] unit-test
|
||||||
|
[ "hello world" v-one-word ] must-fail
|
||||||
|
|
||||||
[ 4561261212345467 ] [ "4561261212345467" v-credit-card ] unit-test
|
[ 4561261212345467 ] [ "4561261212345467" v-credit-card ] unit-test
|
||||||
|
|
||||||
[ 4561261212345467 ] [ "4561-2612-1234-5467" v-credit-card ] unit-test
|
[ 4561261212345467 ] [ "4561-2612-1234-5467" v-credit-card ] unit-test
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
! Copyright (C) 2006, 2008 Slava Pestov
|
! Copyright (C) 2006, 2010 Slava Pestov
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel continuations sequences math namespaces make sets
|
USING: kernel continuations sequences math namespaces make sets
|
||||||
math.parser math.ranges assocs regexp unicode.categories arrays
|
math.parser math.ranges assocs regexp unicode.categories arrays
|
||||||
|
@ -9,7 +9,7 @@ IN: validators
|
||||||
>lower "on" = ;
|
>lower "on" = ;
|
||||||
|
|
||||||
: v-default ( str def -- str/def )
|
: v-default ( str def -- str/def )
|
||||||
[ nip empty? ] 2keep ? ;
|
[ drop empty? not ] 2keep ? ;
|
||||||
|
|
||||||
: v-required ( str -- str )
|
: v-required ( str -- str )
|
||||||
dup empty? [ "required" throw ] when ;
|
dup empty? [ "required" throw ] when ;
|
||||||
|
|
Loading…
Reference in New Issue