db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r595662 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Date Fri, 16 Nov 2007 13:51:57 GMT
Author: dag
Date: Fri Nov 16 05:51:56 2007
New Revision: 595662

URL: http://svn.apache.org/viewvc?rev=595662&view=rev
Log:
DERBY-1749 Implement Bracketed SQL comments (/*...*/ comments)

Patch Derby-1749-4.diff implements SQL feature T352 and adds a test.
Thanks to James F. Adams for help with the change and for providing
the test. I added some extra test cases.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=595662&r1=595661&r2=595662&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Fri Nov
16 05:51:56 2007
@@ -1696,6 +1696,8 @@
 		t.beginOffset = input_stream.getBeginOffset();
 		t.endOffset = input_stream.getEndOffset();
 	}
+	
+	int commentNestingDepth = 0;
 }
 
 SKIP :
@@ -1708,7 +1710,24 @@
 
 SKIP :
 {	/* comments */
-	"--" : IN_COMMENT
+	  "--" : IN_COMMENT
+	| "/*" { commentNestingDepth = 1; } : IN_BRACKETED_COMMENT
+}
+
+<IN_BRACKETED_COMMENT> SKIP :
+{
+	"/*" { commentNestingDepth++; }
+}
+
+<IN_BRACKETED_COMMENT> SKIP :
+{
+	"*/"
+	{ commentNestingDepth--; SwitchTo(commentNestingDepth == 0 ? DEFAULT : IN_BRACKETED_COMMENT);
}
+}
+
+<IN_BRACKETED_COMMENT> SKIP :
+{
+	< ~[] >
 }
 
 <IN_COMMENT> SKIP :

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java?rev=595662&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java
Fri Nov 16 05:51:56 2007
@@ -0,0 +1,141 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.CreateTableFromQueryTest
+
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License
+*/
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Test for comments.
+ */
+public final class CommentTest extends BaseJDBCTestCase {
+    private Statement stmt;
+
+    /**
+     * Public constructor required for running test as standalone JUnit.
+     */
+    public CommentTest(String name)
+    {
+        super(name);
+    }
+
+    /**
+     * Create a suite of tests.
+    */
+    public static Test suite()
+    {
+        return TestConfiguration.embeddedSuite(CommentTest.class);
+    }
+
+    /**
+     * Some simple tests of bracketed comments.
+     */
+    public void testBracketedComments() throws Exception
+    {
+        JDBC.assertFullResultSet(
+            stmt.executeQuery("/* a comment */ VALUES 1"), 
+            new String [][] {{"1"}});
+
+        JDBC.assertFullResultSet(
+            stmt.executeQuery("VALUES 1 /* a comment */"),
+            new String [][] {{"1"}});
+
+        JDBC.assertFullResultSet(
+            stmt.executeQuery("VALUES /* a comment */ 1"),
+            new String [][] {{"1"}});
+
+        JDBC.assertFullResultSet(
+            stmt.executeQuery("VALUES /* a comment \n with newline */ 1"),
+            new String [][] {{"1"}});
+
+        JDBC.assertFullResultSet(
+            stmt.executeQuery("VALUES /* SELECT * from FOO */ 1"),
+            new String [][] {{"1"}});
+
+        JDBC.assertFullResultSet(
+            stmt.executeQuery("VALUES /* a comment /* nested comment */ */ 1"), 
+            new String [][] {{"1"}});
+
+        JDBC.assertFullResultSet(
+            stmt.executeQuery(
+                "VALUES /*/* XXX /*/*/* deeply nested comment */*/*/YYY*/*/ 1"),
+            new String [][] {{"1"}});
+
+        // mix with eol-comments
+        JDBC.assertFullResultSet(
+            stmt.executeQuery(
+                "VALUES 1 --/*/* XXX /*/*/* deeply nested comment */*/*/YYY*/*/ 1"),
+            new String [][] {{"1"}});
+
+        JDBC.assertFullResultSet(
+            stmt.executeQuery(
+                "VALUES 1 --/*/* XXX /*/*/* deeply nested comment */*/*/YYY*/*/ 1--/*"),
+            new String [][] {{"1"}});
+
+        JDBC.assertFullResultSet(
+            stmt.executeQuery("VALUES /* a comment --\n with newline */ 1"),
+            new String [][] {{"1"}});
+
+        JDBC.assertFullResultSet(
+            stmt.executeQuery("VALUES /* a comment -- */ 1"),
+            new String [][] {{"1"}});
+
+        JDBC.assertFullResultSet(
+            stmt.executeQuery("VALUES /* a comment \n-- */ 1"),
+            new String [][] {{"1"}});
+
+        // mix with string quotes
+        JDBC.assertFullResultSet(
+            stmt.executeQuery("VALUES '/* a comment \n-- */'"),
+            new String [][] {{"/* a comment \n-- */"}});
+    }
+    
+    /**
+     * Set the fixture up.
+     */
+    protected void setUp() throws SQLException
+    {    
+        getConnection().setAutoCommit(false);
+        stmt = createStatement();
+    }
+    
+    /**
+     * Tear-down the fixture.
+     */
+    protected void tearDown() throws Exception
+    {
+        stmt.close();
+        super.tearDown();
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=595662&r1=595661&r2=595662&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Fri Nov 16 05:51:56 2007
@@ -121,6 +121,7 @@
         suite.addTest(Bug5054Test.suite());
         suite.addTest(Bug4356Test.suite());
         suite.addTest(SynonymTest.suite());
+        suite.addTest(CommentTest.suite());
 
         // Add the XML tests, which exist as a separate suite
         // so that users can "run all XML tests" easily.



Mime
View raw message