|
14 | 14 | import org.elasticsearch.test.ESTestCase;
|
15 | 15 | import org.hamcrest.Matchers;
|
16 | 16 |
|
| 17 | +import java.nio.charset.StandardCharsets; |
17 | 18 | import java.util.ArrayList;
|
18 | 19 | import java.util.Arrays;
|
19 | 20 | import java.util.Collection;
|
@@ -522,6 +523,31 @@ public void testNoRootAliasForPassThroughFieldOnConflictingField() {
|
522 | 523 | assertEquals(foo.fieldType(), lookup.get("foo"));
|
523 | 524 | }
|
524 | 525 |
|
| 526 | + public void testDotCount() { |
| 527 | + assertEquals(0, FieldTypeLookup.dotCount("")); |
| 528 | + assertEquals(1, FieldTypeLookup.dotCount(".")); |
| 529 | + assertEquals(2, FieldTypeLookup.dotCount("..")); |
| 530 | + assertEquals(3, FieldTypeLookup.dotCount("...")); |
| 531 | + assertEquals(4, FieldTypeLookup.dotCount("....")); |
| 532 | + assertEquals(0, FieldTypeLookup.dotCount("foo")); |
| 533 | + assertEquals(1, FieldTypeLookup.dotCount("foo.bar")); |
| 534 | + assertEquals(2, FieldTypeLookup.dotCount("foo.bar.baz")); |
| 535 | + assertEquals(3, FieldTypeLookup.dotCount("foo.bar.baz.bob")); |
| 536 | + assertEquals(4, FieldTypeLookup.dotCount("foo.bar.baz.bob.")); |
| 537 | + assertEquals(4, FieldTypeLookup.dotCount("foo..bar.baz.bob")); |
| 538 | + assertEquals(5, FieldTypeLookup.dotCount("foo..bar..baz.bob")); |
| 539 | + assertEquals(6, FieldTypeLookup.dotCount("foo..bar..baz.bob.")); |
| 540 | + |
| 541 | + int times = atLeast(50); |
| 542 | + for (int i = 0; i < times; i++) { |
| 543 | + byte[] bytes = new byte[randomInt(1024)]; |
| 544 | + random().nextBytes(bytes); |
| 545 | + String s = new String(bytes, StandardCharsets.UTF_8); |
| 546 | + int expected = s.chars().map(c -> c == '.' ? 1 : 0).sum(); |
| 547 | + assertEquals(expected, FieldTypeLookup.dotCount(s)); |
| 548 | + } |
| 549 | + } |
| 550 | + |
525 | 551 | @SafeVarargs
|
526 | 552 | @SuppressWarnings("varargs")
|
527 | 553 | static <T> List<T> randomizedList(T... values) {
|
|
0 commit comments