1 19 20 package org.netbeans.modules.search.types; 21 22 import junit.framework.*; 23 import java.util.regex.Pattern ; 24 import java.util.regex.PatternSyntaxException ; 25 import java.util.regex.Matcher ; 26 import org.openide.loaders.DataObject; 27 import org.openide.util.HelpCtx; 28 29 33 public class TextTypeTest extends TestCase { 34 35 public TextTypeTest(String testName) { 36 super(testName); 37 } 38 39 protected void setUp() throws Exception { 40 } 41 42 protected void tearDown() throws Exception { 43 } 44 45 public void testMatch() { 46 System.out.println("match"); 47 48 final boolean caseSensitive = true; 49 final boolean caseInsensitive = false; 50 final boolean wholeWords = true; 51 final boolean partialWords = false; 52 53 TextType instance; 54 55 instance = new SubstringTextType("dan", caseSensitive, 57 partialWords); 58 59 assertEquals(true, instance.match("dan")); 60 assertEquals(true, instance.match("danda")); 61 assertEquals(true, instance.match("dadan")); 62 assertEquals(true, instance.match("dandan")); 63 assertEquals(true, instance.match("dan dan")); 64 assertEquals(false, instance.match("")); 65 assertEquals(false, instance.match("da")); 66 assertEquals(false, instance.match("Dan")); 67 68 69 instance = new SubstringTextType("dan", caseSensitive, 71 wholeWords); 72 73 assertEquals(true, instance.match("dan")); 74 assertEquals(true, instance.match("dan dan")); 75 assertEquals(true, instance.match("dan dan dane")); 76 assertEquals(true, instance.match("dane dan dan")); 77 assertEquals(true, instance.match("velkedane dan dan")); 78 assertEquals(true, instance.match("dan dan velkedane")); 79 assertEquals(true, instance.match("velkadan dan dan")); 80 assertEquals(true, instance.match("dan dan velkadan")); 81 assertEquals(true, instance.match("velkadan dan danone")); 82 assertEquals(false, instance.match("")); 83 assertEquals(false, instance.match("da")); 84 assertEquals(false, instance.match("dane")); 85 assertEquals(false, instance.match("dadan")); 86 assertEquals(false, instance.match("dane dadan")); 87 assertEquals(false, instance.match("dadane")); 88 assertEquals(false, instance.match("Dan")); 89 90 91 instance = new SubstringTextType("dan", caseInsensitive, 93 partialWords); 94 95 assertEquals(true, instance.match("dan")); 96 assertEquals(true, instance.match("danda")); 97 assertEquals(true, instance.match("dadan")); 98 assertEquals(true, instance.match("dandan")); 99 assertEquals(true, instance.match("dan dan")); 100 assertEquals(true, instance.match("daN")); 101 assertEquals(true, instance.match("danDa")); 102 assertEquals(true, instance.match("DADAN")); 103 assertEquals(true, instance.match("dAnDaN")); 104 assertEquals(true, instance.match("DAN DAN")); 105 assertEquals(false, instance.match("")); 106 assertEquals(false, instance.match("da")); 107 108 109 instance = new SubstringTextType("dan", caseInsensitive, 111 wholeWords); 112 113 assertEquals(true, instance.match("dan")); 114 assertEquals(true, instance.match("dan dan")); 115 assertEquals(true, instance.match("dan dan dane")); 116 assertEquals(true, instance.match("dane dan dan")); 117 assertEquals(true, instance.match("velkedane dan dan")); 118 assertEquals(true, instance.match("dan dan velkedane")); 119 assertEquals(true, instance.match("velkadan dan dan")); 120 assertEquals(true, instance.match("dan dan velkadan")); 121 assertEquals(true, instance.match("velkadan dan danone")); 122 assertEquals(true, instance.match("Dan")); 123 assertEquals(true, instance.match("daN")); 124 assertEquals(true, instance.match("DAN")); 125 assertEquals(true, instance.match("dan DAN")); 126 assertEquals(true, instance.match("DAN dan")); 127 assertEquals(true, instance.match("dan dan daNE")); 128 assertEquals(true, instance.match("DaNe dAn Dan")); 129 assertEquals(true, instance.match("velkEDAne dan dan")); 130 assertEquals(true, instance.match("dan dan velKEDane")); 131 assertEquals(true, instance.match("velkADAn dAN dan")); 132 assertEquals(true, instance.match("dan dAn vELKAdan")); 133 assertEquals(true, instance.match("velkadan dan danone")); 134 assertEquals(false, instance.match("")); 135 assertEquals(false, instance.match("da")); 136 assertEquals(false, instance.match("Da")); 137 assertEquals(false, instance.match("dA")); 138 assertEquals(false, instance.match("DA")); 139 assertEquals(false, instance.match("dane")); 140 assertEquals(false, instance.match("dAnE")); 141 assertEquals(false, instance.match("dadan")); 142 assertEquals(false, instance.match("daDAn")); 143 assertEquals(false, instance.match("DADAN")); 144 assertEquals(false, instance.match("dane dadan")); 145 assertEquals(false, instance.match("DANe dadan")); 146 assertEquals(false, instance.match("dadane")); 147 assertEquals(false, instance.match("daDANE")); 148 } 149 150 151 class SubstringTextType extends TextType { 152 SubstringTextType(String matchString, boolean caseSens, boolean wholeWords) { 153 super(); 154 setMatchString(matchString); 155 setWholeWords(wholeWords); 156 setCaseSensitive(caseSens); 157 } 158 protected boolean testDataObject(DataObject dataObject) { 159 return false; 160 } 161 public HelpCtx getHelpCtx() { 162 return HelpCtx.DEFAULT_HELP; 163 } 164 } 165 166 } 167 | Popular Tags |