Comparing version 1.0.1 to 1.0.2
@@ -12,3 +12,3 @@ /** | ||
mochaTest: { | ||
test: { | ||
run: { | ||
options: { | ||
@@ -22,11 +22,21 @@ ui : 'bdd', | ||
}, | ||
generate: { | ||
save: { | ||
options: { | ||
ui : 'bdd', | ||
require: [ | ||
function(){ global.save = 1; } //pass save as true when generating/saving test output | ||
function(){ global.save = true; } //pass save as true when generating/saving test output | ||
], | ||
reporter: 'spec', | ||
reporter: 'spec' | ||
}, | ||
src: ['./test/test.js'] | ||
}, | ||
display: { | ||
options: { | ||
ui : 'bdd', | ||
require: [ | ||
function(){ global.display = true; } | ||
], | ||
reporter: 'spec' | ||
}, | ||
src: ['./test/test.js'] | ||
} | ||
@@ -38,10 +48,14 @@ } | ||
grunt.registerTask('test', [ | ||
'mochaTest:test' | ||
grunt.registerTask('test-run', [ | ||
'mochaTest:run' | ||
]); | ||
grunt.registerTask('test-gen', [ | ||
'mochaTest:generate' | ||
grunt.registerTask('test-save', [ | ||
'mochaTest:save' | ||
]); | ||
grunt.registerTask('test-display', [ | ||
'mochaTest:display' | ||
]); | ||
}; |
@@ -107,4 +107,4 @@ function smartWrap(text,options){ | ||
wrapObj.lines[wrapObj.currentLine].push(word); | ||
//reduce space remaining | ||
wrapObj.spacesUsed += wordlength; | ||
//reduce space remaining (add a space between words) | ||
wrapObj.spacesUsed += wordlength + 1; | ||
//increment iterator | ||
@@ -111,0 +111,0 @@ i++; |
{ | ||
"name": "smartwrap", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Wordwrap that doesn't split words unless the word length is greater that the line width.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
var Tests = {}; | ||
var fs = require('fs'); | ||
var glob = require('glob'); | ||
//var glob = require('glob'); | ||
var chai = require('chai'); | ||
@@ -8,47 +8,51 @@ var expect = chai.expect; | ||
var should = chai.should(); | ||
var exec = require('child_process').exec, child; | ||
var smartwrap = require('../index.js'); | ||
var filepath = 'test/tests.json'; | ||
var test = function(testResult,savedResult){ | ||
it('Strings should match',function(){ | ||
testResult.should.equal(savedResult); | ||
}) | ||
}; | ||
//Run through all examples | ||
describe('Examples',function(){ | ||
//get test list | ||
var str = fs.readFileSync(filepath,{ | ||
encoding : 'utf-8' | ||
}); | ||
var obj = JSON.parse(str); | ||
for(var i in obj){ | ||
//string | ||
var str = fs.readFileSync(filepath,{ | ||
encoding : 'utf-8' | ||
//generate new output | ||
var testResult = smartwrap(obj[i].input,{ | ||
width : obj[i].width | ||
}); | ||
obj = JSON.parse(str); | ||
for(var i in obj){ | ||
//generate new output | ||
var output = smartwrap(obj[i].string,{ | ||
width : obj[i].width | ||
}); | ||
console.log("Test Properties:",obj[i]); | ||
console.log("12345678901234567890"); | ||
console.log("BEGIN---------------"); | ||
console.log(output); | ||
console.log("END-----------------\n"); | ||
//save new output to file (save is set in Gruntfile.js) | ||
if(typeof global.save !== 'undefined' && global.save){ | ||
obj[i].output = output; | ||
} | ||
else{ | ||
//compare this output to saved output | ||
it('Test should match saved output.',function(){ | ||
obj[i].output.should.equal(output); | ||
}); | ||
} | ||
console.log("Test Properties:",obj[i]); | ||
console.log("12345678901234567890"); | ||
console.log("BEGIN---------------"); | ||
console.log(testResult); | ||
console.log("END-----------------\n"); | ||
switch(true){ | ||
case(typeof global.save !== 'undefined' && global.save): | ||
//save tests | ||
obj[i].output = testResult; | ||
break; | ||
case(typeof global.display !== 'undefined' && global.display): | ||
//show tests (do nothing) | ||
break; | ||
default: | ||
//run tests | ||
describe('Test '+i,function(){ | ||
test(testResult,obj[i].output); | ||
}) | ||
} | ||
} | ||
if(typeof global.save !== 'undefined' && global.save){ | ||
//write saved object to file | ||
fs.writeFileSync(filepath,JSON.stringify(obj,null,2),'utf8'); | ||
console.log("Tests saved to file."); | ||
} | ||
}); | ||
if(typeof global.save !== 'undefined' && global.save){ | ||
//write saved object to file | ||
fs.writeFileSync(filepath,JSON.stringify(obj,null,2),'utf8'); | ||
console.log("Tests saved to file."); | ||
} | ||
module.exports = Tests; |
[ | ||
{ | ||
"string": "宽字符", | ||
"input": "宽字符", | ||
"width": 0, | ||
@@ -8,3 +8,3 @@ "output": "宽\n字\n符" | ||
{ | ||
"string": "宽字符", | ||
"input": "宽字符", | ||
"width": 1, | ||
@@ -14,3 +14,3 @@ "output": "宽\n字\n符" | ||
{ | ||
"string": "宽字符", | ||
"input": "宽字符", | ||
"width": 2, | ||
@@ -20,3 +20,3 @@ "output": "宽\n字\n符" | ||
{ | ||
"string": "宽字符", | ||
"input": "宽字符", | ||
"width": 4, | ||
@@ -26,3 +26,3 @@ "output": "宽字\n符" | ||
{ | ||
"string": "宽字符", | ||
"input": "宽字符", | ||
"width": 6, | ||
@@ -32,36 +32,41 @@ "output": "宽字符" | ||
{ | ||
"string": "breakthislongstring", | ||
"input": "breakthislonginput", | ||
"width": 0, | ||
"output": "br\nea\nkt\nhi\nsl\non\ngs\ntr\nin\ng" | ||
"output": "br\nea\nkt\nhi\nsl\non\ngi\nnp\nut" | ||
}, | ||
{ | ||
"string": "breakthislongstring", | ||
"input": "breakthislonginput", | ||
"width": 1, | ||
"output": "br\nea\nkt\nhi\nsl\non\ngs\ntr\nin\ng" | ||
"output": "br\nea\nkt\nhi\nsl\non\ngi\nnp\nut" | ||
}, | ||
{ | ||
"string": "breakthislongstring", | ||
"input": "breakthislonginput", | ||
"width": 2, | ||
"output": "br\nea\nkt\nhi\nsl\non\ngs\ntr\nin\ng" | ||
"output": "br\nea\nkt\nhi\nsl\non\ngi\nnp\nut" | ||
}, | ||
{ | ||
"string": "breakthislongstring", | ||
"input": "breakthislonginput", | ||
"width": 4, | ||
"output": "brea\nkthi\nslon\ngstr\ning" | ||
"output": "brea\nkthi\nslon\nginp\nut" | ||
}, | ||
{ | ||
"string": "breakthislongstring", | ||
"input": "breakthislonginput", | ||
"width": 6, | ||
"output": "breakt\nhislon\ngstrin\ng" | ||
"output": "breakt\nhislon\nginput" | ||
}, | ||
{ | ||
"string": "breakthislongstring", | ||
"input": "breakthislonginput", | ||
"width": 19, | ||
"output": "breakthislongstring" | ||
"output": "breakthislonginput" | ||
}, | ||
{ | ||
"string": "LordPablo⚡️", | ||
"input": "LordPablo⚡️", | ||
"width": 10, | ||
"output": "LordPablo⚡️" | ||
}, | ||
{ | ||
"input": "And its corresponding longer value", | ||
"width": 19, | ||
"output": "And its\ncorresponding\nlonger value" | ||
} | ||
] |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
33992
10
285
0