Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit a95de94

Browse files
feat: removes diff from TextDiff validator
1 parent 48251fd commit a95de94

File tree

3 files changed

+18
-55
lines changed

3 files changed

+18
-55
lines changed

lib/validators/text-diff.js

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const DiffMatchPatch = require('googlediff');
1+
// const DiffMatchPatch = require('googlediff');
22
const errors = require('../errors');
33

4-
const sanitizeSurrogatePairs = (data) => {
5-
return data.replace(/[\uD800-\uDBFF]/g, '').replace(/[\uDC00-\uDFFF]/g, '');
6-
};
4+
// const sanitizeSurrogatePairs = (data) => {
5+
// return data.replace(/[\uD800-\uDBFF]/g, '').replace(/[\uDC00-\uDFFF]/g, '');
6+
// };
77

88
class TextDiff {
99
constructor(expected, actual) {
@@ -28,40 +28,21 @@ class TextDiff {
2828
}
2929

3030
validate() {
31-
this.output = null;
32-
const dmp = new DiffMatchPatch();
33-
34-
try {
35-
const patch = dmp.patch_make(this.actual, this.expected);
36-
this.output = dmp.patch_toText(patch);
37-
return this.output;
38-
} catch (error) {
39-
if (error instanceof URIError) {
40-
const patch = dmp.patch_make(
41-
sanitizeSurrogatePairs(this.actual),
42-
sanitizeSurrogatePairs(this.expected)
43-
);
44-
this.output = dmp.patch_toText(patch);
45-
return this.output;
46-
}
47-
48-
throw error;
49-
}
31+
this.valid = this.actual === this.expected;
5032
}
5133

52-
evaluateOutputToResults(data) {
53-
if (!data) {
54-
data = this.output;
55-
}
56-
57-
if (!data) {
34+
evaluateOutputToResults() {
35+
if (this.valid) {
5836
return [];
5937
}
6038

6139
return [
6240
{
63-
// TODO Improve the message to contain real and expected data
64-
message: 'Real and expected data does not match.'
41+
message: 'Actual and expected data do not match.',
42+
values: {
43+
expected: this.expected,
44+
actual: this.actual
45+
}
6546
}
6647
];
6748
}

test/unit/units/validateBody.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ describe('validateBody', () => {
240240
it('with explanatory message', () => {
241241
expect(result)
242242
.to.have.errorAtIndex(0)
243-
.withMessage('Real and expected data does not match.');
243+
.withMessage('Actual and expected data do not match.');
244244
});
245245
});
246246
});

test/unit/validators/text-diff-test.js

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,10 @@ describe('TextDiff', () => {
8888
});
8989

9090
it('should set output property', () => {
91-
assert.isDefined(validator.output);
91+
assert.isDefined(validator.valid);
9292

93-
it('output should be a string', () => {
94-
assert.isString(validator.output);
95-
});
96-
97-
it('output should be empty string', () => {
98-
assert.equal(validator.output, '');
93+
it('output should be marked as valid', () => {
94+
assert.isTrue(validator.vaild);
9995
});
10096
});
10197
});
@@ -108,22 +104,8 @@ describe('TextDiff', () => {
108104
validationResult = validator.validate();
109105
});
110106

111-
it('output property should be a string', () => {
112-
assert.isString(validator.output);
113-
});
114-
115-
it('output property should not be empty string', () => {
116-
assert.notEqual(validator.output, '');
117-
});
118-
119-
it('output property should contain + and -', () => {
120-
assert.include(validator.output, '-');
121-
assert.include(validator.output, '+');
122-
});
123-
124-
it('output property should be persed by googlediff to an array', () => {
125-
dmp = new DiffMatchPatch();
126-
assert.isArray(dmp.patch_fromText(validator.output));
107+
it('output property should not be marked as valid', () => {
108+
assert.isNotTrue(validator.valid);
127109
});
128110
});
129111
});

0 commit comments

Comments
 (0)