forked from cemerick/jsdifflib
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Spencer Thang
committed
Sep 11, 2015
1 parent
fe3b415
commit 9d99aa5
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "jsdifflib", | ||
"version": "1.0.0", | ||
"description": "A javascript library to diff two files.", | ||
"main": "difflib.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "^2.3.2", | ||
"jsdom": "^3.1.2", | ||
"chai": "^3.2.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/red-gate/jsdifflib.git" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/red-gate/jsdifflib/issues" | ||
}, | ||
"homepage": "https://github.com/red-gate/jsdifflib#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var expect = require("chai").expect; | ||
var diffview = require("../diffview.js"); | ||
var difflib = require("../difflib.js"); | ||
var jsdom = require("jsdom").jsdom; | ||
var document = jsdom("<html></html>"); | ||
global.document = document; | ||
|
||
describe("diffview", function() { | ||
describe(".buildView()", function() { | ||
it("can build view with a difference", function () { | ||
var view = testBuildView('a', 'b'); | ||
expect(view.differences).to.equal(1); | ||
expect(view.diffOutput.outerHTML).to.contain('diffview_difference_1'); | ||
expect(view.diffOutput.outerHTML).not.to.contain('diffview_difference_2'); | ||
}); | ||
|
||
it("can build view with no differences", function () { | ||
var view = testBuildView('a', 'a'); | ||
expect(view.differences).to.equal(0); | ||
expect(view.diffOutput.outerHTML).not.to.contain('diffview_difference_1'); | ||
}); | ||
|
||
it("can build view with multi-line difference blocks", function () { | ||
var source = '<ruleEntry>' + | ||
'\r\n<assignedTo>spencerthang@gmail.com</assignedTo>' + | ||
'\r\n<criteriaItems>' + | ||
'\r\n <field>Lead.Country</field>' + | ||
'\r\n <value>US,USA,United States,United States of America</value>' + | ||
'\r\n</criteriaItems>'; | ||
|
||
var target = '<ruleEntry>' + | ||
'\r\n<assignedTo>spencerthang@red-gate.com</assignedTo>' + | ||
'\r\n<criteriaItems>' + | ||
'\r\n <field>Lead.City</field>' + | ||
'\r\n <value>SG,Singapore</value>' + | ||
'\r\n</criteriaItems>'; | ||
|
||
var view = testBuildView(source, target); | ||
expect(view.differences).to.equal(2); | ||
expect(view.diffOutput.outerHTML).to.contain('diffview_difference_1'); | ||
expect(view.diffOutput.outerHTML).to.contain('diffview_difference_2'); | ||
expect(view.diffOutput.outerHTML).not.to.contain('diffview_difference_3'); | ||
}); | ||
}); | ||
}); | ||
|
||
var testBuildView = function(sourceText, targetText) { | ||
var source = difflib.stringAsLines(sourceText); | ||
var target = difflib.stringAsLines(targetText); | ||
var sm = new difflib.SequenceMatcher(source, target); | ||
var opcodes = sm.get_opcodes(); | ||
|
||
var diffResult = diffview.buildView({ | ||
baseTextLines: source, | ||
newTextLines: target, | ||
opcodes: opcodes, | ||
baseTextName: 'Source', | ||
newTextName: 'Target', | ||
viewType: 0 | ||
}); | ||
|
||
return diffResult; | ||
} |