diff --git a/basis/validators/validators-tests.factor b/basis/validators/validators-tests.factor index acdcdda5d2..6b5936977f 100644 --- a/basis/validators/validators-tests.factor +++ b/basis/validators/validators-tests.factor @@ -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 diff --git a/basis/validators/validators.factor b/basis/validators/validators.factor index cf45e7b13f..45287a60c6 100644 --- a/basis/validators/validators.factor +++ b/basis/validators/validators.factor @@ -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 ;