You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/09/17 00:12:45 UTC

[shardingsphere] branch master updated: [20362] Add More Unit Tests for SQLUtil to increase coverage (#21026)

This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 8381452f49a [20362] Add More Unit Tests for SQLUtil to increase coverage (#21026)
8381452f49a is described below

commit 8381452f49a35fb4e2fb45db4bc2fbb8184ec7a7
Author: Noha Nomier <33...@users.noreply.github.com>
AuthorDate: Fri Sep 16 17:12:34 2022 -0700

    [20362] Add More Unit Tests for SQLUtil to increase coverage (#21026)
    
    Add unit tests for the following Methods: isReadOnly, trimComment, trimSemicolon
    
    Co-authored-by: Noha Nomier <nn...@Nohas-MacBook-Pro.local>
---
 .../sql/parser/sql/common/util/SQLUtilTest.java    | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtilTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtilTest.java
index d3ca8aef387..ed548259933 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtilTest.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtilTest.java
@@ -17,6 +17,13 @@
 
 package org.apache.shardingsphere.sql.parser.sql.common.util;
 
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowMasterStatusStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLDeleteStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLInsertStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLUpdateStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDropDimensionStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dcl.SQLServerRevertStatement;
 import org.junit.Test;
 
 import java.math.BigDecimal;
@@ -25,6 +32,8 @@ import java.math.BigInteger;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
 
 public final class SQLUtilTest {
     
@@ -140,4 +149,28 @@ public final class SQLUtilTest {
         assertThat(SQLUtil.convertLikePatternToRegex("SHOW DATABASES LIKE 'sharding_\\%db'"), is("SHOW DATABASES LIKE 'sharding.%db'"));
         assertThat(SQLUtil.convertLikePatternToRegex("SHOW DATABASES LIKE 'sharding\\_%db'"), is("SHOW DATABASES LIKE 'sharding_.*db'"));
     }
+
+    @Test
+    public void assertIsReadOnly() {
+        assertFalse(SQLUtil.isReadOnly(new SQLServerRevertStatement()));
+        assertFalse(SQLUtil.isReadOnly(new OracleDropDimensionStatement()));
+        assertFalse(SQLUtil.isReadOnly(new MySQLUpdateStatement()));
+        assertFalse(SQLUtil.isReadOnly(new MySQLDeleteStatement()));
+        assertFalse(SQLUtil.isReadOnly(new MySQLInsertStatement()));
+        assertTrue(SQLUtil.isReadOnly(new MySQLSelectStatement()));
+        assertTrue(SQLUtil.isReadOnly(new MySQLShowMasterStatusStatement()));
+    }
+
+    @Test
+    public void assertTrimSemiColon() {
+        assertThat(SQLUtil.trimSemicolon("SHOW DATABASES;"), is("SHOW DATABASES"));
+        assertThat(SQLUtil.trimSemicolon("SHOW DATABASES"), is("SHOW DATABASES"));
+    }
+
+    @Test
+    public void assertTrimComment() {
+        assertThat(SQLUtil.trimComment("/* This is a comment */ SHOW DATABASES"), is("SHOW DATABASES"));
+        assertThat(SQLUtil.trimComment("/* This is a query with a semicolon */ SHOW DATABASES;"), is("SHOW DATABASES"));
+        assertThat(SQLUtil.trimComment("/* This is a query with spaces */    SHOW DATABASES   "), is("SHOW DATABASES"));
+    }
 }