Skip to content

Commit e0e9487

Browse files
committed
Merge pull request #50 from redwerk/javadoc_for_textgroups
added javadoc and test for 'getTextGroups'
2 parents cda0f14 + fd4e5b8 commit e0e9487

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/main/java/ru/lanwen/verbalregex/VerbalExpression.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,12 @@ public String getText(final String toTest, final int group) {
750750

751751
/**
752752
* Extract exact group from string and add it to list
753+
*
754+
* Example:
755+
* String text = "SampleHelloWorldString";
756+
* VerbalExpression regex = regex().capt().oneOf("Hello", "World").endCapt().maybe("String").build();
757+
* list = regex.getTextGroups(text, 0) //result: "Hello", "WorldString"
758+
* list = regex.getTextGroups(text, 1) //result: "Hello", "World"
753759
*
754760
* @param toTest - string to extract from
755761
* @param group - group to extract

src/test/java/ru/lanwen/verbalregex/BasicFunctionalityUnitTest.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -611,20 +611,22 @@ public void shouldAddMaybeWithOneOfFromAnotherBuilder() {
611611

612612
@Test
613613
public void testListOfTextGroups() {
614-
String text = "abczbcayyy";
614+
String text = "SampleHelloWorldString";
615615
VerbalExpression regex = regex()
616-
.capture()
617-
.oneOf("abc", "bca", "yyy")
616+
.capt()
617+
.oneOf("Hello", "World")
618+
.endCapt()
619+
.maybe("String")
618620
.build();
619621

620-
List<String> groups = regex.getTextGroups(text, 1);
622+
List<String> groups0 = regex.getTextGroups(text, 0);
621623

622-
assertThat(groups.get(0), equalTo("abc"));
623-
assertThat(groups.get(1), equalTo("bca"));
624-
assertThat(groups.get(2), equalTo("yyy"));
625-
626-
String concatenatedText = groups.get(0) + groups.get(1) + groups.get(2);
627-
628-
assertThat(regex.getText(text, 1), equalTo(concatenatedText));
624+
assertThat(groups0.get(0), equalTo("Hello"));
625+
assertThat(groups0.get(1), equalTo("WorldString"));
626+
627+
List<String> groups1 = regex.getTextGroups(text, 1);
628+
629+
assertThat(groups1.get(0), equalTo("Hello"));
630+
assertThat(groups1.get(1), equalTo("World"));
629631
}
630632
}

0 commit comments

Comments
 (0)