|
24 | 24 | import org.junit.jupiter.api.extension.ExtendWith; |
25 | 25 |
|
26 | 26 | import java.math.BigDecimal; |
| 27 | +import java.nio.ByteBuffer; |
27 | 28 | import java.nio.charset.StandardCharsets; |
28 | 29 | import java.util.Arrays; |
29 | 30 | import java.util.List; |
@@ -465,4 +466,29 @@ public void testFromBytes() { |
465 | 466 | byte[] bytes = Arrays.copyOf(s.getBytes(UTF_8), 10); |
466 | 467 | assertThat(fromBytes(bytes, 0, 6)).isEqualTo(BinaryString.fromString(s)); |
467 | 468 | } |
| 469 | + |
| 470 | + @TestTemplate |
| 471 | + public void testBinarySectionFunctions() throws Exception { |
| 472 | + BinaryString testStr1 = BinaryString.fromString(""); |
| 473 | + BinaryString testStr2 = BinaryString.fromString(""); |
| 474 | + |
| 475 | + BinaryString str = BinaryString.fromString("Hello World"); |
| 476 | + // 1. pointTo |
| 477 | + testStr1.pointTo(str.getSegments(), 0, 5); |
| 478 | + assertThat(testStr1.toString()).isEqualTo("Hello"); |
| 479 | + |
| 480 | + testStr2.pointTo(str.getSegments()[0], 6, 5); |
| 481 | + assertThat(testStr2.toString()).isEqualTo("World"); |
| 482 | + assertThat(testStr2.getOffset()).isEqualTo(6); |
| 483 | + |
| 484 | + // 2. wrapByteBuffer |
| 485 | + ByteBuffer byteBuffer = testStr2.wrapByteBuffer(); |
| 486 | + String str2FromByteBuffer = UTF_8.decode(byteBuffer).toString(); |
| 487 | + assertThat(str2FromByteBuffer).isEqualTo("World"); |
| 488 | + |
| 489 | + // 3. equals |
| 490 | + assertThat(testStr2.equals(testStr2)).isTrue(); |
| 491 | + assertThat(testStr2.equals(null)).isFalse(); |
| 492 | + assertThat(testStr2.equals("World")).isFalse(); |
| 493 | + } |
468 | 494 | } |
0 commit comments