mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-26 03:01:42 +00:00
Initial Commit
This commit is contained in:
@@ -74,6 +74,32 @@ exports.join = makeStringReducingOperator(
|
|||||||
},null
|
},null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var dmp = require("$:/core/modules/utils/diff-match-patch/diff_match_patch.js");
|
||||||
|
|
||||||
|
exports.levenshtein = makeStringBinaryOperator(
|
||||||
|
function(a,b) {
|
||||||
|
var dmpObject = new dmp.diff_match_patch(),
|
||||||
|
diffs = dmpObject.diff_main(a,b);
|
||||||
|
return [dmpObject.diff_levenshtein(diffs) + ""];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
exports.makepatches = makeStringBinaryOperator(
|
||||||
|
function(a,b) {
|
||||||
|
var dmpObject = new dmp.diff_match_patch(),
|
||||||
|
patches = dmpObject.patch_make(a,b);
|
||||||
|
return [dmpObject.patch_toText(patches)];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
exports.applypatches = makeStringBinaryOperator(
|
||||||
|
function(a,b) {
|
||||||
|
var dmpObject = new dmp.diff_match_patch(),
|
||||||
|
patches = dmpObject.patch_fromText(b);
|
||||||
|
return [dmpObject.patch_apply(patches,a)[0]];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
function makeStringBinaryOperator(fnCalc) {
|
function makeStringBinaryOperator(fnCalc) {
|
||||||
return function(source,operator,options) {
|
return function(source,operator,options) {
|
||||||
var result = [];
|
var result = [];
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
title: Filters/DiffMergePatch1
|
||||||
|
description: Tests for diff-merge-patch derived operators
|
||||||
|
type: text/vnd.tiddlywiki-multiple
|
||||||
|
tags: [[$:/tags/wiki-test-spec]]
|
||||||
|
|
||||||
|
title: Output
|
||||||
|
|
||||||
|
\whitespace trim
|
||||||
|
\define text1()
|
||||||
|
the cat sat on the mat
|
||||||
|
\end
|
||||||
|
|
||||||
|
\define text2()
|
||||||
|
the hat saw in every category
|
||||||
|
\end
|
||||||
|
|
||||||
|
<$text text={{{ [<text1>makepatches<text2>] }}}/>
|
||||||
|
+
|
||||||
|
title: ExpectedResult
|
||||||
|
|
||||||
|
<p>@@ -1,22 +1,29 @@
|
||||||
|
the
|
||||||
|
-c
|
||||||
|
+h
|
||||||
|
at sa
|
||||||
|
-t on the mat
|
||||||
|
+w in every category
|
||||||
|
</p>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
title: Filters/DiffMergePatch2
|
||||||
|
description: Tests for diff-merge-patch derived operators
|
||||||
|
type: text/vnd.tiddlywiki-multiple
|
||||||
|
tags: [[$:/tags/wiki-test-spec]]
|
||||||
|
|
||||||
|
title: Output
|
||||||
|
|
||||||
|
\whitespace trim
|
||||||
|
\define text1()
|
||||||
|
the cat sat on the mat
|
||||||
|
\end
|
||||||
|
|
||||||
|
\define text2()
|
||||||
|
the hat saw in every category
|
||||||
|
\end
|
||||||
|
|
||||||
|
<$let patches={{{ [<text1>makepatches<text2>] }}}>
|
||||||
|
|
||||||
|
<$text text={{{ [<text1>applypatches<patches>] }}}/>
|
||||||
|
|
||||||
|
</$let>
|
||||||
|
+
|
||||||
|
title: ExpectedResult
|
||||||
|
|
||||||
|
the hat saw in every category
|
||||||
@@ -1071,6 +1071,20 @@ Tests the filtering mechanism.
|
|||||||
expect(wiki.filterTiddlers("[charcode[9],[10]]").join(" ")).toBe(String.fromCharCode(9) + String.fromCharCode(10));
|
expect(wiki.filterTiddlers("[charcode[9],[10]]").join(" ")).toBe(String.fromCharCode(9) + String.fromCharCode(10));
|
||||||
expect(wiki.filterTiddlers("[charcode[]]").join(" ")).toBe("");
|
expect(wiki.filterTiddlers("[charcode[]]").join(" ")).toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should handle the levenshtein operator", function() {
|
||||||
|
expect(wiki.filterTiddlers("[[apple]levenshtein[apple]]").join(" ")).toBe("0");
|
||||||
|
expect(wiki.filterTiddlers("[[apple]levenshtein[banana]]").join(" ")).toBe("9");
|
||||||
|
expect(wiki.filterTiddlers("[[representation]levenshtein[misreprehensionisation]]").join(" ")).toBe("10");
|
||||||
|
expect(wiki.filterTiddlers("[[the cat sat on the mat]levenshtein[the hat saw in every category]]").join(" ")).toBe("13");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle the makepatches operator", function() {
|
||||||
|
expect(wiki.filterTiddlers("[[apple]makepatches[apple]]").join(" ")).toBe("");
|
||||||
|
expect(wiki.filterTiddlers("[[apple]makepatches[banana]]").join(" ")).toBe("@@ -1,5 +1,6 @@\n-apple\n+banana\n");
|
||||||
|
expect(wiki.filterTiddlers("[[representation]makepatches[misreprehensionisation]]").join(" ")).toBe("@@ -1,13 +1,21 @@\n+mis\n repre\n-sent\n+hensionis\n atio\n");
|
||||||
|
expect(wiki.filterTiddlers("[[the cat sat on the mat]makepatches[the hat saw in every category]]").join(" ")).toBe("@@ -1,22 +1,29 @@\n the \n-c\n+h\n at sa\n-t on the mat\n+w in every category\n");
|
||||||
|
});
|
||||||
|
|
||||||
it("should parse filter variable parameters", function(){
|
it("should parse filter variable parameters", function(){
|
||||||
expect($tw.utils.parseFilterVariable("currentTiddler")).toEqual(
|
expect($tw.utils.parseFilterVariable("currentTiddler")).toEqual(
|
||||||
|
|||||||
Reference in New Issue
Block a user