diff --git a/src/main/java/technology/sola/json/tokenizer/SolaJsonTokenizer.java b/src/main/java/technology/sola/json/tokenizer/SolaJsonTokenizer.java index 29eacac..79134ad 100644 --- a/src/main/java/technology/sola/json/tokenizer/SolaJsonTokenizer.java +++ b/src/main/java/technology/sola/json/tokenizer/SolaJsonTokenizer.java @@ -18,6 +18,10 @@ public class SolaJsonTokenizer { public SolaJsonTokenizer(String text) { characters = text.toCharArray(); currentChar = characters[textIndex]; + + while (currentChar != null && Character.isWhitespace(currentChar)) { + advance(); + } } /** diff --git a/src/test/java/technology/sola/json/parser/SolaJsonParserTest.java b/src/test/java/technology/sola/json/parser/SolaJsonParserTest.java index 6d2bcf8..23c33bf 100644 --- a/src/test/java/technology/sola/json/parser/SolaJsonParserTest.java +++ b/src/test/java/technology/sola/json/parser/SolaJsonParserTest.java @@ -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));