forked from TallerWebSolutions/google-diff-match-patch-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff_match_patch_test.html
146 lines (128 loc) · 4.86 KB
/
diff_match_patch_test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!--
Test Harness for diff_match_patch.js and diff_match_patch_uncompressed.js
Copyright 2006 Google Inc.
http://code.google.com/p/google-diff-match-patch/
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<script type="text/javascript">
// Depending on the URL argument, test the compressed or uncompressed version.
var compressed = (document.location.search == '?compressed');
if (compressed) {
document.write('<TITLE>Test harness for diff_match_patch.js</TITLE>');
document.write('<scr'+'ipt type="text/javascript" src="diff_match_patch.js"></scr'+'ipt>');
} else {
document.write('<TITLE>Test harness for diff_match_patch_uncompressed.js</TITLE>');
document.write('<scr'+'ipt type="text/javascript" src="diff_match_patch_uncompressed.js"></scr'+'ipt>');
}
</script>
<script type="text/javascript" src="diff_match_patch_test.js"></script>
<script type="text/javascript">
// Counters for unit test results.
var test_good = 0;
var test_bad = 0;
// If expected and actual are the identical, print 'Ok', otherwise 'Fail!'
function assertEquals(msg, expected, actual) {
if (typeof actual == 'undefined') {
// msg is optional.
actual = expected;
expected = msg;
msg = 'Expected: \'' + expected + '\' Actual: \'' + actual + '\'';
}
if (expected === actual) {
document.write('<FONT COLOR="#009900">Ok</FONT><BR>');
test_good++;
} else {
document.write('<FONT COLOR="#990000"><BIG>Fail!</BIG></FONT><BR>');
msg = msg.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
document.write('<code>' + msg + '</code><BR>');
test_bad++;
}
}
function assertTrue(msg, actual) {
if (typeof actual == 'undefined') {
// msg is optional.
actual = msg;
assertEquals(true, actual);
} else {
assertEquals(msg, true, actual);
}
}
function assertFalse(msg, actual) {
if (typeof actual == 'undefined') {
// msg is optional.
actual = msg;
assertEquals(false, actual);
} else {
assertEquals(msg, false, actual);
}
}
function runTests() {
for (var x = 0; x < tests.length; x++) {
document.write('<H3>' + tests[x] + ':</H3>');
eval(tests[x] + '()');
}
}
var tests = [
'testDiffCommonPrefix',
'testDiffCommonSuffix',
'testDiffCommonOverlap',
'testDiffHalfMatch',
'testDiffLinesToChars',
'testDiffCharsToLines',
'testDiffCleanupMerge',
'testDiffCleanupSemanticLossless',
'testDiffCleanupSemantic',
'testDiffCleanupEfficiency',
'testDiffPrettyHtml',
'testDiffText',
'testDiffDelta',
'testDiffXIndex',
'testDiffLevenshtein',
'testDiffBisect',
'testDiffMain',
'testMatchAlphabet',
'testMatchBitap',
'testMatchMain',
'testPatchObj',
'testPatchFromText',
'testPatchToText',
'testPatchAddContext',
'testPatchMake',
'testPatchSplitMax',
'testPatchAddPadding',
'testPatchApply'];
</script>
</head>
<body>
<script type="text/javascript">
if (compressed) {
document.write('<H1>Test harness for diff_match_patch.js</H1>');
document.write('[ Switch to <A HREF="?uncompressed">Uncompressed</A>. ]');
} else {
document.write('<H1>Test harness for diff_match_patch_uncompressed.js</H1>');
document.write('[ Switch to <A HREF="?compressed">Compressed</A>. ]');
}
</script>
<P>If debugging errors, start with the first reported error,
subsequent tests often rely on earlier ones.</P>
<script type="text/javascript">
var startTime = (new Date()).getTime();
runTests();
var endTime = (new Date()).getTime();
document.write('<H3>Done.</H3>');
document.write('<P>Tests passed: ' + test_good + '<BR>Tests failed: ' + test_bad + '</P>');
document.write('<P>Total time: ' + (endTime - startTime) + ' ms</P>');
</script>
</body>
</html>