forked from bndtools/bnd
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Character class occupy 1 position so cannot be merged with another ch…
…aracter class --- Signed-off-by: Peter Kriens <[email protected]> Signed-off-by: Peter Kriens <[email protected]>
- Loading branch information
Showing
2 changed files
with
47 additions
and
4 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
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 |
---|---|---|
|
@@ -4,12 +4,14 @@ | |
import static aQute.libg.re.Catalog.ahead; | ||
import static aQute.libg.re.Catalog.atomic; | ||
import static aQute.libg.re.Catalog.back; | ||
import static aQute.libg.re.Catalog.backslash; | ||
import static aQute.libg.re.Catalog.behind; | ||
import static aQute.libg.re.Catalog.capture; | ||
import static aQute.libg.re.Catalog.cc; | ||
import static aQute.libg.re.Catalog.comma; | ||
import static aQute.libg.re.Catalog.dotall; | ||
import static aQute.libg.re.Catalog.dquote; | ||
import static aQute.libg.re.Catalog.endOfInput; | ||
import static aQute.libg.re.Catalog.g; | ||
import static aQute.libg.re.Catalog.if_; | ||
import static aQute.libg.re.Catalog.list; | ||
|
@@ -72,6 +74,30 @@ public class RETest { | |
ids.add("ωAngularFrequency"); // Omega symbol | ||
} | ||
|
||
@Test | ||
public void testComplicatedLineDetect() { | ||
RE NORMAL_LINE_P = g(behind(backslash.not()), nl, ahead(endOfInput).not()); | ||
RE BACKSLASHED_LINE_P = g(backslash, nl, ahead(endOfInput).not()); | ||
|
||
assertThat(NORMAL_LINE_P.findIn(WITH_NORMAL_LINES)).isPresent(); | ||
assertThat(NORMAL_LINE_P.findIn(WITH_ESCAPED_LINES)).isNotPresent(); | ||
assertThat(NORMAL_LINE_P.findIn(WITH_MIXED_LINES)).isPresent(); | ||
|
||
assertThat(BACKSLASHED_LINE_P.findIn(WITH_NORMAL_LINES)).isNotPresent(); | ||
assertThat(BACKSLASHED_LINE_P.findIn(WITH_ESCAPED_LINES)).isPresent(); | ||
assertThat(BACKSLASHED_LINE_P.findIn(WITH_MIXED_LINES)).isPresent(); | ||
|
||
assertThat(NORMAL_LINE_P.append(WITH_NORMAL_LINES, m -> "X")).isEqualTo("line 1Xline 2Xline 3Xline 4\n"); | ||
assertThat(NORMAL_LINE_P.append(WITH_ESCAPED_LINES, m -> "X")).isEqualTo(WITH_ESCAPED_LINES); | ||
assertThat(NORMAL_LINE_P.append(WITH_MIXED_LINES, m -> "X")).isEqualTo("line 1\\\nline 2Xline 3\\\nline 3\n"); | ||
|
||
assertThat(BACKSLASHED_LINE_P.append(WITH_NORMAL_LINES, m -> "X")).isEqualTo(WITH_NORMAL_LINES); | ||
assertThat(BACKSLASHED_LINE_P.append(WITH_ESCAPED_LINES, m -> "X")) | ||
.isEqualTo("line 1Xline 2Xline 3Xline 3\\\n"); | ||
assertThat(BACKSLASHED_LINE_P.append(WITH_MIXED_LINES, m -> "X")) | ||
.isEqualTo("line 1Xline 2\n" + "line 3Xline 3\n"); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
@SuppressWarnings("unused") | ||
|
@@ -482,7 +508,7 @@ class Internet extends Catalog { | |
assertThat(x.email.findAllIn("bla bla [email protected] bal la a [email protected] and more nonsense") | ||
.count()).isEqualTo(2); | ||
|
||
assertThat(Catalog.nl.findAllIn("line 1\rline 2\nline 3\r\nline 4\n") | ||
assertThat(nl.findAllIn("line 1\rline 2\nline 3\r\nline 4\n") | ||
.count()).isEqualTo(4); | ||
assertThat(word.findAllIn( | ||
"The quick brown fox jumped over the lazy dog. However, somewhere on the horizon there was light: 'A ship came into the harbour.'") | ||
|
@@ -531,4 +557,24 @@ public void lookbehind() { | |
.count()).isEqualTo(3); | ||
} | ||
|
||
final static String WITH_NORMAL_LINES = """ | ||
line 1 | ||
line 2 | ||
line 3 | ||
line 4 | ||
"""; | ||
|
||
final static String WITH_ESCAPED_LINES = """ | ||
line 1\\ | ||
line 2\\ | ||
line 3\\ | ||
line 3\\ | ||
"""; | ||
final static String WITH_MIXED_LINES = """ | ||
line 1\\ | ||
line 2 | ||
line 3\\ | ||
line 3 | ||
"""; | ||
|
||
} |