Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/dev/toonformat/jtoon/Delimiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ public enum Delimiter {
public String toString() {
return value;
}

public char getValue() {
return value.charAt(0);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.toonformat.jtoon.decoder;

import dev.toonformat.jtoon.Delimiter;

import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void expectsToExtractSlashFromDelimiter() {
Delimiter result = ArrayDecoder.extractDelimiterFromHeader("[3|]", context);

// Then
assertEquals("|", result.toString());
assertEquals(Delimiter.PIPE.toString(), result.toString());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading