How to use assert method in wpt

Best JavaScript code snippet using wpt

methods.js

Source:methods.js Github

copy

Full Screen

1function methodTest( methodName ) {2 var v = jQuery( "#form" ).validate(),3 method = $.validator.methods[ methodName ],4 element = $( "#firstname" )[ 0 ];5 return function( value, param ) {6 element.value = value;7 return method.call( v, value, element, param );8 };9}10/**11 * Creates a dummy DOM file input with FileList12 * @param filename13 * @param mimeType14 * @returns {{}}15 */16function acceptFileDummyInput( filename, mimeType ) {17 function dummy() {18 return file;19 }20 // https://developer.mozilla.org/en-US/docs/Web/API/FileList21 var file = {22 name: filename,23 size: 500001,24 type: mimeType25 },26 fileList = {27 0: file,28 length: 1,29 item: dummy30 };31 return {32 type: "file",33 files: fileList,34 nodeName: "INPUT",35 value: "/tmp/fake_value",36 hasAttribute: function() { return false; }37 };38}39QUnit.module( "methods" );40QUnit.test( "default messages", function( assert ) {41 var m = $.validator.methods;42 $.each( m, function( key ) {43 assert.ok( jQuery.validator.messages[ key ], key + " has a default message." );44 } );45} );46QUnit.test( "digit", function( assert ) {47 var method = methodTest( "digits" );48 assert.ok( method( "123" ), "Valid digits" );49 assert.ok( !method( "123.000" ), "Invalid digits" );50 assert.ok( !method( "123.000,00" ), "Invalid digits" );51 assert.ok( !method( "123.0.0,0" ), "Invalid digits" );52 assert.ok( !method( "x123" ), "Invalid digits" );53 assert.ok( !method( "100.100,0,0" ), "Invalid digits" );54} );55QUnit.test( "url", function( assert ) {56 var method = methodTest( "url" );57 assert.ok( method( "http://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );58 assert.ok( method( "https://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );59 assert.ok( method( "ftp://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );60 assert.ok( method( "http://www.føtex.dk/" ), "Valid url, danish unicode characters" );61 assert.ok( method( "http://bösendorfer.de/" ), "Valid url, german unicode characters" );62 assert.ok( method( "http://142.42.1.1" ), "Valid IP Address" );63 assert.ok( method( "http://pro.photography" ), "Valid long TLD" );64 assert.ok( method( "//code.jquery.com/jquery-1.11.3.min.js" ), "Valid protocol-relative url" );65 assert.ok( method( "//142.42.1.1" ), "Valid protocol-relative IP Address" );66 assert.ok( !method( "htp://code.jquery.com/jquery-1.11.3.min.js" ), "Invalid protocol" );67 assert.ok( !method( "http://192.168.8." ), "Invalid IP Address" );68 assert.ok( !method( "http://bassistance" ), "Invalid url" ); // Valid69 assert.ok( !method( "http://bassistance." ), "Invalid url" ); // Valid70 assert.ok( !method( "http://bassistance,de" ), "Invalid url" );71 assert.ok( !method( "http://bassistance;de" ), "Invalid url" );72 assert.ok( !method( "http://.bassistancede" ), "Invalid url" );73 assert.ok( !method( "bassistance.de" ), "Invalid url" );74} );75QUnit.test( "url2 (tld optional)", function( assert ) {76 var method = methodTest( "url2" );77 assert.ok( method( "http://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );78 assert.ok( method( "https://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );79 assert.ok( method( "ftp://bassistance.de/jquery/plugin.php?bla=blu" ), "Valid url" );80 assert.ok( method( "http://www.føtex.dk/" ), "Valid url, danish unicode characters" );81 assert.ok( method( "http://bösendorfer.de/" ), "Valid url, german unicode characters" );82 assert.ok( method( "http://192.168.8.5" ), "Valid IP Address" );83 assert.ok( !method( "http://192.168.8." ), "Invalid IP Address" );84 assert.ok( method( "http://bassistance" ), "Invalid url" );85 assert.ok( method( "http://bassistance." ), "Invalid url" );86 assert.ok( !method( "http://bassistance,de" ), "Invalid url" );87 assert.ok( !method( "http://bassistance;de" ), "Invalid url" );88 assert.ok( !method( "http://.bassistancede" ), "Invalid url" );89 assert.ok( !method( "bassistance.de" ), "Invalid url" );90} );91QUnit.test( "email", function( assert ) {92 var method = methodTest( "email" );93 assert.ok( method( "name@domain.tld" ), "Valid email" );94 assert.ok( method( "name@domain.tl" ), "Valid email" );95 assert.ok( method( "bart+bart@tokbox.com" ), "Valid email" );96 assert.ok( method( "bart+bart@tokbox.travel" ), "Valid email" );97 assert.ok( method( "n@d.tld" ), "Valid email" );98 assert.ok( method( "bla.blu@g.mail.com" ), "Valid email" );99 assert.ok( method( "name@domain" ), "Valid email" );100 assert.ok( method( "name.@domain.tld" ), "Valid email" );101 assert.ok( method( "name@website.a" ), "Valid email" );102 assert.ok( method( "name@pro.photography" ), "Valid email" );103 assert.ok( !method( "ole@føtex.dk" ), "Invalid email" );104 assert.ok( !method( "jörn@bassistance.de" ), "Invalid email" );105 assert.ok( !method( "name" ), "Invalid email" );106 assert.ok( !method( "test@test-.com" ), "Invalid email" );107 assert.ok( !method( "name@" ), "Invalid email" );108 assert.ok( !method( "name,@domain.tld" ), "Invalid email" );109 assert.ok( !method( "name;@domain.tld" ), "Invalid email" );110 assert.ok( !method( "name;@domain.tld." ), "Invalid email" );111} );112QUnit.test( "number", function( assert ) {113 var method = methodTest( "number" );114 assert.ok( method( "123" ), "Valid number" );115 assert.ok( method( "-123" ), "Valid number" );116 assert.ok( method( "123,000" ), "Valid number" );117 assert.ok( method( "-123,000" ), "Valid number" );118 assert.ok( method( "123,000.00" ), "Valid number" );119 assert.ok( method( "-123,000.00" ), "Valid number" );120 assert.ok( !method( "-" ), "Invalid number" );121 assert.ok( !method( "123.000,00" ), "Invalid number" );122 assert.ok( !method( "123.0.0,0" ), "Invalid number" );123 assert.ok( !method( "x123" ), "Invalid number" );124 assert.ok( !method( "100.100,0,0" ), "Invalid number" );125 assert.ok( method( "" ), "Blank is valid" );126 assert.ok( method( "123" ), "Valid decimal" );127 assert.ok( method( "123000" ), "Valid decimal" );128 assert.ok( method( "123000.12" ), "Valid decimal" );129 assert.ok( method( "-123000.12" ), "Valid decimal" );130 assert.ok( method( "123.000" ), "Valid decimal" );131 assert.ok( method( "123,000.00" ), "Valid decimal" );132 assert.ok( method( "-123,000.00" ), "Valid decimal" );133 assert.ok( method( ".100" ), "Valid decimal" );134 assert.ok( !method( "1230,000.00" ), "Invalid decimal" );135 assert.ok( !method( "123.0.0,0" ), "Invalid decimal" );136 assert.ok( !method( "x123" ), "Invalid decimal" );137 assert.ok( !method( "100.100,0,0" ), "Invalid decimal" );138} );139/* Disabled for now, need to figure out how to test localized methods140QUnit.test("numberDE", function( assert ) {141 var method = methodTest("numberDE");142 assert.ok( method( "123" ), "Valid numberDE" );143 assert.ok( method( "-123" ), "Valid numberDE" );144 assert.ok( method( "123.000" ), "Valid numberDE" );145 assert.ok( method( "-123.000" ), "Valid numberDE" );146 assert.ok( method( "123.000,00" ), "Valid numberDE" );147 assert.ok( method( "-123.000,00" ), "Valid numberDE" );148 assert.ok(!method( "123,000.00" ), "Invalid numberDE" );149 assert.ok(!method( "123,0,0.0" ), "Invalid numberDE" );150 assert.ok(!method( "x123" ), "Invalid numberDE" );151 assert.ok(!method( "100,100.0.0" ), "Invalid numberDE" );152 assert.ok( method( "" ), "Blank is valid" );153 assert.ok( method( "123" ), "Valid decimalDE" );154 assert.ok( method( "123000" ), "Valid decimalDE" );155 assert.ok( method( "123000,12" ), "Valid decimalDE" );156 assert.ok( method( "-123000,12" ), "Valid decimalDE" );157 assert.ok( method( "123.000" ), "Valid decimalDE" );158 assert.ok( method( "123.000,00" ), "Valid decimalDE" );159 assert.ok( method( "-123.000,00" ), "Valid decimalDE" )160 assert.ok(!method( "123.0.0,0" ), "Invalid decimalDE" );161 assert.ok(!method( "x123" ), "Invalid decimalDE" );162 assert.ok(!method( "100,100.0.0" ), "Invalid decimalDE" );163});164*/165QUnit.test( "date", function( assert ) {166 var method = methodTest( "date" );167 assert.ok( method( "06/06/1990" ), "Valid date" );168 assert.ok( method( "6/6/06" ), "Valid date" );169 assert.ok( !method( "1990x-06-06" ), "Invalid date" );170} );171QUnit.test( "dateISO", function( assert ) {172 var method = methodTest( "dateISO" );173 assert.ok( method( "1990-06-06" ), "Valid date" );174 assert.ok( method( "1990-01-01" ), "Valid date" );175 assert.ok( method( "1990-01-31" ), "Valid date" );176 assert.ok( method( "1990-12-01" ), "Valid date" );177 assert.ok( method( "1990-12-31" ), "Valid date" );178 assert.ok( method( "1990/06/06" ), "Valid date" );179 assert.ok( method( "1990-6-6" ), "Valid date" );180 assert.ok( method( "1990/6/6" ), "Valid date" );181 assert.ok( !method( "1990-106-06" ), "Invalid date" );182 assert.ok( !method( "190-06-06" ), "Invalid date" );183 assert.ok( !method( "1990-00-06" ), "Invalid date" );184 assert.ok( !method( "1990-13-01" ), "Invalid date" );185 assert.ok( !method( "1990-01-00" ), "Invalid date" );186 assert.ok( !method( "1990-01-32" ), "Invalid date" );187 assert.ok( !method( "1990-13-32" ), "Invalid date" );188} );189/* Disabled for now, need to figure out how to test localized methods190QUnit.test("dateDE", function( assert ) {191 var method = methodTest("dateDE");192 assert.ok( method( "03.06.1984" ), "Valid dateDE" );193 assert.ok( method( "3.6.84" ), "Valid dateDE" );194 assert.ok(!method( "6-6-06" ), "Invalid dateDE" );195 assert.ok(!method( "1990-06-06" ), "Invalid dateDE" );196 assert.ok(!method( "06/06/1990" ), "Invalid dateDE" );197 assert.ok(!method( "6/6/06" ), "Invalid dateDE" );198});199*/200QUnit.test( "required", function( assert ) {201 var v = jQuery( "#form" ).validate(),202 method = $.validator.methods.required,203 e = $( "#text1, #text1b, #hidden2, #select1, #select2" );204 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ] ), "Valid text input" );205 assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ] ), "Invalid text input" );206 assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ] ), "Invalid text input" );207 assert.ok( !method.call( v, e[ 3 ].value, e[ 3 ] ), "Invalid select" );208 assert.ok( method.call( v, e[ 4 ].value, e[ 4 ] ), "Valid select" );209 e = $( "#area1, #area2, #pw1, #pw2" );210 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ] ), "Valid textarea" );211 assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ] ), "Invalid textarea" );212 assert.ok( method.call( v, e[ 2 ].value, e[ 2 ] ), "Valid password input" );213 assert.ok( !method.call( v, e[ 3 ].value, e[ 3 ] ), "Invalid password input" );214 e = $( "#radio1, #radio2, #radio3" );215 assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ] ), "Invalid radio" );216 assert.ok( method.call( v, e[ 1 ].value, e[ 1 ] ), "Valid radio" );217 assert.ok( method.call( v, e[ 2 ].value, e[ 2 ] ), "Valid radio" );218 e = $( "#check1, #check2" );219 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ] ), "Valid checkbox" );220 assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ] ), "Invalid checkbox" );221 e = $( "#select1, #select2, #select3, #select4" );222 assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ] ), "Invalid select" );223 assert.ok( method.call( v, e[ 1 ].value, e[ 1 ] ), "Valid select" );224 assert.ok( method.call( v, e[ 2 ].value, e[ 2 ] ), "Valid select" );225 assert.ok( method.call( v, e[ 3 ].value, e[ 3 ] ), "Valid select" );226} );227QUnit.test( "required with dependencies", function( assert ) {228 var v = jQuery( "#form" ).validate(),229 method = $.validator.methods.required,230 e = $( "#hidden2, #select1, #area2, #radio1, #check2" );231 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], "asffsaa" ), "Valid text input due to dependency not met" );232 assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ], "input" ), "Invalid text input" );233 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], function() { return false; } ), "Valid text input due to dependency not met" );234 assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ], function() { return true; } ), "Invalid text input" );235 assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], "asfsfa" ), "Valid select due to dependency not met" );236 assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ], "input" ), "Invalid select" );237 assert.ok( method.call( v, e[ 2 ].value, e[ 2 ], "asfsafsfa" ), "Valid textarea due to dependency not met" );238 assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], "input" ), "Invalid textarea" );239 assert.ok( method.call( v, e[ 3 ].value, e[ 3 ], "asfsafsfa" ), "Valid radio due to dependency not met" );240 assert.ok( !method.call( v, e[ 3 ].value, e[ 3 ], "input" ), "Invalid radio" );241 assert.ok( method.call( v, e[ 4 ].value, e[ 4 ], "asfsafsfa" ), "Valid checkbox due to dependency not met" );242 assert.ok( !method.call( v, e[ 4 ].value, e[ 4 ], "input" ), "Invalid checkbox" );243} );244QUnit.test( "minlength", function( assert ) {245 var v = jQuery( "#form" ).validate(),246 method = $.validator.methods.minlength,247 param = 2,248 e = $( "#text1, #text1c, #text2, #text3" );249 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" );250 assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" );251 assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" );252 assert.ok( method.call( v, e[ 3 ].value, e[ 3 ], param ), "Valid text input" );253 e = $( "#check1, #check2, #check3" );254 assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid checkbox" );255 assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid checkbox" );256 assert.ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid checkbox" );257 e = $( "#select1, #select2, #select3, #select4, #select5" );258 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid select " + e[ 0 ].id );259 assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ], param ), "Invalid select " + e[ 1 ].id );260 assert.ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Valid select " + e[ 2 ].id );261 assert.ok( method.call( v, e[ 3 ].value, e[ 3 ], param ), "Valid select " + e[ 3 ].id );262 assert.ok( method.call( v, e[ 4 ].value, e[ 4 ], param ), "Valid select " + e[ 4 ].id );263} );264QUnit.test( "maxlength", function( assert ) {265 var v = jQuery( "#form" ).validate(),266 method = $.validator.methods.maxlength,267 param = 4,268 e = $( "#text1, #text2, #text3" );269 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" );270 assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" );271 assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" );272 e = $( "#check1, #check2, #check3" );273 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid checkbox" );274 assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Invalid checkbox" );275 assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid checkbox" );276 e = $( "#select1, #select2, #select3, #select4" );277 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid select" );278 assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid select" );279 assert.ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Valid select" );280 assert.ok( !method.call( v, e[ 3 ].value, e[ 3 ], param ), "Invalid select" );281} );282QUnit.test( "rangelength", function( assert ) {283 var v = jQuery( "#form" ).validate(),284 method = $.validator.methods.rangelength,285 param = [ 2, 4 ],286 e = $( "#text1, #text2, #text3" );287 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" );288 assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ], param ), "Invalid text input" );289 assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" );290} );291QUnit.test( "min", function( assert ) {292 var v = jQuery( "#form" ).validate(),293 method = $.validator.methods.min,294 param = 8,295 e = $( "#value1, #value2, #value3" );296 assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ], param ), "Invalid text input" );297 assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" );298 assert.ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Valid text input" );299} );300QUnit.test( "max", function( assert ) {301 var v = jQuery( "#form" ).validate(),302 method = $.validator.methods.max,303 param = 12,304 e = $( "#value1, #value2, #value3" );305 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" );306 assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" );307 assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" );308} );309QUnit.test( "range", function( assert ) {310 var v = jQuery( "#form" ).validate(),311 method = $.validator.methods.range,312 param = [ 4, 12 ],313 e = $( "#value1, #value2, #value3" );314 assert.ok( !method.call( v, e[ 0 ].value, e[ 0 ], param ), "Invalid text input" );315 assert.ok( method.call( v, e[ 1 ].value, e[ 1 ], param ), "Valid text input" );316 assert.ok( !method.call( v, e[ 2 ].value, e[ 2 ], param ), "Invalid text input" );317} );318QUnit.test( "step", function( assert ) {319 var v = jQuery( "#form" ).validate(),320 method = $.validator.methods.step,321 param = 1000,322 e = $( "#value1, #value2, #value3, #value4" );323 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Valid text input" );324 assert.ok( !method.call( v, e[ 1 ].value, e[ 1 ], param ), "Invalid text input" );325 assert.ok( method.call( v, e[ 2 ].value, e[ 2 ], param ), "Valid text input" );326} );327QUnit.test( "#1760 - step modulo/remainder regression tests", function( assert ) {328 var v = jQuery( "#form" ).validate(),329 method = $.validator.methods.step,330 param = 0.00125,331 e = $( "#value4" );332 for ( var i = 1; i <= 1000; i++ ) {333 e[ 0 ].value = ( param * 100000 * i ) / 100000;334 assert.ok( method.call( v, e[ 0 ].value, e[ 0 ], param ), "Ensure " + e[ 0 ].value + " % " + param + " === 0 is valid" );335 }336} );337QUnit.test( "equalTo", function( assert ) {338 var v = jQuery( "#form" ).validate(),339 method = $.validator.methods.equalTo,340 e = $( "#text1, #text2" );341 assert.ok( method.call( v, "Test", e[ 0 ], "#text1" ), "Text input" );342 assert.ok( method.call( v, "T", e[ 1 ], "#text2" ), "Another one" );343} );344QUnit.test( "extension", function( assert ) {345 var method = methodTest( "extension" ),346 v;347 assert.ok( method( "picture.gif" ), "Valid default accept type" );348 assert.ok( method( "picture.jpg" ), "Valid default accept type" );349 assert.ok( method( "picture.jpeg" ), "Valid default accept type" );350 assert.ok( method( "picture.png" ), "Valid default accept type" );351 assert.ok( !method( "picture.pgn" ), "Invalid default accept type" );352 v = jQuery( "#form" ).validate();353 method = function( value, param ) {354 return $.validator.methods.extension.call( v, value, $( "#text1" )[ 0 ], param );355 };356 assert.ok( method( "picture.doc", "doc" ), "Valid custom accept type" );357 assert.ok( method( "picture.pdf", "doc|pdf" ), "Valid custom accept type" );358 assert.ok( method( "picture.pdf", "pdf|doc" ), "Valid custom accept type" );359 assert.ok( !method( "picture.pdf", "doc" ), "Invalid custom accept type" );360 assert.ok( !method( "picture.doc", "pdf" ), "Invalid custom accept type" );361 assert.ok( method( "picture.pdf", "doc,pdf" ), "Valid custom accept type, comma separated" );362 assert.ok( method( "picture.pdf", "pdf,doc" ), "Valid custom accept type, comma separated" );363 assert.ok( !method( "picture.pdf", "gop,top" ), "Invalid custom accept type, comma separated" );364} );365QUnit.test( "remote", function( assert ) {366 assert.expect( 7 );367 var e = $( "#username" ),368 v = $( "#userForm" ).validate( {369 rules: {370 username: {371 required: true,372 remote: "users.php"373 }374 },375 messages: {376 username: {377 required: "Please",378 remote: jQuery.validator.format( "{0} in use" )379 }380 },381 submitHandler: function() {382 assert.ok( false, "submitHandler may never be called when validating only elements" );383 }384 } ),385 done = assert.async();386 $( document ).ajaxStop( function() {387 $( document ).unbind( "ajaxStop" );388 assert.equal( v.size(), 1, "There must be one error" );389 assert.equal( v.errorList[ 0 ].message, "Peter in use" );390 $( document ).ajaxStop( function() {391 $( document ).unbind( "ajaxStop" );392 assert.equal( v.size(), 1, "There must be one error" );393 assert.equal( v.errorList[ 0 ].message, "Peter2 in use" );394 done();395 } );396 e.val( "Peter2" );397 assert.strictEqual( v.element( e ), true, "new value, new request; dependency-mismatch considered as valid though" );398 } );399 assert.strictEqual( v.element( e ), false, "invalid element, nothing entered yet" );400 e.val( "Peter" );401 assert.strictEqual( v.element( e ), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );402} );403QUnit.test( "remote, pending class added to element while call outstanding", function( assert ) {404 assert.expect( 3 );405 var e = $( "#username" ),406 done = assert.async(),407 v = $( "#userForm" ).validate( {408 rules: {409 username: {410 remote: {411 url: "users.php",412 complete: function() {413 assert.strictEqual( e.hasClass( "pending" ), false, "not pending since ajax call complete" );414 done();415 }416 }417 }418 }419 } );420 assert.strictEqual( e.hasClass( "pending" ), false, "not pending since no data entered" );421 e.val( "Peter" );422 // This fires off the validation:423 v.element( e );424 assert.strictEqual( e.hasClass( "pending" ), true, "pending while validation outstanding" );425} );426QUnit.test( "remote, customized ajax options", function( assert ) {427 assert.expect( 2 );428 var done = assert.async();429 $( "#userForm" ).validate( {430 rules: {431 username: {432 required: true,433 remote: {434 url: "users.php",435 type: "POST",436 beforeSend: function( request, settings ) {437 assert.deepEqual( settings.type, "POST" );438 assert.deepEqual( settings.data, "username=asdf&email=email.com" );439 },440 data: {441 email: function() {442 return "email.com";443 }444 },445 complete: function() {446 done();447 }448 }449 }450 }451 } );452 $( "#username" ).val( "asdf" );453 $( "#userForm" ).valid();454} );455QUnit.test( "remote extensions", function( assert ) {456 assert.expect( 5 );457 var e = $( "#username" ),458 v = $( "#userForm" ).validate( {459 rules: {460 username: {461 required: true,462 remote: "users2.php"463 }464 },465 messages: {466 username: {467 required: "Please"468 }469 },470 submitHandler: function() {471 assert.ok( false, "submitHandler may never be called when validating only elements" );472 }473 } ),474 done = assert.async();475 $( document ).ajaxStop( function() {476 $( document ).unbind( "ajaxStop" );477 if ( v.size() !== 0 ) {478 assert.ok( "There must be one error" );479 assert.equal( v.errorList[ 0 ].message, "asdf is already taken, please try something else" );480 v.element( e );481 assert.equal( v.errorList[ 0 ].message, "asdf is already taken, please try something else", "message doesn't change on revalidation" );482 }483 done();484 } );485 assert.strictEqual( v.element( e ), false, "invalid element, nothing entered yet" );486 e.val( "asdf" );487 assert.strictEqual( v.element( e ), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );488} );489QUnit.test( "remote, data previous querystring", function( assert ) {490 assert.expect( 4 );491 var succeeded = 0,492 $f = $( "#firstnamec" ),493 $l = $( "#lastnamec" ),494 done1 = assert.async(),495 done2 = assert.async(),496 done3 = assert.async(),497 v = $( "#testForm1clean" ).validate( {498 rules: {499 lastname: {500 remote: {501 url: "users.php",502 type: "POST",503 data: {504 firstname: function() {505 return $f.val();506 }507 },508 complete: function() {509 succeeded++;510 }511 }512 }513 }514 } );515 $f.val( "first-name" );516 $l.val( "last-name" );517 assert.strictEqual( succeeded, 0, "no valid call means no successful validation" );518 v.element( $l );519 setTimeout( function() {520 assert.strictEqual( succeeded, 1, "first valid check should submit given first name" );521 done1();522 v.element( $l );523 setTimeout( function() {524 assert.strictEqual( succeeded, 1, "second valid check should not resubmit given same first name" );525 done2();526 $f.val( "different-first-name" );527 v.element( $l );528 setTimeout( function() {529 assert.strictEqual( succeeded, 2, "third valid check should resubmit given different first name" );530 done3();531 } );532 } );533 } );534} );535QUnit.test( "remote, highlight all invalid fields", function( assert ) {536 assert.expect( 3 );537 var done = assert.async(),538 $form = $( "#testForm1" ),539 $firstnameField = $form.find( "input[name='firstname']" ),540 $lastnameField = $form.find( "input[name='lastname']" ),541 $somethingField = $form.find( "input[name='something']" ),542 validateOptions = {543 rules: {544 firstname: {545 required: true546 },547 lastname: {548 required: true549 },550 something: {551 required: true,552 remote: {553 url: "response.php",554 type: "post",555 data: {556 responseText: "false"557 }558 }559 }560 }561 };562 $firstnameField.val( "" );563 $lastnameField.val( "" );564 $somethingField.val( "something value" );565 $form.validate( validateOptions );566 $form.valid();567 setTimeout( function() {568 assert.equal( $firstnameField.hasClass( "error" ), true, "Field 'firstname' should have a '.error' class" );569 assert.equal( $lastnameField.hasClass( "error" ), true, "Field 'lastname' should have a '.error' class" );570 assert.equal( $somethingField.hasClass( "error" ), true, "Field 'something' should have a '.error' class" );571 done();572 }, 500 );573} );574QUnit.test( "remote, unhighlighted should be invoked after being highlighted/invalid", function( assert ) {575 assert.expect( 6 );576 var done1 = assert.async(),577 done2 = assert.async(),578 $form = $( "#testForm25" ),579 $somethingField = $form.find( "input[name='something25']" ),580 responseText = "false",581 response = function() { return responseText; },582 validateOptions = {583 highlight: function( e ) {584 $( e ).addClass( "error" );585 assert.ok( true, "highlight should be called" );586 },587 unhighlight: function( e ) {588 $( e ).removeClass( "error" );589 assert.ok( true, "unhighlight should be called" );590 },591 rules: {592 something25: {593 required: true,594 remote: {595 url: "response.php",596 type: "post",597 data: {598 responseText: response599 },600 async: false601 }602 }603 }604 };605 $somethingField.val( "something value" );606 var v = $form.validate( validateOptions );607 v.element( $somethingField );608 setTimeout( function() {609 assert.equal( $somethingField.hasClass( "error" ), true, "Field 'something' should have the error class" );610 done1();611 $somethingField.val( "something value 2" );612 responseText = "true";613 v.element( $somethingField );614 setTimeout( function() {615 assert.equal( $somethingField.hasClass( "error" ), false, "Field 'something' should not have the error class" );616 done2();617 }, 500 );618 }, 500 );619} );620QUnit.test( "Fix #697: remote validation uses wrong error messages", function( assert ) {621 var e = $( "#username" ),622 done1 = assert.async(),623 done2 = assert.async(),624 done3 = assert.async(),625 v = $( "#userForm" ).validate( {626 rules: {627 username: {628 required: true,629 remote: {630 url: "users.php"631 }632 }633 },634 messages: {635 username: {636 remote: $.validator.format( "{0} in use" )637 }638 }639 } );640 $( "#userForm" ).valid();641 e.val( "Peter" );642 v.element( e );643 setTimeout( function() {644 assert.equal( v.errorList[ 0 ].message, "Peter in use" );645 done1();646 e.val( "something" );647 v.element( e );648 e.val( "Peter" );649 v.element( e );650 setTimeout( function() {651 assert.equal( v.errorList[ 0 ].message, "Peter in use" );652 done2();653 e.val( "asdf" );654 v.element( e );655 setTimeout( function() {656 assert.equal( v.errorList[ 0 ].message, "asdf in use", "error message should be updated" );657 done3();658 } );659 } );660 } );661} );662QUnit.module( "additional methods" );663QUnit.test( "phone (us)", function( assert ) {664 var method = methodTest( "phoneUS" );665 assert.ok( method( "1(212)-999-2345" ), "Valid US phone number" );666 assert.ok( method( "212 999 2344" ), "Valid US phone number" );667 assert.ok( method( "212-999-0983" ), "Valid US phone number" );668 assert.ok( !method( "111-123-5434" ), "Invalid US phone number. Area Code cannot start with 1" );669 assert.ok( !method( "212 123 4567" ), "Invalid US phone number. NXX cannot start with 1" );670 assert.ok( !method( "234-911-5678" ), "Invalid US phone number, because the exchange code cannot be in the form N11" );671 assert.ok( !method( "911-333-5678" ), "Invalid US phone number, because the area code cannot be in the form N11" );672 assert.ok( method( "234-912-5678" ), "Valid US phone number" );673} );674QUnit.test( "phoneUK", function( assert ) {675 var method = methodTest( "phoneUK" );676 assert.ok( method( "0117 333 5555" ), "Valid UK Phone Number" );677 assert.ok( method( "0121 555 5555" ), "Valid UK Phone Number" );678 assert.ok( method( "01633 555555" ), "Valid UK Phone Number" );679 assert.ok( method( "01298 28555" ), "Valid UK Phone Number" );680 assert.ok( method( "015395 55555" ), "Valid UK Phone Number" );681 assert.ok( method( "016977 3999" ), "Valid UK Phone Number" );682 assert.ok( method( "020 3000 5555" ), "Valid UK Phone Number" );683 assert.ok( method( "024 7500 5555" ), "Valid UK Phone Number" );684 assert.ok( method( "0333 555 5555" ), "Valid UK Phone Number" );685 assert.ok( method( "0500 555555" ), "Valid UK Phone Number" );686 assert.ok( method( "055 3555 5555" ), "Valid UK Phone Number" );687 assert.ok( method( "07122 555555" ), "Valid UK Phone Number" );688 assert.ok( method( "07222 555555" ), "Valid UK Phone Number" );689 assert.ok( method( "07322 555555" ), "Valid UK Phone Number" );690 assert.ok( method( "0800 555 5555" ), "Valid UK Phone Number" );691 assert.ok( method( "0800 355555" ), "Valid UK Phone Number" );692 assert.ok( method( "0843 555 5555" ), "Valid UK Phone Number" );693 assert.ok( method( "0872 555 5555" ), "Valid UK Phone Number" );694 assert.ok( method( "0903 555 5555" ), "Valid UK Phone Number" );695 assert.ok( method( "0983 555 5555" ), "Valid UK Phone Number" );696 assert.ok( method( "(07122) 555555" ), "Valid UK Phone Number" );697 assert.ok( method( "(07222) 555555" ), "Valid UK Phone Number" );698 assert.ok( method( "(07322) 555555" ), "Valid UK Phone Number" );699 assert.ok( method( "+44 7122 555 555" ), "Valid UK Phone Number" );700 assert.ok( method( "+44 7222 555 555" ), "Valid UK Phone Number" );701 assert.ok( method( "+44 7322 555 555" ), "Valid UK Phone Number" );702 assert.ok( !method( "7222 555555" ), "Invalid UK Phone Number" );703 assert.ok( !method( "+44 07222 555555" ), "Invalid UK Phone Number" );704} );705QUnit.test( "mobileUK", function( assert ) {706 var method = methodTest( "mobileUK" );707 assert.ok( method( "07134234323" ), "Valid UK Mobile Number" );708 assert.ok( method( "07334234323" ), "Valid UK Mobile Number" );709 assert.ok( method( "07624234323" ), "Valid UK Mobile Number" );710 assert.ok( method( "07734234323" ), "Valid UK Mobile Number" );711 assert.ok( method( "+447134234323" ), "Valid UK Mobile Number" );712 assert.ok( method( "+447334234323" ), "Valid UK Mobile Number" );713 assert.ok( method( "+447624234323" ), "Valid UK Mobile Number" );714 assert.ok( method( "+447734234323" ), "Valid UK Mobile Number" );715 assert.ok( !method( "07034234323" ), "Invalid UK Mobile Number" );716 assert.ok( !method( "0753423432" ), "Invalid UK Mobile Number" );717 assert.ok( !method( "07604234323" ), "Invalid UK Mobile Number" );718 assert.ok( !method( "077342343234" ), "Invalid UK Mobile Number" );719 assert.ok( !method( "044342343234" ), "Invalid UK Mobile Number" );720 assert.ok( !method( "+44753423432" ), "Invalid UK Mobile Number" );721 assert.ok( !method( "+447604234323" ), "Invalid UK Mobile Number" );722 assert.ok( !method( "+4477342343234" ), "Invalid UK Mobile Number" );723 assert.ok( !method( "+4444342343234" ), "Invalid UK Mobile Number" );724} );725QUnit.test( "dateITA", function( assert ) {726 var method = methodTest( "dateITA" );727 assert.ok( method( "01/01/1900" ), "Valid date ITA" );728 assert.ok( method( "17/10/2010" ), "Valid date ITA" );729 assert.ok( !method( "01/13/1990" ), "Invalid date ITA" );730 assert.ok( !method( "01.01.1900" ), "Invalid date ITA" );731 assert.ok( !method( "01/01/199" ), "Invalid date ITA" );732} );733QUnit.test( "dateFA", function( assert ) {734 var method = methodTest( "dateFA" );735 assert.ok( method( "1342/12/29" ), "Valid date FA" );736 assert.ok( method( "1342/12/30" ), "Valid date FA" );737 assert.ok( method( "1361/6/31" ), "Valid date FA" );738 assert.ok( method( "1321/11/30" ), "Valid date FA" );739 assert.ok( method( "1361/1/1" ), "Valid date FA" );740 assert.ok( method( "1020/3/3" ), "Valid date FA" );741 assert.ok( method( "1020/03/3" ), "Valid date FA" );742 assert.ok( method( "1020/3/03" ), "Valid date FA" );743 assert.ok( method( "1020/03/03" ), "Valid date FA" );744 assert.ok( method( "1001/7/30" ), "Valid date FA" );745 assert.ok( !method( "1000/1/32" ), "Invalid date FA" );746 assert.ok( !method( "1323/12/31" ), "Invalid date FA" );747 assert.ok( !method( "1361/0/11" ), "Invalid date FA" );748 assert.ok( !method( "63/4/4" ), "Invalid date FA" );749 assert.ok( !method( "15/6/1361" ), "Invalid date FA" );750} );751QUnit.test( "iban", function( assert ) {752 var method = methodTest( "iban" );753 assert.ok( method( "NL20INGB0001234567" ), "Valid IBAN" );754 assert.ok( method( "DE68 2105 0170 0012 3456 78" ), "Valid IBAN" );755 assert.ok( method( "NL20 INGB0001234567" ), "Valid IBAN: invalid spacing" );756 assert.ok( method( "NL20 INGB 00 0123 4567" ), "Valid IBAN: invalid spacing" );757 assert.ok( method( "XX40INGB000123456712341234" ), "Valid (more or less) IBAN: unknown country, but checksum OK" );758 assert.ok( !method( "1" ), "Invalid IBAN: too short" );759 assert.ok( !method( "NL20INGB000123456" ), "Invalid IBAN: too short" );760 assert.ok( !method( "NL20INGB00012345678" ), "Invalid IBAN: too long" );761 assert.ok( !method( "NL20INGB0001234566" ), "Invalid IBAN: checksum incorrect" );762 assert.ok( !method( "DE68 2105 0170 0012 3456 7" ), "Invalid IBAN: too short" );763 assert.ok( !method( "DE68 2105 0170 0012 3456 789" ), "Invalid IBAN: too long" );764 assert.ok( !method( "DE68 2105 0170 0012 3456 79" ), "Invalid IBAN: checksum incorrect" );765 assert.ok( !method( "NL54INGB00012345671234" ), "Invalid IBAN too long, BUT CORRECT CHECKSUM" );766 assert.ok( !method( "XX00INGB000123456712341234" ), "Invalid IBAN: unknown country and checksum incorrect" );767 // Sample IBANs for different countries768 assert.ok( method( "AL47 2121 1009 0000 0002 3569 8741" ), "Valid IBAN - AL" );769 assert.ok( method( "AD12 0001 2030 2003 5910 0100" ), "Valid IBAN - AD" );770 assert.ok( method( "AT61 1904 3002 3457 3201" ), "Valid IBAN - AT" );771 assert.ok( method( "AZ21 NABZ 0000 0000 1370 1000 1944" ), "Valid IBAN - AZ" );772 assert.ok( method( "BH67 BMAG 0000 1299 1234 56" ), "Valid IBAN - BH" );773 assert.ok( method( "BE62 5100 0754 7061" ), "Valid IBAN - BE" );774 assert.ok( method( "BA39 1290 0794 0102 8494" ), "Valid IBAN - BA" );775 assert.ok( method( "BG80 BNBG 9661 1020 3456 78" ), "Valid IBAN - BG" );776 assert.ok( method( "HR12 1001 0051 8630 0016 0" ), "Valid IBAN - HR" );777 assert.ok( method( "CH93 0076 2011 6238 5295 7" ), "Valid IBAN - CH" );778 assert.ok( method( "CY17 0020 0128 0000 0012 0052 7600" ), "Valid IBAN - CY" );779 assert.ok( method( "CZ65 0800 0000 1920 0014 5399" ), "Valid IBAN - CZ" );780 assert.ok( method( "DK50 0040 0440 1162 43" ), "Valid IBAN - DK" );781 assert.ok( method( "EE38 2200 2210 2014 5685" ), "Valid IBAN - EE" );782 assert.ok( method( "FO97 5432 0388 8999 44" ), "Valid IBAN - FO" );783 assert.ok( method( "FI21 1234 5600 0007 85" ), "Valid IBAN - FI" );784 assert.ok( method( "FR14 2004 1010 0505 0001 3M02 606" ), "Valid IBAN - FR" );785 assert.ok( method( "GE29 NB00 0000 0101 9049 17" ), "Valid IBAN - GE" );786 assert.ok( method( "DE89 3704 0044 0532 0130 00" ), "Valid IBAN - DE" );787 assert.ok( method( "GI75 NWBK 0000 0000 7099 453" ), "Valid IBAN - GI" );788 assert.ok( method( "GR16 0110 1250 0000 0001 2300 695" ), "Valid IBAN - GR" );789 assert.ok( method( "GL56 0444 9876 5432 10" ), "Valid IBAN - GL" );790 assert.ok( method( "HU42 1177 3016 1111 1018 0000 0000" ), "Valid IBAN - HU" );791 assert.ok( method( "IS14 0159 2600 7654 5510 7303 39" ), "Valid IBAN - IS" );792 assert.ok( method( "IE29 AIBK 9311 5212 3456 78" ), "Valid IBAN - IE" );793 assert.ok( method( "IL62 0108 0000 0009 9999 999" ), "Valid IBAN - IL" );794 assert.ok( method( "IT40 S054 2811 1010 0000 0123 456" ), "Valid IBAN - IT" );795 assert.ok( method( "LV80 BANK 0000 4351 9500 1" ), "Valid IBAN - LV" );796 assert.ok( method( "LB62 0999 0000 0001 0019 0122 9114" ), "Valid IBAN - LB" );797 assert.ok( method( "LI21 0881 0000 2324 013A A" ), "Valid IBAN - LI" );798 assert.ok( method( "LT12 1000 0111 0100 1000" ), "Valid IBAN - LT" );799 assert.ok( method( "LU28 0019 4006 4475 0000" ), "Valid IBAN - LU" );800 assert.ok( method( "MK07 2501 2000 0058 984" ), "Valid IBAN - MK" );801 assert.ok( method( "MT84 MALT 0110 0001 2345 MTLC AST0 01S" ), "Valid IBAN - MT" );802 assert.ok( method( "MU17 BOMM 0101 1010 3030 0200 000M UR" ), "Valid IBAN - MU" );803 assert.ok( method( "MD24 AG00 0225 1000 1310 4168" ), "Valid IBAN - MD" );804 assert.ok( method( "MC93 2005 2222 1001 1223 3M44 555" ), "Valid IBAN - MC" );805 assert.ok( method( "ME25 5050 0001 2345 6789 51" ), "Valid IBAN - ME" );806 assert.ok( method( "NL39 RABO 0300 0652 64" ), "Valid IBAN - NL" );807 assert.ok( method( "NO93 8601 1117 947" ), "Valid IBAN - NO" );808 assert.ok( method( "PK36 SCBL 0000 0011 2345 6702" ), "Valid IBAN - PK" );809 assert.ok( method( "PL60 1020 1026 0000 0422 7020 1111" ), "Valid IBAN - PL" );810 assert.ok( method( "PT50 0002 0123 1234 5678 9015 4" ), "Valid IBAN - PT" );811 assert.ok( method( "RO49 AAAA 1B31 0075 9384 0000" ), "Valid IBAN - RO" );812 assert.ok( method( "SM86 U032 2509 8000 0000 0270 100" ), "Valid IBAN - SM" );813 assert.ok( method( "SA03 8000 0000 6080 1016 7519" ), "Valid IBAN - SA" );814 assert.ok( method( "RS35 2600 0560 1001 6113 79" ), "Valid IBAN - RS" );815 assert.ok( method( "SK31 1200 0000 1987 4263 7541" ), "Valid IBAN - SK" );816 assert.ok( method( "SI56 1910 0000 0123 438" ), "Valid IBAN - SI" );817 assert.ok( method( "ES80 2310 0001 1800 0001 2345" ), "Valid IBAN - ES" );818 assert.ok( method( "SE35 5000 0000 0549 1000 0003" ), "Valid IBAN - SE" );819 assert.ok( method( "CH93 0076 2011 6238 5295 7" ), "Valid IBAN - CH" );820 assert.ok( method( "TN59 1000 6035 1835 9847 8831" ), "Valid IBAN - TN" );821 assert.ok( method( "TR33 0006 1005 1978 6457 8413 26" ), "Valid IBAN - TR" );822 assert.ok( method( "AE07 0331 2345 6789 0123 456" ), "Valid IBAN - AE" );823 assert.ok( method( "GB29 NWBK 6016 1331 9268 19" ), "Valid IBAN - GB" );824} );825/**826 * BIC tests (For BIC definition take a look on the implementation itself)827 */828QUnit.test( "bic", function( assert ) {829 var method = methodTest( "bic" );830 assert.ok( !method( "PBNKDEF" ), "Invalid BIC: too short" );831 assert.ok( !method( "DEUTDEFFA1" ), "Invalid BIC: disallowed length" );832 assert.ok( !method( "PBNKDEFFXXX1" ), "Invalid BIC: too long" );833 assert.ok( !method( "1BNKDEFF" ), "Invalid BIC: invalid digit" );834 assert.ok( !method( "PBNKDE1F" ), "Invalid BIC: invalid digit" );835 assert.ok( !method( "PBNKDEFO" ), "Invalid BIC: invalid char" );836 assert.ok( !method( "INGDDEFFXAA" ), "Invalid BIC: invalid char" );837 assert.ok( !method( "DEUTDEF0" ), "Invalid BIC: invalid digit" );838 assert.ok( method( "DEUTDEFF" ), "Valid BIC" );839 assert.ok( method( "DEUTDEFFXXX" ), "Valid BIC" );840 assert.ok( method( "PBNKDE2F" ), "Valid BIC" );841 assert.ok( method( "INGDDEFF101" ), "Valid BIC" );842 assert.ok( method( "INGDDEF2134" ), "Valid BIC" );843 assert.ok( method( "INGDDE91XXX" ), "Valid BIC" );844 assert.ok( method( "INGDDEF2" ), "Valid BIC" );845 assert.ok( method( "AAFFFRP1" ), "Valid BIC" );846 assert.ok( method( "DEUTDEFFAB1" ), "Valid BIC" );847 assert.ok( method( "DEUTDEFFAXX" ), "Valid BIC" );848 assert.ok( method( "SSKNDE77XXX" ), "Valid BIC" );849 // BIC accept also lowercased values850 assert.ok( !method( "pbnkdef" ), "Invalid BIC: too short" );851 assert.ok( !method( "deutdeffa1" ), "Invalid BIC: disallowed length" );852 assert.ok( !method( "pbnkdeffxxx1" ), "Invalid BIC: too long" );853 assert.ok( !method( "1bnkdeff" ), "Invalid BIC: invalid digit" );854 assert.ok( !method( "ingddeffxaa" ), "Invalid BIC: invalid char" );855 assert.ok( method( "deutdeff" ), "Valid BIC (lowercase value)" );856 assert.ok( method( "deutdeffxxx" ), "Valid BIC (lowercase value)" );857 assert.ok( method( "pbnkde2f" ), "Valid BIC (lowercase value)" );858 assert.ok( method( "ingdde91xxx" ), "Valid BIC (lowercase value)" );859 assert.ok( method( "ingddef2" ), "Valid BIC (lowercase value)" );860 assert.ok( method( "deutdeffab1" ), "Valid BIC (lowercase value)" );861} );862QUnit.test( "postcodeUK", function( assert ) {863 var method = methodTest( "postcodeUK" );864 assert.ok( method( "AA9A 9AA" ), "Valid postcode" );865 assert.ok( method( "A9A 9AA" ), "Valid postcode" );866 assert.ok( method( "A9 9AA" ), "Valid postcode" );867 assert.ok( method( "A99 9AA" ), "Valid postcode" );868 assert.ok( method( "AA9 9AA" ), "Valid postcode" );869 assert.ok( method( "AA99 9AA" ), "Valid postcode" );870 // Channel Island871 assert.ok( !method( "AAAA 9AA" ), "Invalid postcode" );872 assert.ok( !method( "AA-2640" ), "Invalid postcode" );873 assert.ok( !method( "AAA AAA" ), "Invalid postcode" );874 assert.ok( !method( "AA AAAA" ), "Invalid postcode" );875 assert.ok( !method( "A AAAA" ), "Invalid postcode" );876 assert.ok( !method( "AAAAA" ), "Invalid postcode" );877 assert.ok( !method( "999 999" ), "Invalid postcode" );878 assert.ok( !method( "99 9999" ), "Invalid postcode" );879 assert.ok( !method( "9 9999" ), "Invalid postcode" );880 assert.ok( !method( "99999" ), "Invalid postcode" );881} );882QUnit.test( "dateNL", function( assert ) {883 var method = methodTest( "dateNL" );884 assert.ok( method( "01-01-1900" ), "Valid date NL" );885 assert.ok( method( "01.01.1900" ), "Valid date NL" );886 assert.ok( method( "01/01/1900" ), "Valid date NL" );887 assert.ok( method( "01-01-00" ), "Valid date NL" );888 assert.ok( method( "1-01-1900" ), "Valid date NL" );889 assert.ok( method( "10-10-1900" ), "Valid date NL" );890 assert.ok( !method( "0-01-1900" ), "Invalid date NL" );891 assert.ok( !method( "00-01-1900" ), "Invalid date NL" );892 assert.ok( !method( "35-01-1990" ), "Invalid date NL" );893 assert.ok( !method( "01.01.190" ), "Invalid date NL" );894} );895QUnit.test( "phoneNL", function( assert ) {896 var method = methodTest( "phoneNL" );897 assert.ok( method( "0701234567" ), "Valid phone NL" );898 assert.ok( method( "0687654321" ), "Valid phone NL" );899 assert.ok( method( "020-1234567" ), "Valid phone NL" );900 assert.ok( method( "020 - 12 34 567" ), "Valid phone NL" );901 assert.ok( method( "010-2345678" ), "Valid phone NL" );902 assert.ok( method( "+3120-1234567" ), "Valid phone NL" );903 assert.ok( method( "+31(0)10-2345678" ), "Valid phone NL" );904 assert.ok( !method( "020-123456" ), "Invalid phone NL: too short" );905 assert.ok( !method( "020-12345678" ), "Invalid phone NL: too long" );906 assert.ok( !method( "-0201234567" ), "Invalid phone NL" );907 assert.ok( !method( "+310201234567" ), "Invalid phone NL: no 0 after +31 allowed" );908} );909QUnit.test( "mobileNL", function( assert ) {910 var method = methodTest( "mobileNL" );911 assert.ok( method( "0612345678" ), "Valid NL Mobile Number" );912 assert.ok( method( "06-12345678" ), "Valid NL Mobile Number" );913 assert.ok( method( "06-12 345 678" ), "Valid NL Mobile Number" );914 assert.ok( method( "+316-12345678" ), "Valid NL Mobile Number" );915 assert.ok( method( "+31(0)6-12345678" ), "Valid NL Mobile Number" );916 assert.ok( !method( "abcdefghij" ), "Invalid NL Mobile Number: text" );917 assert.ok( !method( "0123456789" ), "Invalid NL Mobile Number: should start with 06" );918 assert.ok( !method( "0823456789" ), "Invalid NL Mobile Number: should start with 06" );919 assert.ok( !method( "06-1234567" ), "Invalid NL Mobile Number: too short" );920 assert.ok( !method( "06-123456789" ), "Invalid NL Mobile Number: too long" );921 assert.ok( !method( "-0612345678" ), "Invalid NL Mobile Number" );922 assert.ok( !method( "+310612345678" ), "Invalid NL Mobile Number: no 0 after +31 allowed" );923} );924QUnit.test( "postalcodeNL", function( assert ) {925 var method = methodTest( "postalcodeNL" );926 assert.ok( method( "1234AB" ), "Valid NL Postal Code" );927 assert.ok( method( "1234ab" ), "Valid NL Postal Code" );928 assert.ok( method( "1234 AB" ), "Valid NL Postal Code" );929 assert.ok( method( "6789YZ" ), "Valid NL Postal Code" );930 assert.ok( !method( "123AA" ), "Invalid NL Postal Code: not enough digits" );931 assert.ok( !method( "12345ZZ" ), "Invalid NL Postal Code: too many digits" );932 assert.ok( !method( "1234 AA" ), "Invalid NL Postal Code: too many spaces" );933 assert.ok( !method( "AA1234" ), "Invalid NL Postal Code" );934 assert.ok( !method( "1234-AA" ), "Invalid NL Postal Code" );935} );936QUnit.test( "bankaccountNL", function( assert ) {937 var method = methodTest( "bankaccountNL" );938 assert.ok( method( "755490975" ), "Valid NL bank account" );939 assert.ok( method( "75 54 90 975" ), "Valid NL bank account" );940 assert.ok( method( "123456789" ), "Valid NL bank account" );941 assert.ok( method( "12 34 56 789" ), "Valid NL bank account" );942 assert.ok( !method( "12 3456789" ), "Valid NL bank account: inconsistent spaces" );943 assert.ok( !method( "123 45 67 89" ), "Valid NL bank account: incorrect spaces" );944 assert.ok( !method( "755490971" ), "Invalid NL bank account" );945 assert.ok( !method( "755490973" ), "Invalid NL bank account" );946 assert.ok( !method( "755490979" ), "Invalid NL bank account" );947 assert.ok( !method( "123456781" ), "Invalid NL bank account" );948 assert.ok( !method( "123456784" ), "Invalid NL bank account" );949 assert.ok( !method( "123456788" ), "Invalid NL bank account" );950} );951QUnit.test( "giroaccountNL", function( assert ) {952 var method = methodTest( "giroaccountNL" );953 assert.ok( method( "123" ), "Valid NL giro account" );954 assert.ok( method( "1234567" ), "Valid NL giro account" );955 assert.ok( !method( "123456788" ), "Invalid NL giro account" );956} );957QUnit.test( "bankorgiroaccountNL", function( assert ) {958 var method = methodTest( "bankorgiroaccountNL" );959 assert.ok( method( "123" ), "Valid NL giro account" );960 assert.ok( method( "1234567" ), "Valid NL giro account" );961 assert.ok( method( "123456789" ), "Valid NL bank account" );962 assert.ok( !method( "12345678" ), "Invalid NL bank or giro account" );963 assert.ok( !method( "123456788" ), "Invalid NL bank or giro account" );964} );965QUnit.test( "time", function( assert ) {966 var method = methodTest( "time" );967 assert.ok( method( "00:00" ), "Valid time, lower bound" );968 assert.ok( method( "23:59" ), "Valid time, upper bound" );969 assert.ok( method( "3:59" ), "Valid time, single digit hour" );970 assert.ok( !method( "12" ), "Invalid time" );971 assert.ok( !method( "29:59" ), "Invalid time" );972 assert.ok( !method( "00:60" ), "Invalid time" );973 assert.ok( !method( "24:60" ), "Invalid time" );974 assert.ok( !method( "24:00" ), "Invalid time" );975 assert.ok( !method( "30:00" ), "Invalid time" );976 assert.ok( !method( "29:59" ), "Invalid time" );977 assert.ok( !method( "120:00" ), "Invalid time" );978 assert.ok( !method( "12:001" ), "Invalid time" );979 assert.ok( !method( "12:00a" ), "Invalid time" );980} );981QUnit.test( "time12h", function( assert ) {982 var method = methodTest( "time12h" );983 assert.ok( method( "12:00 AM" ), "Valid time, lower bound, am" );984 assert.ok( method( "11:59 AM" ), "Valid time, upper bound, am" );985 assert.ok( method( "12:00AM" ), "Valid time, no space, am" );986 assert.ok( method( "12:00PM" ), "Valid time, no space, pm" );987 assert.ok( method( "12:00 PM" ), "Valid time, lower bound, pm" );988 assert.ok( method( "11:59 PM" ), "Valid time, upper bound, pm" );989 assert.ok( method( "11:59 am" ), "Valid time, also accept lowercase" );990 assert.ok( method( "11:59 pm" ), "Valid time, also accept lowercase" );991 assert.ok( method( "1:59 pm" ), "Valid time, single hour, no leading 0" );992 assert.ok( method( "01:59 pm" ), "Valid time, single hour, leading 0" );993 assert.ok( !method( "12:00" ), "Invalid time" );994 assert.ok( !method( "9" ), "Invalid time" );995 assert.ok( !method( "9 am" ), "Invalid time" );996 assert.ok( !method( "12:61 am" ), "Invalid time" );997 assert.ok( !method( "13:00 am" ), "Invalid time" );998 assert.ok( !method( "00:00 am" ), "Invalid time" );999} );1000QUnit.test( "minWords", function( assert ) {1001 var method = methodTest( "minWords" );1002 assert.ok( method( "hello worlds", 2 ), "plain text, valid" );1003 assert.ok( method( "<b>hello</b> world", 2 ), "html, valid" );1004 assert.ok( !method( "hello", 2 ), "plain text, invalid" );1005 assert.ok( !method( "<b>world</b>", 2 ), "html, invalid" );1006 assert.ok( !method( "world <br/>", 2 ), "html, invalid" );1007} );1008QUnit.test( "maxWords", function( assert ) {1009 var method = methodTest( "maxWords" );1010 assert.ok( method( "hello", 2 ), "plain text, valid" );1011 assert.ok( method( "<b>world</b>", 2 ), "html, valid" );1012 assert.ok( method( "world <br/>", 2 ), "html, valid" );1013 assert.ok( method( "hello worlds", 2 ), "plain text, valid" );1014 assert.ok( method( "<b>hello</b> world", 2 ), "html, valid" );1015 assert.ok( !method( "hello 123 world", 2 ), "plain text, invalid" );1016 assert.ok( !method( "<b>hello</b> 123 world", 2 ), "html, invalid" );1017} );1018QUnit.test( "rangeWords", function( assert ) {1019 var method = methodTest( "rangeWords" );1020 assert.ok( method( "hello", [ 0, 2 ] ), "plain text, valid" );1021 assert.ok( method( "hello worlds", [ 0, 2 ] ), "plain text, valid" );1022 assert.ok( method( "<b>hello</b> world", [ 0, 2 ] ), "html, valid" );1023 assert.ok( !method( "hello worlds what is up", [ 0, 2 ] ), "plain text, invalid" );1024 assert.ok( !method( "<b>Hello</b> <b>world</b> <b>hello</b>", [ 0, 2 ] ), "html, invalid" );1025} );1026QUnit.test( "pattern", function( assert ) {1027 var method = methodTest( "pattern" );1028 assert.ok( method( "AR1004", "AR\\d{4}" ), "Correct format for the given RegExp" );1029 assert.ok( method( "AR1004", /^AR\d{4}$/ ), "Correct format for the given RegExp" );1030 assert.ok( !method( "BR1004", /^AR\d{4}$/ ), "Invalid format for the given RegExp" );1031 assert.ok( method( "1ABC", "[0-9][A-Z]{3}" ), "Correct format for the given RegExp" );1032 assert.ok( !method( "ABC", "[0-9][A-Z]{3}" ), "Invalid format for the given RegExp" );1033 assert.ok( !method( "1ABC DEF", "[0-9][A-Z]{3}" ), "Invalid format for the given RegExp" );1034 assert.ok( method( "1ABCdef", "[a-zA-Z0-9]+" ), "Correct format for the given RegExp" );1035 assert.ok( !method( "1ABC def", "[a-zA-Z0-9]+" ), "Invalid format for the given RegExp" );1036 assert.ok( method( "2014-10-02", "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ), "Correct format for the given RegExp" );1037 assert.ok( !method( "02-10-2014", "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" ), "Invalid format for the given RegExp" );1038} );1039function testCardTypeByNumber( assert, number, cardname, expected ) {1040 $( "#cardnumber" ).val( number );1041 var actual = $( "#ccform" ).valid();1042 assert.equal( actual, expected, $.validator.format( "Expect card number {0} to validate to {1}, actually validated to ", number, expected ) );1043}1044QUnit.test( "creditcardtypes, all", function( assert ) {1045 $( "#ccform" ).validate( {1046 rules: {1047 cardnumber: {1048 creditcard: true,1049 creditcardtypes: {1050 all: true1051 }1052 }1053 }1054 } );1055 testCardTypeByNumber( assert, "4111-1111-1111-1111", "VISA", true );1056 testCardTypeByNumber( assert, "5111-1111-1111-1118", "MasterCard", true );1057 testCardTypeByNumber( assert, "6111-1111-1111-1116", "Discover", true );1058 testCardTypeByNumber( assert, "3400-0000-0000-009", "AMEX", true );1059 testCardTypeByNumber( assert, "4111-1111-1111-1110", "VISA", false );1060 testCardTypeByNumber( assert, "5432-1111-1111-1111", "MasterCard", false );1061 testCardTypeByNumber( assert, "6611-6611-6611-6611", "Discover", false );1062 testCardTypeByNumber( assert, "3777-7777-7777-7777", "AMEX", false );1063} );1064QUnit.test( "creditcardtypes, visa", function( assert ) {1065 $( "#ccform" ).validate( {1066 rules: {1067 cardnumber: {1068 creditcard: true,1069 creditcardtypes: {1070 visa: true1071 }1072 }1073 }1074 } );1075 testCardTypeByNumber( assert, "4111-1111-1111-1111", "VISA", true );1076 testCardTypeByNumber( assert, "5111-1111-1111-1118", "MasterCard", false );1077 testCardTypeByNumber( assert, "6111-1111-1111-1116", "Discover", false );1078 testCardTypeByNumber( assert, "3400-0000-0000-009", "AMEX", false );1079} );1080QUnit.test( "creditcardtypes, mastercard", function( assert ) {1081 $( "#ccform" ).validate( {1082 rules: {1083 cardnumber: {1084 creditcard: true,1085 creditcardtypes: {1086 mastercard: true1087 }1088 }1089 }1090 } );1091 testCardTypeByNumber( assert, "5111-1111-1111-1118", "MasterCard", true );1092 testCardTypeByNumber( assert, "6111-1111-1111-1116", "Discover", false );1093 testCardTypeByNumber( assert, "3400-0000-0000-009", "AMEX", false );1094 testCardTypeByNumber( assert, "4111-1111-1111-1111", "VISA", false );1095} );1096function fillFormWithValuesAndExpect( assert, formSelector, inputValues, expected ) {1097 var i, actual;1098 for ( i = 0; i < inputValues.length; i++ ) {1099 $( formSelector + " input:eq(" + i + ")" ).val( inputValues[ i ] );1100 }1101 actual = $( formSelector ).valid();1102 assert.equal( actual, expected, $.validator.format( "Filled inputs of form '{0}' with {1} values ({2})", formSelector, inputValues.length, inputValues.toString() ) );1103}1104QUnit.test( "require_from_group", function( assert ) {1105 $( "#productInfo" ).validate( {1106 rules: {1107 partnumber: { require_from_group: [ 2, ".productInfo" ] },1108 description: { require_from_group: [ 2, ".productInfo" ] },1109 discount: { require_from_group: [ 2, ".productInfo" ] }1110 }1111 } );1112 fillFormWithValuesAndExpect( assert, "#productInfo", [], false );1113 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123 ], false );1114 $( "#productInfo input[type='checkbox']" ).attr( "checked", "checked" );1115 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123 ], true );1116 $( "#productInfo input[type='checkbox']" ).removeAttr( "checked" );1117 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget" ], true );1118 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "red" ], true );1119 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "red" ], true );1120} );1121QUnit.test( "require_from_group preserve other rules", function( assert ) {1122 $( "#productInfo" ).validate( {1123 rules: {1124 partnumber: { require_from_group: [ 2, ".productInfo" ] },1125 description: { require_from_group: [ 2, ".productInfo" ] },1126 color: { require_from_group: [ 2, ".productInfo" ] },1127 supplier: { required: true }1128 }1129 } );1130 fillFormWithValuesAndExpect( assert, "#productInfo", [], false );1131 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123 ], false );1132 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget" ], false );1133 fillFormWithValuesAndExpect( assert, "#productInfo", [ "", "", "", "Acme" ], false );1134 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "", "", "Acme" ], false );1135 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "", "Acme" ], true );1136 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "red", "Acme" ], true );1137} );1138QUnit.test( "skip_or_fill_minimum", function( assert ) {1139 $( "#productInfo" ).validate( {1140 rules: {1141 partnumber: { skip_or_fill_minimum: [ 2, ".productInfo" ] },1142 description: { skip_or_fill_minimum: [ 2, ".productInfo" ] },1143 color: { skip_or_fill_minimum: [ 2, ".productInfo" ] }1144 }1145 } );1146 fillFormWithValuesAndExpect( assert, "#productInfo", [], true );1147 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123 ], false );1148 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget" ], true );1149 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "red" ], true );1150} );1151QUnit.test( "skip_or_fill_minimum preserve other rules", function( assert ) {1152 $( "#productInfo" ).validate( {1153 rules: {1154 partnumber: { skip_or_fill_minimum: [ 2, ".productInfo" ] },1155 description: { skip_or_fill_minimum: [ 2, ".productInfo" ] },1156 color: { skip_or_fill_minimum: [ 2, ".productInfo" ] },1157 supplier: { required: true }1158 }1159 } );1160 fillFormWithValuesAndExpect( assert, "#productInfo", [], false );1161 fillFormWithValuesAndExpect( assert, "#productInfo", [ "", "", "", "Acme" ], true );1162 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "", "", "Acme" ], false );1163 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "", "Acme" ], true );1164 fillFormWithValuesAndExpect( assert, "#productInfo", [ 123, "widget", "red", "Acme" ], true );1165} );1166QUnit.test( "zipcodeUS", function( assert ) {1167 var method = methodTest( "zipcodeUS" );1168 assert.ok( method( "12345" ), "Valid zip" );1169 assert.ok( method( "12345-2345" ), "Valid zip" );1170 assert.ok( method( "90210-4567" ), "Valid zip" );1171 assert.ok( !method( "1" ), "Invalid zip" );1172 assert.ok( !method( "1234" ), "Invalid zip" );1173 assert.ok( !method( "123-23" ), "Invalid zip" );1174 assert.ok( !method( "12345-43" ), "Invalid zip" );1175 assert.ok( !method( "123456-7890" ), "Invalid zip" );1176} );1177QUnit.test( "nifES", function( assert ) {1178 var method = methodTest( "nifES" );1179 assert.ok( method( "11441059P" ), "NIF valid" );1180 assert.ok( method( "80054306T" ), "NIF valid" );1181 assert.ok( method( "76048581R" ), "NIF valid" );1182 assert.ok( method( "28950849J" ), "NIF valid" );1183 assert.ok( method( "34048598L" ), "NIF valid" );1184 assert.ok( method( "28311529R" ), "NIF valid" );1185 assert.ok( method( "34673804Q" ), "NIF valid" );1186 assert.ok( method( "92133247P" ), "NIF valid" );1187 assert.ok( method( "77149717N" ), "NIF valid" );1188 assert.ok( method( "15762034L" ), "NIF valid" );1189 assert.ok( method( "05122654W" ), "NIF valid" );1190 assert.ok( method( "05122654w" ), "NIF valid: lower case" );1191 assert.ok( method( "M1503708Z" ), "NIF valid. Temporary foreign nif" );1192 assert.ok( !method( "1144105R" ), "NIF invalid: less than 8 digits without zero" );1193 assert.ok( !method( "11441059 R" ), "NIF invalid: white space" );1194 assert.ok( !method( "11441059" ), "NIF invalid: no letter" );1195 assert.ok( !method( "11441059PR" ), "NIF invalid: two letters" );1196 assert.ok( !method( "11440059R" ), "NIF invalid: wrong number" );1197 assert.ok( !method( "11441059S" ), "NIF invalid: wrong letter" );1198 assert.ok( !method( "114410598R" ), "NIF invalid: > 8 digits" );1199 assert.ok( !method( "11441059-R" ), "NIF invalid: dash" );1200 assert.ok( !method( "asdasdasd" ), "NIF invalid: all letters" );1201 assert.ok( !method( "11.144.059R" ), "NIF invalid: two dots" );1202 assert.ok( !method( "05.122.654R" ), "NIF invalid: starts with 0 and dots" );1203 assert.ok( !method( "5.122.654-R" ), "NIF invalid: dots and dash" );1204 assert.ok( !method( "05.122.654-R" ), "NIF invalid: starts with zero and dot and dash" );1205} );1206QUnit.test( "nieES", function( assert ) {1207 var method = methodTest( "nieES" );1208 assert.ok( method( "X0093999K" ), "NIE valid" );1209 assert.ok( method( "X1923000Q" ), "NIE valid" );1210 assert.ok( method( "Z9669587R" ), "NIE valid" );1211 assert.ok( method( "Z8945005B" ), "NIE valid" );1212 assert.ok( method( "Z6663465W" ), "NIE valid" );1213 assert.ok( method( "Y7875935J" ), "NIE valid" );1214 assert.ok( method( "X3390130E" ), "NIE valid" );1215 assert.ok( method( "Y7699182S" ), "NIE valid" );1216 assert.ok( method( "Y1524243R" ), "NIE valid" );1217 assert.ok( method( "X3744072V" ), "NIE valid" );1218 assert.ok( method( "X7436800A" ), "NIE valid" );1219 assert.ok( method( "X00002153Z" ), "NIE valid" );1220 assert.ok( method( "X02323232W" ), "NIE valid" );1221 assert.ok( method( "Z0569549M" ), "NIE valid" );1222 assert.ok( method( "X0479906B" ), "NIE valid" );1223 assert.ok( method( "y7875935j" ), "NIE valid: lower case" );1224 assert.ok( !method( "X0093999 K" ), "NIE invalid: white space" );1225 assert.ok( !method( "X 0093999 K" ), "NIE invalid: white space" );1226 assert.ok( !method( "11441059" ), "NIE invalid: no letter" );1227 assert.ok( !method( "11441059PR" ), "NIE invalid: two letters" );1228 assert.ok( !method( "11440059R" ), "NIE invalid: wrong number" );1229 assert.ok( !method( "11441059S" ), "NIE invalid: wrong letter" );1230 assert.ok( !method( "114410598R" ), "NIE invalid: > 8 digits" );1231 assert.ok( !method( "11441059-R" ), "NIE invalid: dash" );1232 assert.ok( !method( "asdasdasd" ), "NIE invalid: all letters" );1233 assert.ok( !method( "11.144.059R" ), "NIE invalid: two dots" );1234 assert.ok( !method( "05.122.654R" ), "NIE invalid: starts with 0 and dots" );1235 assert.ok( !method( "5.122.654-R" ), "NIE invalid: dots and dash" );1236 assert.ok( !method( "05.122.654-R" ), "NIE invalid: starts with zero and dot and dash" );1237} );1238QUnit.test( "cifES", function( assert ) {1239 var method = methodTest( "cifES" );1240 assert.ok( method( "A58818501" ), "CIF valid" );1241 assert.ok( method( "A79082244" ), "CIF valid" );1242 assert.ok( method( "A60917978" ), "CIF valid" );1243 assert.ok( method( "A39000013" ), "CIF valid" );1244 assert.ok( method( "A28315182" ), "CIF valid" );1245 assert.ok( method( "A75409573" ), "CIF valid" );1246 assert.ok( method( "A34396994" ), "CIF valid" );1247 assert.ok( method( "A08153538" ), "CIF valid" );1248 assert.ok( method( "A09681396" ), "CIF valid" );1249 assert.ok( method( "A06706303" ), "CIF valid" );1250 assert.ok( method( "A66242173" ), "CIF valid" );1251 assert.ok( method( "A61416699" ), "CIF valid" );1252 assert.ok( method( "A99545444" ), "CIF valid" );1253 assert.ok( method( "A10407252" ), "CIF valid" );1254 assert.ok( method( "A76170885" ), "CIF valid" );1255 assert.ok( method( "A83535047" ), "CIF valid" );1256 assert.ok( method( "A46031969" ), "CIF valid" );1257 assert.ok( method( "A97252910" ), "CIF valid" );1258 assert.ok( method( "A79082244" ), "CIF valid" );1259 assert.ok( !method( "A7908224D" ), "CIF invalid: digit control must be a number (4)" );1260 assert.ok( method( "B71413892" ), "CIF valid" );1261 assert.ok( method( "B37484755" ), "CIF valid" );1262 assert.ok( method( "B15940893" ), "CIF valid" );1263 assert.ok( method( "B55429161" ), "CIF valid" );1264 assert.ok( method( "B93337087" ), "CIF valid" );1265 assert.ok( method( "B43522192" ), "CIF valid" );1266 assert.ok( method( "B38624334" ), "CIF valid" );1267 assert.ok( method( "B21920426" ), "CIF valid" );1268 assert.ok( method( "B74940156" ), "CIF valid" );1269 assert.ok( method( "B46125746" ), "CIF valid" );1270 assert.ok( method( "B67077537" ), "CIF valid" );1271 assert.ok( method( "B21283155" ), "CIF valid" );1272 assert.ok( method( "B57104176" ), "CIF valid" );1273 assert.ok( method( "B25060179" ), "CIF valid" );1274 assert.ok( method( "B06536338" ), "CIF valid" );1275 assert.ok( method( "B50964592" ), "CIF valid" );1276 assert.ok( method( "B15653330" ), "CIF valid" );1277 assert.ok( method( "B83524710" ), "CIF valid" );1278 assert.ok( !method( "B8352471J" ), "CIF invalid: digit control must be a number (0)" );1279 assert.ok( !method( "C27827551" ), "CIF invalid: wrong digit control" );1280 assert.ok( !method( "C27827552" ), "CIF invalid: wrong digit control" );1281 assert.ok( !method( "C27827553" ), "CIF invalid: wrong digit control" );1282 assert.ok( !method( "C27827554" ), "CIF invalid: wrong digit control" );1283 assert.ok( !method( "C27827555" ), "CIF invalid: wrong digit control" );1284 assert.ok( !method( "C27827556" ), "CIF invalid: wrong digit control" );1285 assert.ok( !method( "C27827557" ), "CIF invalid: wrong digit control" );1286 assert.ok( !method( "C27827558" ), "CIF invalid: wrong digit control" );1287 assert.ok( !method( "C27827550" ), "CIF invalid: wrong digit control" );1288 assert.ok( !method( "C2782755A" ), "CIF invalid: wrong digit control" );1289 assert.ok( !method( "C2782755B" ), "CIF invalid: wrong digit control" );1290 assert.ok( !method( "C2782755C" ), "CIF invalid: wrong digit control" );1291 assert.ok( !method( "C2782755D" ), "CIF invalid: wrong digit control" );1292 assert.ok( !method( "C2782755E" ), "CIF invalid: wrong digit control" );1293 assert.ok( !method( "C2782755F" ), "CIF invalid: wrong digit control" );1294 assert.ok( !method( "C2782755G" ), "CIF invalid: wrong digit control" );1295 assert.ok( !method( "C2782755H" ), "CIF invalid: wrong digit control" );1296 assert.ok( !method( "C2782755J" ), "CIF invalid: wrong digit control" );1297 assert.ok( method( "C2782755I" ), "CIF valid. Digit control can be either a number or letter" );1298 assert.ok( method( "C27827559" ), "CIF valid. Digit control can be either a number or letter" );1299 assert.ok( method( "E48911572" ), "CIF valid" );1300 assert.ok( method( "E93928703" ), "CIF valid" );1301 assert.ok( method( "E17472952" ), "CIF valid" );1302 assert.ok( !method( "E1747295B" ), "CIF invalid: digit control must be a number (2)" );1303 assert.ok( method( "F41190612" ), "CIF valid" );1304 assert.ok( method( "F4119061B" ), "CIF valid. Digit control can be either a number or letter" );1305 assert.ok( method( "G72102064" ), "CIF valid" );1306 assert.ok( method( "G32937757" ), "CIF valid" );1307 assert.ok( method( "G8984953C" ), "CIF valid" );1308 assert.ok( method( "G3370454E" ), "CIF valid" );1309 assert.ok( method( "G33704545" ), "CIF valid. Digit control can be either a number or letter" );1310 assert.ok( method( "H48911572" ), "CIF valid" );1311 assert.ok( method( "H93928703" ), "CIF valid" );1312 assert.ok( method( "H17472952" ), "CIF valid" );1313 assert.ok( !method( "H1747295B" ), "CIF invalid: digit control must be a number (2)" );1314 assert.ok( !method( "I48911572" ), "CIF invalid: starts with I" );1315 assert.ok( method( "J85081081" ), "CIF valid" );1316 assert.ok( method( "J8508108A" ), "CIF valid" );1317 assert.ok( method( "K3902238I" ), "CIF valid" );1318 assert.ok( !method( "K39022389" ), "CIF invalid. Digit control must be a letter (I)" );1319 assert.ok( method( "M9916080F" ), "CIF valid" );1320 assert.ok( method( "M1566151E" ), "CIF valid" );1321 assert.ok( method( "M15661515" ), "CIF valid" );1322 assert.ok( method( "M4778730D" ), "CIF valid" );1323 assert.ok( method( "N1172218H" ), "CIF valid" );1324 assert.ok( method( "N4094938J" ), "CIF valid" );1325 assert.ok( method( "N40949380" ), "CIF valid. Digit control can be either a number or letter" );1326 assert.ok( method( "P5141387J" ), "CIF valid" );1327 assert.ok( method( "P9803881C" ), "CIF valid" );1328 assert.ok( !method( "P98038813" ), "CIF invalid: digit control must be a letter (C)" );1329 assert.ok( method( "Q5141387J" ), "CIF valid" );1330 assert.ok( method( "Q9803881C" ), "CIF valid" );1331 assert.ok( !method( "Q98038813" ), "CIF invalid: digit control must be a letter (C)" );1332 assert.ok( method( "S5141387J" ), "CIF valid" );1333 assert.ok( method( "S9803881C" ), "CIF valid" );1334 assert.ok( !method( "S98038813" ), "CIF invalid: digit control must be a letter (C)" );1335 assert.ok( method( "s98038813" ), "CIF valid: lower case" );1336 assert.ok( !method( "X48911572" ), "CIF invalid: starts with X" );1337 assert.ok( !method( "Y48911572" ), "CIF invalid: starts with Y" );1338 assert.ok( !method( "Z48911572" ), "CIF invalid: starts with Z" );1339 assert.ok( !method( "Z98038813" ), "CIF invalid: wrong letter" );1340 assert.ok( !method( "B 43522192" ), "CIF invalid: white spaces" );1341 assert.ok( !method( "43522192" ), "CIF invalid: missing letter" );1342 assert.ok( !method( "BB43522192" ), "CIF invalid: two letters" );1343 assert.ok( !method( "B53522192" ), "CIF invalid: wrong number" );1344 assert.ok( !method( "B433522192" ), "CIF invalid: > 8 digits" );1345 assert.ok( !method( "B3522192" ), "CIF invalid: < 8 digits" );1346 assert.ok( !method( "B-43522192" ), "CIF invalid: dash" );1347 assert.ok( !method( "Basdasdas" ), "CIF invalid: all letters" );1348 assert.ok( !method( "B43.522.192" ), "CIF invalid: dots" );1349 assert.ok( !method( "B-43.522.192" ), "CIF invalid: dots and dash" );1350} );1351QUnit.test( "nipPL", function( assert ) {1352 var method = methodTest( "nipPL" );1353 assert.ok( method( "3514242002" ), "NIP valid" );1354 assert.ok( method( "8117892840" ), "NIP valid" );1355 assert.ok( method( "7249598309" ), "NIP valid" );1356 assert.ok( method( "6853539166" ), "NIP valid" );1357 assert.ok( method( "5715750580" ), "NIP valid" );1358 assert.ok( method( "3496120813" ), "NIP valid" );1359 assert.ok( method( "1565710251" ), "NIP valid" );1360 assert.ok( method( "8190761165" ), "NIP valid" );1361 assert.ok( method( "9487499667" ), "NIP valid" );1362 assert.ok( method( "9283384684" ), "NIP valid" );1363 assert.ok( method( "3887569138" ), "NIP valid" );1364 assert.ok( method( "3962898856" ), "NIP valid" );1365 assert.ok( !method( "76355753" ), "NIP invalid: too short" );1366 assert.ok( !method( "454" ), "NIP invalid: too short" );1367 assert.ok( !method( "234565545" ), "NIP invalid: too short" );1368 assert.ok( !method( "543455" ), "NIP invalid: too short" );1369 assert.ok( !method( "6345634563456" ), "NIP invalid: too long" );1370 assert.ok( !method( "53453453455335" ), "NIP invalid: too long" );1371 assert.ok( !method( "543453760902" ), "NIP invalid: too long" );1372 assert.ok( !method( "43090012454" ), "NIP invalid: too long" );1373 assert.ok( !method( "3958250194" ), "NIP invalid: wrong checksum" );1374 assert.ok( !method( "3928541049" ), "NIP invalid: wrong checksum" );1375 assert.ok( !method( "5920397295" ), "NIP invalid: wrong checksum" );1376 assert.ok( !method( "9502947712" ), "NIP invalid: wrong checksum" );1377} );1378QUnit.test( "maxWords", function( assert ) {1379 var method = methodTest( "maxWords" ),1380 maxWords = 6;1381 assert.ok( method( "I am a sentence", maxWords ), "Max Words" );1382 assert.ok( !method( "I'm way too long for this sentence!", maxWords ), "Too many words" );1383 assert.ok( method( "Don’t “count” me as too long", maxWords ), "Right amount of words with smartquotes" );1384 assert.ok( !method( "But you can “count” me as too long", maxWords ), "Too many words with smartquotes" );1385 assert.ok( method( "<div>Don’t “count” me as too long</div>", maxWords ), "Right amount of words with smartquotes w/ HTML" );1386 assert.ok( !method( "<div>But you can “count” me as too long</div>", maxWords ), "Too many words with smartquotes w/ HTML" );1387} );1388QUnit.test( "minWords", function( assert ) {1389 var method = methodTest( "minWords" ),1390 minWords = 6;1391 assert.ok( !method( "I am a short sentence", minWords ), "Max Words" );1392 assert.ok( method( "I'm way too long for this sentence!", minWords ), "Too many words" );1393 assert.ok( !method( "Don’t “count” me as short.", minWords ), "Right amount of words with smartquotes" );1394 assert.ok( method( "But you can “count” me as too short", minWords ), "Too many words with smartquotes" );1395 assert.ok( !method( "<div>“Count” me as too short.</div>", minWords ), "Right amount of words with smartquotes w/ HTML" );1396 assert.ok( method( "<div>But you can “count” me as too long</div>", minWords ), "Too many words with smartquotes w/ HTML" );1397} );1398QUnit.test( "rangeWords", function( assert ) {1399 var method = methodTest( "rangeWords" ),1400 rangeWords = [ 3, 6 ];1401 assert.ok( !method( "I'm going to be longer than “six words!”", rangeWords ), "Longer than 6 with smartquotes" );1402 assert.ok( method( "I'm just the right amount!", rangeWords ), "In between" );1403 assert.ok( method( "Super short sentence’s.", rangeWords ), "Low end" );1404 assert.ok( !method( "I", rangeWords ), "Too short" );1405 assert.ok( method( "<div>“Count” me as perfect.</div>", rangeWords ), "Right amount of words with smartquotes w/ HTML" );1406 assert.ok( !method( "<div>But you can “count” me as too long</div>", rangeWords ), "Too many words with smartquotes w/ HTML" );1407} );1408QUnit.test( "currency", function( assert ) { // Works with any symbol1409 var method = methodTest( "currency" );1410 assert.ok( method( "£9", "£" ), "Symbol no decimal" );1411 assert.ok( method( "£9.9", "£" ), "£, one decimal" );1412 assert.ok( method( "£9.99", "£" ), "£, two decimal" );1413 assert.ok( method( "£9.90", "£" ), "Valid currency" );1414 assert.ok( method( "£9,999.9", "£" ), "£, thousand, comma separator, one decimal" );1415 assert.ok( method( "£9,999.99", "£" ), "£, thousand, comma separator, two decimal" );1416 assert.ok( method( "£9,999,999.9", "£" ), "£, million, comma separators, one decimal" );1417 assert.ok( method( "9", [ "£", false ] ), "Valid currency" );1418 assert.ok( method( "9.9", [ "£", false ] ), "Valid currency" );1419 assert.ok( method( "9.99", [ "£", false ] ), "Valid currency" );1420 assert.ok( method( "9.90", [ "£", false ] ), "Valid currency" );1421 assert.ok( method( "9,999.9", [ "£", false ] ), "Valid currency" );1422 assert.ok( method( "9,999.99", [ "£", false ] ), "Valid currency" );1423 assert.ok( method( "9,999,999.9", [ "£", false ] ), "Valid currency" );1424 assert.ok( !method( "9,", "£" ), "Invalid currency" );1425 assert.ok( !method( "9,99.99", "£" ), "Invalid currency" );1426 assert.ok( !method( "9,", "£" ), "Invalid currency" );1427 assert.ok( !method( "9.999", "£" ), "Invalid currency" );1428 assert.ok( !method( "9.999", "£" ), "Invalid currency" );1429 assert.ok( !method( "9.99,9", "£" ), "Invalid currency" );1430} );1431QUnit.test( "postalCodeCA", function( assert ) {1432 var method = methodTest( "postalCodeCA" );1433 assert.ok( method( "H0H0H0" ), "Valid Canadian postal code: all upper case with no space" );1434 assert.ok( method( "H0H 0H0" ), "Valid Canadian postal code: all upper case with one space" );1435 assert.ok( method( "H0H 0H0" ), "Valid Canadian postal code: all upper case with multiple spaces" );1436 assert.ok( method( "h0h 0h0" ), "Valid Canadian postal code: all lower case with space" );1437 assert.ok( method( "h0h0h0" ), "Valid Canadian postal code: all lower case with no space" );1438 assert.ok( !method( "H0H-0H0" ), "Invalid Canadian postal code: dash used as separator" );1439 assert.ok( !method( "H0H 0H" ), "Invalid Canadian postal code: too short" );1440 assert.ok( !method( "Z0H 0H0" ), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVXY' are valid first characters for the Forward Sorting Area" );1441 assert.ok( !method( "H0D 0H0" ), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVWXYZ' are valid third characters for the Forward Sorting Area" );1442 assert.ok( !method( "H0H 0D0" ), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVWXYZ' are valid second characters for the Local Delivery Unit" );1443} );1444QUnit.test( "stateUS", function( assert ) {1445 var method = methodTest( "stateUS" );1446 assert.ok( method( "AZ" ), "Valid US state" );1447 assert.ok( method( "OH" ), "Valid US state" );1448 assert.ok( method( "DC" ), "Valid US state" );1449 assert.ok( method( "PR", { includeTerritories: true } ), "Valid US territory" );1450 assert.ok( method( "AA", { includeMilitary: true } ), "Valid US military zone" );1451 assert.ok( method( "me", { caseSensitive: false } ), "Valid US state" );1452 assert.ok( !method( "az", { caseSensitive: true } ), "Must be capital letters" );1453 assert.ok( !method( "mp", { caseSensitive: false, includeTerritories: false } ), "US territories not allowed" );1454} );1455QUnit.test( "postalcodeBR", function( assert ) {1456 var method = methodTest( "postalcodeBR" );1457 assert.ok( method( "99999-999" ), "Valid BR Postal Code" );1458 assert.ok( method( "99999999" ), "Valid BR Postal Code" );1459 assert.ok( method( "99.999-999" ), "Valid BR Postal Code" );1460 assert.ok( !method( "99.999999" ), "Invalid BR Postal Code" );1461} );1462QUnit.test( "cpfBR", function( assert ) {1463 var method = methodTest( "cpfBR" );1464 assert.ok( method( "11144477735" ), "Valid CPF Number" );1465 assert.ok( method( "263.946.533-30" ), "Valid CPF Number" );1466 assert.ok( method( "325 861 044 47" ), "Valid CPF Number" );1467 assert.ok( method( "859-684-732-40" ), "Valid CPF Number" );1468 assert.ok( !method( "99999999999" ), "Invalid CPF Number: dump data" );1469 assert.ok( !method( "1114447773" ), "Invalid CPF Number: < 11 digits" );1470 assert.ok( !method( "111444777355" ), "Invalid CPF Number: > 11 digits" );1471 assert.ok( !method( "11144477715" ), "Invalid CPF Number: 1st check number failed" );1472 assert.ok( !method( "11144477737" ), "Invalid CPF Number: 2nd check number failed" );1473} );1474QUnit.test( "file accept - image wildcard", function( assert ) {1475 var input = acceptFileDummyInput( "test.png", "image/png" ),1476 $form = $( "<form />" ),1477 proxy = $.proxy( $.validator.methods.accept, new $.validator( {}, $form[ 0 ] ), null, input, "image/*" );1478 assert.ok( proxy(), "the selected file for upload has specified mime type" );1479} );1480QUnit.test( "file accept - specified mime type", function( assert ) {1481 var input = acceptFileDummyInput( "test.kml", "application/vnd.google-earth.kml+xml" ),1482 $form = $( "<form />" ),1483 proxy = $.proxy( $.validator.methods.accept, new $.validator( {}, $form[ 0 ] ), null, input, "application/vnd.google-earth.kml+xml" );1484 assert.ok( proxy(), "the selected file for upload has specified mime type" );1485} );1486QUnit.test( "file accept - multiple mimetypes", function( assert ) {1487 var input = acceptFileDummyInput( "test.png", "image/png" ),1488 $form = $( "<form />" ),1489 proxy = $.proxy( $.validator.methods.accept, new $.validator( {}, $form[ 0 ] ), null, input, "image/png,video/jpeg" );1490 assert.ok( proxy(), "the selected file for upload has specified mime type" );1491} );1492QUnit.test( "file accept - multiple mimetypes with wildcard", function( assert ) {1493 var input = acceptFileDummyInput( "test.mp3", "audio/mpeg" ),1494 $form = $( "<form />" ),1495 proxy = $.proxy( $.validator.methods.accept, new $.validator( {}, $form[ 0 ] ), null, input, "image/*,audio/*" );1496 assert.ok( proxy(), "the selected file for upload has specified mime type" );1497} );1498QUnit.test( "file accept - invalid mime type", function( assert ) {1499 var input = acceptFileDummyInput( "test.kml", "foobar/vnd.google-earth.kml+xml" ),1500 $form = $( "<form />" ),1501 proxy = $.proxy( $.validator.methods.accept, new $.validator( {}, $form[ 0 ] ), null, input, "application/vnd.google-earth.kml+xml" );1502 assert.equal( proxy(), false, "the selected file for upload has invalid mime type" );...

Full Screen

Full Screen

animation.js

Source:animation.js Github

copy

Full Screen

1suite('animation', function() {2 setup(function() {3 webAnimations1.timeline._animations = [];4 });5 test('zero duration animation works', function() {6 tick(90);7 var a = document.body.animate([], 0);8 tick(100);9 assert.equal(a.startTime, 100);10 assert.equal(a.currentTime, 0);11 });12 test('playing works as expected', function() {13 tick(90);14 var a = document.body.animate([], 2000);15 tick(100);16 assert.equal(a.startTime, 100);17 assert.equal(a.currentTime, 0);18 tick(300);19 assert.equal(a.startTime, 100);20 assert.equal(a.currentTime, 200);21 });22 test('pause at start of play', function() {23 tick(90);24 var a = document.body.animate([], 2000);25 a.pause();26 tick(100);27 assert.equal(a.currentTime, 0);28 tick(300);29 a.play();30 assert.equal(a.currentTime, 0);31 tick(310);32 assert.equal(a.currentTime, 0);33 assert.equal(a.startTime, 310);34 var a = document.body.animate([], 2000);35 a.startTime = -690;36 a.pause();37 assert.equal(a.currentTime, null);38 tick(700);39 a.play();40 tick(701);41 assert.equal(a.currentTime, 1000);42 tick(800);43 assert.equal(a.currentTime, 1099);44 assert.equal(a.startTime, -299);45 });46 test('pausing works as expected', function() {47 tick(190);48 var a = document.body.animate([], 3000);49 tick(200);50 tick(1500);51 assert.equal(a.startTime, 200);52 assert.equal(a.currentTime, 1300);53 a.pause();54 assert.equal(a.startTime, null);55 assert.equal(a.currentTime, null);56 tick(2500);57 assert.equal(a.startTime, null);58 assert.equal(a.currentTime, 1300);59 a.play();60 tick(2510);61 assert.equal(a.startTime, 1210);62 assert.equal(a.currentTime, 1300);63 tick(3500);64 assert.equal(a.startTime, 1210);65 assert.equal(a.currentTime, 2290);66 });67 test('reversing works as expected', function() {68 tick(290);69 var a = document.body.animate([], 1000);70 tick(300);71 assert.equal(a.startTime, 300);72 assert.equal(a.currentTime, 0);73 tick(600);74 assert.equal(a.startTime, 300);75 assert.equal(a.currentTime, 300);76 assert.equal(a.playbackRate, 1);77 a.reverse();78 tick(600);79 assert.equal(a.startTime, 900);80 assert.equal(a.currentTime, 300);81 assert.equal(a.playbackRate, -1);82 tick(700);83 assert.equal(a.startTime, 900);84 assert.equal(a.currentTime, 200);85 });86 test('reversing after pausing', function() {87 tick(90);88 var a = document.body.animate([], 1000);89 tick(100);90 tick(600);91 a.reverse();92 tick(601);93 tick(700);94 assert.equal(a.startTime, 1101);95 assert.equal(a.currentTime, 401);96 });97 test('reversing after finishing works as expected', function() {98 tick(90);99 var a = document.body.animate([], 1000);100 tick(100);101 tick(1200);102 assert.equal(a.playState, 'finished');103 assert.equal(a.startTime, 100);104 assert.equal(a.currentTime, 1000);105 tick(1500);106 assert.equal(a.currentTime, 1000);107 assert.equal(isTicking(), false);108 a.reverse();109 assert.equal(a._startTime, null);110 assert.equal(a.currentTime, 1000);111 tick(1600);112 assert.equal(a.startTime, 2600);113 assert.equal(a.currentTime, 1000);114 });115 test('playing after finishing works as expected', function() {116 tick(90);117 var a = document.body.animate([], 1000);118 tick(100);119 tick(1200);120 assert.equal(a.playState, 'finished');121 assert.equal(a.startTime, 100);122 assert.equal(a.currentTime, 1000);123 tick(1500);124 assert.equal(a.currentTime, 1000);125 assert.equal(isTicking(), false);126 a.play();127 assert.equal(a.startTime, null);128 assert.equal(a.currentTime, 0);129 tick(1600);130 assert.equal(a.startTime, 1600);131 assert.equal(a.currentTime, 0);132 });133 test('limiting works as expected', function() {134 tick(390);135 var a = document.body.animate([], 1000);136 tick(400);137 assert.equal(a.startTime, 400);138 assert.equal(a.currentTime, 0);139 tick(900);140 assert.equal(a.startTime, 400);141 assert.equal(a.currentTime, 500);142 tick(1400);143 assert.equal(a.startTime, 400);144 assert.equal(a.currentTime, 1000);145 tick(1500);146 assert.equal(a.startTime, 400);147 assert.equal(a.currentTime, 1000);148 a.reverse();149 assert.equal(a.playbackRate, -1);150 assert.equal(a.currentTime, 1000);151 assert.equal(a._startTime, null);152 tick(2000);153 assert.equal(a.currentTime, 1000);154 assert.equal(a.startTime, 3000);155 tick(2200);156 assert.equal(a.currentTime, 800);157 assert.equal(a.startTime, 3000);158 tick(3200);159 assert.equal(a.currentTime, 0);160 assert.equal(a.startTime, 3000);161 tick(3500);162 assert.equal(a.currentTime, 0);163 assert.equal(a.startTime, 3000);164 });165 test('play after limit works as expected', function() {166 tick(490);167 var a = document.body.animate([], 2000);168 tick(500);169 tick(2600);170 assert.equal(a.currentTime, 2000);171 assert.equal(a.startTime, 500);172 assert.equal(a.playState, 'finished');173 assert.equal(a.playbackRate, 1);174 setTicking(true);175 a.play();176 tick(2700);177 assert.equal(a.startTime, 2700);178 assert.equal(a.currentTime, 0);179 assert.notEqual(a.playState, 'finished');180 assert.equal(a.playbackRate, 1);181 });182 test('play after limit works as expected (reversed)', function() {183 tick(590);184 var a = document.body.animate([], 3000);185 tick(600);186 tick(700);187 a.reverse();188 tick(701);189 tick(900);190 assert.equal(a.startTime, 801);191 assert.equal(a.currentTime, 0);192 assert.equal(a.playState, 'finished');193 assert.equal(a.playbackRate, -1);194 setTicking(true);195 a.play();196 tick(1000);197 assert.equal(a.startTime, 4000);198 assert.equal(a.currentTime, 3000);199 assert.notEqual(a.playState, 'finished');200 assert.equal(a.playbackRate, -1);201 });202 test('seeking works as expected', function() {203 tick(690);204 var a = document.body.animate([], 2000);205 tick(700);206 tick(900);207 assert.equal(a.currentTime, 200);208 a.currentTime = 600;209 assert.equal(a.currentTime, 600);210 assert.equal(a.startTime, 300);211 a.reverse();212 tick(1000);213 assert.equal(a.startTime, 1600);214 a.currentTime = 300;215 assert.equal(a.currentTime, 300);216 assert.equal(a.startTime, 1300);217 });218 test('seeking while paused works as expected', function() {219 tick(790);220 var a = document.body.animate([], 1000);221 tick(800);222 tick(1000);223 a.pause();224 assert.equal(a.currentTime, null);225 assert.equal(a.startTime, null);226 assert.equal(a._paused, true);227 a.currentTime = 500;228 assert.equal(a.startTime, null);229 assert.equal(a._paused, true);230 });231 test('setting start time while paused is ignored', function() {232 tick(900);233 var a = document.body.animate([], 1234);234 a.pause();235 assert.equal(a.startTime, null);236 assert.equal(a.currentTime, null);237 a.startTime = 2232;238 assert.equal(a.startTime, null);239 assert.equal(a.currentTime, null);240 });241 test('setting playbackRate sets startTime to null unless the playbackRate is not changing, ' +242 'preserves the current time', function() {243 tick(0);244 var a = document.body.animate([], 1000);245 tick(1);246 tick(11);247 assert.equal(a.currentTime, 10);248 a.playbackRate = 2;249 assert.equal(a.playbackRate, 2);250 assert.equal(a.currentTime, 10);251 assert.equal(a.startTime, null);252 tick(12);253 assert.equal(a.currentTime, 10);254 assert.equal(a.startTime, 7);255 tick(22);256 assert.equal(a.currentTime, 30);257 assert.equal(a.startTime, 7);258 a.playbackRate = -1;259 assert.equal(a.playbackRate, -1);260 assert.equal(a.currentTime, 30);261 assert.equal(a.startTime, null);262 tick(23);263 assert.equal(a.currentTime, 30);264 assert.equal(a.startTime, 53);265 tick(33);266 assert.equal(a.currentTime, 20);267 assert.equal(a.startTime, 53);268 a.playbackRate = -1;269 assert.equal(a.playbackRate, -1);270 assert.equal(a.currentTime, 20);271 assert.equal(a.startTime, 53);272 tick(43);273 assert.equal(a.currentTime, 10);274 assert.equal(a.startTime, 53);275 }276 );277 test('setting playbackRate puts animation back into effect if it is not finished', function() {278 tick(0);279 var a = document.body.animate([], 1000);280 assert.equal(a.playbackRate, 1);281 tick(1);282 tick(1002);283 assert.equal(a.currentTime, 1000);284 a.playbackRate = -1;285 assert.equal(a.playbackRate, -1);286 assert.equal(a.currentTime, 1000);287 tick(1003);288 assert.equal(a.currentTime, 1000);289 tick(1503);290 assert.equal(a.currentTime, 500);291 });292 test('setting playbackRate does not put animation back into effect if it is finished', function() {293 tick(0);294 var a = document.body.animate([], 1000);295 assert.equal(a.playbackRate, 1);296 tick(1);297 tick(1002);298 assert.equal(a.currentTime, 1000);299 assert.equal(a.startTime, 1);300 a.playbackRate = 0.5;301 assert.equal(a.playbackRate, 0.5);302 assert.equal(a.currentTime, 1000);303 assert.equal(a.startTime, null);304 tick(1003);305 assert.equal(a.currentTime, 1000);306 assert.equal(a.startTime, -997);307 tick(1503);308 assert.equal(a.currentTime, 1000);309 assert.equal(a.startTime, -997);310 });311 test('finishing works as expected', function() {312 tick(1000);313 var a = document.body.animate([], 2000);314 a.finish();315 assert.equal(a.startTime, 0);316 assert.equal(a.currentTime, 2000);317 a.reverse();318 a.finish();319 assert.equal(a.currentTime, 0);320 assert.equal(a.startTime, 2000);321 tick(2000);322 });323 test('cancelling clears all effects', function() {324 tick(0);325 var target = document.createElement('div');326 document.documentElement.appendChild(target);327 var animation = target.animate([{marginLeft: '50px'}, {marginLeft: '50px'}], 1000);328 tick(10);329 tick(110);330 assert.equal(getComputedStyle(target).marginLeft, '50px');331 animation.cancel();332 tick(110);333 assert.equal(getComputedStyle(target).marginLeft, '0px');334 assert.deepEqual(webAnimations1.timeline._animations, []);335 tick(120);336 assert.equal(getComputedStyle(target).marginLeft, '0px');337 assert.deepEqual(webAnimations1.timeline._animations, []);338 document.documentElement.removeChild(target);339 });340 test('cancelling a newly created animation clears all effects', function() {341 tick(0);342 var target = document.createElement('div');343 document.documentElement.appendChild(target);344 var animation = target.animate([{marginLeft: '50px'}, {marginLeft: '50px'}], 1000);345 assert.equal(getComputedStyle(target).marginLeft, '50px');346 animation.cancel();347 assert.equal(getComputedStyle(target).marginLeft, '0px');348 document.documentElement.removeChild(target);349 });350 test('startTime is set on first tick if timeline hasn\'t started', function() {351 webAnimations1.timeline.currentTime = undefined;352 var a = document.body.animate([], 1000);353 tick(0);354 tick(100);355 assert.equal(a.startTime, 0);356 });357 test('animations which are finished and not filling get discarded', function() {358 tick(90);359 var nofill = document.body.animate([], 100);360 var fill = document.body.animate([], {duration: 100, fill: 'forwards'});361 assert.deepEqual(webAnimations1.timeline._animations, [nofill._animation || nofill, fill._animation || fill]);362 tick(100);363 assert.deepEqual(webAnimations1.timeline._animations, [nofill._animation || nofill, fill._animation || fill]);364 tick(400);365 assert.deepEqual(webAnimations1.timeline._animations, [fill._animation || fill]);366 });367 test('discarded animations get re-added on modification', function() {368 tick(90);369 var animation = document.body.animate([], 100);370 tick(100);371 tick(400);372 assert.deepEqual(webAnimations1.timeline._animations, []);373 animation.currentTime = 0;374 assert.deepEqual(webAnimations1.timeline._animations, [animation._animation || animation]);375 });376 test('animations in the before phase are not discarded', function() {377 tick(100);378 var animation = document.body.animate([], 100);379 animation.currentTime = -50;380 tick(110);381 assert.deepEqual(webAnimations1.timeline._animations, [animation._animation || animation]);382 });383 test('animations that go out of effect should not clear the effect of animations that are in effect', function() {384 var target = document.createElement('div');385 document.body.appendChild(target);386 tick(0);387 var animationBehind = target.animate([{marginLeft: '200px'}, {marginLeft: '200px'}], 200);388 var animationInfront = target.animate([{marginLeft: '100px'}, {marginLeft: '100px'}], 100);389 tick(50);390 assert.equal(getComputedStyle(target).marginLeft, '100px', 't = 50');391 tick(150);392 assert.equal(getComputedStyle(target).marginLeft, '200px', 't = 150');393 tick(250);394 assert.equal(getComputedStyle(target).marginLeft, '0px', 't = 250');395 document.body.removeChild(target);396 });397 test('animation modifications should update CSS effects immediately', function() {398 var target = document.createElement('div');399 document.body.appendChild(target);400 tick(0);401 var animationBehind = target.animate([{width: '1234px'}, {width: '1234px'}], {duration: 1, fill: 'both'});402 var animationInfront = target.animate([{width: '0px'}, {width: '100px'}], 100);403 assert.equal(getComputedStyle(target).width, '0px');404 animationInfront.currentTime = 50;405 assert.equal(getComputedStyle(target).width, '50px');406 animationInfront.currentTime = 100;407 assert.equal(getComputedStyle(target).width, '1234px');408 animationInfront.play();409 assert.equal(getComputedStyle(target).width, '0px');410 animationInfront.startTime = -50;411 assert.equal(getComputedStyle(target).width, '50px');412 document.body.removeChild(target);413 });414 test('KeyframeEffect that hasn\'t been played has playState \'idle\'', function() {415 var effect = new webAnimations1KeyframeEffect(document.body, [], 1000);416 var a = new webAnimations1Animation(effect);417 assert.equal(a.playState, 'idle');418 });419 test('playState works for a simple effect', function() {420 var a = document.body.animate([], 1000);421 tick(0);422 assert.equal(a.playState, 'running');423 tick(100);424 assert.equal(a.playState, 'running');425 a.pause();426 assert.equal(a.playState, 'pending');427 tick(101);428 assert.equal(a.playState, 'paused');429 a.play();430 assert.equal(a.playState, 'pending');431 tick(102);432 assert.equal(a.playState, 'running');433 tick(1002);434 assert.equal(a.playState, 'finished');435 });436 test('Play after cancel', function() {437 var a = document.body.animate([], 1000);438 assert.equal(a.playState, 'pending');439 tick(0);440 a.cancel();441 assert.equal(a.playState, 'idle');442 assert.equal(a.currentTime, null);443 assert.equal(a.startTime, null);444 tick(1);445 assert.equal(a.playState, 'idle');446 assert.equal(a.currentTime, null);447 assert.equal(a.startTime, null);448 a.play();449 assert.equal(a.playState, 'pending');450 assert.equal(a.currentTime, 0);451 assert.equal(a.startTime, null);452 tick(10);453 assert.equal(a.playState, 'running');454 assert.equal(a.currentTime, 0);455 assert.equal(a.startTime, 10);456 });457 test('Reverse after cancel', function() {458 var a = document.body.animate([], 300);459 tick(0);460 a.cancel();461 assert.equal(a.playState, 'idle');462 assert.equal(a.currentTime, null);463 assert.equal(a.startTime, null);464 tick(1);465 a.reverse();466 assert.equal(a.playState, 'pending');467 assert.equal(a.currentTime, 300);468 assert.equal(a.startTime, null);469 tick(100);470 assert.equal(a.playState, 'running');471 assert.equal(a.currentTime, 300);472 assert.equal(a.startTime, 400);473 tick(300);474 assert.equal(a.playState, 'running');475 assert.equal(a.currentTime, 100);476 assert.equal(a.startTime, 400);477 tick(400);478 assert.equal(a.playState, 'finished');479 assert.equal(a.currentTime, 0);480 assert.equal(a.startTime, 400);481 });482 test('Finish after cancel', function() {483 var a = document.body.animate([], 300);484 tick(0);485 a.cancel();486 assert.equal(a.playState, 'idle');487 assert.equal(a.currentTime, null);488 assert.equal(a.startTime, null);489 tick(1);490 a.finish();491 assert.equal(a.playState, 'idle');492 assert.equal(a.currentTime, null);493 assert.equal(a.startTime, null);494 tick(2);495 assert.equal(a.playState, 'idle');496 assert.equal(a.currentTime, null);497 assert.equal(a.startTime, null);498 });499 test('Pause after cancel', function() {500 var a = document.body.animate([], 300);501 tick(0);502 a.cancel();503 assert.equal(a.playState, 'idle');504 assert.equal(a.currentTime, null);505 assert.equal(a.startTime, null);506 tick(1);507 a.pause();508 assert.equal(a.playState, 'paused');509 assert.equal(a.currentTime, 0);510 assert.equal(a.startTime, null);511 });512 test('Animations ignore NaN times', function() {513 var a = document.body.animate([], 300);514 a.startTime = 100;515 tick(110);516 assert.equal(a.currentTime, 10);517 a.startTime = NaN;518 assert.equal(a.startTime, 100);519 a.currentTime = undefined;520 assert.equal(a.currentTime, 10);521 });522 test('play() should not set a start time', function() {523 var a = document.body.animate([], 1000);524 a.cancel();525 assert.equal(a.startTime, null);526 assert.equal(a.playState, 'idle');527 a.play();528 assert.equal(a.startTime, null);529 assert.equal(a.playState, 'pending');530 });531 test('reverse() should not set a start time', function() {532 var a = document.body.animate([], 1000);533 a.cancel();534 assert.equal(a.startTime, null);535 assert.equal(a.playState, 'idle');536 a.reverse();537 assert.equal(a.startTime, null);538 assert.equal(a.playState, 'pending');539 });540 test('Animations have optional ID', function() {541 tick(100);542 var a = document.body.animate([], { duration: 1000 });543 assert.equal(a.id, '');544 a = document.body.animate([], { duration: 1000, id: 'anim-id' });545 assert.equal(a.id, 'anim-id');546 });...

Full Screen

Full Screen

format-test.js

Source:format-test.js Github

copy

Full Screen

1require("../env");2var vows = require("vows"),3 assert = require("assert");4var suite = vows.describe("d3.format");5suite.addBatch({6 "format": {7 topic: function() {8 return d3.format;9 },10 "returns a string": function(format) {11 assert.isString(format("d")(0));12 },13 "can zero fill": function(format) {14 var f = format("08d");15 assert.strictEqual(f(0), "00000000");16 assert.strictEqual(f(42), "00000042");17 assert.strictEqual(f(42000000), "42000000");18 assert.strictEqual(f(420000000), "420000000");19 assert.strictEqual(f(-4), "-0000004");20 assert.strictEqual(f(-42), "-0000042");21 assert.strictEqual(f(-4200000), "-4200000");22 assert.strictEqual(f(-42000000), "-42000000");23 },24 "can space fill": function(format) {25 var f = format("8d");26 assert.strictEqual(f(0), " 0");27 assert.strictEqual(f(42), " 42");28 assert.strictEqual(f(42000000), "42000000");29 assert.strictEqual(f(420000000), "420000000");30 assert.strictEqual(f(-4), " -4");31 assert.strictEqual(f(-42), " -42");32 assert.strictEqual(f(-4200000), "-4200000");33 assert.strictEqual(f(-42000000), "-42000000");34 },35 "can output fixed-point notation": function(format) {36 assert.strictEqual(format(".1f")(0.49), "0.5");37 assert.strictEqual(format(".2f")(0.449), "0.45");38 assert.strictEqual(format(".3f")(0.4449), "0.445");39 assert.strictEqual(format(".5f")(0.444449), "0.44445");40 assert.strictEqual(format(".1f")(100), "100.0");41 assert.strictEqual(format(".2f")(100), "100.00");42 assert.strictEqual(format(".3f")(100), "100.000");43 assert.strictEqual(format(".5f")(100), "100.00000");44 },45 "can output general notation": function(format) {46 assert.strictEqual(format(".1g")(0.049), "0.05");47 assert.strictEqual(format(".1g")(0.49), "0.5");48 assert.strictEqual(format(".2g")(0.449), "0.45");49 assert.strictEqual(format(".3g")(0.4449), "0.445");50 assert.strictEqual(format(".5g")(0.444449), "0.44445");51 assert.strictEqual(format(".1g")(100), "1e+2");52 assert.strictEqual(format(".2g")(100), "1.0e+2");53 assert.strictEqual(format(".3g")(100), "100");54 assert.strictEqual(format(".5g")(100), "100.00");55 assert.strictEqual(format(".5g")(100.2), "100.20");56 assert.strictEqual(format(".2g")(0.002), "0.0020");57 },58 "can output exponent notation ": function(format) {59 var f = format("e");60 assert.strictEqual(f(0), "0e+0");61 assert.strictEqual(f(42), "4.2e+1");62 assert.strictEqual(f(42000000), "4.2e+7");63 assert.strictEqual(f(420000000), "4.2e+8");64 assert.strictEqual(f(-4), "-4e+0");65 assert.strictEqual(f(-42), "-4.2e+1");66 assert.strictEqual(f(-4200000), "-4.2e+6");67 assert.strictEqual(f(-42000000), "-4.2e+7");68 },69 "can output SI prefix notation": function(format) {70 var f = format("s");71 assert.strictEqual(f(0), "0");72 assert.strictEqual(f(1), "1");73 assert.strictEqual(f(10), "10");74 assert.strictEqual(f(100), "100");75 assert.strictEqual(f(999.5), "999.5");76 assert.strictEqual(f(999500), "999.5k");77 assert.strictEqual(f(1000), "1k");78 assert.strictEqual(f(1400), "1.4k");79 assert.strictEqual(f(1500.5), "1.5005k");80 assert.strictEqual(f(.000001), "1µ");81 },82 "can output SI prefix notation with appropriate rounding": function(format) {83 var f = format(".3s");84 assert.strictEqual(f(0), "0.00");85 assert.strictEqual(f(1), "1.00");86 assert.strictEqual(f(10), "10.0");87 assert.strictEqual(f(100), "100");88 assert.strictEqual(f(999.5), "1.00k");89 assert.strictEqual(f(999500), "1.00M");90 assert.strictEqual(f(1000), "1.00k");91 assert.strictEqual(f(1500.5), "1.50k");92 assert.strictEqual(f(145500000), "146M");93 assert.strictEqual(f(145999999.999999347), "146M");94 assert.strictEqual(f(1e26), "100Y");95 assert.strictEqual(f(.000001), "1.00µ");96 assert.strictEqual(f(.009995), "0.0100");97 var f = format(".4s");98 assert.strictEqual(f(999.5), "999.5");99 assert.strictEqual(f(999500), "999.5k");100 assert.strictEqual(f(.009995), "9.995m");101 },102 "can output a percentage": function(format) {103 var f = format("%");104 assert.strictEqual(f(0), "0%");105 assert.strictEqual(f(.042), "4%");106 assert.strictEqual(f(.42), "42%");107 assert.strictEqual(f(4.2), "420%");108 assert.strictEqual(f(-.042), "-4%");109 assert.strictEqual(f(-.42), "-42%");110 assert.strictEqual(f(-4.2), "-420%");111 },112 "can output a percentage with rounding and sign": function(format) {113 var f = format("+.2p");114 assert.strictEqual(f(.00123), "+0.12%");115 assert.strictEqual(f(.0123), "+1.2%");116 assert.strictEqual(f(.123), "+12%");117 assert.strictEqual(f(1.23), "+120%");118 assert.strictEqual(f(-.00123), "-0.12%");119 assert.strictEqual(f(-.0123), "-1.2%");120 assert.strictEqual(f(-.123), "-12%");121 assert.strictEqual(f(-1.23), "-120%");122 },123 "can round to significant digits": function(format) {124 assert.strictEqual(format(".2r")(0), "0.0");125 assert.strictEqual(format(".1r")(0.049), "0.05");126 assert.strictEqual(format(".1r")(-0.049), "-0.05");127 assert.strictEqual(format(".1r")(0.49), "0.5");128 assert.strictEqual(format(".1r")(-0.49), "-0.5");129 assert.strictEqual(format(".2r")(0.449), "0.45");130 assert.strictEqual(format(".3r")(0.4449), "0.445");131 assert.strictEqual(format(".3r")(1.00), "1.00");132 assert.strictEqual(format(".3r")(0.9995), "1.00");133 assert.strictEqual(format(".5r")(0.444449), "0.44445");134 assert.strictEqual(format("r")(123.45), "123.45");135 assert.strictEqual(format(".1r")(123.45), "100");136 assert.strictEqual(format(".2r")(123.45), "120");137 assert.strictEqual(format(".3r")(123.45), "123");138 assert.strictEqual(format(".4r")(123.45), "123.5");139 assert.strictEqual(format(".5r")(123.45), "123.45");140 assert.strictEqual(format(".6r")(123.45), "123.450");141 assert.strictEqual(format(".1r")(.9), "0.9");142 assert.strictEqual(format(".1r")(.09), "0.09");143 assert.strictEqual(format(".1r")(.949), "0.9");144 assert.strictEqual(format(".1r")(.0949), "0.09");145 assert.strictEqual(format(".10r")(.9999999999), "0.9999999999");146 assert.strictEqual(format(".15r")(.999999999999999), "0.999999999999999");147 },148 "can round very small numbers": function(format) {149 var f = format(".2r");150 assert.strictEqual(f(1e-22), "0.00000000000000000000");151 },152 "can group thousands": function(format) {153 var f = format(",d");154 assert.strictEqual(f(0), "0");155 assert.strictEqual(f(42), "42");156 assert.strictEqual(f(42000000), "42,000,000");157 assert.strictEqual(f(420000000), "420,000,000");158 assert.strictEqual(f(-4), "-4");159 assert.strictEqual(f(-42), "-42");160 assert.strictEqual(f(-4200000), "-4,200,000");161 assert.strictEqual(f(-42000000), "-42,000,000");162 },163 "can group thousands and zero fill": function(format) {164 assert.strictEqual(format("01,d")(0), "0");165 assert.strictEqual(format("01,d")(0), "0");166 assert.strictEqual(format("02,d")(0), "00");167 assert.strictEqual(format("03,d")(0), "000");168 assert.strictEqual(format("05,d")(0), "0,000");169 assert.strictEqual(format("08,d")(0), "0,000,000");170 assert.strictEqual(format("013,d")(0), "0,000,000,000");171 assert.strictEqual(format("021,d")(0), "0,000,000,000,000,000");172 assert.strictEqual(format("013,d")(-42000000), "-0,042,000,000");173 },174 "can group thousands and zero fill with overflow": function(format) {175 assert.strictEqual(format("01,d")(1), "1");176 assert.strictEqual(format("01,d")(1), "1");177 assert.strictEqual(format("02,d")(12), "12");178 assert.strictEqual(format("03,d")(123), "123");179 assert.strictEqual(format("05,d")(12345), "12,345");180 assert.strictEqual(format("08,d")(12345678), "12,345,678");181 assert.strictEqual(format("013,d")(1234567890123), "1,234,567,890,123");182 },183 "can group thousands and space fill": function(format) {184 assert.strictEqual(format("1,d")(0), "0");185 assert.strictEqual(format("1,d")(0), "0");186 assert.strictEqual(format("2,d")(0), " 0");187 assert.strictEqual(format("3,d")(0), " 0");188 assert.strictEqual(format("5,d")(0), " 0");189 assert.strictEqual(format("8,d")(0), " 0");190 assert.strictEqual(format("13,d")(0), " 0");191 assert.strictEqual(format("21,d")(0), " 0");192 },193 "can group thousands and space fill with overflow": function(format) {194 assert.strictEqual(format("1,d")(1), "1");195 assert.strictEqual(format("1,d")(1), "1");196 assert.strictEqual(format("2,d")(12), "12");197 assert.strictEqual(format("3,d")(123), "123");198 assert.strictEqual(format("5,d")(12345), "12,345");199 assert.strictEqual(format("8,d")(12345678), "12,345,678");200 assert.strictEqual(format("13,d")(1234567890123), "1,234,567,890,123");201 },202 "can group thousands with general notation": function(format) {203 var f = format(",g");204 assert.strictEqual(f(0), "0");205 assert.strictEqual(f(42), "42");206 assert.strictEqual(f(42000000), "42,000,000");207 assert.strictEqual(f(420000000), "420,000,000");208 assert.strictEqual(f(-4), "-4");209 assert.strictEqual(f(-42), "-42");210 assert.strictEqual(f(-4200000), "-4,200,000");211 assert.strictEqual(f(-42000000), "-42,000,000");212 },213 "can group thousands, space fill, and round to significant digits": function(format) {214 assert.strictEqual(format("10,.1f")(123456.49), " 123,456.5");215 assert.strictEqual(format("10,.2f")(1234567.449), "1,234,567.45");216 assert.strictEqual(format("10,.3f")(12345678.4449), "12,345,678.445");217 assert.strictEqual(format("10,.5f")(123456789.444449), "123,456,789.44445");218 assert.strictEqual(format("10,.1f")(123456), " 123,456.0");219 assert.strictEqual(format("10,.2f")(1234567), "1,234,567.00");220 assert.strictEqual(format("10,.3f")(12345678), "12,345,678.000");221 assert.strictEqual(format("10,.5f")(123456789), "123,456,789.00000");222 },223 "can display integers in fixed-point notation": function(format) {224 assert.strictEqual(format("f")(42), "42");225 },226 "will not display non-integers in integer format": function(format) {227 assert.strictEqual(format("d")(4.2), "");228 },229 "unicode character": function(format) {230 assert.strictEqual(format("c")(9731), "☃");231 },232 "binary": function(format) {233 assert.strictEqual(format("b")(10), "1010");234 },235 "binary with prefix": function(format) {236 assert.strictEqual(format("#b")(10), "0b1010");237 },238 "octal": function(format) {239 assert.strictEqual(format("o")(10), "12");240 },241 "octal with prefix": function(format) {242 assert.strictEqual(format("#o")(10), "0o12");243 },244 "hexadecimal (lowercase)": function(format) {245 assert.strictEqual(format("x")(3735928559), "deadbeef");246 },247 "hexadecimal (lowercase) with prefix": function(format) {248 assert.strictEqual(format("#x")(3735928559), "0xdeadbeef");249 },250 "hexadecimal (uppercase)": function(format) {251 assert.strictEqual(format("X")(3735928559), "DEADBEEF");252 },253 "hexadecimal (uppercase) with prefix": function(format) {254 assert.strictEqual(format("#X")(3735928559), "0xDEADBEEF");255 },256 "fill respects prefix": function(format) {257 assert.strictEqual(format("#20x")(3735928559), " 0xdeadbeef");258 },259 "align left": function(format) {260 assert.strictEqual(format("<1,d")(0), "0");261 assert.strictEqual(format("<1,d")(0), "0");262 assert.strictEqual(format("<2,d")(0), "0 ");263 assert.strictEqual(format("<3,d")(0), "0 ");264 assert.strictEqual(format("<5,d")(0), "0 ");265 assert.strictEqual(format("<8,d")(0), "0 ");266 assert.strictEqual(format("<13,d")(0), "0 ");267 assert.strictEqual(format("<21,d")(0), "0 ");268 },269 "align right": function(format) {270 assert.strictEqual(format(">1,d")(0), "0");271 assert.strictEqual(format(">1,d")(0), "0");272 assert.strictEqual(format(">2,d")(0), " 0");273 assert.strictEqual(format(">3,d")(0), " 0");274 assert.strictEqual(format(">5,d")(0), " 0");275 assert.strictEqual(format(">8,d")(0), " 0");276 assert.strictEqual(format(">13,d")(0), " 0");277 assert.strictEqual(format(">21,d")(0), " 0");278 },279 "align center": function(format) {280 assert.strictEqual(format("^1,d")(0), "0");281 assert.strictEqual(format("^1,d")(0), "0");282 assert.strictEqual(format("^2,d")(0), " 0");283 assert.strictEqual(format("^3,d")(0), " 0 ");284 assert.strictEqual(format("^5,d")(0), " 0 ");285 assert.strictEqual(format("^8,d")(0), " 0 ");286 assert.strictEqual(format("^13,d")(0), " 0 ");287 assert.strictEqual(format("^21,d")(0), " 0 ");288 },289 "pad after sign": function(format) {290 assert.strictEqual(format("=+1,d")(0), "+0");291 assert.strictEqual(format("=+1,d")(0), "+0");292 assert.strictEqual(format("=+2,d")(0), "+0");293 assert.strictEqual(format("=+3,d")(0), "+ 0");294 assert.strictEqual(format("=+5,d")(0), "+ 0");295 assert.strictEqual(format("=+8,d")(0), "+ 0");296 assert.strictEqual(format("=+13,d")(0), "+ 0");297 assert.strictEqual(format("=+21,d")(0), "+ 0");298 },299 "a space can denote positive numbers": function(format) {300 assert.strictEqual(format(" 1,d")(-1), "-1");301 assert.strictEqual(format(" 1,d")(0), " 0");302 assert.strictEqual(format(" 2,d")(0), " 0");303 assert.strictEqual(format(" 3,d")(0), " 0");304 assert.strictEqual(format(" 5,d")(0), " 0");305 assert.strictEqual(format(" 8,d")(0), " 0");306 assert.strictEqual(format(" 13,d")(0), " 0");307 assert.strictEqual(format(" 21,d")(0), " 0");308 },309 "can format negative zero": function(format) {310 assert.strictEqual(format("1d")(-0), "-0");311 assert.strictEqual(format("1f")(-0), "-0");312 },313 "supports \"n\" as an alias for \",g\"": function(format) {314 var f = format("n");315 assert.strictEqual(f(.0042), "0.0042");316 assert.strictEqual(f(.42), "0.42");317 assert.strictEqual(f(0), "0");318 assert.strictEqual(f(42), "42");319 assert.strictEqual(f(42000000), "42,000,000");320 assert.strictEqual(f(420000000), "420,000,000");321 assert.strictEqual(f(-4), "-4");322 assert.strictEqual(f(-42), "-42");323 assert.strictEqual(f(-4200000), "-4,200,000");324 assert.strictEqual(f(-42000000), "-42,000,000");325 }326 }327});...

Full Screen

Full Screen

bisect-test.js

Source:bisect-test.js Github

copy

Full Screen

1require("../env");2var vows = require("vows"),3 assert = require("assert");4var suite = vows.describe("d3.bisect");5var i30 = 1 << 30;6suite.addBatch({7 "bisectLeft": {8 topic: function() {9 return d3.bisectLeft;10 },11 "finds the index of an exact match": function(bisect) {12 var array = [1, 2, 3];13 assert.equal(bisect(array, 1), 0);14 assert.equal(bisect(array, 2), 1);15 assert.equal(bisect(array, 3), 2);16 },17 "finds the index of the first match": function(bisect) {18 var array = [1, 2, 2, 3];19 assert.equal(bisect(array, 1), 0);20 assert.equal(bisect(array, 2), 1);21 assert.equal(bisect(array, 3), 3);22 },23 "finds the insertion point of a non-exact match": function(bisect) {24 var array = [1, 2, 3];25 assert.equal(bisect(array, 0.5), 0);26 assert.equal(bisect(array, 1.5), 1);27 assert.equal(bisect(array, 2.5), 2);28 assert.equal(bisect(array, 3.5), 3);29 },30 "observes the optional lower bound": function(bisect) {31 var array = [1, 2, 3, 4, 5];32 assert.equal(bisect(array, 0, 2), 2);33 assert.equal(bisect(array, 1, 2), 2);34 assert.equal(bisect(array, 2, 2), 2);35 assert.equal(bisect(array, 3, 2), 2);36 assert.equal(bisect(array, 4, 2), 3);37 assert.equal(bisect(array, 5, 2), 4);38 assert.equal(bisect(array, 6, 2), 5);39 },40 "observes the optional bounds": function(bisect) {41 var array = [1, 2, 3, 4, 5];42 assert.equal(bisect(array, 0, 2, 3), 2);43 assert.equal(bisect(array, 1, 2, 3), 2);44 assert.equal(bisect(array, 2, 2, 3), 2);45 assert.equal(bisect(array, 3, 2, 3), 2);46 assert.equal(bisect(array, 4, 2, 3), 3);47 assert.equal(bisect(array, 5, 2, 3), 3);48 assert.equal(bisect(array, 6, 2, 3), 3);49 },50 "large arrays": function(bisect) {51 var array = [],52 i = i30;53 array[i++] = 1;54 array[i++] = 2;55 array[i++] = 3;56 array[i++] = 4;57 array[i++] = 5;58 assert.equal(bisect(array, 0, i - 5, i), i - 5);59 assert.equal(bisect(array, 1, i - 5, i), i - 5);60 assert.equal(bisect(array, 2, i - 5, i), i - 4);61 assert.equal(bisect(array, 3, i - 5, i), i - 3);62 assert.equal(bisect(array, 4, i - 5, i), i - 2);63 assert.equal(bisect(array, 5, i - 5, i), i - 1);64 assert.equal(bisect(array, 6, i - 5, i), i - 0);65 }66 }67});68suite.addBatch({69 "bisectRight": {70 topic: function() {71 return d3.bisectRight;72 },73 "finds the index after an exact match": function(bisect) {74 var array = [1, 2, 3];75 assert.equal(bisect(array, 1), 1);76 assert.equal(bisect(array, 2), 2);77 assert.equal(bisect(array, 3), 3);78 },79 "finds the index after the last match": function(bisect) {80 var array = [1, 2, 2, 3];81 assert.equal(bisect(array, 1), 1);82 assert.equal(bisect(array, 2), 3);83 assert.equal(bisect(array, 3), 4);84 },85 "finds the insertion point of a non-exact match": function(bisect) {86 var array = [1, 2, 3];87 assert.equal(bisect(array, 0.5), 0);88 assert.equal(bisect(array, 1.5), 1);89 assert.equal(bisect(array, 2.5), 2);90 assert.equal(bisect(array, 3.5), 3);91 },92 "observes the optional lower bound": function(bisect) {93 var array = [1, 2, 3, 4, 5];94 assert.equal(bisect(array, 0, 2), 2);95 assert.equal(bisect(array, 1, 2), 2);96 assert.equal(bisect(array, 2, 2), 2);97 assert.equal(bisect(array, 3, 2), 3);98 assert.equal(bisect(array, 4, 2), 4);99 assert.equal(bisect(array, 5, 2), 5);100 assert.equal(bisect(array, 6, 2), 5);101 },102 "observes the optional bounds": function(bisect) {103 var array = [1, 2, 3, 4, 5];104 assert.equal(bisect(array, 0, 2, 3), 2);105 assert.equal(bisect(array, 1, 2, 3), 2);106 assert.equal(bisect(array, 2, 2, 3), 2);107 assert.equal(bisect(array, 3, 2, 3), 3);108 assert.equal(bisect(array, 4, 2, 3), 3);109 assert.equal(bisect(array, 5, 2, 3), 3);110 assert.equal(bisect(array, 6, 2, 3), 3);111 },112 "large arrays": function(bisect) {113 var array = [],114 i = i30;115 array[i++] = 1;116 array[i++] = 2;117 array[i++] = 3;118 array[i++] = 4;119 array[i++] = 5;120 assert.equal(bisect(array, 0, i - 5, i), i - 5);121 assert.equal(bisect(array, 1, i - 5, i), i - 4);122 assert.equal(bisect(array, 2, i - 5, i), i - 3);123 assert.equal(bisect(array, 3, i - 5, i), i - 2);124 assert.equal(bisect(array, 4, i - 5, i), i - 1);125 assert.equal(bisect(array, 5, i - 5, i), i - 0);126 assert.equal(bisect(array, 6, i - 5, i), i - 0);127 }128 }129});130suite.addBatch({131 "bisector(key)": {132 topic: function() {133 return d3.bisector(function(d) { return d.key; });134 },135 "left": {136 topic: function(bisector) {137 return bisector.left;138 },139 "finds the index of an exact match": function(bisect) {140 var array = [{key: 1}, {key: 2}, {key: 3}];141 assert.equal(bisect(array, 1), 0);142 assert.equal(bisect(array, 2), 1);143 assert.equal(bisect(array, 3), 2);144 },145 "finds the index of the first match": function(bisect) {146 var array = [{key: 1}, {key: 2}, {key: 2}, {key: 3}];147 assert.equal(bisect(array, 1), 0);148 assert.equal(bisect(array, 2), 1);149 assert.equal(bisect(array, 3), 3);150 },151 "finds the insertion point of a non-exact match": function(bisect) {152 var array = [{key: 1}, {key: 2}, {key: 3}];153 assert.equal(bisect(array, 0.5), 0);154 assert.equal(bisect(array, 1.5), 1);155 assert.equal(bisect(array, 2.5), 2);156 assert.equal(bisect(array, 3.5), 3);157 },158 "observes the optional lower bound": function(bisect) {159 var array = [{key: 1}, {key: 2}, {key: 3}, {key: 4}, {key: 5}];160 assert.equal(bisect(array, 0, 2), 2);161 assert.equal(bisect(array, 1, 2), 2);162 assert.equal(bisect(array, 2, 2), 2);163 assert.equal(bisect(array, 3, 2), 2);164 assert.equal(bisect(array, 4, 2), 3);165 assert.equal(bisect(array, 5, 2), 4);166 assert.equal(bisect(array, 6, 2), 5);167 },168 "observes the optional bounds": function(bisect) {169 var array = [{key: 1}, {key: 2}, {key: 3}, {key: 4}, {key: 5}];170 assert.equal(bisect(array, 0, 2, 3), 2);171 assert.equal(bisect(array, 1, 2, 3), 2);172 assert.equal(bisect(array, 2, 2, 3), 2);173 assert.equal(bisect(array, 3, 2, 3), 2);174 assert.equal(bisect(array, 4, 2, 3), 3);175 assert.equal(bisect(array, 5, 2, 3), 3);176 assert.equal(bisect(array, 6, 2, 3), 3);177 },178 "large arrays": function(bisect) {179 var array = [],180 i = i30;181 array[i++] = {key: 1};182 array[i++] = {key: 2};183 array[i++] = {key: 3};184 array[i++] = {key: 4};185 array[i++] = {key: 5};186 assert.equal(bisect(array, 0, i - 5, i), i - 5);187 assert.equal(bisect(array, 1, i - 5, i), i - 5);188 assert.equal(bisect(array, 2, i - 5, i), i - 4);189 assert.equal(bisect(array, 3, i - 5, i), i - 3);190 assert.equal(bisect(array, 4, i - 5, i), i - 2);191 assert.equal(bisect(array, 5, i - 5, i), i - 1);192 assert.equal(bisect(array, 6, i - 5, i), i - 0);193 }194 },195 "right": {196 topic: function(bisector) {197 return bisector.right;198 },199 "finds the index after an exact match": function(bisect) {200 var array = [{key: 1}, {key: 2}, {key: 3}];201 assert.equal(bisect(array, 1), 1);202 assert.equal(bisect(array, 2), 2);203 assert.equal(bisect(array, 3), 3);204 },205 "finds the index after the last match": function(bisect) {206 var array = [{key: 1}, {key: 2}, {key: 2}, {key: 3}];207 assert.equal(bisect(array, 1), 1);208 assert.equal(bisect(array, 2), 3);209 assert.equal(bisect(array, 3), 4);210 },211 "finds the insertion point of a non-exact match": function(bisect) {212 var array = [{key: 1}, {key: 2}, {key: 3}];213 assert.equal(bisect(array, 0.5), 0);214 assert.equal(bisect(array, 1.5), 1);215 assert.equal(bisect(array, 2.5), 2);216 assert.equal(bisect(array, 3.5), 3);217 },218 "observes the optional lower bound": function(bisect) {219 var array = [{key: 1}, {key: 2}, {key: 3}, {key: 4}, {key: 5}];220 assert.equal(bisect(array, 0, 2), 2);221 assert.equal(bisect(array, 1, 2), 2);222 assert.equal(bisect(array, 2, 2), 2);223 assert.equal(bisect(array, 3, 2), 3);224 assert.equal(bisect(array, 4, 2), 4);225 assert.equal(bisect(array, 5, 2), 5);226 assert.equal(bisect(array, 6, 2), 5);227 },228 "observes the optional bounds": function(bisect) {229 var array = [{key: 1}, {key: 2}, {key: 3}, {key: 4}, {key: 5}];230 assert.equal(bisect(array, 0, 2, 3), 2);231 assert.equal(bisect(array, 1, 2, 3), 2);232 assert.equal(bisect(array, 2, 2, 3), 2);233 assert.equal(bisect(array, 3, 2, 3), 3);234 assert.equal(bisect(array, 4, 2, 3), 3);235 assert.equal(bisect(array, 5, 2, 3), 3);236 assert.equal(bisect(array, 6, 2, 3), 3);237 },238 "large arrays": function(bisect) {239 var array = [],240 i = i30;241 array[i++] = {key: 1};242 array[i++] = {key: 2};243 array[i++] = {key: 3};244 array[i++] = {key: 4};245 array[i++] = {key: 5};246 assert.equal(bisect(array, 0, i - 5, i), i - 5);247 assert.equal(bisect(array, 1, i - 5, i), i - 4);248 assert.equal(bisect(array, 2, i - 5, i), i - 3);249 assert.equal(bisect(array, 3, i - 5, i), i - 2);250 assert.equal(bisect(array, 4, i - 5, i), i - 1);251 assert.equal(bisect(array, 5, i - 5, i), i - 0);252 assert.equal(bisect(array, 6, i - 5, i), i - 0);253 }254 }255 }256});...

Full Screen

Full Screen

stream-test.js

Source:stream-test.js Github

copy

Full Screen

1require("../env");2var vows = require("vows"),3 assert = require("assert");4var suite = vows.describe("d3.geo.stream");5suite.addBatch({6 "stream": {7 topic: function() {8 return d3.geo.stream;9 },10 "does not allow null input": function(stream) {11 try {12 stream(null);13 assert.fail("expected error");14 } catch (expected) {}15 },16 "ignores unknown types": function(stream) {17 stream({type: "Unknown"}, {});18 stream({type: "Feature", geometry: {type: "Unknown"}}, {});19 stream({type: "FeatureCollection", features: [{type: "Feature", geometry: {type: "Unknown"}}]}, {});20 stream({type: "GeometryCollection", geometries: [{type: "Unknown"}]}, {});21 },22 "returns void": function(stream) {23 assert.isUndefined(stream({type: "Point", coordinates: [1, 2]}, {point: function() { return true; }}));24 },25 "allows empty multi-geometries": function(stream) {26 stream({type: "MultiPoint", coordinates: []}, {});27 stream({type: "MultiLineString", coordinates: []}, {});28 stream({type: "MultiPolygon", coordinates: []}, {});29 },30 "Sphere ↦ sphere": function(stream) {31 var calls = 0;32 stream({type: "Sphere"}, {33 sphere: function() {34 ++calls;35 assert.equal(arguments.length, 0);36 }37 });38 assert.equal(calls, 1);39 },40 "Point ↦ point": function(stream) {41 var calls = 0;42 stream({type: "Point", coordinates: [1, 2]}, {43 point: function(x, y) {44 ++calls;45 assert.equal(arguments.length, 2);46 assert.equal(x, 1);47 assert.equal(y, 2);48 }49 });50 assert.equal(calls, 1);51 },52 "MultiPoint ↦ point*": function(stream) {53 var calls = 0;54 stream({type: "MultiPoint", coordinates: [[1, 2], [3, 4]]}, {55 point: function(x, y) {56 assert.equal(arguments.length, 2);57 if (++calls === 1) {58 assert.equal(x, 1);59 assert.equal(y, 2);60 } else {61 assert.equal(x, 3);62 assert.equal(y, 4);63 }64 }65 });66 assert.equal(calls, 2);67 },68 "LineString ↦ lineStart, point{2,}, lineEnd": function(stream) {69 var calls = 0;70 stream({type: "LineString", coordinates: [[1, 2], [3, 4]]}, {71 lineStart: function() {72 assert.equal(++calls, 1);73 assert.equal(arguments.length, 0);74 },75 point: function(x, y) {76 assert.equal(arguments.length, 2);77 if (++calls === 2) {78 assert.equal(x, 1);79 assert.equal(y, 2);80 } else if (calls === 3) {81 assert.equal(x, 3);82 assert.equal(y, 4);83 } else {84 assert.fail("too many points");85 }86 },87 lineEnd: function() {88 assert.equal(++calls, 4);89 assert.equal(arguments.length, 0);90 }91 });92 assert.equal(calls, 4);93 },94 "MultiLineString ↦ (lineStart, point{2,}, lineEnd)*": function(stream) {95 var calls = 0;96 stream({type: "MultiLineString", coordinates: [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]}, {97 lineStart: function() {98 ++calls;99 assert.isTrue(calls === 1 || calls === 5);100 assert.equal(arguments.length, 0);101 },102 point: function(x, y) {103 ++calls;104 assert.equal(arguments.length, 2);105 if (calls === 2) {106 assert.equal(x, 1);107 assert.equal(y, 2);108 } else if (calls === 3) {109 assert.equal(x, 3);110 assert.equal(y, 4);111 } else if (calls === 6) {112 assert.equal(x, 5);113 assert.equal(y, 6);114 } else if (calls === 7) {115 assert.equal(x, 7);116 assert.equal(y, 8);117 } else {118 assert.fail("too many points");119 }120 },121 lineEnd: function() {122 ++calls;123 assert.isTrue(calls === 4 || calls === 8);124 assert.equal(arguments.length, 0);125 }126 });127 assert.equal(calls, 8);128 },129 "Polygon ↦ polygonStart, lineStart, point{2,}, lineEnd, polygonEnd": function(stream) {130 var calls = 0;131 stream({type: "Polygon", coordinates: [[[1, 2], [3, 4], [1, 2]], [[5, 6], [7, 8], [5, 6]]]}, {132 polygonStart: function() {133 ++calls;134 assert.isTrue(calls === 1);135 assert.equal(arguments.length, 0);136 },137 lineStart: function() {138 ++calls;139 assert.isTrue(calls === 2 || calls === 6);140 assert.equal(arguments.length, 0);141 },142 point: function(x, y) {143 ++calls;144 assert.equal(arguments.length, 2);145 if (calls === 3) {146 assert.equal(x, 1);147 assert.equal(y, 2);148 } else if (calls === 4) {149 assert.equal(x, 3);150 assert.equal(y, 4);151 } else if (calls === 7) {152 assert.equal(x, 5);153 assert.equal(y, 6);154 } else if (calls === 8) {155 assert.equal(x, 7);156 assert.equal(y, 8);157 } else {158 assert.fail("too many points");159 }160 },161 lineEnd: function() {162 ++calls;163 assert.isTrue(calls === 5 || calls === 9);164 assert.equal(arguments.length, 0);165 },166 polygonEnd: function() {167 ++calls;168 assert.isTrue(calls === 10);169 assert.equal(arguments.length, 0);170 }171 });172 assert.equal(calls, 10);173 },174 "MultiPolygon ↦ (polygonStart, lineStart, point{2,}, lineEnd, polygonEnd)*": function(stream) {175 var calls = 0;176 stream({type: "MultiPolygon", coordinates: [[[[1, 2], [3, 4], [1, 2]]], [[[5, 6], [7, 8], [5, 6]]]]}, {177 polygonStart: function() {178 ++calls;179 assert.isTrue(calls === 1 || calls === 7);180 assert.equal(arguments.length, 0);181 },182 lineStart: function() {183 ++calls;184 assert.isTrue(calls === 2 || calls === 8);185 assert.equal(arguments.length, 0);186 },187 point: function(x, y) {188 ++calls;189 assert.equal(arguments.length, 2);190 if (calls === 3) {191 assert.equal(x, 1);192 assert.equal(y, 2);193 } else if (calls === 4) {194 assert.equal(x, 3);195 assert.equal(y, 4);196 } else if (calls === 9) {197 assert.equal(x, 5);198 assert.equal(y, 6);199 } else if (calls === 10) {200 assert.equal(x, 7);201 assert.equal(y, 8);202 } else {203 assert.fail("too many points");204 }205 },206 lineEnd: function() {207 ++calls;208 assert.isTrue(calls === 5 || calls === 11);209 assert.equal(arguments.length, 0);210 },211 polygonEnd: function() {212 ++calls;213 assert.isTrue(calls === 6 || calls === 12);214 assert.equal(arguments.length, 0);215 }216 });217 assert.equal(calls, 12);218 },219 "Feature ↦ .*": function(stream) {220 var calls = 0;221 stream({type: "Feature", geometry: {type: "Point", coordinates: [1, 2]}}, {222 point: function(x, y) {223 ++calls;224 assert.equal(arguments.length, 2);225 assert.equal(x, 1);226 assert.equal(y, 2);227 }228 });229 assert.equal(calls, 1);230 },231 "FeatureCollection ↦ .*": function(stream) {232 var calls = 0;233 stream({type: "FeatureCollection", features: [{type: "Feature", geometry: {type: "Point", coordinates: [1, 2]}}]}, {234 point: function(x, y) {235 ++calls;236 assert.equal(arguments.length, 2);237 assert.equal(x, 1);238 assert.equal(y, 2);239 }240 });241 assert.equal(calls, 1);242 },243 "GeometryCollection ↦ .*": function(stream) {244 var calls = 0;245 stream({type: "GeometryCollection", geometries: [{type: "Point", coordinates: [1, 2]}]}, {246 point: function(x, y) {247 ++calls;248 assert.equal(arguments.length, 2);249 assert.equal(x, 1);250 assert.equal(y, 2);251 }252 });253 assert.equal(calls, 1);254 }255 }256});...

Full Screen

Full Screen

invalid.js

Source:invalid.js Github

copy

Full Screen

1import { module, test } from '../qunit';2import moment from '../../moment';3module('invalid');4test('invalid', function (assert) {5 var m = moment.invalid();6 assert.equal(m.isValid(), false);7 assert.equal(m.parsingFlags().userInvalidated, true);8 assert.ok(isNaN(m.valueOf()));9});10test('invalid with existing flag', function (assert) {11 var m = moment.invalid({invalidMonth : 'whatchamacallit'});12 assert.equal(m.isValid(), false);13 assert.equal(m.parsingFlags().userInvalidated, false);14 assert.equal(m.parsingFlags().invalidMonth, 'whatchamacallit');15 assert.ok(isNaN(m.valueOf()));16});17test('invalid with custom flag', function (assert) {18 var m = moment.invalid({tooBusyWith : 'reiculating splines'});19 assert.equal(m.isValid(), false);20 assert.equal(m.parsingFlags().userInvalidated, false);21 assert.equal(m.parsingFlags().tooBusyWith, 'reiculating splines');22 assert.ok(isNaN(m.valueOf()));23});24test('invalid operations', function (assert) {25 var invalids = [26 moment.invalid(),27 moment('xyz', 'l'),28 moment('2015-01-35', 'YYYY-MM-DD'),29 moment('2015-01-25 a', 'YYYY-MM-DD', true)30 ],31 i,32 invalid,33 valid = moment();34 for (i = 0; i < invalids.length; ++i) {35 invalid = invalids[i];36 assert.ok(!invalid.clone().add(5, 'hours').isValid(), 'invalid.add is invalid');37 assert.equal(invalid.calendar(), 'Invalid date', 'invalid.calendar is \'Invalid date\'');38 assert.ok(!invalid.clone().isValid(), 'invalid.clone is invalid');39 assert.ok(isNaN(invalid.diff(valid)), 'invalid.diff(valid) is NaN');40 assert.ok(isNaN(valid.diff(invalid)), 'valid.diff(invalid) is NaN');41 assert.ok(isNaN(invalid.diff(invalid)), 'invalid.diff(invalid) is NaN');42 assert.ok(!invalid.clone().endOf('month').isValid(), 'invalid.endOf is invalid');43 assert.equal(invalid.format(), 'Invalid date', 'invalid.format is \'Invalid date\'');44 assert.equal(invalid.from(), 'Invalid date');45 assert.equal(invalid.from(valid), 'Invalid date');46 assert.equal(valid.from(invalid), 'Invalid date');47 assert.equal(invalid.fromNow(), 'Invalid date');48 assert.equal(invalid.to(), 'Invalid date');49 assert.equal(invalid.to(valid), 'Invalid date');50 assert.equal(valid.to(invalid), 'Invalid date');51 assert.equal(invalid.toNow(), 'Invalid date');52 assert.ok(isNaN(invalid.get('year')), 'invalid.get is NaN');53 // TODO invalidAt54 assert.ok(!invalid.isAfter(valid));55 assert.ok(!valid.isAfter(invalid));56 assert.ok(!invalid.isAfter(invalid));57 assert.ok(!invalid.isBefore(valid));58 assert.ok(!valid.isBefore(invalid));59 assert.ok(!invalid.isBefore(invalid));60 assert.ok(!invalid.isBetween(valid, valid));61 assert.ok(!valid.isBetween(invalid, valid));62 assert.ok(!valid.isBetween(valid, invalid));63 assert.ok(!invalid.isSame(invalid));64 assert.ok(!invalid.isSame(valid));65 assert.ok(!valid.isSame(invalid));66 assert.ok(!invalid.isValid());67 assert.equal(invalid.locale(), 'en');68 assert.equal(invalid.localeData()._abbr, 'en');69 assert.ok(!invalid.clone().max(valid).isValid());70 assert.ok(!valid.clone().max(invalid).isValid());71 assert.ok(!invalid.clone().max(invalid).isValid());72 assert.ok(!invalid.clone().min(valid).isValid());73 assert.ok(!valid.clone().min(invalid).isValid());74 assert.ok(!invalid.clone().min(invalid).isValid());75 assert.ok(!moment.min(invalid, valid).isValid());76 assert.ok(!moment.min(valid, invalid).isValid());77 assert.ok(!moment.max(invalid, valid).isValid());78 assert.ok(!moment.max(valid, invalid).isValid());79 assert.ok(!invalid.clone().set('year', 2005).isValid());80 assert.ok(!invalid.clone().startOf('month').isValid());81 assert.ok(!invalid.clone().subtract(5, 'days').isValid());82 assert.deepEqual(invalid.toArray(), [NaN, NaN, NaN, NaN, NaN, NaN, NaN]);83 assert.deepEqual(invalid.toObject(), {84 years: NaN,85 months: NaN,86 date: NaN,87 hours: NaN,88 minutes: NaN,89 seconds: NaN,90 milliseconds: NaN91 });92 assert.ok(moment.isDate(invalid.toDate()));93 assert.ok(isNaN(invalid.toDate().valueOf()));94 assert.equal(invalid.toJSON(), 'null');95 assert.equal(invalid.toString(), 'Invalid date');96 assert.ok(isNaN(invalid.unix()));97 assert.ok(isNaN(invalid.valueOf()));98 assert.ok(isNaN(invalid.year()));99 assert.ok(isNaN(invalid.weekYear()));100 assert.ok(isNaN(invalid.isoWeekYear()));101 assert.ok(isNaN(invalid.quarter()));102 assert.ok(isNaN(invalid.quarters()));103 assert.ok(isNaN(invalid.month()));104 assert.ok(isNaN(invalid.daysInMonth()));105 assert.ok(isNaN(invalid.week()));106 assert.ok(isNaN(invalid.weeks()));107 assert.ok(isNaN(invalid.isoWeek()));108 assert.ok(isNaN(invalid.isoWeeks()));109 assert.ok(isNaN(invalid.weeksInYear()));110 assert.ok(isNaN(invalid.isoWeeksInYear()));111 assert.ok(isNaN(invalid.date()));112 assert.ok(isNaN(invalid.day()));113 assert.ok(isNaN(invalid.days()));114 assert.ok(isNaN(invalid.weekday()));115 assert.ok(isNaN(invalid.isoWeekday()));116 assert.ok(isNaN(invalid.dayOfYear()));117 assert.ok(isNaN(invalid.hour()));118 assert.ok(isNaN(invalid.hours()));119 assert.ok(isNaN(invalid.minute()));120 assert.ok(isNaN(invalid.minutes()));121 assert.ok(isNaN(invalid.second()));122 assert.ok(isNaN(invalid.seconds()));123 assert.ok(isNaN(invalid.millisecond()));124 assert.ok(isNaN(invalid.milliseconds()));125 assert.ok(isNaN(invalid.utcOffset()));126 assert.ok(!invalid.clone().year(2001).isValid());127 assert.ok(!invalid.clone().weekYear(2001).isValid());128 assert.ok(!invalid.clone().isoWeekYear(2001).isValid());129 assert.ok(!invalid.clone().quarter(1).isValid());130 assert.ok(!invalid.clone().quarters(1).isValid());131 assert.ok(!invalid.clone().month(1).isValid());132 assert.ok(!invalid.clone().week(1).isValid());133 assert.ok(!invalid.clone().weeks(1).isValid());134 assert.ok(!invalid.clone().isoWeek(1).isValid());135 assert.ok(!invalid.clone().isoWeeks(1).isValid());136 assert.ok(!invalid.clone().date(1).isValid());137 assert.ok(!invalid.clone().day(1).isValid());138 assert.ok(!invalid.clone().days(1).isValid());139 assert.ok(!invalid.clone().weekday(1).isValid());140 assert.ok(!invalid.clone().isoWeekday(1).isValid());141 assert.ok(!invalid.clone().dayOfYear(1).isValid());142 assert.ok(!invalid.clone().hour(1).isValid());143 assert.ok(!invalid.clone().hours(1).isValid());144 assert.ok(!invalid.clone().minute(1).isValid());145 assert.ok(!invalid.clone().minutes(1).isValid());146 assert.ok(!invalid.clone().second(1).isValid());147 assert.ok(!invalid.clone().seconds(1).isValid());148 assert.ok(!invalid.clone().millisecond(1).isValid());149 assert.ok(!invalid.clone().milliseconds(1).isValid());150 assert.ok(!invalid.clone().utcOffset(1).isValid());151 assert.ok(!invalid.clone().utc().isValid());152 assert.ok(!invalid.clone().local().isValid());153 assert.ok(!invalid.clone().parseZone('05:30').isValid());154 assert.ok(!invalid.hasAlignedHourOffset());155 assert.ok(!invalid.isDST());156 assert.ok(!invalid.isDSTShifted());157 assert.ok(!invalid.isLocal());158 assert.ok(!invalid.isUtcOffset());159 assert.ok(!invalid.isUtc());160 assert.ok(!invalid.isUTC());161 assert.ok(!invalid.isLeapYear());162 assert.equal(moment.duration({from: invalid, to: valid}).asMilliseconds(), 0);163 assert.equal(moment.duration({from: valid, to: invalid}).asMilliseconds(), 0);164 assert.equal(moment.duration({from: invalid, to: invalid}).asMilliseconds(), 0);165 }...

Full Screen

Full Screen

formatPrefix-test.js

Source:formatPrefix-test.js Github

copy

Full Screen

1require("../env");2var vows = require("vows"),3 assert = require("assert");4var suite = vows.describe("d3.formatPrefix");5suite.addBatch({6 "formatPrefix": {7 topic: function() {8 return d3.formatPrefix;9 },10 "determines the appropriate prefix for small numbers": function(prefix) {11 assert.equal(prefix(0).symbol, "");12 assert.equal(prefix(1e-00).symbol, "");13 assert.equal(prefix(1e-01).symbol, "");14 assert.equal(prefix(1e-02).symbol, "");15 assert.equal(prefix(1e-03).symbol, "m");16 assert.equal(prefix(1e-04).symbol, "m");17 assert.equal(prefix(1e-05).symbol, "m");18 assert.equal(prefix(1e-06).symbol, "µ");19 assert.equal(prefix(1e-07).symbol, "µ");20 assert.equal(prefix(1e-08).symbol, "µ");21 assert.equal(prefix(1e-09).symbol, "n");22 assert.equal(prefix(1e-10).symbol, "n");23 assert.equal(prefix(1e-11).symbol, "n");24 assert.equal(prefix(1e-12).symbol, "p");25 assert.equal(prefix(1e-13).symbol, "p");26 assert.equal(prefix(1e-14).symbol, "p");27 assert.equal(prefix(1e-15).symbol, "f");28 assert.equal(prefix(1e-16).symbol, "f");29 assert.equal(prefix(1e-17).symbol, "f");30 assert.equal(prefix(1e-18).symbol, "a");31 assert.equal(prefix(1e-19).symbol, "a");32 assert.equal(prefix(1e-20).symbol, "a");33 assert.equal(prefix(1e-21).symbol, "z");34 assert.equal(prefix(1e-22).symbol, "z");35 assert.equal(prefix(1e-23).symbol, "z");36 assert.equal(prefix(1e-24).symbol, "y");37 assert.equal(prefix(1e-25).symbol, "y");38 assert.equal(prefix(1e-26).symbol, "y");39 assert.equal(prefix(1e-27).symbol, "y");40 },41 "determines the appropriate prefix for large numbers": function(prefix) {42 assert.equal(prefix(0).symbol, "");43 assert.equal(prefix(1e00).symbol, "");44 assert.equal(prefix(1e01).symbol, "");45 assert.equal(prefix(1e02).symbol, "");46 assert.equal(prefix(1e03).symbol, "k");47 assert.equal(prefix(1e04).symbol, "k");48 assert.equal(prefix(1e05).symbol, "k");49 assert.equal(prefix(1e06).symbol, "M");50 assert.equal(prefix(1e07).symbol, "M");51 assert.equal(prefix(1e08).symbol, "M");52 assert.equal(prefix(1e09).symbol, "G");53 assert.equal(prefix(1e10).symbol, "G");54 assert.equal(prefix(1e11).symbol, "G");55 assert.equal(prefix(1e12).symbol, "T");56 assert.equal(prefix(1e13).symbol, "T");57 assert.equal(prefix(1e14).symbol, "T");58 assert.equal(prefix(1e15).symbol, "P");59 assert.equal(prefix(1e16).symbol, "P");60 assert.equal(prefix(1e17).symbol, "P");61 assert.equal(prefix(1e18).symbol, "E");62 assert.equal(prefix(1e19).symbol, "E");63 assert.equal(prefix(1e20).symbol, "E");64 assert.equal(prefix(1e21).symbol, "Z");65 assert.equal(prefix(1e22).symbol, "Z");66 assert.equal(prefix(1e23).symbol, "Z");67 assert.equal(prefix(1e24).symbol, "Y");68 assert.equal(prefix(1e25).symbol, "Y");69 assert.equal(prefix(1e26).symbol, "Y");70 assert.equal(prefix(1e27).symbol, "Y");71 },72 "determines the appropriate prefix for negative numbers": function(prefix) {73 assert.equal(prefix(-0).symbol, "");74 assert.equal(prefix(-1e-00).symbol, "");75 assert.equal(prefix(-1e-03).symbol, "m");76 assert.equal(prefix(-1e-06).symbol, "µ");77 assert.equal(prefix(-1e-09).symbol, "n");78 assert.equal(prefix(-1e-12).symbol, "p");79 assert.equal(prefix(-1e-15).symbol, "f");80 assert.equal(prefix(-1e-18).symbol, "a");81 assert.equal(prefix(-1e-21).symbol, "z");82 assert.equal(prefix(-1e-24).symbol, "y");83 assert.equal(prefix(-1e-27).symbol, "y");84 assert.equal(prefix(-1e00).symbol, "");85 assert.equal(prefix(-1e03).symbol, "k");86 assert.equal(prefix(-1e06).symbol, "M");87 assert.equal(prefix(-1e09).symbol, "G");88 assert.equal(prefix(-1e12).symbol, "T");89 assert.equal(prefix(-1e15).symbol, "P");90 assert.equal(prefix(-1e18).symbol, "E");91 assert.equal(prefix(-1e21).symbol, "Z");92 assert.equal(prefix(-1e24).symbol, "Y");93 assert.equal(prefix(-1e27).symbol, "Y");94 },95 "considers the effect of rounding based on precision": function(prefix) {96 assert.equal(prefix(999.5000000, 4).symbol, "");97 assert.equal(prefix(999.5000000, 3).symbol, "k");98 assert.equal(prefix(995.0000000, 3).symbol, "");99 assert.equal(prefix(995.0000000, 2).symbol, "k");100 assert.equal(prefix(950.0000000, 2).symbol, "");101 assert.equal(prefix(950.0000000, 1).symbol, "k");102 assert.equal(prefix(0.000009995, 4).symbol, "µ");103 assert.equal(prefix(0.000009995, 3).symbol, "m");104 assert.equal(prefix(0.000009950, 3).symbol, "µ");105 assert.equal(prefix(0.000009950, 2).symbol, "m");106 assert.equal(prefix(0.000009500, 2).symbol, "µ");107 assert.equal(prefix(0.000009500, 1).symbol, "m");108 }109 }110});...

Full Screen

Full Screen

query_test.js

Source:query_test.js Github

copy

Full Screen

1goog.require('goog.dom');2goog.require('goog.dom.query');3goog.require('goog.testing.asserts'); // assertThrows4function testBasicSelectors() {5 assertQuery(4, 'h3');6 assertQuery(1, 'h1:first-child');7 assertQuery(2, 'h3:first-child');8 assertQuery(1, '#t');9 assertQuery(1, '#bug');10 assertQuery(4, '#t h3');11 assertQuery(1, 'div#t');12 assertQuery(4, 'div#t h3');13 assertQuery(0, 'span#t');14 assertQuery(1, '#t div > h3');15 assertQuery(2, '.foo');16 assertQuery(1, '.foo.bar');17 assertQuery(2, '.baz');18 assertQuery(3, '#t > h3');19}20function testSyntacticEquivalents() {21 // syntactic equivalents22 assertQuery(12, '#t > *');23 assertQuery(12, '#t >');24 assertQuery(3, '.foo > *');25 assertQuery(3, '.foo >');26}27function testWithARootById() {28 // with a root, by ID29 assertQuery(3, '> *', 'container');30 assertQuery(3, '> h3', 't');31}32function testCompoundQueries() {33 // compound queries34 assertQuery(2, '.foo, .bar');35 assertQuery(2, '.foo,.bar');36}37function testMultipleClassAttributes() {38 // multiple class attribute39 assertQuery(1, '.foo.bar');40 assertQuery(2, '.foo');41 assertQuery(2, '.baz');42}43function testCaseSensitivity() {44 // case sensitivity45 assertQuery(1, 'span.baz');46 assertQuery(1, 'sPaN.baz');47 assertQuery(1, 'SPAN.baz');48 assertQuery(1, '[class = \"foo bar\"]');49 assertQuery(2, '[foo~=\"bar\"]');50 assertQuery(2, '[ foo ~= \"bar\" ]');51}52function testAttributes() {53 assertQuery(3, '[foo]');54 assertQuery(1, '[foo$=\"thud\"]');55 assertQuery(1, '[foo$=thud]');56 assertQuery(1, '[foo$=\"thudish\"]');57 assertQuery(1, '#t [foo$=thud]');58 assertQuery(1, '#t [ title $= thud ]');59 assertQuery(0, '#t span[ title $= thud ]');60 assertQuery(2, '[foo|=\"bar\"]');61 assertQuery(1, '[foo|=\"bar-baz\"]');62 assertQuery(0, '[foo|=\"baz\"]');63}64function testDescendantSelectors() {65 assertQuery(3, '>', 'container');66 assertQuery(3, '> *', 'container');67 assertQuery(2, '> [qux]', 'container');68 assertEquals('child1', goog.dom.query('> [qux]', 'container')[0].id);69 assertEquals('child3', goog.dom.query('> [qux]', 'container')[1].id);70 assertQuery(3, '>', 'container');71 assertQuery(3, '> *', 'container');72}73function testSiblingSelectors() {74 assertQuery(1, '+', 'container');75 assertQuery(3, '~', 'container');76 assertQuery(1, '.foo + span');77 assertQuery(4, '.foo ~ span');78 assertQuery(1, '#foo ~ *');79 assertQuery(1, '#foo ~');80}81function testSubSelectors() {82 // sub-selector parsing83 assertQuery(1, '#t span.foo:not(span:first-child)');84 assertQuery(1, '#t span.foo:not(:first-child)');85}86function testNthChild() {87 assertEquals(goog.dom.$('_foo'), goog.dom.query('.foo:nth-child(2)')[0]);88 assertQuery(2, '#t > h3:nth-child(odd)');89 assertQuery(3, '#t h3:nth-child(odd)');90 assertQuery(3, '#t h3:nth-child(2n+1)');91 assertQuery(1, '#t h3:nth-child(even)');92 assertQuery(1, '#t h3:nth-child(2n)');93 assertQuery(1, '#t h3:nth-child(2n+3)');94 assertQuery(2, '#t h3:nth-child(1)');95 assertQuery(1, '#t > h3:nth-child(1)');96 assertQuery(3, '#t :nth-child(3)');97 assertQuery(0, '#t > div:nth-child(1)');98 assertQuery(7, '#t span');99 assertQuery(3, '#t > *:nth-child(n+10)');100 assertQuery(1, '#t > *:nth-child(n+12)');101 assertQuery(10, '#t > *:nth-child(-n+10)');102 assertQuery(5, '#t > *:nth-child(-2n+10)');103 assertQuery(6, '#t > *:nth-child(2n+2)');104 assertQuery(5, '#t > *:nth-child(2n+4)');105 assertQuery(5, '#t > *:nth-child(2n+4)');106 assertQuery(12, '#t > *:nth-child(n-5)');107 assertQuery(6, '#t > *:nth-child(2n-5)');108}109function testEmptyPseudoSelector() {110 assertQuery(4, '#t > span:empty');111 assertQuery(6, '#t span:empty');112 assertQuery(0, 'h3 span:empty');113 assertQuery(1, 'h3 :not(:empty)');114}115function testIdsWithColons(){116 assertQuery(1, "#silly\\:id\\:\\:with\\:colons");117}118function testOrder() {119 var els = goog.dom.query('.myupperclass .myclass input');120 assertEquals('myid1', els[0].id);121 assertEquals('myid2', els[1].id);122}123function testCorrectDocumentInFrame() {124 var frameDocument = window.frames['ifr'].document;125 frameDocument.body.innerHTML =126 document.getElementById('iframe-test').innerHTML;127 var els = goog.dom.query('#if1 .if2 div', document);128 var frameEls = goog.dom.query('#if1 .if2 div', frameDocument);129 assertEquals(els.length, frameEls.length);130 assertEquals(1, frameEls.length);131 assertNotEquals(document.getElementById('if3'),132 frameDocument.getElementById('if3'));133}134/**135 * @param {number} expectedNumberOfNodes136 * @param {...*} var_args137 */138function assertQuery(expectedNumberOfNodes, var_args) {139 var args = Array.prototype.slice.call(arguments, 1);140 assertEquals(expectedNumberOfNodes,141 goog.dom.query.apply(null, args).length);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2describe('webdriver.io page', function() {3 it('should have the right title', function () {4 var title = browser.getTitle();5 assert.equal(title, 'WebdriverIO - Selenium 2.0 javascript bindings for nodejs');6 });7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var webdriver = require('selenium-webdriver');3var By = webdriver.By;4var until = webdriver.until;5var driver = new webdriver.Builder().forBrowser('chrome').build();6driver.findElement(By.name('username')).sendKeys('admin');7driver.findElement(By.name('password')).sendKeys('admin');8driver.findElement(By.name('login')).click();9driver.wait(until.titleIs('Admin Page'), 1000);10driver.findElement(By.name('logout')).click();11driver.wait(until.titleIs('Login Page'), 1000);12driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var wpt = require('webpagetest');3var fs = require('fs');4var test = require('tape');5var wpt = new WebPageTest('www.webpagetest.org');6var options = {7};8wpt.runTest(testUrl, options, function(err, data) {9 if (err) return console.error(err);10 console.log('Test submitted to WebPageTest for %s', testUrl);11 console.log('View your test at: %s', data.data.userUrl);12 wpt.getTestResults(data.data.testId, function(err, data) {13 if (err) return console.error(err);14 console.log('Your test is complete!');15 console.log('First View (i.e. Load Time): %s', data.data.average.firstView.loadTime);16 console.log('First View (i.e. Speed Index): %s', data.data.average.firstView.SpeedIndex);17 console.log('First View (i.e. TTFB): %s', data.data.average.firstView.TTFB);18 console.log('First View (i.e. Start Render): %s', data.data.average.firstView.render);19 console.log('First View (i.e. Visual Complete): %s', data.data.average.firstView.visualComplete);20 console.log('First View (i.e. Fully Loaded): %s', data.data.average.firstView.fullyLoaded);21 console.log('First View (i.e. Requests): %s', data.data.average.firstView.requests);22 console.log('First View (i.e. Bytes In): %s', data.data.average.firstView.bytesIn);23 console.log('First View (i.e. Bytes Out): %s', data.data.average.firstView.bytesOut);24 console.log('First View (i.e. Result): %s', data.data.average.firstView.result);25 console.log('First View (i.e. Load Time): %s', data.data.average.firstView.loadTime);26 console.log('First View (i.e. Speed Index): %s', data.data.average.firstView.SpeedIndex);27 console.log('First View (

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful