| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
<html> |
| 22 |
<head> |
| 23 |
<script type="text/javascript"> |
| 24 |
// Depending on the URL argument, test the compressed or uncompressed version. |
| 25 |
var compressed = (document.location.search == '?compressed'); |
| 26 |
if (compressed) { |
| 27 |
document.write('<TITLE>Test harness for diff_match_patch.js</TITLE>'); |
| 28 |
document.write('<scr'+'ipt type="text/javascript" src="diff_match_patch.js"></scr'+'ipt>'); |
| 29 |
} else { |
| 30 |
document.write('<TITLE>Test harness for diff_match_patch_uncompressed.js</TITLE>'); |
| 31 |
document.write('<scr'+'ipt type="text/javascript" src="diff_match_patch_uncompressed.js"></scr'+'ipt>'); |
| 32 |
} |
| 33 |
</script> |
| 34 |
|
| 35 |
<script type="text/javascript" src="diff_match_patch_test.js"></script> |
| 36 |
|
| 37 |
<script type="text/javascript"> |
| 38 |
// Counters for unit test results. |
| 39 |
var test_good = 0; |
| 40 |
var test_bad = 0; |
| 41 |
|
| 42 |
// If expected and actual are the identical, print 'Ok', otherwise 'Fail!' |
| 43 |
function assertEquals(msg, expected, actual) { |
| 44 |
if (typeof actual == 'undefined') { |
| 45 |
// msg is optional. |
| 46 |
actual = expected; |
| 47 |
expected = msg; |
| 48 |
msg = 'Expected: \'' + expected + '\' Actual: \'' + actual + '\''; |
| 49 |
} |
| 50 |
if (expected === actual) { |
| 51 |
document.write('<FONT COLOR="#009900">Ok</FONT><BR>'); |
| 52 |
test_good++; |
| 53 |
} else { |
| 54 |
document.write('<FONT COLOR="#990000"><BIG>Fail!</BIG></FONT><BR>'); |
| 55 |
msg = msg.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); |
| 56 |
document.write('<code>' + msg + '</code><BR>'); |
| 57 |
test_bad++; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
function assertTrue(msg, actual) { |
| 62 |
if (typeof actual == 'undefined') { |
| 63 |
// msg is optional. |
| 64 |
actual = msg; |
| 65 |
assertEquals(true, actual); |
| 66 |
} else { |
| 67 |
assertEquals(msg, true, actual); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
function assertFalse(msg, actual) { |
| 72 |
if (typeof actual == 'undefined') { |
| 73 |
// msg is optional. |
| 74 |
actual = msg; |
| 75 |
assertEquals(false, actual); |
| 76 |
} else { |
| 77 |
assertEquals(msg, false, actual); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
function runTests() { |
| 82 |
for (var x = 0; x < tests.length; x++) { |
| 83 |
document.write('<H3>' + tests[x] + ':</H3>'); |
| 84 |
eval(tests[x] + '()'); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
var tests = [ |
| 89 |
'testDiffCommonPrefix', |
| 90 |
'testDiffCommonSuffix', |
| 91 |
'testDiffCommonOverlap', |
| 92 |
'testDiffHalfMatch', |
| 93 |
'testDiffLinesToChars', |
| 94 |
'testDiffCharsToLines', |
| 95 |
'testDiffCleanupMerge', |
| 96 |
'testDiffCleanupSemanticLossless', |
| 97 |
'testDiffCleanupSemantic', |
| 98 |
'testDiffCleanupEfficiency', |
| 99 |
'testDiffPrettyHtml', |
| 100 |
'testDiffText', |
| 101 |
'testDiffDelta', |
| 102 |
'testDiffXIndex', |
| 103 |
'testDiffLevenshtein', |
| 104 |
'testDiffBisect', |
| 105 |
'testDiffMain', |
| 106 |
|
| 107 |
'testMatchAlphabet', |
| 108 |
'testMatchBitap', |
| 109 |
'testMatchMain', |
| 110 |
|
| 111 |
'testPatchObj', |
| 112 |
'testPatchFromText', |
| 113 |
'testPatchToText', |
| 114 |
'testPatchAddContext', |
| 115 |
'testPatchMake', |
| 116 |
'testPatchSplitMax', |
| 117 |
'testPatchAddPadding', |
| 118 |
'testPatchApply']; |
| 119 |
|
| 120 |
</script> |
| 121 |
</head> |
| 122 |
<body> |
| 123 |
|
| 124 |
<script type="text/javascript"> |
| 125 |
if (compressed) { |
| 126 |
document.write('<H1>Test harness for diff_match_patch.js</H1>'); |
| 127 |
document.write('[ Switch to <A HREF="?uncompressed">Uncompressed</A>. ]'); |
| 128 |
} else { |
| 129 |
document.write('<H1>Test harness for diff_match_patch_uncompressed.js</H1>'); |
| 130 |
document.write('[ Switch to <A HREF="?compressed">Compressed</A>. ]'); |
| 131 |
} |
| 132 |
</script> |
| 133 |
|
| 134 |
<P>If debugging errors, start with the first reported error, |
| 135 |
subsequent tests often rely on earlier ones.</P> |
| 136 |
|
| 137 |
<script type="text/javascript"> |
| 138 |
var startTime = (new Date()).getTime(); |
| 139 |
runTests(); |
| 140 |
var endTime = (new Date()).getTime(); |
| 141 |
document.write('<H3>Done.</H3>'); |
| 142 |
document.write('<P>Tests passed: ' + test_good + '<BR>Tests failed: ' + test_bad + '</P>'); |
| 143 |
document.write('<P>Total time: ' + (endTime - startTime) + ' ms</P>'); |
| 144 |
</script> |
| 145 |
</body> |
| 146 |
</html> |