Skip to content

Commit

Permalink
fix: remove escape sequence in case of noise values
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Shyngle <[email protected]>
  • Loading branch information
Sarthak160 committed Jul 17, 2024
1 parent b814c07 commit a963afd
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 911 deletions.
14 changes: 0 additions & 14 deletions lib/compute-lines.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,5 @@ export interface JsDiffChangeObject {
value?: string;
noised?: boolean;
}
/**
* [TODO]: Think about moving common left and right value assignment to a
* common place. Better readability?
*
* Computes line wise information based in the js diff information passed. Each
* line contains information about left and right section. Left side denotes
* deletion and right side denotes addition.
*
* @param oldString Old string to compare.
* @param newString New string to compare with old string.
* @param disableWordDiff Flag to enable/disable word diff.
* @param compareMethod JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
* @param linesOffset line number to start counting from
*/
declare const computeLineInformation: (oldString: string, newString: string, noise: string[], disableWordDiff?: boolean, compareMethod?: string | ((oldStr: string, newStr: string) => DiffChange[]), linesOffset?: number) => ComputedLineInformation;
export { computeLineInformation };
10 changes: 10 additions & 0 deletions lib/compute-lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ const constructLines = (value) => {
if (value === undefined) {
return [];
}
console.log(value, ":: value");
value = value.replace(/\n,/gi, "\n");
if (value.trim() === ",") {
value = "";
}
const lines = value.split('\n');
console.log(lines, ":: lines");
const isAllEmpty = lines.every((val) => !val);
if (isAllEmpty) {
// This is to avoid added an extra new line in the UI.
Expand Down Expand Up @@ -114,6 +116,8 @@ function noiseDiffArray(expectedObj, actualObj, key) {
const result = [];
const expectedLines = constructLines(JSON.stringify(expectedObj, null, 2));
const actualLines = constructLines(JSON.stringify(actualObj, null, 2));
console.log(expectedLines, ":: expectedLinse");
console.log(actualLines, ":: actualLines");
expectedLines.map((el, elIndex) => {
// to handle common length of both lines array.
if (elIndex < actualLines.length) {
Expand Down Expand Up @@ -150,6 +154,7 @@ function CompareJSON(expectedStr, actualStr, noise, flattenKeyPath) {
const result = [];
const expectedJSON = JSON.parse(expectedStr);
const actualJSON = JSON.parse(actualStr);
console.log(expectedJSON, ":: HAHHAH expectedJSON");
// expectedJSON and actualJSON are not of same data types
if (typeof expectedJSON !== typeof actualJSON) {
if (!noise.includes(flattenKeyPath)) {
Expand Down Expand Up @@ -454,7 +459,12 @@ function CompareJSON(expectedStr, actualStr, noise, flattenKeyPath) {
* @param compareMethod JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
* @param linesOffset line number to start counting from
*/
const sanitizeInput = (input) => {
return input.replace(/\\n/g, '\n').replace(/\\t/g, '\t').replace(/\\/g, '');
};
const computeLineInformation = (oldString, newString, noise, disableWordDiff = false, compareMethod = DiffMethod.CHARS, linesOffset = 0) => {
oldString = sanitizeInput(oldString);
newString = sanitizeInput(newString);
// let noiseTmp:string[] = []
// for(let i=0; i<noise.length ;i++){
// noiseTmp.push(noise[i])
Expand Down
Loading

0 comments on commit a963afd

Please sign in to comment.