From 9acca8658bbf7bbffccc88a85d4361c63c4f9744 Mon Sep 17 00:00:00 2001 From: darc Date: Fri, 15 May 2015 16:37:27 -0300 Subject: [PATCH] chore: test coverage improvements --- gulpfile.js | 5 +++-- releases/br-masks-standalone.js | 6 +----- releases/br-masks-standalone.min.js | 2 +- releases/br-masks.js | 6 +----- releases/br-masks.min.js | 2 +- src/ie.js | 4 ---- test/cep.test.js | 11 +++++++++- test/cnpj.test.js | 11 +++++++++- test/cpf-cnpj.test.js | 11 +++++++++- test/cpf.test.js | 11 +++++++++- test/finance.test.js | 2 +- test/ie.test.js | 31 +++++++++++++++-------------- test/nfe-access-key.test.js | 11 +++++++++- test/phone.test.js | 10 +++++++++- 14 files changed, 83 insertions(+), 40 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index acf9539..9ec2f86 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,7 +9,8 @@ var gulp = require('gulp'), var config = { src: { - files: 'src/**/*.js' + files: 'src/**/*.js', + release: 'releases/br-masks.js' }, test: { files: 'test/**/*.test.js' @@ -118,7 +119,7 @@ gulp.task('test-watch', ['jshint', 'build', 'runtest'], function() { }); gulp.task('test-coverage', function(done) { - gulp.src(config.src.files) + gulp.src(config.src.release) .pipe(plugins.istanbul()) .pipe(plugins.istanbul.hookRequire()) .on('finish', function() { diff --git a/releases/br-masks-standalone.js b/releases/br-masks-standalone.js index 2be1830..af5083d 100644 --- a/releases/br-masks-standalone.js +++ b/releases/br-masks-standalone.js @@ -194,7 +194,7 @@ /** * br-masks * A library of masks applicable to several Brazilian data like I.E., CNPJ, CPF and others - * @version v0.3.4 + * @version v0.4.0 * @link http://github.com/the-darc/br-masks * @license MIT */ @@ -322,10 +322,6 @@ var IE = function(value, uf) { }; function clearValue (value) { - if(!value) { - return value; - } - return value.replace(/[^0-9]/g, ''); } diff --git a/releases/br-masks-standalone.min.js b/releases/br-masks-standalone.min.js index c2ad69b..3195d68 100644 --- a/releases/br-masks-standalone.min.js +++ b/releases/br-masks-standalone.min.js @@ -1 +1 @@ -!function(e,n){"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?module.exports=n():e.StringMask=n()}(this,function(){function e(e,n){for(var t=0,r=n-1,s={escape:!0};r>=0&&s&&s.escape;)s=a[e.charAt(r)],t+=s&&s.escape?1:0,r--;return t>0&&t%2===1}function n(e,n){var t=e.replace(/[^0]/g,"").length,r=n.replace(/[^\d]/g,"").length;return r-t}function t(e,n,t,r){return r&&"function"==typeof r.transform&&(n=r.transform(n)),t.reverse?n+e:e+n}function r(e,n,t){var s=e.charAt(n),i=a[s];return""===s?!1:i&&!i.escape?!0:r(e,n+t,t)}function s(e,n,t){var r=e.split("");return r.splice(t>=0?t:0,0,n),r.join("")}function i(e,n){this.options=n||{},this.options={reverse:this.options.reverse||!1,usedefaults:this.options.usedefaults||this.options.reverse},this.pattern=e}var a={0:{pattern:/\d/,_default:"0"},9:{pattern:/\d/,optional:!0},"#":{pattern:/\d/,optional:!0,recursive:!0},S:{pattern:/[a-zA-Z]/},U:{pattern:/[a-zA-Z]/,transform:function(e){return e.toLocaleUpperCase()}},L:{pattern:/[a-zA-Z]/,transform:function(e){return e.toLocaleLowerCase()}},$:{escape:!0}};return i.prototype.process=function(i){function o(e){if(!w&&r(p,k,m.inc))return!0;if(w||(w=v.length>0),w){var n=v.shift();if(v.push(n),e.reverse&&c>=0)return k++,p=s(p,n,k),!0;if(!e.reverse&&c=0}if(!i)return"";i+="";for(var p=this.pattern,u=!0,f="",c=this.options.reverse?i.length-1:0,l=n(p,i),h=!1,v=[],w=!1,m={start:this.options.reverse?p.length-1:0,end:this.options.reverse?-1:p.length,inc:this.options.reverse?-1:1},k=m.start;o(this.options);k+=m.inc){var d=p.charAt(k),g=i.charAt(c),y=a[d];if(!w||g){if(this.options.reverse&&e(p,k)){f=t(f,d,this.options,y),k+=m.inc;continue}if(!this.options.reverse&&h){f=t(f,d,this.options,y),h=!1;continue}if(!this.options.reverse&&y&&y.escape){h=!0;continue}}if(!w&&y&&y.recursive)v.push(d);else{if(w&&!g){y&&y.recursive||(f=t(f,d,this.options,y));continue}if(v.length>0&&y&&!y.recursive){u=!1;continue}if(!w&&v.length>0&&!g)continue}if(y)if(y.optional){if(y.pattern.test(g)&&l)f=t(f,g,this.options,y),c+=m.inc,l--;else if(v.length>0&&g){u=!1;break}}else if(y.pattern.test(g))f=t(f,g,this.options,y),c+=m.inc;else{if(g||!y._default||!this.options.usedefaults){u=!1;break}f=t(f,y._default,this.options,y)}else f=t(f,d,this.options,y),!w&&v.length&&v.push(d)}return{result:f,valid:u}},i.prototype.apply=function(e){return this.process(e).result},i.prototype.validate=function(e){return this.process(e).valid},i.process=function(e,n,t){return new i(n,t).process(e)},i.apply=function(e,n,t){return new i(n,t).apply(e)},i.validate=function(e,n,t){return new i(n,t).validate(e)},i}),function(e,n){"function"==typeof define&&define.amd?define(["string-mask"],n):"object"==typeof exports?module.exports=n(require("string-mask")):e.BrM=n(e.StringMask)}(this,function(e){if(!e)throw new Error("StringMask not found");var n=function(n){var t=new e("00000-000");if(!n)return n;var r=t.process(n);return r.result},t=function(n){if(!n)return n;var t=new e("00.000.000/0000-00"),r=t.apply(n);return r},r=function(e){return e&&e.length?e.length<=11?s(e):t(e):e},s=function(n){var t=new e("000.000.000-00");if(!n)return n;var r=t.apply(n);return r},i=function(n,t,r,s){t=!t&&0!==t||0>t?2:t,r=r||".",s=s||"";var i=t>0?r+new Array(t+1).join("0"):"",a="#"+s+"##0"+i;n=parseFloat(n),n||(n=0);var o=!1;0>n&&(n=-1*n,o=!0);var p=new e(a,{reverse:!0}),u=p.apply(n.toFixed(t).replace(/[^\d]+/g,""));return o?"("+u+")":u},a=function(n,t){function r(e){return e?e.replace(/[^0-9]/g,""):e}function s(e,n){if(!e||!i[e])return void 0;var t=e.toUpperCase();if("SP"===t&&/^P/i.test(n))return i.SP[1].mask;for(var s=i[e],a=0;s[a].chars&&s[a].chars=0&&s&&s.escape;)s=a[e.charAt(r)],t+=s&&s.escape?1:0,r--;return t>0&&t%2===1}function n(e,n){var t=e.replace(/[^0]/g,"").length,r=n.replace(/[^\d]/g,"").length;return r-t}function t(e,n,t,r){return r&&"function"==typeof r.transform&&(n=r.transform(n)),t.reverse?n+e:e+n}function r(e,n,t){var s=e.charAt(n),i=a[s];return""===s?!1:i&&!i.escape?!0:r(e,n+t,t)}function s(e,n,t){var r=e.split("");return r.splice(t>=0?t:0,0,n),r.join("")}function i(e,n){this.options=n||{},this.options={reverse:this.options.reverse||!1,usedefaults:this.options.usedefaults||this.options.reverse},this.pattern=e}var a={0:{pattern:/\d/,_default:"0"},9:{pattern:/\d/,optional:!0},"#":{pattern:/\d/,optional:!0,recursive:!0},S:{pattern:/[a-zA-Z]/},U:{pattern:/[a-zA-Z]/,transform:function(e){return e.toLocaleUpperCase()}},L:{pattern:/[a-zA-Z]/,transform:function(e){return e.toLocaleLowerCase()}},$:{escape:!0}};return i.prototype.process=function(i){function o(e){if(!w&&r(p,k,m.inc))return!0;if(w||(w=v.length>0),w){var n=v.shift();if(v.push(n),e.reverse&&c>=0)return k++,p=s(p,n,k),!0;if(!e.reverse&&c=0}if(!i)return"";i+="";for(var p=this.pattern,u=!0,f="",c=this.options.reverse?i.length-1:0,l=n(p,i),h=!1,v=[],w=!1,m={start:this.options.reverse?p.length-1:0,end:this.options.reverse?-1:p.length,inc:this.options.reverse?-1:1},k=m.start;o(this.options);k+=m.inc){var d=p.charAt(k),g=i.charAt(c),y=a[d];if(!w||g){if(this.options.reverse&&e(p,k)){f=t(f,d,this.options,y),k+=m.inc;continue}if(!this.options.reverse&&h){f=t(f,d,this.options,y),h=!1;continue}if(!this.options.reverse&&y&&y.escape){h=!0;continue}}if(!w&&y&&y.recursive)v.push(d);else{if(w&&!g){y&&y.recursive||(f=t(f,d,this.options,y));continue}if(v.length>0&&y&&!y.recursive){u=!1;continue}if(!w&&v.length>0&&!g)continue}if(y)if(y.optional){if(y.pattern.test(g)&&l)f=t(f,g,this.options,y),c+=m.inc,l--;else if(v.length>0&&g){u=!1;break}}else if(y.pattern.test(g))f=t(f,g,this.options,y),c+=m.inc;else{if(g||!y._default||!this.options.usedefaults){u=!1;break}f=t(f,y._default,this.options,y)}else f=t(f,d,this.options,y),!w&&v.length&&v.push(d)}return{result:f,valid:u}},i.prototype.apply=function(e){return this.process(e).result},i.prototype.validate=function(e){return this.process(e).valid},i.process=function(e,n,t){return new i(n,t).process(e)},i.apply=function(e,n,t){return new i(n,t).apply(e)},i.validate=function(e,n,t){return new i(n,t).validate(e)},i}),function(e,n){"function"==typeof define&&define.amd?define(["string-mask"],n):"object"==typeof exports?module.exports=n(require("string-mask")):e.BrM=n(e.StringMask)}(this,function(e){if(!e)throw new Error("StringMask not found");var n=function(n){var t=new e("00000-000");if(!n)return n;var r=t.process(n);return r.result},t=function(n){if(!n)return n;var t=new e("00.000.000/0000-00"),r=t.apply(n);return r},r=function(e){return e&&e.length?e.length<=11?s(e):t(e):e},s=function(n){var t=new e("000.000.000-00");if(!n)return n;var r=t.apply(n);return r},i=function(n,t,r,s){t=!t&&0!==t||0>t?2:t,r=r||".",s=s||"";var i=t>0?r+new Array(t+1).join("0"):"",a="#"+s+"##0"+i;n=parseFloat(n),n||(n=0);var o=!1;0>n&&(n=-1*n,o=!0);var p=new e(a,{reverse:!0}),u=p.apply(n.toFixed(t).replace(/[^\d]+/g,""));return o?"("+u+")":u},a=function(n,t){function r(e){return e.replace(/[^0-9]/g,"")}function s(e,n){if(!e||!i[e])return void 0;var t=e.toUpperCase();if("SP"===t&&/^P/i.test(n))return i.SP[1].mask;for(var s=i[e],a=0;s[a].chars&&s[a].charsr?2:r,a=a||".",s=s||"";var t=r>0?a+new Array(r+1).join("0"):"",w="#"+s+"##0"+t;e=parseFloat(e),e||(e=0);var i=!1;0>e&&(e=-1*e,i=!0);var u=new n(w,{reverse:!0}),k=u.apply(e.toFixed(r).replace(/[^\d]+/g,""));return i?"("+k+")":k},w=function(e,r){function a(n){return n?n.replace(/[^0-9]/g,""):n}function s(n,e){if(!n||!t[n])return void 0;var r=n.toUpperCase();if("SP"===r&&/^P/i.test(e))return t.SP[1].mask;for(var s=t[n],w=0;s[w].chars&&s[w].charsr?2:r,a=a||".",s=s||"";var t=r>0?a+new Array(r+1).join("0"):"",w="#"+s+"##0"+t;e=parseFloat(e),e||(e=0);var i=!1;0>e&&(e=-1*e,i=!0);var u=new n(w,{reverse:!0}),k=u.apply(e.toFixed(r).replace(/[^\d]+/g,""));return i?"("+k+")":k},w=function(e,r){function a(n){return n.replace(/[^0-9]/g,"")}function s(n,e){if(!n||!t[n])return void 0;var r=n.toUpperCase();if("SP"===r&&/^P/i.test(e))return t.SP[1].mask;for(var s=t[n],w=0;s[w].chars&&s[w].chars