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

tuichenchuxin 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 8fa47253566 Add more unit tests for ExpressionSegmentBinder(#28538) 
(#32043)
8fa47253566 is described below

commit 8fa472535661a0705915e8322251bce2fce6a4ae
Author: Skitii <[email protected]>
AuthorDate: Tue Jul 9 13:06:15 2024 +0800

    Add more unit tests for ExpressionSegmentBinder(#28538) (#32043)
    
    Co-authored-by: Skitii <[email protected]>
---
 .../impl/BinaryOperationExpressionBinderTest.java  | 47 ++++++++++++++++++
 .../impl/ExistsSubqueryExpressionBinderTest.java   | 56 ++++++++++++++++++++++
 .../impl/FunctionExpressionSegmentBinderTest.java  | 45 +++++++++++++++++
 .../expression/impl/InExpressionBinderTest.java    | 46 ++++++++++++++++++
 4 files changed, 194 insertions(+)

diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/BinaryOperationExpressionBinderTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/BinaryOperationExpressionBinderTest.java
new file mode 100644
index 00000000000..445de08bccb
--- /dev/null
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/BinaryOperationExpressionBinderTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.shardingsphere.infra.binder.segment.expression.impl;
+
+import org.apache.shardingsphere.infra.binder.segment.SegmentType;
+import 
org.apache.shardingsphere.infra.binder.statement.SQLStatementBinderContext;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
+
+class BinaryOperationExpressionBinderTest {
+    
+    @Test
+    void assertBinaryOperationExpression() {
+        BinaryOperationExpression binaryOperationExpression = new 
BinaryOperationExpression(0, 0,
+                new LiteralExpressionSegment(0, 0, "test"),
+                new LiteralExpressionSegment(0, 0, "test"), "=", "test");
+        SQLStatementBinderContext statementBinderContext = 
mock(SQLStatementBinderContext.class);
+        BinaryOperationExpression actual = 
BinaryOperationExpressionBinder.bind(binaryOperationExpression, 
SegmentType.PROJECTION,
+                statementBinderContext, Collections.emptyMap(), 
Collections.emptyMap());
+        assertThat(actual.getLeft().getText(), is("test"));
+        assertThat(actual.getRight().getText(), is("test"));
+        assertThat(actual.getOperator(), is("="));
+        assertThat(actual.getText(), is("test"));
+    }
+}
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/ExistsSubqueryExpressionBinderTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/ExistsSubqueryExpressionBinderTest.java
new file mode 100644
index 00000000000..d6b08ea87a4
--- /dev/null
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/ExistsSubqueryExpressionBinderTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.shardingsphere.infra.binder.segment.expression.impl;
+
+import 
org.apache.shardingsphere.infra.binder.statement.SQLStatementBinderContext;
+import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExistsSubqueryExpression;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionsSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.mysql.dml.MySQLSelectStatement;
+import org.apache.shardingsphere.test.fixture.database.MockedDatabaseType;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
+
+class ExistsSubqueryExpressionBinderTest {
+    
+    @Test
+    void assertBindExistsSubqueryExpression() {
+        MySQLSelectStatement selectStatement = new MySQLSelectStatement();
+        selectStatement.setProjections(new ProjectionsSegment(0, 0));
+        ExistsSubqueryExpression existsSubqueryExpression = new 
ExistsSubqueryExpression(0, 0,
+                new SubquerySegment(0, 0, selectStatement, "t_test"));
+        SQLStatementBinderContext statementBinderContext = new 
SQLStatementBinderContext(mock(ShardingSphereMetaData.class),
+                DefaultDatabase.LOGIC_NAME, new MockedDatabaseType(), 
Collections.emptyList());
+        ExistsSubqueryExpression actual = 
ExistsSubqueryExpressionBinder.bind(existsSubqueryExpression, 
statementBinderContext, Collections.emptyMap());
+        assertThat(actual.getStartIndex(), 
is(existsSubqueryExpression.getStartIndex()));
+        assertThat(actual.getStopIndex(), 
is(existsSubqueryExpression.getStopIndex()));
+        assertThat(actual.getText(), is("t_test"));
+        assertThat(actual.getSubquery().getStartIndex(), 
is(existsSubqueryExpression.getSubquery().getStartIndex()));
+        assertThat(actual.getSubquery().getStopIndex(), 
is(existsSubqueryExpression.getSubquery().getStopIndex()));
+        assertThat(actual.getSubquery().getSubqueryType(), 
is(existsSubqueryExpression.getSubquery().getSubqueryType()));
+        assertThat(actual.getSubquery().getText(), is("t_test"));
+        assertThat(actual.getSubquery().getSelect().getDatabaseType(), 
is(existsSubqueryExpression.getSubquery().getSelect().getDatabaseType()));
+    }
+}
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/FunctionExpressionSegmentBinderTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/FunctionExpressionSegmentBinderTest.java
new file mode 100644
index 00000000000..019369fa643
--- /dev/null
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/FunctionExpressionSegmentBinderTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.shardingsphere.infra.binder.segment.expression.impl;
+
+import org.apache.shardingsphere.infra.binder.segment.SegmentType;
+import 
org.apache.shardingsphere.infra.binder.statement.SQLStatementBinderContext;
+import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.FunctionSegment;
+import org.apache.shardingsphere.test.fixture.database.MockedDatabaseType;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class FunctionExpressionSegmentBinderTest {
+    
+    @Test
+    void assertBindFunctionExpressionSegment() {
+        FunctionSegment functionSegment = new FunctionSegment(0, 0, "CONCAT", 
"('%','abc','%')");
+        SQLStatementBinderContext statementBinderContext = new 
SQLStatementBinderContext(new ShardingSphereMetaData(), 
DefaultDatabase.LOGIC_NAME, new MockedDatabaseType(), Collections.emptyList());
+        FunctionSegment actual = 
FunctionExpressionSegmentBinder.bind(functionSegment, SegmentType.PROJECTION, 
statementBinderContext, Collections.emptyMap(), Collections.emptyMap());
+        assertThat(actual.getStartIndex(), 
is(functionSegment.getStartIndex()));
+        assertThat(actual.getStopIndex(), is(functionSegment.getStopIndex()));
+        assertThat(actual.getFunctionName(), is("CONCAT"));
+        assertThat(actual.getText(), is("('%','abc','%')"));
+    }
+}
diff --git 
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/InExpressionBinderTest.java
 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/InExpressionBinderTest.java
new file mode 100644
index 00000000000..2336d062644
--- /dev/null
+++ 
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/expression/impl/InExpressionBinderTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.shardingsphere.infra.binder.segment.expression.impl;
+
+import org.apache.shardingsphere.infra.binder.segment.SegmentType;
+import 
org.apache.shardingsphere.infra.binder.statement.SQLStatementBinderContext;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.InExpression;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+
+class InExpressionBinderTest {
+    
+    @Test
+    void assertInExpressionBinder() {
+        InExpression inExpression = new InExpression(0, 10,
+                new LiteralExpressionSegment(0, 0, "left"),
+                new LiteralExpressionSegment(0, 0, "right"), true);
+        SQLStatementBinderContext statementBinderContext = 
mock(SQLStatementBinderContext.class);
+        InExpression actual = InExpressionBinder.bind(inExpression, 
SegmentType.PROJECTION,
+                statementBinderContext, Collections.emptyMap(), 
Collections.emptyMap());
+        assertThat(actual.getText(), is("leftright"));
+        assertTrue(actual.isNot());
+    }
+}

Reply via email to