validators: fix v-default (reported by Niklas Waern)

release
Slava Pestov 2010-03-30 15:35:36 -04:00
parent 000c21fc66
commit 26c4aec91a
2 changed files with 13 additions and 10 deletions

View File

@ -2,17 +2,12 @@ IN: validators.tests
USING: kernel sequences tools.test validators accessors
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
[ 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
[ 123 ] [ "123" v-number ] unit-test
[ 123 ] [ "123" v-integer ] unit-test
@ -42,6 +37,14 @@ namespaces assocs ;
[ "http:/www.factorcode.org" v-url ]
[ "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 ] [ "4561-2612-1234-5467" v-credit-card ] unit-test

View File

@ -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.
USING: kernel continuations sequences math namespaces make sets
math.parser math.ranges assocs regexp unicode.categories arrays
@ -9,7 +9,7 @@ IN: validators
>lower "on" = ;
: v-default ( str def -- str/def )
[ nip empty? ] 2keep ? ;
[ drop empty? not ] 2keep ? ;
: v-required ( str -- str )
dup empty? [ "required" throw ] when ;