Skip to content
Prev Previous commit
Next Next commit
Add test of case with identical texts
  • Loading branch information
ExplodingCabbage committed Jan 8, 2024
commit ae2911d76b015241c9119b51c1930fdfb49e6ab9
11 changes: 10 additions & 1 deletion test/diff/character.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@ describe('diff/character', function() {
});

describe('oneChangePerToken option', function() {
it('emits one change per token', function() {
it('emits one change per character', function() {
const diffResult = diffChars('Old Value.', 'New ValueMoreData.', {oneChangePerToken: true});
expect(diffResult.length).to.equal(21);
expect(convertChangesToXML(diffResult)).to.equal('<del>O</del><del>l</del><del>d</del><ins>N</ins><ins>e</ins><ins>w</ins> Value<ins>M</ins><ins>o</ins><ins>r</ins><ins>e</ins><ins>D</ins><ins>a</ins><ins>t</ins><ins>a</ins>.');
});

it('correctly handles the case where the texts are identical', function() {
const diffResult = diffChars('foo bar baz qux', 'foo bar baz qux', {oneChangePerToken: true});
expect(diffResult).to.deep.equal(
['f', 'o', 'o', ' ', 'b', 'a', 'r', ' ', 'b', 'a', 'z', ' ', 'q', 'u', 'x'].map(
char => ({value: char, count: 1, added: false, removed: false})
)
);
});
});

describe('case insensitivity', function() {
Expand Down