diff --git a/src/main/java/dev/toonformat/jtoon/Delimiter.java b/src/main/java/dev/toonformat/jtoon/Delimiter.java index 442cec1..4e5ebe0 100644 --- a/src/main/java/dev/toonformat/jtoon/Delimiter.java +++ b/src/main/java/dev/toonformat/jtoon/Delimiter.java @@ -33,4 +33,8 @@ public enum Delimiter { public String toString() { return value; } + + public char getValue() { + return value.charAt(0); + } } diff --git a/src/main/java/dev/toonformat/jtoon/decoder/DecodeHelper.java b/src/main/java/dev/toonformat/jtoon/decoder/DecodeHelper.java index 75c6c99..2eaf392 100644 --- a/src/main/java/dev/toonformat/jtoon/decoder/DecodeHelper.java +++ b/src/main/java/dev/toonformat/jtoon/decoder/DecodeHelper.java @@ -1,5 +1,7 @@ package dev.toonformat.jtoon.decoder; +import dev.toonformat.jtoon.Delimiter; + import java.util.List; import java.util.Map; @@ -47,7 +49,7 @@ private static int computeLeadingSpaces(String line, DecodeContext context) { char c = line.charAt(i); if (c == ' ') { leadingSpaces++; - } else if (c == '\t') { + } else if (c == Delimiter.TAB.getValue()) { if (context.options.strict()) { throw new IllegalArgumentException( "Tab character used in indentation at line " + (context.currentLine + 1)); diff --git a/src/main/java/dev/toonformat/jtoon/decoder/TabularArrayDecoder.java b/src/main/java/dev/toonformat/jtoon/decoder/TabularArrayDecoder.java index e4aeece..1feaeb6 100644 --- a/src/main/java/dev/toonformat/jtoon/decoder/TabularArrayDecoder.java +++ b/src/main/java/dev/toonformat/jtoon/decoder/TabularArrayDecoder.java @@ -118,15 +118,16 @@ private static void validateKeysDelimiter(String keysStr, Delimiter expectedDeli * @param actualChar the actual delimiter character */ private static void checkDelimiterMismatch(char expectedChar, char actualChar) { - if (expectedChar == '\t' && actualChar == ',') { + if (expectedChar == Delimiter.TAB.getValue() && actualChar == Delimiter.COMMA.getValue()) { throw new IllegalArgumentException( "Delimiter mismatch: bracket declares tab, brace fields use comma"); } - if (expectedChar == '|' && actualChar == ',') { + if (expectedChar == Delimiter.PIPE.getValue() && actualChar == Delimiter.COMMA.getValue()) { throw new IllegalArgumentException( "Delimiter mismatch: bracket declares pipe, brace fields use comma"); } - if (expectedChar == ',' && (actualChar == '\t' || actualChar == '|')) { + if (expectedChar == Delimiter.COMMA.getValue() && + (actualChar == Delimiter.TAB.getValue() || actualChar == Delimiter.PIPE.getValue())) { throw new IllegalArgumentException( "Delimiter mismatch: bracket declares comma, brace fields use different delimiter"); } diff --git a/src/test/java/dev/toonformat/jtoon/decoder/ArrayDecoderTest.java b/src/test/java/dev/toonformat/jtoon/decoder/ArrayDecoderTest.java index 353385e..197ec25 100644 --- a/src/test/java/dev/toonformat/jtoon/decoder/ArrayDecoderTest.java +++ b/src/test/java/dev/toonformat/jtoon/decoder/ArrayDecoderTest.java @@ -120,7 +120,7 @@ void expectsToExtractSlashFromDelimiter() { Delimiter result = ArrayDecoder.extractDelimiterFromHeader("[3|]", context); // Then - assertEquals("|", result.toString()); + assertEquals(Delimiter.PIPE.toString(), result.toString()); } @Test diff --git a/src/test/java/dev/toonformat/jtoon/decoder/TabularArrayDecoderTest.java b/src/test/java/dev/toonformat/jtoon/decoder/TabularArrayDecoderTest.java index e31ca49..7c737ee 100644 --- a/src/test/java/dev/toonformat/jtoon/decoder/TabularArrayDecoderTest.java +++ b/src/test/java/dev/toonformat/jtoon/decoder/TabularArrayDecoderTest.java @@ -172,8 +172,8 @@ void validateKeysDelimiter() throws Exception { @DisplayName("validateKeysDelimiter get called and branches will be checked") void checkDelimiterMismatchExecution() { // Given - String expectedChar = "|"; - String actualChar = ","; + String expectedChar = Delimiter.PIPE.toString(); + String actualChar = Delimiter.COMMA.toString(); // When InvocationTargetException exception = assertThrows(InvocationTargetException.class, @@ -187,8 +187,8 @@ void checkDelimiterMismatchExecution() { @DisplayName("validateKeysDelimiter get called and branches will be checked") void checkDelimiterMismatchExecutionWithComa() { // Given - String expectedChar = ","; - String actualChar = "|"; + String expectedChar = Delimiter.COMMA.toString(); + String actualChar = Delimiter.PIPE.toString(); // When InvocationTargetException exception = assertThrows(InvocationTargetException.class,