Skip to content

Commit

Permalink
feat: ignore whitespaces between blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
qoomon committed Nov 10, 2020
1 parent d87e2da commit 4396e22
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.lang.Character.isWhitespace;

/**
* Created by qoomon on 07/07/16.
*/
Expand Down Expand Up @@ -53,7 +55,10 @@ public GeneralBlock readBlock() throws BlockParseException {
lineCharIndex++;

if (blockBuilder.length() == 0 && messageCharacter != '{') {
if (messageCharacter == '}') {
if (isWhitespace(messageCharacter)) {
// ignore whitespaces between blocks
continue;
} else if (messageCharacter == '}') {
throw new BlockParseException("Found closing bracket without preceding opening bracket", lineNumber);
} else {
throw new BlockParseException("No characters are allowed outside of blocks, but was: '" + messageCharacter + "'", lineNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public void readBlock_SHOULD_read_valid_blocks() throws Exception {
assertThat(blockList.get(1).getContent()).isEqualTo("b");
assertThat(blockList.get(2).getId()).isEqualTo("3");
assertThat(blockList.get(2).getContent()).isEqualTo("c");

}

@Test
Expand Down Expand Up @@ -101,4 +100,26 @@ public void readBlock_SHOULD_handle_LF_line_endings() throws Exception {
assertThat(blockList.get(3).getContent()).isEqualTo("\n-");
}

@Test
public void readBlock_SHOULD_ignore_whitespaces_between_blocks() throws Exception {
// Given

String blockText = "{1:a} \t{2:b} \n\r{3:c}";

SwiftBlockReader subjectUnderTest = new SwiftBlockReader(new StringReader(blockText));

// When
List<GeneralBlock> blockList = TestUtils.collectUntilNull(subjectUnderTest::readBlock);

// Then

assertThat(blockList).hasSize(3);
assertThat(blockList.get(0).getId()).isEqualTo("1");
assertThat(blockList.get(0).getContent()).isEqualTo("a");
assertThat(blockList.get(1).getId()).isEqualTo("2");
assertThat(blockList.get(1).getContent()).isEqualTo("b");
assertThat(blockList.get(2).getId()).isEqualTo("3");
assertThat(blockList.get(2).getContent()).isEqualTo("c");
}

}

0 comments on commit 4396e22

Please sign in to comment.