Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Strip tab indentation in `clean` utility method

Mike Pennisic927846ec425
diff --git a/lib/utils.js b/lib/utils.js
index 2bf0978a..0ac93709 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -196,8 +196,8 @@ exports.clean = function(str) {
.replace(/^function *\(.*\) *{/, '')
.replace(/\s+\}$/, '');
- var spaces = str.match(/^\n?( *)/)[1].length
- , re = new RegExp('^ {' + spaces + '}', 'gm');
+ var whitespace = str.match(/^\n?(\s*)/)[1]
+ , re = new RegExp('^' + whitespace, 'gm');
str = str.replace(re, '');
diff --git a/test/utils.js b/test/utils.js
new file mode 100644
index 00000000..007afe97
--- /dev/null
+++ b/test/utils.js
@@ -0,0 +1,22 @@
+
+var mocha = require('../')
+ , utils = mocha.utils;
+
+describe("Utils", function (){
+
+ describe('.clean()', function() {
+ var clean = utils.clean;
+
+ it('should remove the wrapping function declaration', function(){
+ clean('function (one, two, three) {\n//code\n}').should.equal('//code');
+ })
+
+ it('should remove space character indentation from the function body', function(){
+ clean(' //line1\n //line2').should.equal('//line1\n //line2');
+ })
+
+ it('should remove tab character indentation from the function body', function(){
+ clean('\t//line1\n\t\t//line2').should.equal('//line1\n\t//line2');
+ })
+ })
+})