01: package org.drools.eclipse.editors.completion;
02:
03: import java.util.regex.Matcher;
04: import java.util.regex.Pattern;
05:
06: import junit.framework.TestCase;
07:
08: public class ContextScanningTest extends TestCase {
09:
10: public void testCheckAfterToken() {
11:
12: assertTrue(checkContains("when",
13: "rule something \nwhen \t blah"));
14: assertTrue(checkContains("when", "rule something when nothing"));
15: assertFalse(checkContains("when", "rule something whennothing"));
16: assertTrue(checkContains("when",
17: "rule something \twhen nothing"));
18: }
19:
20: private boolean checkContains(String keyword, String chunk) {
21: //Pattern p = Pattern.compile(".*(.)" + keyword + "(.).*", Pattern.DOTALL);
22: Pattern p = Pattern.compile(".*rule.*\\W" + keyword + "\\W.*",
23: Pattern.DOTALL);
24: Matcher matcher = p.matcher(chunk);
25:
26: return matcher.matches();
27: }
28:
29: }
|