Skip to content

Commit 482570e

Browse files
authored
Using Delimiter enum values instead of hardcoded chars (#94)
* refactor: using delimiter values instead of hardcoded chars * turning value to final * using string for value instead of char * removing hardcoded values referent to Delimiter in tests
1 parent 3690ba9 commit 482570e

5 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/main/java/dev/toonformat/jtoon/Delimiter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ public enum Delimiter {
3333
public String toString() {
3434
return value;
3535
}
36+
37+
public char getValue() {
38+
return value.charAt(0);
39+
}
3640
}

src/main/java/dev/toonformat/jtoon/decoder/DecodeHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.toonformat.jtoon.decoder;
22

3+
import dev.toonformat.jtoon.Delimiter;
4+
35
import java.util.List;
46
import java.util.Map;
57

@@ -47,7 +49,7 @@ private static int computeLeadingSpaces(String line, DecodeContext context) {
4749
char c = line.charAt(i);
4850
if (c == ' ') {
4951
leadingSpaces++;
50-
} else if (c == '\t') {
52+
} else if (c == Delimiter.TAB.getValue()) {
5153
if (context.options.strict()) {
5254
throw new IllegalArgumentException(
5355
"Tab character used in indentation at line " + (context.currentLine + 1));

src/main/java/dev/toonformat/jtoon/decoder/TabularArrayDecoder.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,16 @@ private static void validateKeysDelimiter(String keysStr, Delimiter expectedDeli
118118
* @param actualChar the actual delimiter character
119119
*/
120120
private static void checkDelimiterMismatch(char expectedChar, char actualChar) {
121-
if (expectedChar == '\t' && actualChar == ',') {
121+
if (expectedChar == Delimiter.TAB.getValue() && actualChar == Delimiter.COMMA.getValue()) {
122122
throw new IllegalArgumentException(
123123
"Delimiter mismatch: bracket declares tab, brace fields use comma");
124124
}
125-
if (expectedChar == '|' && actualChar == ',') {
125+
if (expectedChar == Delimiter.PIPE.getValue() && actualChar == Delimiter.COMMA.getValue()) {
126126
throw new IllegalArgumentException(
127127
"Delimiter mismatch: bracket declares pipe, brace fields use comma");
128128
}
129-
if (expectedChar == ',' && (actualChar == '\t' || actualChar == '|')) {
129+
if (expectedChar == Delimiter.COMMA.getValue() &&
130+
(actualChar == Delimiter.TAB.getValue() || actualChar == Delimiter.PIPE.getValue())) {
130131
throw new IllegalArgumentException(
131132
"Delimiter mismatch: bracket declares comma, brace fields use different delimiter");
132133
}

src/test/java/dev/toonformat/jtoon/decoder/ArrayDecoderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void expectsToExtractSlashFromDelimiter() {
120120
Delimiter result = ArrayDecoder.extractDelimiterFromHeader("[3|]", context);
121121

122122
// Then
123-
assertEquals("|", result.toString());
123+
assertEquals(Delimiter.PIPE.toString(), result.toString());
124124
}
125125

126126
@Test

src/test/java/dev/toonformat/jtoon/decoder/TabularArrayDecoderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ void validateKeysDelimiter() throws Exception {
172172
@DisplayName("validateKeysDelimiter get called and branches will be checked")
173173
void checkDelimiterMismatchExecution() {
174174
// Given
175-
String expectedChar = "|";
176-
String actualChar = ",";
175+
String expectedChar = Delimiter.PIPE.toString();
176+
String actualChar = Delimiter.COMMA.toString();
177177

178178
// When
179179
InvocationTargetException exception = assertThrows(InvocationTargetException.class,
@@ -187,8 +187,8 @@ void checkDelimiterMismatchExecution() {
187187
@DisplayName("validateKeysDelimiter get called and branches will be checked")
188188
void checkDelimiterMismatchExecutionWithComa() {
189189
// Given
190-
String expectedChar = ",";
191-
String actualChar = "|";
190+
String expectedChar = Delimiter.COMMA.toString();
191+
String actualChar = Delimiter.PIPE.toString();
192192

193193
// When
194194
InvocationTargetException exception = assertThrows(InvocationTargetException.class,

0 commit comments

Comments
 (0)