From 726e117656ef5f153adea486d16d21041fcc06b0 Mon Sep 17 00:00:00 2001 From: Gustavo Silva Date: Tue, 29 Oct 2019 23:12:24 +0000 Subject: [PATCH 1/2] diff.mjs: Allows showing subtraction Adds "Show Subtraction" button to allow seeing only the difference between two texts. When selected and combined, user can see only the characters or words that were added. If not combined, with either removed or added but selected, then nothing is displayed. --- src/core/operations/Diff.mjs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/operations/Diff.mjs b/src/core/operations/Diff.mjs index 7adea178..921369e8 100644 --- a/src/core/operations/Diff.mjs +++ b/src/core/operations/Diff.mjs @@ -47,6 +47,11 @@ class Diff extends Operation { "type": "boolean", "value": true }, + { + "name": "Show subtraction", + "type": "boolean", + "value": true + }, { "name": "Ignore whitespace", "type": "boolean", @@ -67,6 +72,7 @@ class Diff extends Operation { diffBy, showAdded, showRemoved, + showSubtraction, ignoreWhitespace ] = args, samples = input.split(sampleDelim); @@ -116,8 +122,8 @@ class Diff extends Operation { if (showAdded) output += "" + Utils.escapeHtml(diff[i].value) + ""; } else if (diff[i].removed) { if (showRemoved) output += "" + Utils.escapeHtml(diff[i].value) + ""; - } else { - output += Utils.escapeHtml(diff[i].value); + } else if (!showSubtraction) { + output += Utils.escapeHtml(diff[i].value) + ""; } } From 9108b3923b689cf035744d420e56cd1f1af7e87c Mon Sep 17 00:00:00 2001 From: Gustavo Silva Date: Tue, 29 Oct 2019 23:35:35 +0000 Subject: [PATCH 2/2] diff.mjs: Fixes tests and adds default flag * Sets default flag to `false` for `showSubtraction` flag. * Removes extra span for else case that was causing some tests to fail. Moreover, the previous behavior was defined as that. * Adds custom test for the showSubtraction option, both using the `showAdded` and `showRemoved` flags. --- src/core/operations/Diff.mjs | 4 ++-- tests/operations/tests/StrUtils.mjs | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/core/operations/Diff.mjs b/src/core/operations/Diff.mjs index 921369e8..84107245 100644 --- a/src/core/operations/Diff.mjs +++ b/src/core/operations/Diff.mjs @@ -50,7 +50,7 @@ class Diff extends Operation { { "name": "Show subtraction", "type": "boolean", - "value": true + "value": false }, { "name": "Ignore whitespace", @@ -123,7 +123,7 @@ class Diff extends Operation { } else if (diff[i].removed) { if (showRemoved) output += "" + Utils.escapeHtml(diff[i].value) + ""; } else if (!showSubtraction) { - output += Utils.escapeHtml(diff[i].value) + ""; + output += Utils.escapeHtml(diff[i].value); } } diff --git a/tests/operations/tests/StrUtils.mjs b/tests/operations/tests/StrUtils.mjs index 9098d2f1..c78b6b23 100644 --- a/tests/operations/tests/StrUtils.mjs +++ b/tests/operations/tests/StrUtils.mjs @@ -15,7 +15,29 @@ TestRegister.addTests([ recipeConfig: [ { "op": "Diff", - "args": ["\\n\\n", "Character", true, true, false] + "args": ["\\n\\n", "Character", true, true, false, false] + } + ], + }, + { + name: "Diff added with subtraction, basic usage", + input: "testing23\n\ntesting123", + expectedOutput: "1", + recipeConfig: [ + { + "op": "Diff", + "args": ["\\n\\n", "Character", true, true, true, false] + } + ], + }, + { + name: "Diff removed with subtraction, basic usage", + input: "testing123\n\ntesting3", + expectedOutput: "12", + recipeConfig: [ + { + "op": "Diff", + "args": ["\\n\\n", "Character", true, true, true, false] } ], },