mirror of
https://kevinblog.sytes.net/Code/Jibo-Revival-Group/RoboCommander.git
synced 2026-06-15 16:56:01 +00:00
Initial commit
This commit is contained in:
115
node_modules/power-assert-renderer-comparison/index.js
generated
vendored
Normal file
115
node_modules/power-assert-renderer-comparison/index.js
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
'use strict';
|
||||
|
||||
var BaseRenderer = require('power-assert-renderer-base');
|
||||
var inherits = require('util').inherits;
|
||||
var typeName = require('type-name');
|
||||
var keys = require('core-js/library/fn/object/keys');
|
||||
var forEach = require('core-js/library/fn/array/for-each');
|
||||
var udiff = require('./lib/udiff');
|
||||
var stringifier = require('stringifier');
|
||||
var assign = require('core-js/library/fn/object/assign');
|
||||
var defaultOptions = require('./lib/default-options');
|
||||
var literalPattern = /^(?:String|Numeric|Null|Boolean|RegExp)?Literal$/;
|
||||
|
||||
function isLiteral (node) {
|
||||
return literalPattern.test(node.type);
|
||||
}
|
||||
|
||||
/**
|
||||
* options.stringify [function]
|
||||
* options.maxDepth [number]
|
||||
* options.lineSeparator [string]
|
||||
* options.anonymous [string]
|
||||
* options.circular [string]
|
||||
*
|
||||
* options.diff [function]
|
||||
* options.lineDiffThreshold [number]
|
||||
*/
|
||||
function ComparisonRenderer (config) {
|
||||
BaseRenderer.call(this);
|
||||
this.config = assign({}, defaultOptions(), config);
|
||||
if (typeof this.config.stringify === 'function') {
|
||||
this.stringify = this.config.stringify;
|
||||
} else {
|
||||
this.stringify = stringifier(this.config);
|
||||
}
|
||||
if (typeof this.config.diff === 'function') {
|
||||
this.diff = this.config.diff;
|
||||
} else {
|
||||
this.diff = udiff(this.config);
|
||||
}
|
||||
this.espathToPair = {};
|
||||
}
|
||||
inherits(ComparisonRenderer, BaseRenderer);
|
||||
|
||||
ComparisonRenderer.prototype.onData = function (esNode) {
|
||||
var pair;
|
||||
if (!esNode.isCaptured) {
|
||||
if (isTargetBinaryExpression(esNode.parent) && isLiteral(esNode.node)) {
|
||||
this.espathToPair[esNode.parent.espath][esNode.key] = {code: esNode.code, value: esNode.value};
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (isTargetBinaryExpression(esNode.parent)) {
|
||||
this.espathToPair[esNode.parent.espath][esNode.key] = {code: esNode.code, value: esNode.value};
|
||||
}
|
||||
if (isTargetBinaryExpression(esNode)) {
|
||||
pair = {
|
||||
operator: esNode.node.operator,
|
||||
value: esNode.value
|
||||
};
|
||||
this.espathToPair[esNode.espath] = pair;
|
||||
}
|
||||
};
|
||||
|
||||
ComparisonRenderer.prototype.onEnd = function () {
|
||||
var _this = this;
|
||||
var pairs = [];
|
||||
forEach(keys(this.espathToPair), function (espath) {
|
||||
var pair = _this.espathToPair[espath];
|
||||
if (pair.left && pair.right) {
|
||||
pairs.push(pair);
|
||||
}
|
||||
});
|
||||
forEach(pairs, function (pair) {
|
||||
_this.compare(pair);
|
||||
});
|
||||
};
|
||||
|
||||
ComparisonRenderer.prototype.compare = function (pair) {
|
||||
if (isStringDiffTarget(pair)) {
|
||||
this.showStringDiff(pair);
|
||||
} else {
|
||||
this.showExpectedAndActual(pair);
|
||||
}
|
||||
};
|
||||
|
||||
ComparisonRenderer.prototype.showExpectedAndActual = function (pair) {
|
||||
this.write('');
|
||||
this.write('[' + typeName(pair.right.value) + '] ' + pair.right.code);
|
||||
this.write('=> ' + this.stringify(pair.right.value));
|
||||
this.write('[' + typeName(pair.left.value) + '] ' + pair.left.code);
|
||||
this.write('=> ' + this.stringify(pair.left.value));
|
||||
};
|
||||
|
||||
ComparisonRenderer.prototype.showStringDiff = function (pair) {
|
||||
this.write('');
|
||||
this.write('--- [string] ' + pair.right.code);
|
||||
this.write('+++ [string] ' + pair.left.code);
|
||||
this.write(this.diff(pair.right.value, pair.left.value, this.config));
|
||||
};
|
||||
|
||||
function isTargetBinaryExpression (esNode) {
|
||||
return esNode &&
|
||||
esNode.node.type === 'BinaryExpression' &&
|
||||
(esNode.node.operator === '===' || esNode.node.operator === '==') &&
|
||||
esNode.isCaptured &&
|
||||
!(esNode.value);
|
||||
}
|
||||
|
||||
function isStringDiffTarget(pair) {
|
||||
return typeof pair.left.value === 'string' && typeof pair.right.value === 'string';
|
||||
}
|
||||
|
||||
ComparisonRenderer.udiff = udiff;
|
||||
module.exports = ComparisonRenderer;
|
||||
13
node_modules/power-assert-renderer-comparison/lib/default-options.js
generated
vendored
Normal file
13
node_modules/power-assert-renderer-comparison/lib/default-options.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function defaultOptions () {
|
||||
return {
|
||||
lineDiffThreshold: 5,
|
||||
maxDepth: 2,
|
||||
indent: null,
|
||||
outputOffset: 2,
|
||||
anonymous: 'Object',
|
||||
circular: '#@Circular#',
|
||||
lineSeparator: '\n'
|
||||
};
|
||||
};
|
||||
38
node_modules/power-assert-renderer-comparison/lib/udiff.js
generated
vendored
Normal file
38
node_modules/power-assert-renderer-comparison/lib/udiff.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
var DiffMatchPatch = require('diff-match-patch');
|
||||
var dmp = new DiffMatchPatch();
|
||||
|
||||
function udiff (config) {
|
||||
return function diff (text1, text2) {
|
||||
var patch;
|
||||
if (config && shouldUseLineLevelDiff(text1, config)) {
|
||||
patch = udiffLines(text1, text2);
|
||||
} else {
|
||||
patch = udiffChars(text1, text2);
|
||||
}
|
||||
return decodeURIComponent(patch);
|
||||
};
|
||||
}
|
||||
|
||||
function shouldUseLineLevelDiff (text, config) {
|
||||
return config.lineDiffThreshold < text.split(/\r\n|\r|\n/).length;
|
||||
}
|
||||
|
||||
function udiffLines(text1, text2) {
|
||||
/*jshint camelcase: false */
|
||||
var a = dmp.diff_linesToChars_(text1, text2);
|
||||
var diffs = dmp.diff_main(a.chars1, a.chars2, false);
|
||||
dmp.diff_charsToLines_(diffs, a.lineArray);
|
||||
dmp.diff_cleanupSemantic(diffs);
|
||||
return dmp.patch_toText(dmp.patch_make(text1, diffs));
|
||||
}
|
||||
|
||||
function udiffChars (text1, text2) {
|
||||
/*jshint camelcase: false */
|
||||
var diffs = dmp.diff_main(text1, text2, false);
|
||||
dmp.diff_cleanupSemantic(diffs);
|
||||
return dmp.patch_toText(dmp.patch_make(text1, diffs));
|
||||
}
|
||||
|
||||
module.exports = udiff;
|
||||
33
node_modules/power-assert-renderer-comparison/package.json
generated
vendored
Normal file
33
node_modules/power-assert-renderer-comparison/package.json
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "power-assert-renderer-comparison",
|
||||
"description": "comparison renderer for power-assert context",
|
||||
"version": "1.2.0",
|
||||
"author": {
|
||||
"name": "Takuto Wada",
|
||||
"email": "takuto.wada@gmail.com",
|
||||
"url": "https://github.com/twada"
|
||||
},
|
||||
"dependencies": {
|
||||
"core-js": "^2.0.0",
|
||||
"diff-match-patch": "^1.0.0",
|
||||
"power-assert-renderer-base": "^1.1.1",
|
||||
"stringifier": "^1.3.0",
|
||||
"type-name": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^5.0.0",
|
||||
"power-assert-renderer-assertion": "^1.2.0"
|
||||
},
|
||||
"files": [
|
||||
"README.md",
|
||||
"index.js",
|
||||
"lib"
|
||||
],
|
||||
"homepage": "https://github.com/twada/power-assert-runtime",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twada/power-assert-runtime.git"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user