From 45834046dde555e9ebd1f857086134b62406403a Mon Sep 17 00:00:00 2001 From: JPilson Date: Sun, 21 Apr 2024 11:09:20 +0200 Subject: [PATCH] feat: Replace Camel case uppercase with Pascal case The main modification is in `NamingConvention.java` replacing the enumeration `CAMEL_CASE_UPPERCASE` with `PASCAL_CASE`. This change can help to improve the readability of the code by reducing the verbosity of names and ensure convention consistency. Also, a new test file `NamingConventionTest.java` has been introduced to ensure correctness and stability of the code against these modifications. --- .../settings/presets/NamingConvention.java | 4 +-- .../settings/NamingConventionTest.java | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/test/java/de/marhali/easyi18n/settings/NamingConventionTest.java diff --git a/src/main/java/de/marhali/easyi18n/settings/presets/NamingConvention.java b/src/main/java/de/marhali/easyi18n/settings/presets/NamingConvention.java index 48db48a..71aa619 100644 --- a/src/main/java/de/marhali/easyi18n/settings/presets/NamingConvention.java +++ b/src/main/java/de/marhali/easyi18n/settings/presets/NamingConvention.java @@ -10,7 +10,7 @@ */ public enum NamingConvention { CAMEL_CASE("Camel Case"), - CAMEL_CASE_UPPERCASE("Camel Case (Uppercase)"), + PASCAL_CASE("Pascal Case"), SNAKE_CASE("Snake Case"), SNAKE_CASE_UPPERCASE("Snake Case (Uppercase)"); @@ -76,7 +76,7 @@ static public String convertKeyToConvention(String key, NamingConvention convent yield formatToSnakeCase(newKey, true); case CAMEL_CASE: yield formatToCamelCase(newKey, false); - case CAMEL_CASE_UPPERCASE: + case PASCAL_CASE: yield formatToCamelCase(newKey, true); }; diff --git a/src/test/java/de/marhali/easyi18n/settings/NamingConventionTest.java b/src/test/java/de/marhali/easyi18n/settings/NamingConventionTest.java new file mode 100644 index 0000000..72e0d3d --- /dev/null +++ b/src/test/java/de/marhali/easyi18n/settings/NamingConventionTest.java @@ -0,0 +1,35 @@ +package de.marhali.easyi18n.settings; + +import com.intellij.testFramework.fixtures.BasePlatformTestCase; +import de.marhali.easyi18n.settings.presets.NamingConvention; + +import java.io.IOException; + +public class NamingConventionTest extends BasePlatformTestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + public void testConvertToNamingConvention() throws IOException { + assertEquals("helloWorld", NamingConvention.convertKeyToConvention("Hello World", NamingConvention.CAMEL_CASE)); + assertEquals("hello_world", NamingConvention.convertKeyToConvention("Hello World", NamingConvention.SNAKE_CASE)); + assertEquals("HelloWorld", NamingConvention.convertKeyToConvention("Hello World", NamingConvention.PASCAL_CASE)); + assertEquals("HELLO_WORLD", NamingConvention.convertKeyToConvention("Hello World", NamingConvention.SNAKE_CASE_UPPERCASE)); + } + + public void testGetEnumNames() throws Exception { + String[] expected = {"Camel Case", "Pascal Case", "Snake Case", "Snake Case (Uppercase)"}; + String[] actual = NamingConvention.getEnumNames(); + assertEquals(expected.length, actual.length); + } + + + public void testFromString() { + assertEquals(NamingConvention.CAMEL_CASE, NamingConvention.fromString("Camel Case")); + assertEquals(NamingConvention.PASCAL_CASE, NamingConvention.fromString("Pascal Case")); + assertEquals(NamingConvention.SNAKE_CASE, NamingConvention.fromString("Snake Case")); + assertEquals(NamingConvention.SNAKE_CASE_UPPERCASE, NamingConvention.fromString("Snake Case (Uppercase)")); + assertEquals(NamingConvention.CAMEL_CASE, NamingConvention.fromString("Invalid Input")); + } +}