SHOW:
|
|
- or go back to the newest paste.
1 | - | // Copyright (C) 2014 Josh Ventura |
1 | + | @Test |
2 | - | // Code is part of LateralGM <lateralgm.org> and is released under the terms of |
2 | + | public void testThing() { |
3 | - | // the GNU General Public License as published by the Free Software Foundation; |
3 | + | String CODE = "runatestinatestwith\nsomemoretestsandthen\nyou'redone"; |
4 | - | // version 3 of the license, or any later version. |
4 | + | LineMatch[] matches = YourClass.getMatchingLines(CODE, Pattern.compile("test")); |
5 | - | |
5 | + | assertEquals(2, matches.length); |
6 | - | private static final Pattern newline = Pattern.compile("\r\n|\r|\n"); |
6 | + | assertEquals(5, matches[0].matchedText.size()); |
7 | - | public static LineMatch[] getMatchingLines(String code, Pattern content) { |
7 | + | assertEquals("runa", matches[0].matchedText.get(0).content); |
8 | - | List<LineMatch> res = new ArrayList<>(); |
8 | + | assertEquals("test", matches[0].matchedText.get(1).content); |
9 | - | Matcher m = content.matcher(code), nl = newline.matcher(code); |
9 | + | assertEquals("ina", matches[0].matchedText.get(2).content); |
10 | - | int lineNum = 1, lineAt = 0, lastEnd = -1; |
10 | + | assertEquals("test", matches[0].matchedText.get(3).content); |
11 | - | LineMatch lastMatch = null; |
11 | + | assertEquals("with", matches[0].matchedText.get(4).content); |
12 | - | while (m.find()) { |
12 | + | assertEquals(3, matches[1].matchedText.size()); |
13 | - | nl.region(lineAt, m.start()); |
13 | + | assertEquals("somemore", matches[1].matchedText.get(0).content); |
14 | - | int firstSkippedLineAt = lineAt; |
14 | + | assertEquals("test", matches[1].matchedText.get(1).content); |
15 | - | if (nl.find()) { |
15 | + | assertEquals("sandthen", matches[1].matchedText.get(2).content); |
16 | - | firstSkippedLineAt = nl.start(); |
16 | + | } |