Skip to content

Commit

Permalink
getContentList корректно разбирает переводы строк с одиночным CR
Browse files Browse the repository at this point in the history
  • Loading branch information
nixel2007 committed Sep 8, 2021
1 parent 79fb62c commit 397a417
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.md eol=lf
*.json eol=lf
*.bat eol=crlf
src/test/resources/context/DocumentContextBrokenLineFeeds.bsl binary
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static java.util.Objects.requireNonNull;
Expand All @@ -75,6 +76,8 @@
@RequiredArgsConstructor
public class DocumentContext {

private static final Pattern CONTENT_SPLIT_PATTERN = Pattern.compile("\r?\n|\r");

private final URI uri;

@Nullable
Expand Down Expand Up @@ -315,7 +318,7 @@ private static FileType computeFileType(URI uri) {
}

private String[] computeContentList() {
return getContent().split("\n", -1);
return CONTENT_SPLIT_PATTERN.split(getContent(), -1);
}

private SymbolTree computeSymbolTree() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ void testContentList() {
assertThat(contentList).hasSize(40);
}

@Test
void testContentListWithStandaloneCR() {
// given
var documentContext = getDocumentContext("./src/test/resources/context/DocumentContextBrokenLineFeeds.bsl");

// when
var contentList = documentContext.getContentList();

// then
assertThat(contentList).hasSize(3);
}

@Test
void testEOF() {
// given
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ПереводCRЕщеОдинCR
Expand Down

0 comments on commit 397a417

Please sign in to comment.