KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > search > types > TextTypeTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.search.types;
21
22 import junit.framework.*;
23 import java.util.regex.Pattern JavaDoc;
24 import java.util.regex.PatternSyntaxException JavaDoc;
25 import java.util.regex.Matcher JavaDoc;
26 import org.openide.loaders.DataObject;
27 import org.openide.util.HelpCtx;
28
29 /**
30  *
31  * @author Marian Petras
32  */

33 public class TextTypeTest extends TestCase {
34     
35     public TextTypeTest(String JavaDoc testName) {
36         super(testName);
37     }
38
39     protected void setUp() throws Exception JavaDoc {
40     }
41
42     protected void tearDown() throws Exception JavaDoc {
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", //pattern
56
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", //pattern
70
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", //pattern
92
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", //pattern
110
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 JavaDoc 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