unexpected
Advanced tools
Comparing version 10.17.2 to 10.18.0
@@ -350,2 +350,116 @@ var utils = require('./utils'); | ||
}); | ||
expect.addStyle('arrow', function (options) { | ||
options = options || {}; | ||
var styles = options.styles || []; | ||
var i; | ||
this.nl(options.top || 0).sp(options.left || 0).text('┌', styles); | ||
for (i = 1 ; i < options.width ; i += 1) { | ||
this.text(i === options.width - 1 && options.direction === 'up' ? '▷' : '─', styles); | ||
} | ||
this.nl(); | ||
for (i = 1 ; i < options.height - 1 ; i += 1) { | ||
this.sp(options.left || 0).text('│', styles).nl(); | ||
} | ||
this.sp(options.left || 0).text('└', styles); | ||
for (i = 1 ; i < options.width ; i += 1) { | ||
this.text(i === options.width - 1 && options.direction === 'down' ? '▷' : '─', styles); | ||
} | ||
}); | ||
var flattenBlocksInLines = require('magicpen/lib/flattenBlocksInLines'); | ||
expect.addStyle('merge', function (pens) { | ||
var flattenedPens = pens.map(function (pen) { | ||
return flattenBlocksInLines(pen.output); | ||
}).reverse(); | ||
var maxHeight = flattenedPens.reduce(function (maxHeight, pen) { | ||
return Math.max(maxHeight, pen.length); | ||
}, 0); | ||
var blockNumbers = new Array(flattenedPens.length); | ||
var blockOffsets = new Array(flattenedPens.length); | ||
// As long as there's at least one pen with a line left: | ||
for (var lineNumber = 0 ; lineNumber < maxHeight ; lineNumber += 1) { | ||
if (lineNumber > 0) { | ||
this.nl(); | ||
} | ||
var i; | ||
for (i = 0 ; i < blockNumbers.length ; i += 1) { | ||
blockNumbers[i] = 0; | ||
blockOffsets[i] = 0; | ||
} | ||
var contentLeft; | ||
do { | ||
contentLeft = false; | ||
var hasOutputChar = false; | ||
for (i = 0 ; i < flattenedPens.length ; i += 1) { | ||
var currentLine = flattenedPens[i][lineNumber]; | ||
if (currentLine) { | ||
while (currentLine[blockNumbers[i]] && blockOffsets[i] >= currentLine[blockNumbers[i]].args.content.length) { | ||
blockNumbers[i] += 1; | ||
blockOffsets[i] = 0; | ||
} | ||
var currentBlock = currentLine[blockNumbers[i]]; | ||
if (currentBlock) { | ||
contentLeft = true; | ||
if (!hasOutputChar) { | ||
var ch = currentBlock.args.content.charAt(blockOffsets[i]); | ||
if (ch !== ' ') { | ||
this.text(ch, currentBlock.args.styles); | ||
hasOutputChar = true; | ||
} | ||
} | ||
blockOffsets[i] += 1; | ||
} | ||
} | ||
} | ||
if (!hasOutputChar && contentLeft) { | ||
this.sp(); | ||
} | ||
} while (contentLeft); | ||
} | ||
}); | ||
expect.addStyle('arrowsAlongsideChangeOutputs', function (packing, changeOutputs) { | ||
if (packing) { | ||
var topByChangeNumber = {}; | ||
var top = 0; | ||
changeOutputs.forEach(function (changeOutput, index) { | ||
topByChangeNumber[index] = top; | ||
top += changeOutput.size().height; | ||
}); | ||
var that = this; | ||
var arrows = []; | ||
packing.forEach(function (columnSet, i, packing) { | ||
columnSet.forEach(function (entry) { | ||
arrows.push(that.clone().arrow({ | ||
left: i * 2, | ||
top: topByChangeNumber[entry.start], | ||
width: 1 + (packing.length - i) * 2, | ||
height: topByChangeNumber[entry.end] - topByChangeNumber[entry.start] + 1, | ||
direction: entry.direction | ||
})); | ||
}); | ||
}); | ||
if (arrows.length === 1) { | ||
this.block(arrows[0]); | ||
} else if (arrows.length > 1) { | ||
this.block(function () { | ||
this.merge(arrows); | ||
}); | ||
} | ||
} else { | ||
this.i(); | ||
} | ||
this.block(function () { | ||
changeOutputs.forEach(function (changeOutput, index) { | ||
this.nl(index > 0 ? 1 : 0); | ||
if (!changeOutput.isEmpty()) { | ||
this.sp(packing ? 1 : 0).append(changeOutput); | ||
} | ||
}, this); | ||
}); | ||
}); | ||
}; |
@@ -560,43 +560,50 @@ var utils = require('./utils'); | ||
}, -1); | ||
changes.forEach(function (diffItem, index) { | ||
var packing = utils.packArrows(changes); // NOTE: Will have side effects in changes if the packing results in too many arrow lanes | ||
output.arrowsAlongsideChangeOutputs(packing, changes.map(function (diffItem, index) { | ||
var delimiterOutput = type.delimiter(output.clone(), index, indexOfLastNonInsert + 1); | ||
output.nl(index > 0 ? 1 : 0).i().block(function () { | ||
var type = diffItem.type; | ||
if (type === 'insert') { | ||
this.annotationBlock(function () { | ||
this.error('missing ').block(function () { | ||
var index = typeof diffItem.actualIndex !== 'undefined' ? diffItem.actualIndex : diffItem.expectedIndex; | ||
this.property(index, inspect(diffItem.value), true); | ||
if (diffItem.type === 'moveTarget') { | ||
return output.clone(); | ||
} else { | ||
return output.clone().block(function () { | ||
if (diffItem.type === 'moveSource') { | ||
this.property(diffItem.actualIndex, inspect(diffItem.value), true) | ||
.amend(delimiterOutput.sp()).error('// should be moved'); | ||
} else if (diffItem.type === 'insert') { | ||
this.annotationBlock(function () { | ||
this.error('missing ').block(function () { | ||
var index = typeof diffItem.actualIndex !== 'undefined' ? diffItem.actualIndex : diffItem.expectedIndex; | ||
this.property(index, inspect(diffItem.value), true); | ||
}); | ||
}); | ||
}); | ||
} else if (type === 'remove') { | ||
this.block(function () { | ||
this.property(diffItem.actualIndex, inspect(diffItem.value), true) | ||
.amend(delimiterOutput.sp()).error('// should be removed'); | ||
}); | ||
} else if (type === 'equal') { | ||
this.block(function () { | ||
this.property(diffItem.actualIndex, inspect(diffItem.value), true) | ||
.amend(delimiterOutput); | ||
}); | ||
} else { | ||
this.block(function () { | ||
var valueDiff = diff(diffItem.value, diffItem.expected); | ||
this.property(diffItem.actualIndex, output.clone().block(function () { | ||
if (valueDiff && valueDiff.inline) { | ||
this.append(valueDiff.amend(delimiterOutput)); | ||
} else if (valueDiff) { | ||
this.append(inspect(diffItem.value).amend(delimiterOutput.sp())).annotationBlock(function () { | ||
this.shouldEqualError(diffItem.expected, inspect).nl(2).append(valueDiff); | ||
}); | ||
} else { | ||
this.append(inspect(diffItem.value).amend(delimiterOutput.sp())).annotationBlock(function () { | ||
this.shouldEqualError(diffItem.expected, inspect); | ||
}); | ||
} | ||
}), true); | ||
}); | ||
} | ||
}); | ||
}); | ||
} else if (diffItem.type === 'remove') { | ||
this.block(function () { | ||
this.property(diffItem.actualIndex, inspect(diffItem.value), true) | ||
.amend(delimiterOutput.sp()).error('// should be removed'); | ||
}); | ||
} else if (diffItem.type === 'equal') { | ||
this.block(function () { | ||
this.property(diffItem.actualIndex, inspect(diffItem.value), true) | ||
.amend(delimiterOutput); | ||
}); | ||
} else { | ||
this.block(function () { | ||
var valueDiff = diff(diffItem.value, diffItem.expected); | ||
this.property(diffItem.actualIndex, output.clone().block(function () { | ||
if (valueDiff && valueDiff.inline) { | ||
this.append(valueDiff.amend(delimiterOutput)); | ||
} else if (valueDiff) { | ||
this.append(inspect(diffItem.value).amend(delimiterOutput.sp())).annotationBlock(function () { | ||
this.shouldEqualError(diffItem.expected, inspect).nl(2).append(valueDiff); | ||
}); | ||
} else { | ||
this.append(inspect(diffItem.value).amend(delimiterOutput.sp())).annotationBlock(function () { | ||
this.shouldEqualError(diffItem.expected, inspect); | ||
}); | ||
} | ||
}), true); | ||
}); | ||
} | ||
}); | ||
} | ||
})); | ||
@@ -603,0 +610,0 @@ if (this.indent) { |
/* eslint-disable no-proto */ | ||
var canSetPrototype = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array); | ||
var greedyIntervalPacker = require('greedy-interval-packer'); | ||
@@ -150,3 +151,44 @@ var setPrototypeOf = Object.setPrototypeOf || function setPrototypeOf(obj, proto) { | ||
numericalRegExp: /^(?:0|[1-9][0-9]*)$/ | ||
numericalRegExp: /^(?:0|[1-9][0-9]*)$/, | ||
packArrows: function (changes) { | ||
var moveSourceAndTargetByActualIndex = {}; | ||
changes.forEach(function (diffItem, index) { | ||
if (diffItem.type === 'moveSource') { | ||
diffItem.changeIndex = index; | ||
(moveSourceAndTargetByActualIndex[diffItem.actualIndex] = moveSourceAndTargetByActualIndex[diffItem.actualIndex] || {}).source = diffItem; | ||
} else if (diffItem.type === 'moveTarget') { | ||
diffItem.changeIndex = index; | ||
(moveSourceAndTargetByActualIndex[diffItem.actualIndex] = moveSourceAndTargetByActualIndex[diffItem.actualIndex] || {}).target = diffItem; | ||
} | ||
}); | ||
var moveIndices = Object.keys(moveSourceAndTargetByActualIndex); | ||
if (moveIndices.length > 0) { | ||
var arrowSpecs = []; | ||
moveIndices.sort(function (a, b) { | ||
// Order by distance between change indices descending | ||
return Math.abs(moveSourceAndTargetByActualIndex[b].source.changeIndex - moveSourceAndTargetByActualIndex[b].target.changeIndex) - Math.abs(moveSourceAndTargetByActualIndex[a].source.changeIndex - moveSourceAndTargetByActualIndex[a].target.changeIndex); | ||
}).forEach(function (actualIndex, i, keys) { | ||
var moveSourceAndMoveTarget = moveSourceAndTargetByActualIndex[actualIndex]; | ||
var firstChangeIndex = Math.min(moveSourceAndMoveTarget.source.changeIndex, moveSourceAndMoveTarget.target.changeIndex); | ||
var lastChangeIndex = Math.max(moveSourceAndMoveTarget.source.changeIndex, moveSourceAndMoveTarget.target.changeIndex); | ||
arrowSpecs.push({ | ||
start: firstChangeIndex, | ||
end: lastChangeIndex, | ||
direction: moveSourceAndMoveTarget.source.changeIndex < moveSourceAndMoveTarget.target.changeIndex ? 'down' : 'up' | ||
}); | ||
}); | ||
var packing = greedyIntervalPacker(arrowSpecs); | ||
while (packing.length > 3) { | ||
// The arrow packing takes up too many lanes. Turn the moveSource/moveTarget items into inserts and removes | ||
packing.shift().forEach(function (entry) { | ||
changes[entry.direction === 'up' ? entry.start : entry.end].type = 'insert'; | ||
changes[entry.direction === 'up' ? entry.end : entry.start].type = 'remove'; | ||
}); | ||
} | ||
return packing; | ||
} | ||
} | ||
}; |
{ | ||
"name": "unexpected", | ||
"version": "10.17.2", | ||
"version": "10.18.0", | ||
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>", | ||
@@ -25,4 +25,4 @@ "keywords": [ | ||
"dependencies": { | ||
"array-changes": "1.3.1", | ||
"array-changes-async": "2.2.1", | ||
"array-changes": "2.0.0", | ||
"array-changes-async": "3.0.0", | ||
"detect-indent": "3.0.1", | ||
@@ -42,2 +42,3 @@ "diff": "1.1.0", | ||
"eslint-config-onelint": "1.0.2", | ||
"greedy-interval-packer": "1.2.0", | ||
"istanbul": "0.3.16", | ||
@@ -44,0 +45,0 @@ "jasmine": "2.2.1", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
761322
19059
22
1
+ Addedarray-changes@2.0.0(transitive)
+ Addedarray-changes-async@3.0.0(transitive)
- Removedarray-changes@1.3.1(transitive)
- Removedarray-changes-async@2.2.1(transitive)
Updatedarray-changes@2.0.0
Updatedarray-changes-async@3.0.0