1 19 20 package org.netbeans.modules.diff.builtin.visualizer; 21 22 import java.io.*; 23 import junit.framework.*; 24 import java.awt.Component ; 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.io.Reader ; 28 import java.io.BufferedReader ; 29 import java.io.ByteArrayInputStream ; 30 import java.io.Serializable ; 31 import org.netbeans.modules.diff.builtin.provider.*; 32 import org.netbeans.modules.diff.builtin.provider.BuiltInDiffProvider; 33 import org.openide.windows.CloneableOpenSupport; 34 import org.openide.util.NbBundle; 35 import org.netbeans.api.diff.Difference; 36 import org.netbeans.spi.diff.DiffVisualizer; 37 import org.netbeans.modules.diff.builtin.DiffPresenter; 38 39 43 public class TextDiffVisualizerTest extends TestCase { 44 45 public TextDiffVisualizerTest(String testName) { 46 super(testName); 47 } 48 49 public static Test suite() { 50 TestSuite suite = new TestSuite(TextDiffVisualizerTest.class); 51 52 return suite; 53 } 54 55 public void testDifferenceToContextDiffText() throws Exception { 56 testDifferenceToContextDiffText("WordLibrar"); 57 testDifferenceToContextDiffText("start-add"); 58 testDifferenceToContextDiffText("start-ch"); 59 testDifferenceToContextDiffText("start-rm"); 60 testDifferenceToContextDiffText("end-add"); 61 testDifferenceToContextDiffText("end-ch"); 62 testDifferenceToContextDiffText("end-rm"); 63 } 64 65 public void testDifferenceToContextDiffText(String tcase) throws Exception { 66 System.out.println("differenceToContextDiffText(" + tcase + ")"); 67 68 Reader r1 = new InputStreamReader(getClass().getResourceAsStream("data/" + tcase + "0.txt"), "utf8"); 69 Reader r2 = new InputStreamReader(getClass().getResourceAsStream("data/" + tcase + "1.txt"), "utf8"); 70 Difference[] diffs = new BuiltInDiffProvider().computeDiff(r1, r2); 71 72 r1 = new InputStreamReader(getClass().getResourceAsStream("data/" + tcase + "0.txt"), "utf8"); 73 r2 = new InputStreamReader(getClass().getResourceAsStream("data/" + tcase + "1.txt"), "utf8"); 74 TextDiffVisualizer.TextDiffInfo diffInfo = new TextDiffVisualizer.TextDiffInfo("name1", "name2", "tit1", "tit2", r1, r2, diffs); 75 diffInfo.setContextMode(true, 3); 76 77 LineNumberReader expResult = new LineNumberReader(new InputStreamReader(getClass().getResourceAsStream("data/" + tcase + ".diff"), "utf8")); 78 InputStream result = TextDiffVisualizer.differenceToContextDiffText(diffInfo); 79 80 LineNumberReader actResult = new LineNumberReader(new InputStreamReader(result, "utf8")); 81 82 expResult.readLine(); 84 expResult.readLine(); 85 86 actResult.readLine(); 87 actResult.readLine(); 88 89 while (true) { 90 String expLine = expResult.readLine(); 91 String actLine = actResult.readLine(); 92 if (expLine == null && actLine == null) { 93 break; 94 } 95 System.out.println("" + actLine); 96 assertEquals(expLine, actLine); 97 } 98 } 99 100 } 101 | Popular Tags |