Skip to content

Commit

Permalink
pre-processor keys no longer accept underscores; pre-processor interp…
Browse files Browse the repository at this point in the history
…olations no longer accept hyphens
  • Loading branch information
BlvckBytes committed Oct 20, 2024
1 parent bb08e30 commit 62c0e84
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private boolean isValidSubstitutionChar(char c) {
return (
(c >= 'a' && c <= 'z') ||
(c >= '0' && c <= '9') ||
c == '_' || c == '-'
c == '_'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ private PreProcessorLine parseLine(String line, int lineNumber, List<CommentLine
if (!(
(keyChar >= 'A' && keyChar <= 'Z') ||
(keyChar >= '0' && keyChar <= '9') ||
keyChar == '-' ||
keyChar == '_'
keyChar == '-'
))
throw new PreProcessorInputException(lineNumber, InputConflict.INVALID_KEY_CHARACTERS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ public void shouldParseInput() throws IOException {
var processorInput = parseInputFile("/preprocessor/input.txt");

assertEquals(7, processorInput.getKeys().size());
assertEquals("Value of the first key", processorInput.getValue("FIRST_KEY"));
assertEquals(" Value of the second key", processorInput.getValue("SECOND_KEY"));
assertEquals(" Value of the third key ", processorInput.getValue("THIRD_KEY"));
assertEquals("\\ Value of the fourth key \\", processorInput.getValue("FOURTH_KEY"));
assertEquals("\\\\Value of the fifth key\\\\", processorInput.getValue("5TH_KEY"));
assertEquals("\\", processorInput.getValue("6TH_KEY"));
assertEquals("\\\\", processorInput.getValue("7TH_KEY"));
assertEquals("Value of the first key", processorInput.getValue("FIRST-KEY"));
assertEquals(" Value of the second key", processorInput.getValue("SECOND-KEY"));
assertEquals(" Value of the third key ", processorInput.getValue("THIRD-KEY"));
assertEquals("\\ Value of the fourth key \\", processorInput.getValue("FOURTH-KEY"));
assertEquals("\\\\Value of the fifth key\\\\", processorInput.getValue("5TH-KEY"));
assertEquals("\\", processorInput.getValue("6TH-KEY"));
assertEquals("\\\\", processorInput.getValue("7TH-KEY"));
}

@Test
public void shouldThrowOnMalformedInput() {
makeInputExceptionCase("lowercase-key test value", InputConflict.INVALID_KEY_CHARACTERS);
makeInputExceptionCase("illègal_chärs test value", InputConflict.INVALID_KEY_CHARACTERS);
makeInputExceptionCase("NO_VALUE", InputConflict.BLANK_VALUE);
makeInputExceptionCase("EMPTY_VALUE ", InputConflict.BLANK_VALUE);
makeInputExceptionCase("BLANK_VALUE ", InputConflict.BLANK_VALUE);
makeInputExceptionCase("NO-VALUE", InputConflict.BLANK_VALUE);
makeInputExceptionCase("EMPTY-VALUE ", InputConflict.BLANK_VALUE);
makeInputExceptionCase("BLANK-VALUE ", InputConflict.BLANK_VALUE);
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions src/test/resources/preprocessor/base.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
simpleKey: '@{KEY_A}'
simpleKey: '@{KEY-A}'
multilineValue$: |
hello world @{KEY_B}
hello world @{KEY-B}
multilineList:
- |
hello world
test
@{KEY_C}
@{KEY-C}
another line
14 changes: 7 additions & 7 deletions src/test/resources/preprocessor/input.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# This is a comment

FIRST_KEY Value of the first key
SECOND_KEY \ Value of the second key
FIRST-KEY Value of the first key
SECOND-KEY \ Value of the second key
# Comment attached to third key
THIRD_KEY \ Value of the third key \
THIRD-KEY \ Value of the third key \

# Dangling comment in the middle

# Comment attached to fourth key
FOURTH_KEY \\ Value of the fourth key \\
5TH_KEY \\Value of the fifth key\\
FOURTH-KEY \\ Value of the fourth key \\
5TH-KEY \\Value of the fifth key\\

6TH_KEY \
7TH_KEY \\
6TH-KEY \
7TH-KEY \\

# Dangling comment at the end
10 changes: 5 additions & 5 deletions src/test/resources/preprocessor/migration_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# - var_a: TypeA
# - var_b: TypeB
# - var_c: TypeC
KEY_A Value A
KEY-A Value A

# This is key b
# - var_a: TypeA
# - var_x: TypeX
KEY_B Value B
KEY_Y Value Y
KEY_DISCONTINUED This one will be left untouched
KEY-B Value B
KEY-Y Value Y
KEY-DISCONTINUED This one will be left untouched

# This is key c
KEY_C Value C
KEY-C Value C
22 changes: 11 additions & 11 deletions src/test/resources/preprocessor/migration_result.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
KEY_VERY_TOP_1 Value very top 1
KEY_VERY_TOP_2 Value very top 2
KEY-VERY-TOP-1 Value very top 1
KEY-VERY-TOP-2 Value very top 2

# This is key a
# - var_a: TypeA
# - var_b: TypeB
# - var_c: TypeC
# - var_d: TypeD
KEY_A Value A
KEY_NEAR_TO_A Value near to a
KEY-A Value A
KEY-NEAR-TO-A Value near to a

# This is key b
# - var_b: TypeB
# - var_a: TypeUpdated
KEY_B Value B
KEY_NEAR_TO_B_1 Value near to b 1
KEY_NEAR_TO_B_2 Value near to b 2
KEY_Y Value Y
KEY_DISCONTINUED This one will be left untouched
KEY-B Value B
KEY-NEAR-TO-B-1 Value near to b 1
KEY-NEAR-TO-B-2 Value near to b 2
KEY-Y Value Y
KEY-DISCONTINUED This one will be left untouched

# This is key c
# - var_y: TypeY
KEY_C Value C
KEY-C Value C

KEY_AT_BOTTOM Value at bottom
KEY-AT-BOTTOM Value at bottom
20 changes: 10 additions & 10 deletions src/test/resources/preprocessor/migration_updated.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
KEY_VERY_TOP_1 Value very top 1
KEY_VERY_TOP_2 Value very top 2
KEY-VERY-TOP-1 Value very top 1
KEY-VERY-TOP-2 Value very top 2

# This is key a
# - var_d: TypeD
# - var_a: TypeA
# - var_b: TypeB
# - var_c: TypeC
KEY_A Value A
KEY_NEAR_TO_A Value near to a
KEY-A Value A
KEY-NEAR-TO-A Value near to a

# This is key b
# - var_b: TypeB
# - var_a: TypeUpdated
KEY_B Value B
KEY_NEAR_TO_B_1 Value near to b 1
KEY_NEAR_TO_B_2 Value near to b 2
KEY_Y Value Y
KEY-B Value B
KEY-NEAR-TO-B-1 Value near to b 1
KEY-NEAR-TO-B-2 Value near to b 2
KEY-Y Value Y

# This is key c
# - var_y: TypeY
KEY_C Value C
KEY-C Value C

KEY_AT_BOTTOM Value at bottom
KEY-AT-BOTTOM Value at bottom
6 changes: 3 additions & 3 deletions src/test/resources/preprocessor/substitution_input.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
KEY_A value a
KEY_B value b
KEY_C before {x} after
KEY-A value a
KEY-B value b
KEY-C before {x} after

0 comments on commit 62c0e84

Please sign in to comment.