Skip to content

Add some more exhaustive tests of ignoreWhitespace based on @Mingun's work #488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions test/diff/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,41 @@ describe('diff/line', function() {
});

it('should ignore leading and trailing whitespace', function() {
const diffResult = diffTrimmedLines(
const diffResult1 = diffTrimmedLines(
'line\nvalue \nline',
'line \nvalue\nline');
expect(convertChangesToXML(diffResult)).to.equal('line \nvalue\nline');
'line\nvalue\nline');
expect(convertChangesToXML(diffResult1)).to.equal('line\nvalue\nline');

const diffResult2 = diffTrimmedLines(
'line\nvalue\nline',
'line\nvalue \nline');
expect(convertChangesToXML(diffResult2)).to.equal('line\nvalue \nline');

const diffResult3 = diffTrimmedLines(
'line\n value\nline',
'line\nvalue\nline');
expect(convertChangesToXML(diffResult3)).to.equal('line\nvalue\nline');

const diffResult4 = diffTrimmedLines(
'line\nvalue\nline',
'line\n value\nline');
expect(convertChangesToXML(diffResult4)).to.equal('line\n value\nline');
});

it('should keep leading and trailing whitespace in the output', function() {
function stringify(value) {
return JSON.stringify(value, null, 2);
}
const diffResult = diffTrimmedLines(
stringify([10, 20, 30]),
stringify({ data: [10, 42, 30] }));
expect(diffResult.filter(change => !change.removed).map(change => change.value).join('')).to.equal(`{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide not to use convertChangesToXML as was in original? It is simpler assert the whole result rather than part of it to make test less fragile, isn't it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make the full JSON text with all its indentation clearly visible & readable as plain text, so it's easy to confirm by eyeballing the test case that the indentation we're checking for is correct. But you're probably right that your way is better; I'll add it in as well.

"data": [
10,
42,
30
]
}`);
});

it('should not consider adding whitespace to an empty line an insertion', function() {
Expand Down