-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle parsing `len` and `matches` in any order;
- Loading branch information
Showing
2 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/test/java/io/lettuce/core/output/StringMatchResultOutputUnitTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.lettuce.core.output; | ||
|
||
import io.lettuce.core.StringMatchResult; | ||
import io.lettuce.core.codec.StringCodec; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class StringMatchResultOutputUnitTests { | ||
|
||
@Test | ||
void parseLenAndMatches() { | ||
StringMatchResultOutput<String, String> output = new StringMatchResultOutput<>(new StringCodec(), false); | ||
|
||
output.set(ByteBuffer.wrap("len".getBytes())); | ||
output.set(42); | ||
|
||
output.set(ByteBuffer.wrap("matches".getBytes())); | ||
output.set(0); | ||
output.set(5); | ||
output.set(10); | ||
output.set(15); | ||
|
||
output.complete(2); | ||
output.complete(0); | ||
|
||
StringMatchResult result = output.get(); | ||
|
||
assertThat(result.getLen()).isEqualTo(42); | ||
|
||
assertThat(result.getMatches()).hasSize(1).satisfies(m -> assertMatchedPositions(m.get(0), 0, 5, 10, 15)); | ||
} | ||
|
||
private void assertMatchedPositions(StringMatchResult.MatchedPosition match, int... expected) { | ||
assertThat(match.getA().getStart()).isEqualTo(expected[0]); | ||
assertThat(match.getA().getEnd()).isEqualTo(expected[1]); | ||
assertThat(match.getB().getStart()).isEqualTo(expected[2]); | ||
assertThat(match.getB().getEnd()).isEqualTo(expected[3]); | ||
} | ||
|
||
} |