1 19 package org.netbeans.api.java.source.gen; 20 21 import org.netbeans.junit.NbTestCase; 22 import org.netbeans.junit.NbTestSuite; 23 import org.netbeans.modules.java.source.save.ListMatcher; 24 25 30 public class ListMatcherTest extends NbTestCase { 31 32 33 public ListMatcherTest(String testName) { 34 super(testName); 35 } 36 37 public static NbTestSuite suite() { 38 NbTestSuite suite = new NbTestSuite(); 39 suite.addTestSuite(ListMatcherTest.class); 40 return suite; 41 } 42 43 public void testAddToEmpty() { 44 String [] oldL = { }; 45 String [] newL = { "A", "B", "C" }; 46 String golden = 47 "{insert} A\n" + 48 "{insert} B\n" + 49 "{insert} C\n"; 50 ListMatcher matcher = ListMatcher.instance(oldL, newL); 51 if (matcher.match()) { 52 String result = matcher.printResult(false); 53 System.err.println("-------------"); 54 System.err.println("testAddToEmpty"); 55 System.err.println("-------------"); 56 System.err.println(result); 57 assertEquals(golden, result); 58 } else { 59 assertTrue("No match!", false); 60 } 61 } 62 63 public void testRemoveAll() { 64 String [] oldL= { "A", "B", "C" }; 65 String [] newL = { }; 66 String golden = 67 "{delete} A\n" + 68 "{delete} B\n" + 69 "{delete} C\n"; 70 ListMatcher matcher = ListMatcher.instance(oldL, newL); 71 if (matcher.match()) { 72 String result = matcher.printResult(false); 73 System.err.println("-------------"); 74 System.err.println("testRemoveAll"); 75 System.err.println("-------------"); 76 System.err.println(result); 77 assertEquals(golden, result); 78 } else { 79 assertTrue("No match!", false); 80 } 81 } 82 83 public void testAddToIndex0() { 84 String [] oldL= { "B" }; 85 String [] newL = { "A", "B" }; 86 String golden = 87 "{insert} A\n" + 88 "{nochange} B\n"; 89 ListMatcher matcher = ListMatcher.instance(oldL, newL); 90 if (matcher.match()) { 91 String result = matcher.printResult(false); 92 System.err.println("---------------"); 93 System.err.println("testAddToIndex0"); 94 System.err.println("---------------"); 95 System.err.println(result); 96 assertEquals(golden, result); 97 } else { 98 assertTrue("No match!", false); 99 } 100 } 101 102 public void testRemoveAtIndex0() { 103 String [] oldL = { "A", "B" }; 104 String [] newL = { "B" }; 105 String golden = 106 "{delete} A\n" + 107 "{nochange} B\n"; 108 ListMatcher matcher = ListMatcher.instance(oldL, newL); 109 if (matcher.match()) { 110 String result = matcher.printResult(false); 111 System.err.println("------------------"); 112 System.err.println("testRemoveAtIndex0"); 113 System.err.println("------------------"); 114 System.err.println(result); 115 assertEquals(golden, result); 116 } else { 117 assertTrue("No match!", false); 118 } 119 } 120 121 public void testComplex() { 122 String [] oldL = { "A", "B", "C", "D", "E", "F", "G" }; 123 String [] newL = { "B", "C", "C1", "D", "E", "G", "H" }; 124 String golden = 125 "{delete} A\n" + 126 "{nochange} B\n" + 127 "{nochange} C\n" + 128 "{insert} C1\n" + 129 "{nochange} D\n" + 130 "{nochange} E\n" + 131 "{delete} F\n" + 132 "{nochange} G\n" + 133 "{insert} H\n"; 134 ListMatcher matcher = ListMatcher.instance(oldL, newL); 135 if (matcher.match()) { 136 String result = matcher.printResult(false); 137 System.err.println("-----------"); 138 System.err.println("testComplex"); 139 System.err.println("-----------"); 140 System.err.println(result); 141 assertEquals(golden, result); 142 } else { 143 assertTrue("No match!", false); 144 } 145 } 146 } 147 | Popular Tags |