1) {
+ var first = this.concat(arguments[0]);
+ return first.concat.apply(first, Array.prototype.slice.call(arguments, 1));
+ }
+
+ // Make sure input is a utf32_string
+ var other = arguments[0];
+ if (!other.codePoints) {
+ other = diff_match_patch.utf32_string.from(other);
+ }
+
+ var result = new diff_match_patch.utf32_string();
+ result.string = this.string + other.string;
+ result.codePoints = [].concat(this.codePoints, other.codePoints);
+ result.length = result.codePoints.length;
+ return result;
+};
+
+
+diff_match_patch.utf32_string.prototype.match = function() {
+ return this.string.match.apply(this.string, arguments);
+};
+
+
+diff_match_patch.utf32_string.prototype.replace = function() {
+ return diff_match_patch.utf32_string.from(this.string.replace.apply(this.string, arguments));
+};
+
+
+diff_match_patch.utf32_string.prototype.valueOf = function() {
+ throw new Error("warning: implicit conversion attempted on utf32_string; use toString instead");
+ return this.string;
+};
+
+
+diff_match_patch.utf32_string.prototype.toString = function() {
+ return this.string;
+};
+
+
// Export these global variables so that they survive Google's JS compiler.
// In a browser, 'this' will be 'window'.
// Users of node.js should 'require' the uncompressed version since Google's
diff --git a/javascript/tests/diff_match_patch_test.html b/javascript/tests/diff_match_patch_test.html
index 7a7003ca..03a01282 100644
--- a/javascript/tests/diff_match_patch_test.html
+++ b/javascript/tests/diff_match_patch_test.html
@@ -45,7 +45,7 @@
// msg is optional.
actual = expected;
expected = msg;
- msg = 'Expected: \'' + expected + '\' Actual: \'' + actual + '\'';
+ msg = 'Expected: \'' + (expected && expected.toString()) + '\' Actual: \'' + (actual && actual.toString()) + '\'';
}
if (expected === actual) {
document.write('Ok
');
@@ -78,9 +78,17 @@
}
}
- function runTests() {
+ function runTests(force_utf32_string) {
+ test_good = 0;
+ test_bad = 0;
+ diff_match_patch.force_utf32_string = force_utf32_string;
+ if (force_utf32_string) {
+ document.write('Forced UTF-32 Strings
');
+ } else {
+ document.write('Normal Strings
');
+ }
for (var x = 0; x < tests.length; x++) {
- document.write('' + tests[x] + ':
');
+ document.write('' + tests[x] + ' (' + (force_utf32_string ? 'utf32_string' : 'standard string') + '):
');
eval(tests[x] + '()');
}
}
@@ -115,7 +123,10 @@
'testPatchMake',
'testPatchSplitMax',
'testPatchAddPadding',
- 'testPatchApply'];
+ 'testPatchApply',
+
+ 'testUnicode',
+ ];
@@ -136,11 +147,17 @@
+
+ var startTime = (new Date()).getTime();
+ runTests(true);
+ var endTime = (new Date()).getTime();
+ document.write('Done with utf32_string test.
');
+ document.write('Tests passed: ' + test_good + '
Tests failed: ' + test_bad + '
');
+ document.write('Total time: ' + (endTime - startTime) + ' ms
');