jeqo commented on code in PR #12637:
URL: https://github.com/apache/kafka/pull/12637#discussion_r975569257


##########
connect/transforms/src/test/java/org/apache/kafka/connect/transforms/field/FieldPathTest.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.kafka.connect.transforms.field;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Collections;
+import java.util.Map;
+import org.apache.kafka.connect.data.Schema;
+import org.apache.kafka.connect.data.SchemaBuilder;
+import org.apache.kafka.connect.data.Struct;
+import org.apache.kafka.connect.transforms.util.SchemaUtil;
+import org.junit.jupiter.api.Test;
+
+class FieldPathTest {
+    final static String[] EMPTY_PATH = new String[]{};
+
+    @Test void shouldBuildV1WithDotsAndBacktickPair() {
+        assertArrayEquals(new String[] {"foo.bar.baz"}, 
FieldPath.ofV1("foo.bar.baz").path());
+        assertArrayEquals(new String[] {"foo.`bar.baz`"}, 
FieldPath.ofV1("foo.`bar.baz`").path());
+    }
+
+    @Test void shouldBuildV2WithEmptyPath() {
+        assertArrayEquals(EMPTY_PATH, FieldPath.of("", 
FieldSyntaxVersion.V2).path());
+    }
+
+    @Test void shouldBuildV2WithNullPath() {
+        assertArrayEquals(EMPTY_PATH, FieldPath.of(null, 
FieldSyntaxVersion.V2).path());
+    }
+
+    @Test void shouldBuildV2WithoutDots() {
+        assertArrayEquals(new String[] {"foobarbaz"}, 
FieldPath.of("foobarbaz", FieldSyntaxVersion.V2).path());
+    }
+    @Test void shouldBuildV2WithoutWrappingBackticks() {
+        assertArrayEquals(new String[] {"foo`bar`baz"}, 
FieldPath.of("foo`bar`baz", FieldSyntaxVersion.V2).path());
+    }
+
+    @Test void shouldBuildV2WhenIncludesDots() {
+        assertArrayEquals(new String[] {"foo", "bar", "baz"}, 
FieldPath.of("foo.bar.baz", FieldSyntaxVersion.V2).path());
+    }
+
+    @Test void shouldBuildV2WhenIncludesDotsAndBacktickPair() {
+        assertArrayEquals(new String[] {"foo", "bar.baz"}, 
FieldPath.of("foo.`bar.baz`", FieldSyntaxVersion.V2).path());
+        assertArrayEquals(new String[] {"foo", "bar", "baz"}, 
FieldPath.of("foo.`bar`.baz", FieldSyntaxVersion.V2).path());
+    }
+
+    @Test void shouldBuildV2AndIgnoreBackticksThatAreNotWrapping() {
+        assertArrayEquals(new String[] {"foo", "ba`r.baz"}, 
FieldPath.of("foo.`ba`r.baz`", FieldSyntaxVersion.V2).path());
+        assertArrayEquals(new String[] {"foo", "ba`r", "baz"}, 
FieldPath.of("foo.ba`r.baz", FieldSyntaxVersion.V2).path());
+    }
+
+    @Test void shouldBuildV2AndEscapeBackticks() {
+        assertArrayEquals(new String[] {"foo", "bar`.`baz"}, 
FieldPath.of("foo.`bar\\`.\\`baz`", FieldSyntaxVersion.V2).path());
+        assertArrayEquals(new String[] {"foo", "bar\\`.`baz"}, 
FieldPath.of("foo.`bar\\\\`.\\`baz`", FieldSyntaxVersion.V2).path());
+    }
+
+    @Test void shouldBuildV2WithBackticksWrappingBackticks() {

Review Comment:
   Good catch. I will stick to the rules in this case, as there is no need for 
this special case by using backslash to escape backticks.
   Tests are updated.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to