Skip to content

Commit

Permalink
fixed minor bug where an invalid syntax exception would have the wron…
Browse files Browse the repository at this point in the history
…g start index if the first token was unexpected (#17)
  • Loading branch information
iamdudeman authored Nov 28, 2024
1 parent ca6d8c0 commit 84c2f7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class SolaJsonTokenizer {
public SolaJsonTokenizer(String text) {
characters = text.toCharArray();
currentChar = characters[textIndex];

while (currentChar != null && Character.isWhitespace(currentChar)) {
advance();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
class SolaJsonParserTest {
@Test
void whenInvalidRoot_shouldThrowException() {
String input = """
"test"
""";
String input = " \"test\" ";

InvalidSyntaxException invalidSyntaxException = assertThrows(InvalidSyntaxException.class, () -> createTest(input));
assertEquals(0, invalidSyntaxException.getStartIndex());
assertEquals(1, invalidSyntaxException.getStartIndex());
assertEquals(TokenType.STRING, invalidSyntaxException.getActual());
var expectedList = List.of(invalidSyntaxException.getExpected());
assertTrue(expectedList.contains(TokenType.L_BRACKET));
Expand Down

0 comments on commit 84c2f7f

Please sign in to comment.