Comparing version 0.1.4 to 0.1.5
@@ -15,3 +15,2 @@ module.exports = function(grunt) { | ||
pkg: pkg, | ||
ver: '<%= pkg.version %>', | ||
jshint: { | ||
@@ -25,64 +24,14 @@ files: [ | ||
}, | ||
unit: { | ||
dir: ['test/**/*.js'] | ||
} | ||
}); | ||
grunt.registerTask('qunit-test', function() { | ||
var done = this.async(), | ||
QUnit = require("qunitjs"); | ||
var tap = (function (qu) { | ||
var qunitTap = require("qunit-tap"), | ||
util = require('util'); | ||
return qunitTap(qu, util.puts, {showSourceOnFailure: false}); | ||
})(QUnit); | ||
function removeCallback (ary, element) { | ||
var index = ary.indexOf(element); | ||
if (index !== -1) { | ||
ary.splice(index, 1); | ||
mochaTest: { | ||
unit: { | ||
options: { | ||
ui: 'tdd', | ||
reporter: 'spec' | ||
}, | ||
src: ['test/**/*.js'] | ||
} | ||
} | ||
var gruntQunitTaskDone = function gruntQunitTaskDone ( details ) { | ||
var succeeded = (details.failed === 0), | ||
message = details.total + " assertions in (" + | ||
details.runtime + "ms), passed: " + | ||
details.passed + ", failed: " + details.failed; | ||
if ( succeeded ) { | ||
grunt.log.ok(message); | ||
} else { | ||
grunt.log.error(message); | ||
} | ||
tap.unsubscribe(); | ||
removeCallback(QUnit.config.done, gruntQunitTaskDone); | ||
done( succeeded ); | ||
}; | ||
QUnit.done(gruntQunitTaskDone); | ||
QUnit.config.autorun = false; | ||
QUnit.config.autostart = false; | ||
QUnit.config.updateRate = 0; | ||
if (QUnit.config.semaphore === 1) { | ||
QUnit.config.semaphore = 0; | ||
} | ||
QUnit.load(); | ||
grunt.config.get('unit.dir').forEach(function (pattern) { | ||
grunt.log.ok('searching for ' + pattern + '...'); | ||
grunt.file.glob(pattern, function (err, files) { | ||
if (err) { | ||
grunt.log.error('error ' + err.message); | ||
return; | ||
} | ||
files.forEach(function (file) { | ||
grunt.log.write('require ' + file + '...').ok(); | ||
require('./' + file); | ||
}); | ||
}); | ||
}); | ||
}); | ||
grunt.registerTask('test', ['jshint', 'qunit-test']); | ||
grunt.registerTask('test', ['jshint', 'mochaTest:unit']); | ||
}; |
@@ -33,3 +33,4 @@ /** | ||
destructive: false, | ||
formatter: defaultFormatter | ||
formatter: defaultFormatter, | ||
lineSeparator: '\n' | ||
}; | ||
@@ -113,3 +114,3 @@ } | ||
} else { | ||
powerAssertText = config.formatter.format(context).join('\n'); | ||
powerAssertText = config.formatter.format(context).join(config.lineSeparator); | ||
baseAssert(context.result, message ? message + ' ' + powerAssertText : powerAssertText); | ||
@@ -116,0 +117,0 @@ } |
@@ -24,41 +24,9 @@ /** | ||
var newRowFor = (function () { | ||
function createRow (numCols, initial) { | ||
var row = [], i; | ||
for(i = 0; i < numCols; i += 1) { | ||
row[i] = initial; | ||
} | ||
return row; | ||
} | ||
return function (assertionLine) { | ||
return createRow(widthOf(assertionLine), ' '); | ||
}; | ||
})(); | ||
function widthOf (str) { | ||
var i, c, width = 0; | ||
for(i = 0; i < str.length; i+=1){ | ||
c = str.charCodeAt(i); | ||
if ((0x0 <= c && c < 0x81) || (c === 0xf8f0) || (0xff61 <= c && c < 0xffa0) || (0xf8f1 <= c && c < 0xf8f4)) { | ||
width += 1; | ||
} else { | ||
width += 2; | ||
} | ||
} | ||
return width; | ||
} | ||
function isOverlapped (prevCapturing, nextCaputuring, dumpedValue) { | ||
return (typeof prevCapturing !== 'undefined') && prevCapturing.location.start.column <= (nextCaputuring.location.start.column + widthOf(dumpedValue)); | ||
} | ||
function rightToLeft (a, b) { | ||
return b.location.start.column - a.location.start.column; | ||
} | ||
function PowerAssertContextRenderer (dump, context) { | ||
function PowerAssertContextRenderer (dump, widthOf, context) { | ||
this.dump = dump; | ||
this.widthOf = widthOf; | ||
this.initialVertivalBarLength = 1; | ||
this.initWithContext(context); | ||
} | ||
PowerAssertContextRenderer.prototype.initWithContext = function (context) { | ||
@@ -74,8 +42,15 @@ context.events.sort(rightToLeft); | ||
}; | ||
PowerAssertContextRenderer.prototype.newRowFor = function (assertionLine) { | ||
return createRow(this.widthOf(assertionLine), ' '); | ||
}; | ||
PowerAssertContextRenderer.prototype.addOneMoreRow = function () { | ||
this.rows.push(newRowFor(this.assertionLine)); | ||
this.rows.push(this.newRowFor(this.assertionLine)); | ||
}; | ||
PowerAssertContextRenderer.prototype.lastRow = function () { | ||
return this.rows[this.rows.length - 1]; | ||
}; | ||
PowerAssertContextRenderer.prototype.renderVerticalBarAt = function (columnIndex) { | ||
@@ -87,4 +62,5 @@ var i, lastRowIndex = this.rows.length - 1; | ||
}; | ||
PowerAssertContextRenderer.prototype.renderValueAt = function (columnIndex, dumpedValue) { | ||
var i, width = widthOf(dumpedValue); | ||
var i, width = this.widthOf(dumpedValue); | ||
for (i = 0; i < width; i += 1) { | ||
@@ -94,2 +70,7 @@ this.lastRow().splice(columnIndex + i, 1, dumpedValue.charAt(i)); | ||
}; | ||
PowerAssertContextRenderer.prototype.isOverlapped = function (prevCapturing, nextCaputuring, dumpedValue) { | ||
return (typeof prevCapturing !== 'undefined') && prevCapturing.location.start.column <= (nextCaputuring.location.start.column + this.widthOf(dumpedValue)); | ||
}; | ||
PowerAssertContextRenderer.prototype.constructRows = function (capturedEvents) { | ||
@@ -100,3 +81,3 @@ var that = this, | ||
var dumpedValue = that.dump(captured.value); | ||
if (isOverlapped(prevCaptured, captured, dumpedValue)) { | ||
if (that.isOverlapped(prevCaptured, captured, dumpedValue)) { | ||
that.addOneMoreRow(); | ||
@@ -109,2 +90,3 @@ } | ||
}; | ||
PowerAssertContextRenderer.prototype.renderLines = function () { | ||
@@ -128,2 +110,30 @@ var lines = []; | ||
function createRow (numCols, initial) { | ||
var row = [], i; | ||
for(i = 0; i < numCols; i += 1) { | ||
row[i] = initial; | ||
} | ||
return row; | ||
} | ||
function rightToLeft (a, b) { | ||
return b.location.start.column - a.location.start.column; | ||
} | ||
function multibyteStringWidthOf (str) { | ||
var i, c, width = 0; | ||
for(i = 0; i < str.length; i+=1){ | ||
c = str.charCodeAt(i); | ||
if ((0x0 <= c && c < 0x81) || (c === 0xf8f0) || (0xff61 <= c && c < 0xffa0) || (0xf8f1 <= c && c < 0xf8f4)) { | ||
width += 1; | ||
} else { | ||
width += 2; | ||
} | ||
} | ||
return width; | ||
} | ||
function jsonDump (obj) { | ||
@@ -150,4 +160,5 @@ var seen = [], | ||
dump: jsonDump, | ||
widthOf: multibyteStringWidthOf, | ||
format: function (context) { | ||
var renderer = new PowerAssertContextRenderer(this.dump, context); | ||
var renderer = new PowerAssertContextRenderer(this.dump, this.widthOf, context); | ||
return renderer.renderLines(); | ||
@@ -154,0 +165,0 @@ }, |
{ | ||
"name": "empower", | ||
"description": "Power Assert feature enhancer for assert function/object", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"keywords": [ | ||
@@ -28,9 +28,9 @@ "test", | ||
"devDependencies": { | ||
"espower": "~0.1.4", | ||
"esprima": "1.0.4", | ||
"escodegen": "0.0.26", | ||
"espower": "~0.1.5", | ||
"esprima": "~1.0.4", | ||
"escodegen": "~0.0.27", | ||
"coffee-script-redux": "2.0.0-beta7", | ||
"qunitjs": "1.10.0", | ||
"qunit-tap": "1.4.0", | ||
"mocha": "1.12.1", | ||
"grunt": "~0.4.1", | ||
"grunt-mocha-test": "~0.6.3", | ||
"grunt-contrib-jshint": "~0.6.4" | ||
@@ -37,0 +37,0 @@ }, |
var espower = require('espower'), | ||
esprima = require('esprima'), | ||
escodegen = require('escodegen'), | ||
q = require('qunitjs'); | ||
instrument; | ||
(function (qu) { | ||
if (!q.config.done.some(function (callback) { return callback.name === 'gruntQunitTaskDone'; })) { | ||
var qunitTap = require("qunit-tap"), | ||
util = require('util'), | ||
tap = qunitTap(qu, util.puts, {showSourceOnFailure: false}); | ||
qu.init(); | ||
qu.config.updateRate = 0; | ||
function extractBodyFrom (source) { | ||
var tree = esprima.parse(source, {tolerant: true, loc: true, range: true}); | ||
return tree.body[0]; | ||
} | ||
function extractBodyOfAssertionAsCode (node) { | ||
var expression; | ||
if (node.type === 'ExpressionStatement') { | ||
expression = node.expression; | ||
} else if (node.type === 'ReturnStatement') { | ||
expression = node.argument; | ||
} | ||
})(q); | ||
return escodegen.generate(expression.arguments[0], {format: {compact: true}}); | ||
} | ||
var instrument = function () { | ||
var extractBodyFrom = function (source) { | ||
var tree = esprima.parse(source, {tolerant: true, loc: true, range: true}); | ||
return tree.body[0]; | ||
}; | ||
var extractBodyOfAssertionAsCode = function (node) { | ||
var expression; | ||
if (node.type === 'ExpressionStatement') { | ||
expression = node.expression; | ||
} else if (node.type === 'ReturnStatement') { | ||
expression = node.argument; | ||
} | ||
return escodegen.generate(expression.arguments[0], {format: {compact: true}}); | ||
}; | ||
instrument = function () { | ||
return function (line, options) { | ||
options = options || {destructive: false, source: line, path: '/path/to/some_test.js', powerAssertVariableName: 'assert'}; | ||
var tree = extractBodyFrom(line); | ||
var result = espower(tree, options); | ||
var instrumentedCode = extractBodyOfAssertionAsCode(result); | ||
//tap.note(instrumentedCode); | ||
var tree = extractBodyFrom(line), | ||
result = espower(tree, options), | ||
instrumentedCode = extractBodyOfAssertionAsCode(result); | ||
return instrumentedCode; | ||
@@ -42,6 +31,5 @@ }; | ||
module.exports = { | ||
instrument: instrument, | ||
QUnit: q | ||
extractBodyOfAssertionAsCode: extractBodyOfAssertionAsCode | ||
}; |
@@ -1,9 +0,22 @@ | ||
var q = require('../test_helper').QUnit, | ||
empower = require('../lib/empower'), | ||
config = empower.defaultOptions(), | ||
powerAssertTextLines = [], | ||
var empower = require('../lib/empower'), | ||
espower = require('espower'), | ||
esprima = require('esprima'), | ||
escodegen = require('escodegen'), | ||
CoffeeScript = require('coffee-script-redux'); | ||
baseAssert = require('assert'), | ||
config = empower.defaultOptions(), | ||
powerAssertTextLines = [], | ||
CoffeeScript = require('coffee-script-redux'), | ||
extractBodyOfAssertionAsCode = require('../test_helper').extractBodyOfAssertionAsCode, | ||
espowerCoffee = function () { | ||
return function (csCode) { | ||
var parseOptions = {raw: true}, | ||
csAST = CoffeeScript.parse(csCode, parseOptions), | ||
compileOptions = {bare: false}, | ||
jsAST = CoffeeScript.compile(csAST, compileOptions), | ||
espoweredAst = espower(jsAST, {destructive: false, source: csCode, path: '/path/to/bar_test.coffee', powerAssertVariableName: 'assert'}), | ||
expression = espoweredAst.body[0], | ||
instrumentedCode = extractBodyOfAssertionAsCode(expression); | ||
return instrumentedCode; | ||
}; | ||
}(); | ||
@@ -13,84 +26,59 @@ config.callback = function (context, message) { | ||
}; | ||
var assert = empower(q.assert, config); | ||
var assert = empower(baseAssert, config); | ||
q.module('CoffeeScriptRedux integration', { | ||
setup: function () { | ||
suite('CoffeeScriptRedux integration', function () { | ||
setup(function () { | ||
powerAssertTextLines.length = 0; | ||
} | ||
}); | ||
}); | ||
var espowerCoffee = function () { | ||
var extractBodyOfAssertionAsCode = function (node) { | ||
var expression; | ||
if (node.type === 'ExpressionStatement') { | ||
expression = node.expression; | ||
} else if (node.type === 'ReturnStatement') { | ||
expression = node.argument; | ||
} | ||
return escodegen.generate(expression.arguments[0], {format: {compact: true}}); | ||
}; | ||
return function (csCode) { | ||
var parseOptions = {raw: true}, | ||
csAST = CoffeeScript.parse(csCode, parseOptions), | ||
compileOptions = {bare: false}, | ||
jsAST = CoffeeScript.compile(csAST, compileOptions), | ||
espoweredAst = espower(jsAST, {destructive: false, source: csCode, path: '/path/to/bar_test.coffee', powerAssertVariableName: 'assert'}), | ||
expression = espoweredAst.body[0], | ||
instrumentedCode = extractBodyOfAssertionAsCode(expression); | ||
//tap.note(instrumentedCode); | ||
return instrumentedCode; | ||
}; | ||
}(); | ||
test('assert.ok dog.speak() == says', function () { | ||
var dog = { speak: function () { return 'woof'; } }, | ||
says = 'meow'; | ||
assert.ok(eval(espowerCoffee('assert.ok dog.speak() == says'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/bar_test.coffee:1', | ||
'', | ||
'assert.ok dog.speak() == says', | ||
' | | | | ', | ||
' | | | "meow"', | ||
' {} "woof" false ', | ||
'' | ||
]); | ||
}); | ||
test('assert.ok dog.age is four', function () { | ||
var dog = { age: 3 }, | ||
four = 4; | ||
assert.ok(eval(espowerCoffee('assert.ok dog.age is four'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/bar_test.coffee:1', | ||
'', | ||
'assert.ok dog.age is four', | ||
' | | | | ', | ||
' | | | 4 ', | ||
' | 3 false ', | ||
' {"age":3} ', | ||
'' | ||
]); | ||
}); | ||
q.test('assert.ok dog.speak() == says', function () { | ||
var dog = { speak: function () { return 'woof'; } }, | ||
says = 'meow'; | ||
assert.ok(eval(espowerCoffee('assert.ok dog.speak() == says'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/bar_test.coffee:1', | ||
'', | ||
'assert.ok dog.speak() == says', | ||
' | | | | ', | ||
' | | | "meow"', | ||
' {} "woof" false ', | ||
'' | ||
]); | ||
test('assert.ok dog[prop].year is lastYear', function () { | ||
var dog = {birthday: { year: 2011 }}, | ||
lastYear = 2012, | ||
prop = 'birthday'; | ||
assert.ok(eval(espowerCoffee('assert.ok dog[prop].year is lastYear'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/bar_test.coffee:1', | ||
'', | ||
'assert.ok dog[prop].year is lastYear', | ||
' | || | | | ', | ||
' | || | | 2012 ', | ||
' | || 2011 false ', | ||
' | |"birthday" ', | ||
' | {"year":2011} ', | ||
' {"birthday":{"year":2011}}', | ||
'' | ||
]); | ||
}); | ||
}); | ||
q.test('assert.ok dog.age is four', function () { | ||
var dog = { age: 3 }, | ||
four = 4; | ||
assert.ok(eval(espowerCoffee('assert.ok dog.age is four'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/bar_test.coffee:1', | ||
'', | ||
'assert.ok dog.age is four', | ||
' | | | | ', | ||
' | | | 4 ', | ||
' | 3 false ', | ||
' {"age":3} ', | ||
'' | ||
]); | ||
}); | ||
q.test('assert.ok dog[prop].year is lastYear', function () { | ||
var dog = {birthday: { year: 2011 }}, | ||
lastYear = 2012, | ||
prop = 'birthday'; | ||
assert.ok(eval(espowerCoffee('assert.ok dog[prop].year is lastYear'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/bar_test.coffee:1', | ||
'', | ||
'assert.ok dog[prop].year is lastYear', | ||
' | || | | | ', | ||
' | || | | 2012 ', | ||
' | || 2011 false ', | ||
' | |"birthday" ', | ||
' | {"year":2011} ', | ||
' {"birthday":{"year":2011}}', | ||
'' | ||
]); | ||
}); |
@@ -1,157 +0,185 @@ | ||
var q = require('../test_helper').QUnit, | ||
empower = require('../lib/empower'); | ||
var empower = require('../lib/empower'), | ||
instrument = require('../test_helper').instrument, | ||
assert = require('assert'); | ||
q.module('empower.defaultOptions()', { | ||
setup: function () { | ||
suite('empower.defaultOptions()', function () { | ||
setup (function () { | ||
this.options = empower.defaultOptions(); | ||
}); | ||
test('destructive: false', function () { | ||
assert.equal(this.options.destructive, false); | ||
}); | ||
test('formatter: power-assert-formatter module', function () { | ||
assert.deepEqual(this.options.formatter, require('../lib/power-assert-formatter')); | ||
}); | ||
}); | ||
suite('lineSeparator option', function () { | ||
function lineSeparatorTest (name, option, expectedSeparator) { | ||
test(name, function () { | ||
var baseAssert = require('assert'); | ||
var assert = empower(baseAssert, option); | ||
var falsyNum = 0; | ||
try { | ||
assert(eval(instrument('assert(falsyNum);'))); | ||
} catch (e) { | ||
baseAssert.equal(e.message, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(falsyNum);', | ||
' | ', | ||
' 0 ', | ||
'' | ||
].join(expectedSeparator)); | ||
} | ||
}); | ||
} | ||
lineSeparatorTest('default is LF', {}, '\n'); | ||
lineSeparatorTest('LF', {lineSeparator: '\n'}, '\n'); | ||
lineSeparatorTest('CR', {lineSeparator: '\r'}, '\r'); | ||
lineSeparatorTest('CRLF', {lineSeparator: '\r\n'}, '\r\n'); | ||
}); | ||
q.test('destructive: false', function () { | ||
q.equal(this.options.destructive, false); | ||
}); | ||
q.test('formatter: power-assert-formatter module', function () { | ||
q.deepEqual(this.options.formatter, require('../lib/power-assert-formatter')); | ||
}); | ||
suite('assert object empowerment', function () { | ||
q.module('assert object empowerment'); | ||
test('destructive: false', function () { | ||
var assertOk = function (actual, message) { | ||
if (!actual) { | ||
throw new Error('FakeAssert: assertion failed. ' + message); | ||
} | ||
}; | ||
var fakeAssertObject = { | ||
ok: assertOk, | ||
equal: function (actual, expected, message) { | ||
this.ok(actual == expected, message); | ||
}, | ||
strictEqual: function (actual, expected, message) { | ||
this.ok(actual === expected, message); | ||
} | ||
}; | ||
q.test('destructive: false', function () { | ||
var assertOk = function (actual, message) { | ||
if (!actual) { | ||
throw new Error('FakeAssert: assertion failed. ' + message); | ||
var empoweredAssert = empower(fakeAssertObject, {destructive: false}); | ||
assert.ok(typeof empoweredAssert === 'object'); | ||
assert.ok(typeof empoweredAssert.ok === 'function'); | ||
assert.ok(typeof empoweredAssert._capt === 'function'); | ||
assert.ok(typeof empoweredAssert._expr === 'function'); | ||
assert.ok(typeof empoweredAssert.equal === 'function'); | ||
assert.ok(typeof empoweredAssert.strictEqual === 'function'); | ||
assert.notEqual(empoweredAssert, fakeAssertObject); | ||
assert.notEqual(empoweredAssert.ok, fakeAssertObject.ok); | ||
assert.equal(fakeAssertObject.ok, assertOk); | ||
try { | ||
empoweredAssert.ok(false, 'empoweredAssert.ok'); | ||
} catch (e) { | ||
assert.ok(e instanceof Error); | ||
assert.equal(e.message, 'FakeAssert: assertion failed. empoweredAssert.ok'); | ||
} | ||
}; | ||
var fakeAssertObject = { | ||
ok: assertOk, | ||
equal: function (actual, expected, message) { | ||
this.ok(actual == expected, message); | ||
}, | ||
strictEqual: function (actual, expected, message) { | ||
this.ok(actual === expected, message); | ||
try { | ||
empoweredAssert.strictEqual(1, '1', 'empoweredAssert.strictEqual'); | ||
} catch (e) { | ||
assert.ok(e instanceof Error); | ||
assert.equal(e.message, 'FakeAssert: assertion failed. empoweredAssert.strictEqual'); | ||
} | ||
}; | ||
var empoweredAssert = empower(fakeAssertObject, {destructive: false}); | ||
q.ok(typeof empoweredAssert === 'object'); | ||
q.ok(typeof empoweredAssert.ok === 'function'); | ||
q.ok(typeof empoweredAssert._capt === 'function'); | ||
q.ok(typeof empoweredAssert._expr === 'function'); | ||
q.ok(typeof empoweredAssert.equal === 'function'); | ||
q.ok(typeof empoweredAssert.strictEqual === 'function'); | ||
var empoweredAgain = empower(empoweredAssert, {destructive: false}); | ||
assert.equal(empoweredAgain, empoweredAssert, 'avoid empowering multiple times'); | ||
}); | ||
q.notEqual(empoweredAssert, fakeAssertObject); | ||
q.notEqual(empoweredAssert.ok, fakeAssertObject.ok); | ||
q.equal(fakeAssertObject.ok, assertOk); | ||
try { | ||
empoweredAssert.ok(false, 'empoweredAssert.ok'); | ||
} catch (e) { | ||
q.ok(e instanceof Error); | ||
q.equal(e.message, 'FakeAssert: assertion failed. empoweredAssert.ok'); | ||
} | ||
test('destructive: true', function () { | ||
var assertOk = function (actual, message) { | ||
if (!actual) { | ||
throw new Error('FakeAssert: assertion failed. ' + message); | ||
} | ||
}; | ||
var fakeAssertObject = { | ||
ok: assertOk, | ||
equal: function (actual, expected, message) { | ||
this.ok(actual == expected, message); | ||
}, | ||
strictEqual: function (actual, expected, message) { | ||
this.ok(actual === expected, message); | ||
} | ||
}; | ||
try { | ||
empoweredAssert.strictEqual(1, '1', 'empoweredAssert.strictEqual'); | ||
} catch (e) { | ||
q.ok(e instanceof Error); | ||
q.equal(e.message, 'FakeAssert: assertion failed. empoweredAssert.strictEqual'); | ||
} | ||
empower(fakeAssertObject, {destructive: true}); | ||
assert.ok(typeof fakeAssertObject === 'object'); | ||
assert.ok(typeof fakeAssertObject.ok === 'function'); | ||
assert.ok(typeof fakeAssertObject._capt === 'function'); | ||
assert.ok(typeof fakeAssertObject._expr === 'function'); | ||
assert.ok(typeof fakeAssertObject.equal === 'function'); | ||
assert.ok(typeof fakeAssertObject.strictEqual === 'function'); | ||
var empoweredAgain = empower(empoweredAssert, {destructive: false}); | ||
q.equal(empoweredAgain, empoweredAssert, 'avoid empowering multiple times'); | ||
}); | ||
assert.notEqual(fakeAssertObject.ok, assertOk); | ||
try { | ||
fakeAssertObject.ok(false, 'fakeAssertObject.ok'); | ||
} catch (e) { | ||
assert.ok(e instanceof Error); | ||
assert.equal(e.message, 'FakeAssert: assertion failed. fakeAssertObject.ok'); | ||
} | ||
q.test('destructive: true', function () { | ||
var assertOk = function (actual, message) { | ||
if (!actual) { | ||
throw new Error('FakeAssert: assertion failed. ' + message); | ||
try { | ||
fakeAssertObject.strictEqual(1, '1', 'fakeAssertObject.strictEqual'); | ||
} catch (e) { | ||
assert.ok(e instanceof Error); | ||
assert.equal(e.message, 'FakeAssert: assertion failed. fakeAssertObject.strictEqual'); | ||
} | ||
}; | ||
var fakeAssertObject = { | ||
ok: assertOk, | ||
equal: function (actual, expected, message) { | ||
this.ok(actual == expected, message); | ||
}, | ||
strictEqual: function (actual, expected, message) { | ||
this.ok(actual === expected, message); | ||
} | ||
}; | ||
empower(fakeAssertObject, {destructive: true}); | ||
q.ok(typeof fakeAssertObject === 'object'); | ||
q.ok(typeof fakeAssertObject.ok === 'function'); | ||
q.ok(typeof fakeAssertObject._capt === 'function'); | ||
q.ok(typeof fakeAssertObject._expr === 'function'); | ||
q.ok(typeof fakeAssertObject.equal === 'function'); | ||
q.ok(typeof fakeAssertObject.strictEqual === 'function'); | ||
var empoweredAgain = empower(fakeAssertObject, {destructive: true}); | ||
assert.equal(empoweredAgain, fakeAssertObject, 'avoid empowering multiple times'); | ||
}); | ||
}); | ||
q.notEqual(fakeAssertObject.ok, assertOk); | ||
try { | ||
fakeAssertObject.ok(false, 'fakeAssertObject.ok'); | ||
} catch (e) { | ||
q.ok(e instanceof Error); | ||
q.equal(e.message, 'FakeAssert: assertion failed. fakeAssertObject.ok'); | ||
} | ||
try { | ||
fakeAssertObject.strictEqual(1, '1', 'fakeAssertObject.strictEqual'); | ||
} catch (e) { | ||
q.ok(e instanceof Error); | ||
q.equal(e.message, 'FakeAssert: assertion failed. fakeAssertObject.strictEqual'); | ||
} | ||
suite('assert function empowerment', function () { | ||
test('destructive: false', function () { | ||
var assertOk = function (actual, message) { | ||
if (!actual) { | ||
throw new Error('FakeAssert: assertion failed. ' + message); | ||
} | ||
}; | ||
assertOk.ok = assertOk; | ||
assertOk.equal = function (actual, expected, message) { | ||
this.ok(actual == expected, message); | ||
}; | ||
assertOk.strictEqual = function (actual, expected, message) { | ||
this.ok(actual === expected, message); | ||
}; | ||
var empoweredAgain = empower(fakeAssertObject, {destructive: true}); | ||
q.equal(empoweredAgain, fakeAssertObject, 'avoid empowering multiple times'); | ||
}); | ||
var empoweredAssert = empower(assertOk, {destructive: false}); | ||
assert.ok(typeof empoweredAssert === 'function'); | ||
assert.ok(typeof empoweredAssert.ok === 'function'); | ||
assert.ok(typeof empoweredAssert._capt === 'function'); | ||
assert.ok(typeof empoweredAssert._expr === 'function'); | ||
assert.ok(typeof empoweredAssert.equal === 'function'); | ||
assert.ok(typeof empoweredAssert.strictEqual === 'function'); | ||
assert.notEqual(empoweredAssert, assertOk); | ||
assert.notEqual(empoweredAssert.ok, assertOk); | ||
try { | ||
empoweredAssert.ok(false, 'empoweredAssert.ok'); | ||
} catch (e) { | ||
assert.ok(e instanceof Error); | ||
assert.equal(e.message, 'FakeAssert: assertion failed. empoweredAssert.ok'); | ||
} | ||
q.module('assert function empowerment'); | ||
q.test('destructive: false', function () { | ||
var assertOk = function (actual, message) { | ||
if (!actual) { | ||
throw new Error('FakeAssert: assertion failed. ' + message); | ||
try { | ||
empoweredAssert.strictEqual(1, '1', 'empoweredAssert.strictEqual'); | ||
} catch (e) { | ||
assert.ok(e instanceof Error); | ||
assert.equal(e.message, 'FakeAssert: assertion failed. empoweredAssert.strictEqual'); | ||
} | ||
}; | ||
assertOk.ok = assertOk; | ||
assertOk.equal = function (actual, expected, message) { | ||
this.ok(actual == expected, message); | ||
}; | ||
assertOk.strictEqual = function (actual, expected, message) { | ||
this.ok(actual === expected, message); | ||
}; | ||
var empoweredAssert = empower(assertOk, {destructive: false}); | ||
q.ok(typeof empoweredAssert === 'function'); | ||
q.ok(typeof empoweredAssert.ok === 'function'); | ||
q.ok(typeof empoweredAssert._capt === 'function'); | ||
q.ok(typeof empoweredAssert._expr === 'function'); | ||
q.ok(typeof empoweredAssert.equal === 'function'); | ||
q.ok(typeof empoweredAssert.strictEqual === 'function'); | ||
q.notEqual(empoweredAssert, assertOk); | ||
q.notEqual(empoweredAssert.ok, assertOk); | ||
try { | ||
empoweredAssert.ok(false, 'empoweredAssert.ok'); | ||
} catch (e) { | ||
q.ok(e instanceof Error); | ||
q.equal(e.message, 'FakeAssert: assertion failed. empoweredAssert.ok'); | ||
} | ||
try { | ||
empoweredAssert.strictEqual(1, '1', 'empoweredAssert.strictEqual'); | ||
} catch (e) { | ||
q.ok(e instanceof Error); | ||
q.equal(e.message, 'FakeAssert: assertion failed. empoweredAssert.strictEqual'); | ||
} | ||
var empoweredAgain = empower(empoweredAssert, {destructive: false}); | ||
q.equal(empoweredAgain, empoweredAssert, 'avoid empowering multiple times'); | ||
var empoweredAgain = empower(empoweredAssert, {destructive: false}); | ||
assert.equal(empoweredAgain, empoweredAssert, 'avoid empowering multiple times'); | ||
}); | ||
}); |
@@ -1,320 +0,280 @@ | ||
var q = require('../test_helper').QUnit, | ||
var empower = require('../lib/empower'), | ||
instrument = require('../test_helper').instrument, | ||
empower = require('../lib/empower'), | ||
baseAssert = require('assert'), | ||
config = empower.defaultOptions(), | ||
powerAssertTextLines = []; | ||
config.callback = function (context, message) { | ||
powerAssertTextLines = config.formatter.format(context); | ||
}; | ||
var assert = empower(q.assert, config); | ||
var assert = empower(baseAssert, config); | ||
q.module('power-assert-formatter', { | ||
setup: function () { | ||
suite('power-assert-formatter', function () { | ||
setup(function () { | ||
powerAssertTextLines.length = 0; | ||
} | ||
}); | ||
}); | ||
q.test('Identifier with empty string', function () { | ||
var falsyStr = ''; | ||
assert.ok(eval(instrument('assert(falsyStr);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(falsyStr);', | ||
' | ', | ||
' "" ', | ||
'' | ||
]); | ||
}); | ||
test('Identifier with empty string', function () { | ||
var falsyStr = ''; | ||
assert(eval(instrument('assert(falsyStr);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(falsyStr);', | ||
' | ', | ||
' "" ', | ||
'' | ||
]); | ||
}); | ||
q.test('ReturnStatement', function () { | ||
var falsyStr = ''; | ||
assert.ok(eval(instrument('return assert(falsyStr);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'return assert(falsyStr);', | ||
' | ', | ||
' "" ', | ||
'' | ||
]); | ||
}); | ||
test('ReturnStatement', function () { | ||
var falsyStr = ''; | ||
assert(eval(instrument('return assert(falsyStr);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'return assert(falsyStr);', | ||
' | ', | ||
' "" ', | ||
'' | ||
]); | ||
}); | ||
q.test('Identifier with falsy number', function () { | ||
var falsyNum = 0; | ||
assert.ok(eval(instrument('assert(falsyNum);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(falsyNum);', | ||
' | ', | ||
' 0 ', | ||
'' | ||
]); | ||
}); | ||
test('Identifier with falsy number', function () { | ||
var falsyNum = 0; | ||
assert(eval(instrument('assert(falsyNum);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(falsyNum);', | ||
' | ', | ||
' 0 ', | ||
'' | ||
]); | ||
}); | ||
q.test('UnaryExpression, negation', function () { | ||
var truth = true; | ||
assert.ok(eval(instrument('assert(!truth);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(!truth);', | ||
' || ', | ||
' |true ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
test('UnaryExpression, negation', function () { | ||
var truth = true; | ||
assert(eval(instrument('assert(!truth);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(!truth);', | ||
' || ', | ||
' |true ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
q.test('UnaryExpression, double negative', function () { | ||
var some = ''; | ||
assert.ok(eval(instrument('assert(!!some);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(!!some);', | ||
' ||| ', | ||
' ||"" ', | ||
' |true ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
test('UnaryExpression, double negative', function () { | ||
var some = ''; | ||
assert(eval(instrument('assert(!!some);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(!!some);', | ||
' ||| ', | ||
' ||"" ', | ||
' |true ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
q.test('typeof operator: assert(typeof foo !== "undefined");', function () { | ||
assert.ok(eval(instrument('assert(typeof foo !== "undefined");'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(typeof foo !== "undefined");', | ||
' | | ', | ||
' | false ', | ||
' "undefined" ', | ||
'' | ||
]); | ||
}); | ||
q.test('undefined property: assert({}.hoge === "xxx");', function () { | ||
assert.ok(eval(instrument('assert({}.hoge === "xxx");'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert({}.hoge === "xxx");', | ||
' | | ', | ||
' | false ', | ||
' undefined ', | ||
'' | ||
]); | ||
}); | ||
test('typeof operator: assert(typeof foo !== "undefined");', function () { | ||
assert(eval(instrument('assert(typeof foo !== "undefined");'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(typeof foo !== "undefined");', | ||
' | | ', | ||
' | false ', | ||
' "undefined" ', | ||
'' | ||
]); | ||
}); | ||
q.test('assert((delete foo.bar) === false);', function () { | ||
var foo = { | ||
bar: { | ||
baz: false | ||
} | ||
}; | ||
assert.ok(eval(instrument('assert((delete foo.bar) === false);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert((delete foo.bar) === false);', | ||
' | | | | ', | ||
' | | | false ', | ||
' | | {"baz":false} ', | ||
' true {"bar":{"baz":false}}', | ||
'' | ||
]); | ||
}); | ||
test('undefined property: assert({}.hoge === "xxx");', function () { | ||
assert(eval(instrument('assert({}.hoge === "xxx");'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert({}.hoge === "xxx");', | ||
' | | ', | ||
' | false ', | ||
' undefined ', | ||
'' | ||
]); | ||
}); | ||
q.test('assert((delete nonexistent) === false);', function () { | ||
assert.ok(eval(instrument('assert((delete nonexistent) === false);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert((delete nonexistent) === false);', | ||
' | | ', | ||
' true false ', | ||
'' | ||
]); | ||
}); | ||
test('assert((delete foo.bar) === false);', function () { | ||
var foo = { | ||
bar: { | ||
baz: false | ||
} | ||
}; | ||
assert(eval(instrument('assert((delete foo.bar) === false);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert((delete foo.bar) === false);', | ||
' | | | | ', | ||
' | | | false ', | ||
' | | {"baz":false} ', | ||
' true {"bar":{"baz":false}}', | ||
'' | ||
]); | ||
}); | ||
q.test('assert(fuga === piyo);', function () { | ||
var fuga = 'foo', | ||
piyo = 8; | ||
assert.ok(eval(instrument('assert(fuga === piyo);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(fuga === piyo);', | ||
' | | | ', | ||
' | | 8 ', | ||
' | false ', | ||
' "foo" ', | ||
'' | ||
]); | ||
}); | ||
test('assert((delete nonexistent) === false);', function () { | ||
assert(eval(instrument('assert((delete nonexistent) === false);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert((delete nonexistent) === false);', | ||
' | | ', | ||
' true false ', | ||
'' | ||
]); | ||
}); | ||
q.test('assert(fuga !== piyo);', function () { | ||
var fuga = 'foo', | ||
piyo = 'foo'; | ||
assert.ok(eval(instrument('assert(fuga !== piyo);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(fuga !== piyo);', | ||
' | | | ', | ||
' | | "foo" ', | ||
' | false ', | ||
' "foo" ', | ||
'' | ||
]); | ||
}); | ||
test('assert(fuga === piyo);', function () { | ||
var fuga = 'foo', | ||
piyo = 8; | ||
assert(eval(instrument('assert(fuga === piyo);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(fuga === piyo);', | ||
' | | | ', | ||
' | | 8 ', | ||
' | false ', | ||
' "foo" ', | ||
'' | ||
]); | ||
}); | ||
q.test('BinaryExpression with Literal and Identifier: assert(fuga !== 4);', function () { | ||
var fuga = 4; | ||
assert.ok(eval(instrument('assert(fuga !== 4);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(fuga !== 4);', | ||
' | | ', | ||
' 4 false ', | ||
'' | ||
]); | ||
}); | ||
test('assert(fuga !== piyo);', function () { | ||
var fuga = 'foo', | ||
piyo = 'foo'; | ||
assert(eval(instrument('assert(fuga !== piyo);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(fuga !== piyo);', | ||
' | | | ', | ||
' | | "foo" ', | ||
' | false ', | ||
' "foo" ', | ||
'' | ||
]); | ||
}); | ||
q.test('assert(4 !== 4);', function () { | ||
assert.ok(eval(instrument('assert(4 !== 4);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(4 !== 4);', | ||
' | ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
test('BinaryExpression with Literal and Identifier: assert(fuga !== 4);', function () { | ||
var fuga = 4; | ||
assert(eval(instrument('assert(fuga !== 4);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(fuga !== 4);', | ||
' | | ', | ||
' 4 false ', | ||
'' | ||
]); | ||
}); | ||
q.test('MemberExpression: assert(ary1.length === ary2.length);', function () { | ||
var ary1 = ['foo', 'bar']; | ||
var ary2 = ['aaa', 'bbb', 'ccc']; | ||
assert.ok(eval(instrument('assert(ary1.length === ary2.length);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(ary1.length === ary2.length);', | ||
' | | | | | ', | ||
' | | | | 3 ', | ||
' | | | ["aaa","bbb","ccc"]', | ||
' | 2 false ', | ||
' ["foo","bar"] ', | ||
'' | ||
]); | ||
}); | ||
test('assert(4 !== 4);', function () { | ||
assert(eval(instrument('assert(4 !== 4);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(4 !== 4);', | ||
' | ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
q.test('LogicalExpression: assert(5 < actual && actual < 13);', function () { | ||
var actual = 16; | ||
assert.ok(eval(instrument('assert(5 < actual && actual < 13);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(5 < actual && actual < 13);', | ||
' | | | | | ', | ||
' | | | 16 false ', | ||
' | 16 false ', | ||
' true ', | ||
'' | ||
]); | ||
}); | ||
test('MemberExpression: assert(ary1.length === ary2.length);', function () { | ||
var ary1 = ['foo', 'bar']; | ||
var ary2 = ['aaa', 'bbb', 'ccc']; | ||
assert(eval(instrument('assert(ary1.length === ary2.length);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(ary1.length === ary2.length);', | ||
' | | | | | ', | ||
' | | | | 3 ', | ||
' | | | ["aaa","bbb","ccc"]', | ||
' | 2 false ', | ||
' ["foo","bar"] ', | ||
'' | ||
]); | ||
}); | ||
q.test('LogicalExpression OR: assert.ok(actual < 5 || 13 < actual);', function () { | ||
var actual = 10; | ||
assert.ok(eval(instrument('assert.ok(actual < 5 || 13 < actual);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert.ok(actual < 5 || 13 < actual);', | ||
' | | | | | ', | ||
' | | | | 10 ', | ||
' | | false false ', | ||
' 10 false ', | ||
'' | ||
]); | ||
}); | ||
test('LogicalExpression: assert(5 < actual && actual < 13);', function () { | ||
var actual = 16; | ||
assert(eval(instrument('assert(5 < actual && actual < 13);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(5 < actual && actual < 13);', | ||
' | | | | | ', | ||
' | | | 16 false ', | ||
' | 16 false ', | ||
' true ', | ||
'' | ||
]); | ||
}); | ||
q.test('Characterization test of LogicalExpression current spec: assert(2 > actual && actual < 13);', function () { | ||
var actual = 5; | ||
assert.ok(eval(instrument('assert(2 > actual && actual < 13);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(2 > actual && actual < 13);', | ||
' | | | ', | ||
' | 5 false ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
test('LogicalExpression OR: assert.ok(actual < 5 || 13 < actual);', function () { | ||
var actual = 10; | ||
assert(eval(instrument('assert.ok(actual < 5 || 13 < actual);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert.ok(actual < 5 || 13 < actual);', | ||
' | | | | | ', | ||
' | | | | 10 ', | ||
' | | false false ', | ||
' 10 false ', | ||
'' | ||
]); | ||
}); | ||
q.test('Deep MemberExpression chain: assert(foo.bar.baz);', function () { | ||
var foo = { | ||
bar: { | ||
baz: false | ||
} | ||
}; | ||
assert.ok(eval(instrument('assert(foo.bar.baz);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(foo.bar.baz);', | ||
' | | | ', | ||
' | | false', | ||
' | {"baz":false}', | ||
' {"bar":{"baz":false}}', | ||
'' | ||
]); | ||
}); | ||
test('Characterization test of LogicalExpression current spec: assert(2 > actual && actual < 13);', function () { | ||
var actual = 5; | ||
assert(eval(instrument('assert(2 > actual && actual < 13);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(2 > actual && actual < 13);', | ||
' | | | ', | ||
' | 5 false ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
q.test('computed MemberExpression with Literal key: assert(foo["bar"].baz);', function () { | ||
var foo = { | ||
bar: { | ||
baz: false | ||
} | ||
}; | ||
assert.ok(eval(instrument('assert(foo["bar"].baz);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(foo["bar"].baz);', | ||
' | | | ', | ||
' | | false', | ||
' | {"baz":false}', | ||
' {"bar":{"baz":false}}', | ||
'' | ||
]); | ||
}); | ||
q.test('computed MemberExpression with Identifier key: assert(foo[propName].baz);', function () { | ||
var propName = 'bar', | ||
foo = { | ||
test('Deep MemberExpression chain: assert(foo.bar.baz);', function () { | ||
var foo = { | ||
bar: { | ||
@@ -324,419 +284,467 @@ baz: false | ||
}; | ||
assert.ok(eval(instrument('assert(foo[propName].baz);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(foo[propName].baz);', | ||
' | || | ', | ||
' | |"bar" false', | ||
' | {"baz":false} ', | ||
' {"bar":{"baz":false}}', | ||
'' | ||
]); | ||
}); | ||
assert(eval(instrument('assert(foo.bar.baz);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(foo.bar.baz);', | ||
' | | | ', | ||
' | | false', | ||
' | {"baz":false}', | ||
' {"bar":{"baz":false}}', | ||
'' | ||
]); | ||
}); | ||
q.test('computed MemberExpression chain with various key: assert(foo[propName]["baz"][keys()[0]]);', function () { | ||
var keys = function () { return ["toto"]; }, | ||
propName = "bar", | ||
foo = { | ||
test('computed MemberExpression with Literal key: assert(foo["bar"].baz);', function () { | ||
var foo = { | ||
bar: { | ||
baz: { | ||
toto: false | ||
} | ||
baz: false | ||
} | ||
}; | ||
assert.ok(eval(instrument('assert(foo[propName]["baz"][keys()[0]]);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(foo[propName]["baz"][keys()[0]]);', | ||
' | || | || | ', | ||
' | || | || "toto"', | ||
' | || | |["toto"] ', | ||
' | || | false ', | ||
' | |"bar" {"toto":false} ', | ||
' | {"baz":{"toto":false}} ', | ||
' {"bar":{"baz":{"toto":false}}} ', | ||
'' | ||
]); | ||
}); | ||
assert(eval(instrument('assert(foo["bar"].baz);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(foo["bar"].baz);', | ||
' | | | ', | ||
' | | false', | ||
' | {"baz":false}', | ||
' {"bar":{"baz":false}}', | ||
'' | ||
]); | ||
}); | ||
q.test('assert(func());', function () { | ||
var func = function () { return false; }; | ||
assert.ok(eval(instrument('assert(func());'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(func());', | ||
' | ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
test('computed MemberExpression with Identifier key: assert(foo[propName].baz);', function () { | ||
var propName = 'bar', | ||
foo = { | ||
bar: { | ||
baz: false | ||
} | ||
}; | ||
assert(eval(instrument('assert(foo[propName].baz);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(foo[propName].baz);', | ||
' | || | ', | ||
' | |"bar" false', | ||
' | {"baz":false} ', | ||
' {"bar":{"baz":false}}', | ||
'' | ||
]); | ||
}); | ||
q.test('assert(obj.age());', function () { | ||
var obj = { | ||
age: function () { | ||
return 0; | ||
} | ||
}; | ||
assert.ok(eval(instrument('assert(obj.age());'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(obj.age());', | ||
' | | ', | ||
' {} 0 ', | ||
'' | ||
]); | ||
}); | ||
test('computed MemberExpression chain with various key: assert(foo[propName]["baz"][keys()[0]]);', function () { | ||
var keys = function () { return ["toto"]; }, | ||
propName = "bar", | ||
foo = { | ||
bar: { | ||
baz: { | ||
toto: false | ||
} | ||
} | ||
}; | ||
assert(eval(instrument('assert(foo[propName]["baz"][keys()[0]]);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(foo[propName]["baz"][keys()[0]]);', | ||
' | || | || | ', | ||
' | || | || "toto"', | ||
' | || | |["toto"] ', | ||
' | || | false ', | ||
' | |"bar" {"toto":false} ', | ||
' | {"baz":{"toto":false}} ', | ||
' {"bar":{"baz":{"toto":false}}} ', | ||
'' | ||
]); | ||
}); | ||
q.test('CallExpression with arguments: assert(isFalsy(positiveInt));', function () { | ||
var isFalsy = function (arg) { | ||
return !(arg); | ||
}; | ||
var positiveInt = 50; | ||
assert.ok(eval(instrument('assert(isFalsy(positiveInt));'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(isFalsy(positiveInt));', | ||
' | | ', | ||
' false 50 ', | ||
'' | ||
]); | ||
}); | ||
test('assert(func());', function () { | ||
var func = function () { return false; }; | ||
assert(eval(instrument('assert(func());'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(func());', | ||
' | ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
q.test('assert(sum(one, two, three) === seven);', function () { | ||
var sum = function () { | ||
var result = 0; | ||
for (var i = 0; i < arguments.length; i += 1) { | ||
result += arguments[i]; | ||
} | ||
return result; | ||
}; | ||
var one = 1, two = 2, three = 3, seven = 7, ten = 10; | ||
assert.ok(eval(instrument('assert(sum(one, two, three) === seven);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(sum(one, two, three) === seven);', | ||
' | | | | | | ', | ||
' | | | | | 7 ', | ||
' 6 1 2 3 false ', | ||
'' | ||
]); | ||
}); | ||
test('assert(obj.age());', function () { | ||
var obj = { | ||
age: function () { | ||
return 0; | ||
} | ||
}; | ||
assert(eval(instrument('assert(obj.age());'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(obj.age());', | ||
' | | ', | ||
' {} 0 ', | ||
'' | ||
]); | ||
}); | ||
q.test('CallExpression with CallExpressions as arguments: assert(sum(sum(one, two), three) === sum(sum(two, three), seven));', function () { | ||
var sum = function () { | ||
var result = 0; | ||
for (var i = 0; i < arguments.length; i += 1) { | ||
result += arguments[i]; | ||
} | ||
return result; | ||
}; | ||
var one = 1, two = 2, three = 3, seven = 7, ten = 10; | ||
assert.ok(eval(instrument('assert(sum(sum(one, two), three) === sum(sum(two, three), seven));'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(sum(sum(one, two), three) === sum(sum(two, three), seven));', | ||
' | | | | | | | | | | | ', | ||
' | | | | | | 12 5 2 3 7 ', | ||
' 6 3 1 2 3 false ', | ||
'' | ||
]); | ||
}); | ||
test('CallExpression with arguments: assert(isFalsy(positiveInt));', function () { | ||
var isFalsy = function (arg) { | ||
return !(arg); | ||
}; | ||
var positiveInt = 50; | ||
assert(eval(instrument('assert(isFalsy(positiveInt));'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(isFalsy(positiveInt));', | ||
' | | ', | ||
' false 50 ', | ||
'' | ||
]); | ||
}); | ||
q.test('assert(math.calc.sum(one, two, three) === seven);', function () { | ||
var math = { | ||
calc: { | ||
sum: function () { | ||
var result = 0; | ||
for (var i = 0; i < arguments.length; i += 1) { | ||
result += arguments[i]; | ||
} | ||
return result; | ||
test('assert(sum(one, two, three) === seven);', function () { | ||
var sum = function () { | ||
var result = 0; | ||
for (var i = 0; i < arguments.length; i += 1) { | ||
result += arguments[i]; | ||
} | ||
} | ||
}; | ||
var one = 1, two = 2, three = 3, seven = 7, ten = 10; | ||
assert.ok(eval(instrument('assert(math.calc.sum(one, two, three) === seven);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(math.calc.sum(one, two, three) === seven);', | ||
' | | | | | | | | ', | ||
' | | | | | | | 7 ', | ||
' | {} 6 1 2 3 false ', | ||
' {"calc":{}} ', | ||
'' | ||
]); | ||
}); | ||
return result; | ||
}; | ||
var one = 1, two = 2, three = 3, seven = 7, ten = 10; | ||
assert(eval(instrument('assert(sum(one, two, three) === seven);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(sum(one, two, three) === seven);', | ||
' | | | | | | ', | ||
' | | | | | 7 ', | ||
' 6 1 2 3 false ', | ||
'' | ||
]); | ||
}); | ||
q.test('Nested CallExpression with BinaryExpression: assert((three * (seven * ten)) === three);', function () { | ||
var one = 1, two = 2, three = 3, seven = 7, ten = 10; | ||
assert.ok(eval(instrument('assert((three * (seven * ten)) === three);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert((three * (seven * ten)) === three);', | ||
' | | | | | | | ', | ||
' | | | | | | 3 ', | ||
' | | | | 10 false ', | ||
' | | 7 70 ', | ||
' 3 210 ', | ||
'' | ||
]); | ||
}); | ||
test('CallExpression with CallExpressions as arguments: assert(sum(sum(one, two), three) === sum(sum(two, three), seven));', function () { | ||
var sum = function () { | ||
var result = 0; | ||
for (var i = 0; i < arguments.length; i += 1) { | ||
result += arguments[i]; | ||
} | ||
return result; | ||
}; | ||
var one = 1, two = 2, three = 3, seven = 7, ten = 10; | ||
assert(eval(instrument('assert(sum(sum(one, two), three) === sum(sum(two, three), seven));'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(sum(sum(one, two), three) === sum(sum(two, three), seven));', | ||
' | | | | | | | | | | | ', | ||
' | | | | | | 12 5 2 3 7 ', | ||
' 6 3 1 2 3 false ', | ||
'' | ||
]); | ||
}); | ||
q.test('Simple BinaryExpression with comment', function () { | ||
var hoge = 'foo'; | ||
var fuga = 'bar'; | ||
assert.ok(eval(instrument('assert.ok(hoge === fuga, "comment");'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert.ok(hoge === fuga, "comment");', | ||
' | | | ', | ||
' | | "bar" ', | ||
' | false ', | ||
' "foo" ', | ||
'' | ||
]); | ||
}); | ||
test('assert(math.calc.sum(one, two, three) === seven);', function () { | ||
var math = { | ||
calc: { | ||
sum: function () { | ||
var result = 0; | ||
for (var i = 0; i < arguments.length; i += 1) { | ||
result += arguments[i]; | ||
} | ||
return result; | ||
} | ||
} | ||
}; | ||
var one = 1, two = 2, three = 3, seven = 7, ten = 10; | ||
assert(eval(instrument('assert(math.calc.sum(one, two, three) === seven);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(math.calc.sum(one, two, three) === seven);', | ||
' | | | | | | | | ', | ||
' | | | | | | | 7 ', | ||
' | {} 6 1 2 3 false ', | ||
' {"calc":{}} ', | ||
'' | ||
]); | ||
}); | ||
q.test('Looooong string', function () { | ||
var longString = 'very very loooooooooooooooooooooooooooooooooooooooooooooooooooong message'; | ||
var anotherLongString = 'yet another loooooooooooooooooooooooooooooooooooooooooooooooooooong message'; | ||
assert.ok(eval(instrument('assert(longString === anotherLongString);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(longString === anotherLongString);', | ||
' | | | ', | ||
' | | "yet another loooooooooooooooooooooooooooooooooooooooooooooooooooong message"', | ||
' | false ', | ||
' "very very loooooooooooooooooooooooooooooooooooooooooooooooooooong message"', | ||
'' | ||
]); | ||
}); | ||
test('Nested CallExpression with BinaryExpression: assert((three * (seven * ten)) === three);', function () { | ||
var one = 1, two = 2, three = 3, seven = 7, ten = 10; | ||
assert(eval(instrument('assert((three * (seven * ten)) === three);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert((three * (seven * ten)) === three);', | ||
' | | | | | | | ', | ||
' | | | | | | 3 ', | ||
' | | | | 10 false ', | ||
' | | 7 70 ', | ||
' 3 210 ', | ||
'' | ||
]); | ||
}); | ||
q.test('double byte character width', function () { | ||
var fuga = 'あい', | ||
piyo = 'うえお'; | ||
var concat = function (a, b) { | ||
return a + b; | ||
}; | ||
assert.ok(eval(instrument('assert(!concat(fuga, piyo));'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(!concat(fuga, piyo));', | ||
' || | | ', | ||
' || | "うえお"', | ||
' || "あい" ', | ||
' |"あいうえお" ', | ||
' false ', | ||
'' | ||
]); | ||
test('Simple BinaryExpression with comment', function () { | ||
var hoge = 'foo'; | ||
var fuga = 'bar'; | ||
assert(eval(instrument('assert.ok(hoge === fuga, "comment");'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert.ok(hoge === fuga, "comment");', | ||
' | | | ', | ||
' | | "bar" ', | ||
' | false ', | ||
' "foo" ', | ||
'' | ||
]); | ||
}); | ||
}); | ||
test('Looooong string', function () { | ||
var longString = 'very very loooooooooooooooooooooooooooooooooooooooooooooooooooong message'; | ||
var anotherLongString = 'yet another loooooooooooooooooooooooooooooooooooooooooooooooooooong message'; | ||
assert(eval(instrument('assert(longString === anotherLongString);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(longString === anotherLongString);', | ||
' | | | ', | ||
' | | "yet another loooooooooooooooooooooooooooooooooooooooooooooooooooong message"', | ||
' | false ', | ||
' "very very loooooooooooooooooooooooooooooooooooooooooooooooooooong message"', | ||
'' | ||
]); | ||
}); | ||
q.test('Japanese hankaku width', function () { | ||
var fuga = 'アイ', | ||
piyo = 'ウエオ'; | ||
var concat = function (a, b) { | ||
return a + b; | ||
}; | ||
assert.ok(eval(instrument('assert(!concat(fuga, piyo));'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(!concat(fuga, piyo));', | ||
' || | | ', | ||
' || "アイ" "ウエオ" ', | ||
' |"アイウエオ" ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
test('double byte character width', function () { | ||
var fuga = 'あい', | ||
piyo = 'うえお'; | ||
var concat = function (a, b) { | ||
return a + b; | ||
}; | ||
assert(eval(instrument('assert(!concat(fuga, piyo));'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(!concat(fuga, piyo));', | ||
' || | | ', | ||
' || | "うえお"', | ||
' || "あい" ', | ||
' |"あいうえお" ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
q.test('Object having circular structure', function () { | ||
var cyclic = [], two = 2; | ||
cyclic.push('foo'); | ||
cyclic.push(cyclic); | ||
cyclic.push('baz'); | ||
assert.ok(eval(instrument('assert.ok(cyclic[two] === cyclic);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert.ok(cyclic[two] === cyclic);', | ||
' | || | | ', | ||
' | || | ["foo","#Circular#","baz"]', | ||
' | |2 false ', | ||
' | "baz" ', | ||
' ["foo","#Circular#","baz"]', | ||
'' | ||
]); | ||
}); | ||
test('Japanese hankaku width', function () { | ||
var fuga = 'アイ', | ||
piyo = 'ウエオ'; | ||
var concat = function (a, b) { | ||
return a + b; | ||
}; | ||
assert(eval(instrument('assert(!concat(fuga, piyo));'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(!concat(fuga, piyo));', | ||
' || | | ', | ||
' || "アイ" "ウエオ" ', | ||
' |"アイウエオ" ', | ||
' false ', | ||
'' | ||
]); | ||
}); | ||
q.test('UnaryExpression of UnaryExpression: assert(typeof + twoStr === -twoStr);', function () { | ||
var twoStr = '2'; | ||
assert.ok(eval(instrument('assert(typeof + twoStr === -twoStr);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(typeof + twoStr === -twoStr);', | ||
' | | | | || ', | ||
' | | | | |"2" ', | ||
' | | | | -2 ', | ||
' | 2 "2" false ', | ||
' "number" ', | ||
'' | ||
]); | ||
}); | ||
test('Object having circular structure', function () { | ||
var cyclic = [], two = 2; | ||
cyclic.push('foo'); | ||
cyclic.push(cyclic); | ||
cyclic.push('baz'); | ||
assert(eval(instrument('assert.ok(cyclic[two] === cyclic);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert.ok(cyclic[two] === cyclic);', | ||
' | || | | ', | ||
' | || | ["foo","#Circular#","baz"]', | ||
' | |2 false ', | ||
' | "baz" ', | ||
' ["foo","#Circular#","baz"]', | ||
'' | ||
]); | ||
}); | ||
test('UnaryExpression of UnaryExpression: assert(typeof + twoStr === -twoStr);', function () { | ||
var twoStr = '2'; | ||
assert(eval(instrument('assert(typeof + twoStr === -twoStr);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(typeof + twoStr === -twoStr);', | ||
' | | | | || ', | ||
' | | | | |"2" ', | ||
' | | | | -2 ', | ||
' | 2 "2" false ', | ||
' "number" ', | ||
'' | ||
]); | ||
}); | ||
q.test('AssignmentExpression: assert(minusOne += 1);', function () { | ||
var minusOne = -1; | ||
assert.ok(eval(instrument('assert(minusOne += 1);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(minusOne += 1);', | ||
' | ', | ||
' 0 ', | ||
'' | ||
]); | ||
}); | ||
test('AssignmentExpression: assert(minusOne += 1);', function () { | ||
var minusOne = -1; | ||
assert(eval(instrument('assert(minusOne += 1);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(minusOne += 1);', | ||
' | ', | ||
' 0 ', | ||
'' | ||
]); | ||
}); | ||
q.test('AssignmentExpression with MemberExpression: assert((dog.age += 1) === four);', function () { | ||
var dog = { age: 2 }, four = 4; | ||
assert.ok(eval(instrument('assert((dog.age += 1) === four);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert((dog.age += 1) === four);', | ||
' | | | ', | ||
' | | 4 ', | ||
' 3 false ', | ||
'' | ||
]); | ||
}); | ||
test('AssignmentExpression with MemberExpression: assert((dog.age += 1) === four);', function () { | ||
var dog = { age: 2 }, four = 4; | ||
assert(eval(instrument('assert((dog.age += 1) === four);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert((dog.age += 1) === four);', | ||
' | | | ', | ||
' | | 4 ', | ||
' 3 false ', | ||
'' | ||
]); | ||
}); | ||
test('ArrayExpression: assert([foo, bar].length === four);', function () { | ||
var foo = 'hoge', bar = 'fuga', four = 4; | ||
assert(eval(instrument('assert([foo, bar].length === four);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert([foo, bar].length === four);', | ||
' | | | | | ', | ||
' | | | | 4 ', | ||
' | | 2 false ', | ||
' | "fuga" ', | ||
' "hoge" ', | ||
'' | ||
]); | ||
}); | ||
q.test('ArrayExpression: assert([foo, bar].length === four);', function () { | ||
var foo = 'hoge', bar = 'fuga', four = 4; | ||
assert.ok(eval(instrument('assert([foo, bar].length === four);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert([foo, bar].length === four);', | ||
' | | | | | ', | ||
' | | | | 4 ', | ||
' | | 2 false ', | ||
' | "fuga" ', | ||
' "hoge" ', | ||
'' | ||
]); | ||
}); | ||
test('various expressions in ArrayExpression: assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");', function () { | ||
var foo = {bar: 'fuga'}, baz = function (arg) { return null; }, moo = 'boo', fourStr = '4'; | ||
assert(eval(instrument('assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");', | ||
' | | | | | | | | ', | ||
' | | | | "boo" 4 "4" false ', | ||
' | | | null ', | ||
' | | "fuga" ', | ||
' "object" {"bar":"fuga"} ', | ||
'' | ||
]); | ||
}); | ||
q.test('various expressions in ArrayExpression: assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");', function () { | ||
var foo = {bar: 'fuga'}, baz = function (arg) { return null; }, moo = 'boo', fourStr = '4'; | ||
assert.ok(eval(instrument('assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");', | ||
' | | | | | | | | ', | ||
' | | | | "boo" 4 "4" false ', | ||
' | | | null ', | ||
' | | "fuga" ', | ||
' "object" {"bar":"fuga"} ', | ||
'' | ||
]); | ||
}); | ||
test('prefix UpdateExpression: assert(++minusOne);', function () { | ||
var minusOne = -1; | ||
assert(eval(instrument('assert(++minusOne);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(++minusOne);', | ||
' | ', | ||
' 0 ', | ||
'' | ||
]); | ||
}); | ||
test('suffix UpdateExpression: assert(zero--);', function () { | ||
var zero = 0; | ||
assert(eval(instrument('assert(zero--);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(zero--);', | ||
' | ', | ||
' 0 ', | ||
'' | ||
]); | ||
}); | ||
q.test('prefix UpdateExpression: assert(++minusOne);', function () { | ||
var minusOne = -1; | ||
assert.ok(eval(instrument('assert(++minusOne);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(++minusOne);', | ||
' | ', | ||
' 0 ', | ||
'' | ||
]); | ||
}); | ||
test('ConditionalExpression: assert(truthy ? falsy : anotherFalsy);', function () { | ||
var truthy = 'truthy', falsy = 0, anotherFalsy = null; | ||
assert(eval(instrument('assert(truthy ? falsy : anotherFalsy);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(truthy ? falsy : anotherFalsy);', | ||
' | | ', | ||
' "truthy" 0 ', | ||
'' | ||
]); | ||
}); | ||
q.test('suffix UpdateExpression: assert(zero--);', function () { | ||
var zero = 0; | ||
assert.ok(eval(instrument('assert(zero--);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(zero--);', | ||
' | ', | ||
' 0 ', | ||
'' | ||
]); | ||
}); | ||
test('ConditionalExpression of ConditionalExpression: assert(falsy ? truthy : truthy ? anotherFalsy : truthy);', function () { | ||
var truthy = 'truthy', falsy = 0, anotherFalsy = null; | ||
assert(eval(instrument('assert(falsy ? truthy : truthy ? anotherFalsy : truthy);'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(falsy ? truthy : truthy ? anotherFalsy : truthy);', | ||
' | | | ', | ||
' 0 "truthy" null ', | ||
'' | ||
]); | ||
}); | ||
test('RegularExpression will not be instrumented: assert(/^not/.exec(str));', function () { | ||
var str = 'ok'; | ||
assert(eval(instrument('assert(/^not/.exec(str));'))); | ||
baseAssert.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(/^not/.exec(str));', | ||
' | | ', | ||
' null "ok" ', | ||
'' | ||
]); | ||
}); | ||
q.test('ConditionalExpression: assert(truthy ? falsy : anotherFalsy);', function () { | ||
var truthy = 'truthy', falsy = 0, anotherFalsy = null; | ||
assert.ok(eval(instrument('assert(truthy ? falsy : anotherFalsy);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(truthy ? falsy : anotherFalsy);', | ||
' | | ', | ||
' "truthy" 0 ', | ||
'' | ||
]); | ||
}); | ||
q.test('ConditionalExpression of ConditionalExpression: assert(falsy ? truthy : truthy ? anotherFalsy : truthy);', function () { | ||
var truthy = 'truthy', falsy = 0, anotherFalsy = null; | ||
assert.ok(eval(instrument('assert(falsy ? truthy : truthy ? anotherFalsy : truthy);'))); | ||
q.deepEqual(powerAssertTextLines, [ | ||
'# /path/to/some_test.js:1', | ||
'', | ||
'assert(falsy ? truthy : truthy ? anotherFalsy : truthy);', | ||
' | | | ', | ||
' 0 "truthy" null ', | ||
'' | ||
]); | ||
}); |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
52598
0
12
1239
47