Permalink
Browse files

test: add tests for Parser.parseDelete/Select/Move/WithKeyword

This ensures the keywords are parsed properly even when mixed case is used.
  • Loading branch information...
vlsi committed Aug 7, 2016
1 parent ec5fb4f commit 3b7c7c48ceba3bd13c31f74c89f95ab506b94b6d
@@ -0,0 +1,106 @@
/*-------------------------------------------------------------------------
*
* Copyright (c) 2003-2016, PostgreSQL Global Development Group
*
*
*-------------------------------------------------------------------------
*/
package org.postgresql.core;
import junit.framework.TestCase;
import org.junit.Assert;
/**
* Test cases for the Parser.
* @author Jeremy Whiting jwhiting@redhat.com
*/
public class ParserTest extends TestCase {
/**
* Test to make sure delete command is detected by parser and detected via
* api. Mix up the case of the command to check detection continues to work.
*/
public void testDeleteCommandParsing() {
char[] command = new char[6];
"DELETE".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse upper case command.", Parser.parseDeleteKeyword(command, 0));
"DelEtE".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseDeleteKeyword(command, 0));
"deleteE".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseDeleteKeyword(command, 0));
"delete".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse lower case command.", Parser.parseDeleteKeyword(command, 0));
"Delete".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseDeleteKeyword(command, 0));
}
/**
* Test UPDATE command parsing.
*/
public void testUpdateCommandParsing() {
char[] command = new char[6];
"UPDATE".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse upper case command.", Parser.parseUpdateKeyword(command, 0));
"UpDateE".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseUpdateKeyword(command, 0));
"updatE".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseUpdateKeyword(command, 0));
"Update".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseUpdateKeyword(command, 0));
"update".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse lower case command.", Parser.parseUpdateKeyword(command, 0));
}
/**
* Test MOVE command parsing.
*/
public void testMoveCommandParsing() {
char[] command = new char[4];
"MOVE".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse upper case command.", Parser.parseMoveKeyword(command, 0));
"mOVe".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseMoveKeyword(command, 0));
"movE".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseMoveKeyword(command, 0));
"Move".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseMoveKeyword(command, 0));
"move".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse lower case command.", Parser.parseMoveKeyword(command, 0));
}
/**
* Test WITH command parsing.
*/
public void testWithCommandParsing() {
char[] command = new char[4];
"WITH".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse upper case command.", Parser.parseWithKeyword(command, 0));
"wITh".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseWithKeyword(command, 0));
"witH".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseWithKeyword(command, 0));
"With".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseWithKeyword(command, 0));
"with".getChars(0, 4, command, 0);
Assert.assertTrue("Failed to correctly parse lower case command.", Parser.parseWithKeyword(command, 0));
}
/**
* Test SELECT command parsing.
*/
public void testSelectCommandParsing() {
char[] command = new char[6];
"SELECT".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse upper case command.", Parser.parseSelectKeyword(command, 0));
"sELect".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseSelectKeyword(command, 0));
"selecT".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseSelectKeyword(command, 0));
"Select".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse mixed case command.", Parser.parseSelectKeyword(command, 0));
"select".getChars(0, 6, command, 0);
Assert.assertTrue("Failed to correctly parse lower case command.", Parser.parseSelectKeyword(command, 0));
}
}
@@ -8,6 +8,7 @@
package org.postgresql.test.jdbc2;
import org.postgresql.core.ParserTest;
import org.postgresql.core.v3.V3ParameterListTests;
import org.postgresql.jdbc.DeepBatchedInsertStatementTest;
import org.postgresql.test.CursorFetchBinaryTest;
@@ -68,6 +69,7 @@ public static TestSuite suite() throws Exception {
suite.addTest(new JUnit4TestAdapter(PGTimeTest.class));
suite.addTestSuite(PGTimestampTest.class);
suite.addTest(new JUnit4TestAdapter(TimezoneCachingTest.class));
suite.addTestSuite(ParserTest.class);
// PreparedStatement
suite.addTest(new JUnit4TestAdapter(PreparedStatementTest.class));

0 comments on commit 3b7c7c4

Please sign in to comment.