1+ 'use strict'
2+
3+ import assert from 'node:assert' ;
4+ import test from 'node:test' ;
5+ import { diff_match_patch , DIFF_DELETE , DIFF_INSERT , DIFF_EQUAL } from '../index.mjs' ;
6+
17/**
28 * Diff Match and Patch -- Test Harness
39 * Copyright 2018 The diff-match-patch Authors.
1824
1925
2026// If expected and actual are the equivalent, pass the test.
21- function assertEquivalent ( msg , expected , actual ) {
22- if ( typeof actual == 'undefined' ) {
23- // msg is optional.
24- actual = expected ;
25- expected = msg ;
26- msg = 'Expected: \'' + expected + '\' Actual: \'' + actual + '\'' ;
27- }
27+ function assertEquivalent ( expected , actual ) {
2828 if ( _equivalent ( expected , actual ) ) {
29- return assertEquals ( msg , String ( expected ) , String ( actual ) ) ;
29+ return assertEquals ( String ( expected ) , String ( actual ) ) ;
3030 } else {
31- return assertEquals ( msg , expected , actual ) ;
31+ return assertEquals ( expected , actual ) ;
3232 }
3333}
3434
@@ -556,7 +556,7 @@ function testDiffDelta() {
556556 }
557557
558558 for ( let i = 0 ; i < 1000 ; i ++ ) {
559- newText = applyRandomTextEdit ( originalText ) ;
559+ const newText = applyRandomTextEdit ( originalText ) ;
560560 dmp . diff_toDelta ( dmp . diff_main ( originalText , newText ) ) ;
561561 }
562562 } ) ( ) ;
@@ -1105,3 +1105,58 @@ function testPatchApply() {
11051105 results = dmp . patch_apply ( patches , 'x' ) ;
11061106 assertEquivalent ( [ 'x123' , [ true ] ] , results ) ;
11071107}
1108+
1109+
1110+ /**
1111+ * Ported from the assertion functions in google's HTML test suite for diff-match-patch
1112+ *
1113+ * In order to avoid changing the test code, at least at first, this replicates the browser environment and runs the exact same tests
1114+ */
1115+
1116+ function assertEquals ( expected , actual ) {
1117+ assert . equal ( actual , expected ) ;
1118+ }
1119+
1120+ function assertTrue ( actual ) {
1121+ assertEquals ( true , actual ) ;
1122+ }
1123+
1124+ function assertFalse ( actual ) {
1125+ assertEquals ( false , actual ) ;
1126+ }
1127+
1128+ const tests = [
1129+ 'testDiffIsDestructurable' ,
1130+ 'testDiffCommonPrefix' ,
1131+ 'testDiffCommonSuffix' ,
1132+ 'testDiffCommonOverlap' ,
1133+ 'testDiffHalfMatch' ,
1134+ 'testDiffLinesToChars' ,
1135+ 'testDiffCharsToLines' ,
1136+ 'testDiffCleanupMerge' ,
1137+ 'testDiffCleanupSemanticLossless' ,
1138+ 'testDiffCleanupSemantic' ,
1139+ 'testDiffCleanupEfficiency' ,
1140+ 'testDiffPrettyHtml' ,
1141+ 'testDiffText' ,
1142+ 'testDiffDelta' ,
1143+ 'testDiffXIndex' ,
1144+ 'testDiffLevenshtein' ,
1145+ 'testDiffBisect' ,
1146+ 'testDiffMain' ,
1147+ 'testMatchAlphabet' ,
1148+ 'testMatchBitap' ,
1149+ 'testMatchMain' ,
1150+ 'testPatchObj' ,
1151+ 'testPatchFromText' ,
1152+ 'testPatchToText' ,
1153+ 'testPatchAddContext' ,
1154+ 'testPatchMake' ,
1155+ 'testPatchSplitMax' ,
1156+ 'testPatchAddPadding' ,
1157+ 'testPatchApply'
1158+ ] ;
1159+
1160+ tests . forEach ( item => {
1161+ test ( item , eval ( item ) )
1162+ } ) ;
0 commit comments