SQL Eval support like & not like

This commit is contained in:
wenshao
2013-01-26 00:31:20 +08:00
parent 5ee276d9bc
commit 9cd061eb5e
3 changed files with 258 additions and 99 deletions
@@ -0,0 +1,19 @@
package com.alibaba.druid.bvt.sql.eval;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
import com.alibaba.druid.util.JdbcConstants;
public class EvalLikeTest extends TestCase {
public void test_like() throws Exception {
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "'a' LIKE '[a-d]'"));
}
public void test_not_like() throws Exception {
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "'a' NOT LIKE '[a-d]'"));
}
}
@@ -0,0 +1,58 @@
package com.alibaba.druid.bvt.sql.eval;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
public class LikeTest extends TestCase {
public void test_any_0() throws Exception {
Assert.assertTrue(SQLEvalVisitorUtils.like("abcdefg", "%"));
}
public void test_any_1() throws Exception {
Assert.assertTrue(SQLEvalVisitorUtils.like("abcdefg", "%%"));
}
public void test_any_2() throws Exception {
Assert.assertTrue(SQLEvalVisitorUtils.like("abcdefg", "%b%"));
}
public void test_any_3() throws Exception {
Assert.assertTrue(SQLEvalVisitorUtils.like("abcdefg", "a%"));
}
public void test_any_4() throws Exception {
Assert.assertTrue(SQLEvalVisitorUtils.like("abcdefg", "%g"));
}
public void test_single_0() throws Exception {
Assert.assertTrue(SQLEvalVisitorUtils.like("a", "_"));
}
public void test_single_1() throws Exception {
Assert.assertTrue(SQLEvalVisitorUtils.like("ab", "__"));
}
public void test_single_2() throws Exception {
Assert.assertTrue(SQLEvalVisitorUtils.like("abcd", "a__d"));
}
public void test_single_3() throws Exception {
Assert.assertTrue(SQLEvalVisitorUtils.like("abcdf", "a__d_"));
}
public void test_range_0() throws Exception {
Assert.assertTrue(SQLEvalVisitorUtils.like("abcdf", "abcd[a-f]"));
}
public void test_range_1() throws Exception {
Assert.assertFalse(SQLEvalVisitorUtils.like("abcdf", "abcd[a-e]"));
}
public void test_range_2() throws Exception {
Assert.assertTrue(SQLEvalVisitorUtils.like("ab", "a[abf]"));
}
}