assertvanish
Version:
assert that an object will vanish
31 lines (30 loc) • 764 B
JavaScript
(function() {
var extractWayFromTree, getIndentation, getParentLine;
extractWayFromTree = function(tree, line) {
var lines, way;
lines = tree.split('\n');
way = [];
while (line != null) {
way.unshift(lines[line]);
line = getParentLine(lines, line);
}
return way.join('\n');
};
getIndentation = function(line) {
return line.match(/^ */)[0].length;
};
getParentLine = function(lines, line) {
var childIndentation;
childIndentation = getIndentation(lines[line]);
while (line > 0) {
line--;
if (childIndentation - 2 === getIndentation(lines[line])) {
return line;
}
}
return null;
};
module.exports = {
extractWayFromTree: extractWayFromTree
};
}).call(this);