File jqValidatorTest.js (r31)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	module("validate form");
	test('we can check rules with jQuery and be passed a form',
	     function() {
		 expect(2);
		 var rules = function(form) {
		     equals(form.age.value,23,"age is 23");
		     return false;
		 };
		 $('#testform').checkWith(rules).find('input[name=age]').val("23").end().submit();
		 equals($('#testform input[name=age]').val(),"23");
	     });

	test('we can create a field with default rule',
	     function() {
		 var age = new Field("age");
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(age.validate({}).result,"age validate anything");
	     }
	    );

    	test('we can attach a rule to a field',
	     function() {
		 var age = new Field("age");
		 age.must(beANumber().and(range().from(10).to(12)));
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(!age.validate({}).result,"age is undefined");
		 ok(!age.validate({age: "toto"}).result,"age is not anumber");
	     }
	    );

	test("a field has a value",
	     function() {
		 var values = {age: 23};
		 var age = new Field("age",values);
		 equals(age.value, 23,"age is 23");
	     });

	test("a field has an undefined value",
	     function() {
		 var age = new Field("age");
		 equals(age.value, undefined,"age is undefined");
	     });

	var rules = function(form) {
	     with(form) {
		 age.must(beANumber().and(range().from(18)));
		 name.must(match("^[A-Z-]+$"));
		 nbYearDL.must(beANumber().and(range().from(0).to(function() {
								      return age.value - 18; })));
									  }
	     };

	test('checkWith invoke rules and validate form with errors',
	     function() {
		 $('#testform').checkWith(rules,'#errorslist');
		 $('#testform')
		     .find('input[name=nbYearDL]').val("6").end()
		     .find('input[name=age]').val("23").end()
		     .find('input[name=name]').val("Dupont");

		 $('#testform').submit();
		 ok($('#errorslist>li').size() == 2,'two errors expected');
	     });

	test('validate a form',
	     function() {
		 $('#testform').checkWith(rules,'#errorslist');
		 $('#testform')
		     .find('input[name=nbYearDL]').val("6").end()
		     .find('input[name=age]').val("27").end()
		     .find('input[name=name]').val("DUPONT");

		 $('#testform').submit();
		 ok($('#errorslist>li').size() == 0,'no error expected');
	     });
    }
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r30)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	module("validate form");
	test('we can check rules with jQuery and be passed a form',
	     function() {
		 expect(2);
		 var rules = function(form) {
		     equals(form.age,23,"age is 23");
		     return false;
		 };
		 $('#testform').checkWith(rules).find('input[name=age]').val("23").end().submit();
		 equals($('#testform input[name=age]').val(),"23");
	     });

	test('we can create a field with default rule',
	     function() {
		 var age = new Field("age");
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(age.validate({}).result,"age validate anything");
	     }
	    );

    	test('we can attach a rule to a field',
	     function() {
		 var age = new Field("age");
		 age.must(beANumber().and(range().from(10).to(12)));
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(!age.validate({}).result,"age is undefined");
		 ok(!age.validate({age: "toto"}).result,"age is not anumber");
	     }
	    );

	test("a field has a value",
	     function() {
		 var values = {age: 23};
		 var age = new Field("age",values);
		 equals(age.value, 23,"age is 23");
	     });

	test("a field has an undefined value",
	     function() {
		 var age = new Field("age");
		 equals(age.value, undefined,"age is undefined");
	     });

	var rules = function(form) {
	     with(form) {
		 age.must(beANumber().and(range().from(18)));
		 name.must(match("^[A-Z-]+$"));
		 nbYearDL.must(beANumber().and(range().from(0).to(function() {
								      return age.value - 18; })));
									  }
	     };

	test('checkWith invoke rules and validate form with errors',
	     function() {
		 $('#testform').checkWith(rules,'#errorslist');
		 $('#testform')
		     .find('input[name=nbYearDL]').val("6").end()
		     .find('input[name=age]').val("23").end()
		     .find('input[name=name]').val("Dupont");

		 $('#testform').submit();
		 ok($('#errorslist>li').size() == 2,'two errors expected');
	     });

	test('validate a form',
	     function() {
		 $('#testform').checkWith(rules,'#errorslist');
		 $('#testform')
		     .find('input[name=nbYearDL]').val("6").end()
		     .find('input[name=age]').val("27").end()
		     .find('input[name=name]').val("DUPONT");

		 $('#testform').submit();
		 ok($('#errorslist>li').size() == 0,'no error expected');
	     });
    }
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r29)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	module("validate form");
	test('we can check rules with jQuery and be passed a form',
	     function() {
		 expect(2);
		 var rules = function(form) {
		     equals(form.age,23,"age is 23");
		     return false;
		 };
		 $('#testform').checkWith(rules).find('input[name=age]').val("23").end().submit();
		 equals($('#testform input[name=age]').val(),"23");
	     });

	test('we can create a field with default rule',
	     function() {
		 var age = new Field("age");
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(age.validate({}).result,"age validate anything");
	     }
	    );

    	test('we can attach a rule to a field',
	     function() {
		 var age = new Field("age");
		 age.must(beANumber().and(range().from(10).to(12)));
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(!age.validate({}).result,"age is undefined");
		 ok(!age.validate({age: "toto"}).result,"age is not anumber");
	     }
	    );

	test("a field has a value",
	     function() {
		 var values = {age: 23};
		 var age = new Field("age",values);
		 equals(age.value, 23,"age is 23");
	     });

	test("a field has an undefined value",
	     function() {
		 var age = new Field("age");
		 equals(age.value, undefined,"age is undefined");
	     });

	test('checkWith invoke rules and validate form with errors',
	     function() {
		 var rules = function(form) {
		     with(form) {
			 age.must(beANumber().and(range().from(18)));
			 name.must(match("^[A-Z-]+$"));
			 nbYearDL.must(beANumber().and(range().from(0).to(function() {
									      return age.value - 18; })));
									      }
		 };
		 $('#testform').checkWith(rules,'#errorslist');
		 $('#testform')
		     .find('input[name=nbYearDL]').val("6").end()
		     .find('input[name=age]').val("23").end()
		     .find('input[name=name]').val("Dupont");

		 $('#testform').submit();
		 ok($('#errorslist>li').size() == 2,'two errors expected');
	     });
    }
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r27)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	module("validate form");
	test('we can check rules with jQuery and be passed a form',
	     function() {
		 expect(2);
		 var rules = function(form) {
		     equals(form.age,23,"age is 23");
		     return false;
		 };
		 $('#testform').checkWith(rules).find('input[name=age]').val("23").end().submit();
		 equals($('#testform input[name=age]').val(),"23");
	     });

	test('we can create a field with default rule',
	     function() {
		 var age = new Field("age");
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(age.validate({}).result,"age validate anything");
	     }
	    );

    	test('we can attach a rule to a field',
	     function() {
		 var age = new Field("age");
		 age.must(beANumber().and(range().from(10).to(12)));
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(!age.validate({}).result,"age is undefined");
		 ok(!age.validate({age: "toto"}).result,"age is not anumber");
	     }
	    );

	test("a field has a value",
	     function() {
		 var values = {age: 23};
		 var age = new Field("age",values);
		 equals(age.value, 23,"age is 23");
	     });

	test("a field has an undefined value",
	     function() {
		 var age = new Field("age");
		 equals(age.value, undefined,"age is undefined");
	     });

    }
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r26)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	module("validate form");
	test('we can check rules with jQuery and be passed a form',
	     function() {
		 expect(2);
		 var rules = function(form) {
		     equals(form.age,23,"age is 23");
		     return false;
		 };
		 $('#testform').checkWith(rules).find('input[name=age]').val("23").end().submit();
		 equals($('#testform input[name=age]').val(),"23");
	     });

	test('we can create a field with default rule',
	     function() {
		 var age = new Field("age");
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(age.validate({}).result,"age validate anything");
	     }
	    );

    	test('we can attach a rule to a field',
	     function() {
		 var age = new Field("age");
		 age.must(beANumber().and(range().from(10).to(12)));
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(!age.validate({}).result,"age is undefined");
		 ok(!age.validate({age: "toto"}).result,"age is not anumber");
	     }
	    );

	test("a field has a value",
	     function() {
		 var values = {age: 23};
		 var age = new Field("age",values);
		 equals(age.value, 23,"age is 23");
	     });

	test("a field has an undefined value",
	     function() {
		 var age = new Field("age");
		 equals(age.value, undefined,"age is undefined");
	     });
    }
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r25)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	module("validate form");
	test('we can check rules with jQuery and be passed a form',
	     function() {
		 expect(2);
		 var rules = function(form) {
		     equals(form.age,23,"age is 23");
		     return false;
		 };
		 $('#testform').checkWith(rules).find('input[name=age]').val("23").end().submit();
		 equals($('#testform input[name=age]').val(),"23");
	     });

	test('we can create a field with default rule',
	     function() {
		 var age = new Field("age");
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(age.validate({}).result,"age validate anything");
	     }
	    );

    	test('we can attach a rule to a field',
	     function() {
		 var age = new Field("age");
		 age.must(beANumber().and(range().from(10).to(12)));
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(!age.validate({}).result,"age is undefined");
		 ok(!age.validate({age: "toto"}).result,"age is not anumber");
	     }
	    );

	test("a field has a value",
	     function() {
		 var values = {age: 23};
		 var age = new Field("age",values);
		 equals(age.value, 23,"age is 23");
	     });
    }
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r24)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	module("validate form");
	test('we can check rules with jQuery and be passed a form',
	     function() {
		 expect(2);
		 var rules = function(form) {
		     equals(form.age,23,"age is 23");
		     return false;
		 };
		 $('#testform').checkWith(rules).find('input[name=age]').val("23").end().submit();
		 equals($('#testform input[name=age]').val(),"23");
	     });

	test('we can create a field with default rule',
	     function() {
		 var age = new Field("age");
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(age.validate({}).result,"age validate anything");
	     }
	    );

    	test('we can attach a rule to a field',
	     function() {
		 var age = new Field("age");
		 age.must(beANumber().and(range().from(10).to(12)));
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(!age.validate({}).result,"age is undefined");
		 ok(!age.validate({age: "toto"}).result,"age is not anumber");
	     }
	    );

	test("a field has a value",
	     function() {
		 var values = [{
				   name: "age",
				   value: 23
			       }];
		 var age = new Field("age",values);
		 equals(age.value, 23,"age is 23");
	     });
    }
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r22)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	module("validate form");
	test('we can check rules with jQuery and be passed a form',
	     function() {
		 expect(2);
		 var rules = function(form) {
		     equals(form.age,23,"age is 23");
		     return false;
		 };
		 $('#testform').checkWith(rules).find('input[name=age]').val("23").end().submit();
		 equals($('#testform input[name=age]').val(),"23");
	     });

	test('we can create a field with default rule',
	     function() {
		 var age = new Field("age");
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(age.validate({}).result,"age validate anything");
	     }
	    );

    	test('we can attach a rule to a field',
	     function() {
		 var age = new Field("age");
		 age.must(beANumber().and(range().from(10).to(12)));
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(!age.validate({}).result,"age is undefined");
		 ok(!age.validate({age: "toto"}).result,"age is not anumber");
	     }
	    );
}
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r21)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	module("validate form");
	test('we can check rules with jQuery and be passed a form',
	     function() {
		 expect(2);
		 var rules = function(form) {
		     equals(form.age,23,"age is 23");
		     return false;
		 };
		 $('#testform').checkWith(rules).find('input[name=age]').val("23").end().submit();
		 equals($('#testform input[name=age]').val(),"23");
	     });

	test('we can create a field with default rule',
	     function() {
		 var age = new Field("age");
		 ok(age.validate({age: 10}).result,"age of 10 is valid with default");
		 ok(age.validate({}).result,"age validate anything");
	     }
	    );
}
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r19)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	module("validate form");
	test('we can check rules with jQuery and be passed a form',
	     function() {
		 expect(2);
		 var rules = function(form) {
		     equals(form.age,23,"age is 23");
		     return false;
		 };
		 $('#testform').checkWith(rules).find('input[name=age]').val("23").end().submit();
		 equals($('#testform input[name=age]').val(),"23");
	     });

	test('we can create a field with default rule',
	     function() {
		 var age = new Field("age");
		 ok(age.validate({age: 10}),"age of 10 is valid with default");
		 ok(age.validate({}),"age validate anything");
	     }
	    );
}
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r18)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	module("validate form");
	test('we can check rules with jQuery and be passed a form',
	     function() {
		 expect(2);
		 var rules = function(form) {
		     equals(form.age,23,"age is 23");
		     return false;
		 };
		 $('#testform').checkWith(rules).find('input[name=age]').val("23").end().submit();
		 equals($('#testform input[name=age]').val(),"23");
	     });

}
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r17)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	module("validate form");
	test('we can check rules with jQuery and be passed a form',
	     function() {
		 expect(2);
		 var rules = function(form) {
		     equals(form.age,23,"age is 23");
		     return false;
		 };
		 $('#testform').checkWith(rules).find('input[name=age]').val("23").end().submit();
	     });

}
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r14)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

	test('we can use factory methods',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new Not(new ValidateRange().from(14).and(new ValidateRange().to(16))));
		var sameComplex = range().from(10).and(range().to(12)).or(not(range().from(14).and(range().to(16))));
		 ok(complex.isOk(13).result,"13 is ok");
		 ok(!complex.isOk(15).result,"15 is ko");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );

}
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r11)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });

	test('we can nest or/ands/nots in expressions (A and B) or (C and D)',
	    function() {
		var complex = new ValidateRange().from(10).and(new ValidateRange().to(12))
		    .or(new ValidateRange().from(14).and(new ValidateRange().to(16)));
		 ok(!complex.isOk(13).result,"13 is ko");
		 ok(complex.isOk(15).result,"15 is ok");
		 ok(complex.isOk(10).result,"10 is ok");
	     }
	    );
}
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r9)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });

	test('we can combine arbitrary expressions',
	    function() {
		var complex = new Not(new ValidateRange(10,13)).and(new ValidateRange(7,10).or(new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
	     });
}
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r7)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });

	test('we can combine 2 different base combinators',
	     function() {
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 var checkNum = beANumber().and(lb.or(ub));
		 ok(!checkNum.isOk("toto").result,
			"'toto' is not a number");
		 ok(checkNum.isOk(11).result,
		     "11 is OK with or combinators");
	     });
}
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r6)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });
	
}
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r5)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });

        test('we can use .or() to link base validators',
	     function() {
		 var range = new Not(new ValidateRange().from(12).to(25));
		 var lb = new ValidateRange().from(25);
		 var ub = new ValidateRange().to(12);
		 equals(range.isOk(12).result, lb.or(ub).isOk(12).result,
			"12 is KO with or combinators");
		 equals(range.isOk(11).result, lb.or(ub).isOk(11).result,
			"11 is OK with or combinators");
	     });
}
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r4)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13).result,
			"13 is Ok with combinators");
	     });
   }
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r3)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

	module('combinators');
        test('we can use .and() to link base validators',
	     function() {
		 var range = new ValidateRange().from(12).to(25);
		 var lb = new ValidateRange().from(12);
		 var ub = new ValidateRange().to(25);
		 equals(range.isOk(13).result, lb.and(ub).isOk(13),
			"13 is Ok with combinators");
	     });
   }
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r1)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){

    $ = jQuery;

    with (jqUnit) {
        module('base validators');
        test('we have base validators available',
             function() {
                 var regexp = new ValidateRegex("^\\d+\\w+$");
                 var check = regexp.isOk("113dfsf121");
                 var range = new ValidateRange().from(12).to(25);
                 ok(range.isOk(14).result ,"'14' is ok");
                 ok(beANumber().isOk(14).result ,"14 is a number");
                 var not = new Not(new ValidateRange(10,13));
                 ok(not.isOk(13).result,"13 is ok");
                 ok(!not.isOk(10).result,"10 is ko");

                 var complex = new And(new Not(new ValidateRange(10,13))
				       ,new Or(new ValidateRange(7,10)
					       ,new ValidateRange(13,18)));
		 ok(complex.isOk(13).result,"13 is ok");
             });

   }
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidatorTest.js (r0)

<<< >>>
 

/*
 * Copyright (C) 2008 - OQube / Arnaud Bailly
 */
function doTest(){
    
    $ = jQuery;
        
    with (jqUnit) {
        module('First module');
        test('First test',
             function() {
                 ok(true,"fake test");
             });

   }
}

jQuery(document).ready(
    function() {
        function waitForShow() {
            if(jqValidator)
                doTest();
            else
                setTimeout(waitForShow,200);
        }
        setTimeout(waitForShow,200);
    }
    );

File jqValidator.js (r29)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

Validator.prototype.and = function(that) {
    return new And(this,that);
};

Validator.prototype.or = function(that) {
    return new Or(this,that);
};

function range(lb,ub) {
    return new ValidateRange(lb,ub);
};

function not(expr) {
    return new Not(expr);
};

function match(regexp) {
    return new ValidateRegex(regexp);
};

$.fn.checkWith = function(rules, errorslist) {
    this.submit(function() {
            var values = {};
            var form  = {};
	    var input = $(this).serializeArray();
	    input.forEach(function(element,index)  {
                    form[element.name] = new Field(element.name,values);
                    values[element.name] = element.value;
                });
            rules(form);
            var errors = input.map(function(elem,index) {
				 return form[elem.name].validate(values);
			     })
			.filter(function(res) { return !res.result; })
			.map(function(result) {
				 $("<li></li>").append(result.message).appendTo(errorslist);
				 return result;
			     });
            return errors.length == 0;
    });
    return this;
};

var alwaysTrue = {isOk:function() { return {result:true}; }};

function Field(name,values) {
    this.name = name;
    this.validator = alwaysTrue;
    this.values = values || {};
};

Field.prototype = {
    get value() {
        return this.values[this.name];
    },

    validate: function(values) {
        this.values = values || {};
        return this.validator.isOk(this.value);
    },

    must: function(rule) {
        this.validator = rule;
    }
};

File jqValidator.js (r28)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

Validator.prototype.and = function(that) {
    return new And(this,that);
};

Validator.prototype.or = function(that) {
    return new Or(this,that);
};

function range(lb,ub) {
    return new ValidateRange(lb,ub);
};

function not(expr) {
    return new Not(expr);
};

function matches(regexp) {
    return new ValidateRegex(regexp);
};

$.fn.checkWith = function(rules) {
    this.submit(function() {
            var form = {};
            $(this).serializeArray().forEach(function(element,index)  {
                    form[element.name] = element.value;
                });
            return rules(form);
        });
    return this;
};

var alwaysTrue = {isOk:function() { return {result:true}}};

function Field(name,values) {
    this.name = name;
    this.validator = alwaysTrue;
    this.values = values || {};
};

Field.prototype = {
    get value() {
        return this.values[this.name];
    },
    
    validate: function(values) {
        this.values = values || {};
        return this.validator.isOk(this.value);
    },

    must: function(rule) {
        this.validator = rule;
    }
};

File jqValidator.js (r27)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

Validator.prototype.and = function(that) {
    return new And(this,that);
};

Validator.prototype.or = function(that) {
    return new Or(this,that);
};

function range(lb,ub) {
    return new ValidateRange(lb,ub);
};

function not(expr) {
    return new Not(expr);
};

function matches(regexp) {
    return new ValidateRegex(regexp);
};

$.fn.checkWith = function(rules) {
    this.submit(function() {
            var form = {};
            $(this).serializeArray().forEach(function(element,index)  {
                    form[element.name] = element.value;
                });
            return rules(form);
        });
    return this;
};

var alwaysTrue = {isOk:function() { return {result:true}}};

function Field(name,values) {
    this.name = name;
    this.validator = alwaysTrue;
    this.values = values || {};
};

Field.prototype = {
    get value() {
        return this.values[this.name];
    },
    
    validate: function(form) {
        return this.validator.isOk(form[this.name]);
    },

    must: function(rule) {
        this.validator = rule;
    }
};

File jqValidator.js (r25)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

Validator.prototype.and = function(that) {
    return new And(this,that);
};

Validator.prototype.or = function(that) {
    return new Or(this,that);
};

function range(lb,ub) {
    return new ValidateRange(lb,ub);
};

function not(expr) {
    return new Not(expr);
};

function matches(regexp) {
    return new ValidateRegex(regexp);
};

$.fn.checkWith = function(rules) {
    this.submit(function() {
            var form = {};
            $(this).serializeArray().forEach(function(element,index)  {
                    form[element.name] = element.value;
                });
            return rules(form);
        });
    return this;
};

var alwaysTrue = {isOk:function() { return {result:true}}};

function Field(name,values) {
    this.name = name;
    this.validator = alwaysTrue;
    this.values = values;
};

Field.prototype = {
    get value() {
        return this.values[this.name];
    },
    
    validate: function(form) {
        return this.validator.isOk(form[this.name]);
    },

    must: function(rule) {
        this.validator = rule;
    }
};

File jqValidator.js (r23)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

Validator.prototype.and = function(that) {
    return new And(this,that);
};

Validator.prototype.or = function(that) {
    return new Or(this,that);
};

function range(lb,ub) {
    return new ValidateRange(lb,ub);
};

function not(expr) {
    return new Not(expr);
};

function matches(regexp) {
    return new ValidateRegex(regexp);
};

$.fn.checkWith = function(rules) {
    this.submit(function() {
            var form = {};
            $(this).serializeArray().forEach(function(element,index)  {
                    form[element.name] = element.value;
                });
            return rules(form);
        });
    return this;
};

var alwaysTrue = {isOk:function() { return {result:true}}};

function Field(name) {
    this.name = name;
    this.validator = alwaysTrue;
};

Field.prototype = {
    validate: function(form) {
        return this.validator.isOk(form[this.name]);
    },

    must: function(rule) {
        this.validator = rule;
    }
};

File jqValidator.js (r21)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

Validator.prototype.and = function(that) {
    return new And(this,that);
};

Validator.prototype.or = function(that) {
    return new Or(this,that);
};

function range(lb,ub) {
    return new ValidateRange(lb,ub);
};

function not(expr) {
    return new Not(expr);
};

function matches(regexp) {
    return new ValidateRegex(regexp);
};

$.fn.checkWith = function(rules) {
    this.submit(function() {
            var form = {};
            $(this).serializeArray().forEach(function(element,index)  {
                    form[element.name] = element.value;
                });
            return rules(form);
        });
    return this;
};

function alwaysTrue(form){
    return {result:true};
};

function Field(name) {
    this.name = name;
    this.validator = alwaysTrue;
};

Field.prototype = {
    validate: function(form) {
        return this.validator(form);
    }
};

File jqValidator.js (r20)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

Validator.prototype.and = function(that) {
    return new And(this,that);
};

Validator.prototype.or = function(that) {
    return new Or(this,that);
};

function range(lb,ub) {
    return new ValidateRange(lb,ub);
};

function not(expr) {
    return new Not(expr);
};

function matches(regexp) {
    return new ValidateRegex(regexp);
};

$.fn.checkWith = function(rules) {
    this.submit(function() {
            var form = {};
            $(this).serializeArray().forEach(function(element,index)  {
                    form[element.name] = element.value;
                });
            return rules(form);
        });
    return this;
};

function Field(name) {
    this.name = name;
};

Field.prototype = {
    validate: function(form) {
        return true;
    }
};

File jqValidator.js (r19)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

Validator.prototype.and = function(that) {
    return new And(this,that);
};

Validator.prototype.or = function(that) {
    return new Or(this,that);
};

function range(lb,ub) {
    return new ValidateRange(lb,ub);
};

function not(expr) {
    return new Not(expr);
};

function matches(regexp) {
    return new ValidateRegex(regexp);
};

$.fn.checkWith = function(rules) {
    this.submit(function() {
            var form = {};
            $(this).serializeArray().forEach(function(element,index)  {
                    form[element.name] = element.value;
                });
            return rules(form);
        });
    return this;
};


File jqValidator.js (r18)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

Validator.prototype.and = function(that) {
    return new And(this,that);
};

Validator.prototype.or = function(that) {
    return new Or(this,that);
};

function range(lb,ub) {
    return new ValidateRange(lb,ub);
};

function not(expr) {
    return new Not(expr);
};

function matches(regexp) {
    return new ValidateRegex(regexp);
};

$.fn.checkWith = function(rules) {
    this.submit(function() {
            var form = {};
            $(this).serializeArray().forEach(function(element,index)  {
                    form[element.name] = element.value;
                });
            return rules(form);
        });
    return this;
};

File jqValidator.js (r16)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

Validator.prototype.and = function(that) {
    return new And(this,that);
};

Validator.prototype.or = function(that) {
    return new Or(this,that);
};

function range(lb,ub) {
    return new ValidateRange(lb,ub);
};

function not(expr) {
    return new Not(expr);
};

function matches(regexp) {
    return new ValidateRegex(regexp);
};

File jqValidator.js (r15)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

Validator.prototype.and = function(that) {
    return new And(this,that);
};

Validator.prototype.or = function(that) {
    return new Or(this,that);
};

function range(lb,ub) {
    return new ValidateRange(lb,ub);
};

function not(expr) {
    return new Not(expr);
};

File jqValidator.js (r8)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

Validator.prototype.and = function(that) {
    return new And(this,that);
};

Validator.prototype.or = function(that) {
    return new Or(this,that);
};

File jqValidator.js (r6)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

ValidateRange.prototype.and = function(that) {
    return new And(this,that);
};

ValidateRange.prototype.or = function(that) {
    return new Or(this,that);
};

File jqValidator.js (r4)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};

ValidateRange.prototype.and = function(that) {
    return new And(this,that);
};

File jqValidator.js (r0)

<<< >>>
 

/**
 * @fileoverview
 * Javascript main code.
 */
var jqValidator  = jqValidator || {};