1 5 package org.h2.test.unit; 6 7 import org.h2.expression.CompareLike; 8 import org.h2.test.TestBase; 9 import org.h2.value.CompareMode; 10 11 14 public class TestPattern extends TestBase { 15 16 public void test() throws Exception { 17 CompareMode mode = new CompareMode(null, null); 18 CompareLike comp = new CompareLike(mode, null, null, null); 19 test(comp, "B", "%_"); 20 test(comp, "A", "A%"); 21 test(comp, "A", "A%%"); 22 23 for(int i=0; i<10; i++) { 24 String pattern=getRandomPattern(); 25 String value=getRandomValue(); 26 test(comp, value, pattern); 27 } 28 } 29 30 void test(CompareLike comp, String value, String pattern) throws Exception { 31 comp.test(pattern, value, 'X'); 36 37 } 41 42 static String getRandomValue() { 43 StringBuffer buff = new StringBuffer (); 44 int len = (int)(Math.random() * 10); 45 String s = "ABCDEFGHIJKLMNOP"; 46 for(int i=0; i<len; i++) { 47 buff.append(s.charAt((int)(Math.random()*s.length()))); 48 } 49 return buff.toString(); 50 } 51 52 static String getRandomPattern() { 53 StringBuffer buff = new StringBuffer (); 54 int len = (int)(Math.random() * 4); 55 String s = "AB_"; 57 for(int i=0; i<len; i++) { 58 buff.append(s.charAt((int)(Math.random()*s.length()))); 59 } 60 return buff.toString(); 61 } 62 63 91 } 92 | Popular Tags |