Esempio n. 1
0
 @Test
 public void parseAeqBandXgrtY() {
   assertTrue(parser.hasHigherPrecedence("=", "AND"));
   assertFalse(parser.hasHigherPrecedence("=", ">"));
   List<String> list = parser.toPrefix("a = b AND x > y");
   assertEquals(Arrays.asList("a", "b", "=", "x", "y", ">", "AND"), list);
 }
Esempio n. 2
0
 @Test
 public void split5() {
   List<String> tokens = parser.split("a and b AND(((a>=c AND b> d) OR (x <> y )) ) OR t>u");
   assertEquals(
       Arrays.asList(
           "a", "and", "b", "AND", "(", "(", "(", "a", ">=", "c", "AND", "b", ">", "d", ")", "OR",
           "(", "x", "<>", "y", ")", ")", ")", "OR", "t", ">", "u"),
       tokens);
 }
Esempio n. 3
0
 @Test
 public void testTwoInnerParanthesis() {
   String s = "a and b AND ( ( ( a > c AND b > d ) OR ( x = y ) ) ) OR t > u";
   List<String> list = parser.toPrefix(s);
   assertEquals(
       Arrays.asList(
           "a", "b", "and", "a", "c", ">", "b", "d", ">", "AND", "x", "y", "=", "OR", "AND", "t",
           "u", ">", "OR"),
       list);
 }
Esempio n. 4
0
 @Test
 public void testComplexStatement() {
   String s =
       "age > 5 AND ( ( ( active = true ) AND ( age = 23 ) ) OR age > 40 ) AND ( salary > 10 ) OR age = 10";
   List<String> list = parser.toPrefix(s);
   assertEquals(
       Arrays.asList(
           "age", "5", ">", "active", "true", "=", "age", "23", "=", "AND", "age", "40", ">", "OR",
           "AND", "salary", "10", ">", "AND", "age", "10", "=", "OR"),
       list);
 }
Esempio n. 5
0
 @Test
 public void shouldNotThrowOnRandomInput() {
   Random random = new SecureRandom();
   StringBuilder stringBuilder = new StringBuilder();
   for (int i = 0; i < 1000; i++) {
     stringBuilder.setLength(0);
     for (int n = 0; n < 1000; n++) {
       stringBuilder.append((char) (random.nextInt() & 0xFFFF));
     }
     parser.toPrefix(stringBuilder.toString());
   }
 }
Esempio n. 6
0
 @Test
 public void testBetween() {
   String s = "b between 10 and 15";
   List<String> list = parser.toPrefix(s);
   assertEquals(Arrays.asList("b", "10", "15", "between"), list);
 }
Esempio n. 7
0
 @Test
 public void parseAeqBandOpenBsmlCorDgtEclose() {
   String s = "A = B AND ( B < C OR D > E )";
   List<String> list = parser.toPrefix(s);
   assertEquals(Arrays.asList("A", "B", "=", "B", "C", "<", "D", "E", ">", "OR", "AND"), list);
 }
Esempio n. 8
0
 @Test
 public void parseAEqB() {
   String s = "a = b";
   List<String> list = parser.toPrefix(s);
   assertEquals(Arrays.asList("a", "b", "="), list);
 }
Esempio n. 9
0
 @Test
 public void parseEmpty() {
   List<String> l = parser.toPrefix("");
   assertEquals(Arrays.asList(), l);
 }
Esempio n. 10
0
 @Test
 public void parserShouldThrowOnInvalidInput() {
   parser.toPrefix(")");
 }
Esempio n. 11
0
 @Test(expected = NullPointerException.class)
 public void parserShouldNotAcceptNull() {
   parser.toPrefix(null);
   fail();
 }
Esempio n. 12
0
 @Test
 public void split3() {
   List<String> tokens = parser.split("((a and b))");
   assertEquals(Arrays.asList("(", "(", "a", "and", "b", ")", ")"), tokens);
 }
Esempio n. 13
0
 @Test
 public void split1() {
   List<String> tokens = parser.split("a and b");
   assertEquals(Arrays.asList("a", "and", "b"), tokens);
 }
Esempio n. 14
0
 @Test
 public void testNotEqual() {
   String s = "b != 30";
   List<String> list = parser.toPrefix(s);
   assertEquals(Arrays.asList("b", "30", "!="), list);
 }
Esempio n. 15
0
 @Test
 public void testNot() {
   String s = "a and not(b) OR c not in ( 4, 5, 6 )";
   List<String> list = parser.toPrefix(s);
   assertEquals(Arrays.asList("a", "b", "not", "and", "c", "4,5,6", "in", "not", "OR"), list);
 }