Skip to content

Commit

Permalink
Use the "control pictures" unicode chars to represent bytes < 0x20 in…
Browse files Browse the repository at this point in the history
… hex dumps.
  • Loading branch information
papandreou committed Sep 18, 2014
1 parent 4f69e53 commit a698ca3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 19 additions & 2 deletions lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,16 +649,33 @@ module.exports = function (expect) {
for (var j = 0 ; j < result.diff.output[i].length ; j += 1) {
var obj = result.diff.output[i][j];
var replacement = '';
var leftover;
for (var k = 0 ; k < obj.args[0].length ; k += 1) {
var ch = obj.args[0].charAt(k);
if (ch === '│') {
isInAsciiChars = true;
} else if (isInAsciiChars) {
if (/[\x00-\x1f\x7f-\xff]/.test(ch)) {
if (/[\x00-\x1f]/.test(ch)) {
ch = String.fromCharCode(9216 + ch.charCodeAt(0));
leftover = obj.args[0].substr(k + 1);
if (replacement) {
obj.args[0] = replacement;
j += 1;
} else {
result.diff.output[i].splice(j, 1);
}
result.diff.output[i].splice(j, 0, {style: 'text', args: [ch, (obj.args[1] ? obj.args[1] + ', ' : '') + 'bold']});
replacement = '';
if (leftover.length > 0) {
result.diff.output[i].splice(j + 1, 0, {style: 'text', args: [leftover, obj.args[1]]});
}
obj = result.diff.output[i][j];
k = 1;
} else if (/[\x7f-\xff]/.test(ch)) {
ch = '.';
}
} else if (ch === ' ' && /\bbg/.test(obj.args[1])) {
var leftover = obj.args[0].substr(k + 1);
leftover = obj.args[0].substr(k + 1);
if (replacement) {
obj.args[0] = replacement;
j += 1;
Expand Down
6 changes: 3 additions & 3 deletions test/unexpected.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ describe('unexpected', function () {
'\n' +
'Diff:\n' +
'\n' +
' 00 01 02 48 65 72 65 20 69 73 20 74 68 65 20 74 │...Here is the t│\n' +
' 00 01 02 48 65 72 65 20 69 73 20 74 68 65 20 74 │␀␁␂Here is the t│\n' +
'-68 69 6E 67 20 49 20 77 61 73 20 74 61 6C 6B 69 │hing I was talki│\n' +
'+68 69 6E 67 20 49 20 77 61 73 20 71 75 75 78 69 │hing I was quuxi│\n' +
' 6E 67 20 61 62 6F 75 74 │ng about│');
Expand All @@ -527,7 +527,7 @@ describe('unexpected', function () {
'\n' +
'Diff:\n' +
'\n' +
' 00 01 02 48 65 72 65 20 69 73 20 74 68 65 20 74 │...Here is the t│\n' +
' 00 01 02 48 65 72 65 20 69 73 20 74 68 65 20 74 │␀␁␂Here is the t│\n' +
'-68 69 6E 67 20 49 20 77 61 73 20 74 61 6C 6B 69 │hing I was talki│\n' +
'+68 69 6E 67 20 49 20 77 61 73 20 71 75 75 78 69 │hing I was quuxi│\n' +
' 6E 67 20 61 62 6F 75 74 │ng about│');
Expand All @@ -554,7 +554,7 @@ describe('unexpected', function () {
'\n' +
'Diff:\n' +
'\n' +
' 00 01 02 48 65 72 65 20 69 73 20 74 68 65 20 74 │...Here is the t│\n' +
' 00 01 02 48 65 72 65 20 69 73 20 74 68 65 20 74 │␀␁␂Here is the t│\n' +
'-68 69 6E 67 20 49 20 77 61 73 20 74 61 6C 6B 69 │hing I was talki│\n' +
'+68 69 6E 67 20 49 20 77 61 73 20 71 75 75 78 69 │hing I was quuxi│\n' +
' 6E 67 20 61 62 6F 75 74 │ng about│');
Expand Down

0 comments on commit a698ca3

Please sign in to comment.