From cc5e082b458e224df0d85ed772c6500f60b38cf7 Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 15 Feb 2025 15:48:55 +0900 Subject: [PATCH 1/2] new!: added camelCaseWithOptions, updated camelCase to use it, and deprecated camelCaseWithSep/Keep --- .../com/github/sttk/stringcase/Options.java | 56 + .../github/sttk/stringcase/StringCase.java | 300 ++-- .../sttk/stringcase/StringCaseTest.java | 254 ---- .../stringcase/StringCase_CamelCaseTest.java | 1344 +++++++++++++++++ 4 files changed, 1493 insertions(+), 461 deletions(-) create mode 100644 src/main/java/com/github/sttk/stringcase/Options.java create mode 100644 src/test/java/com/github/sttk/stringcase/StringCase_CamelCaseTest.java diff --git a/src/main/java/com/github/sttk/stringcase/Options.java b/src/main/java/com/github/sttk/stringcase/Options.java new file mode 100644 index 0000000..027627b --- /dev/null +++ b/src/main/java/com/github/sttk/stringcase/Options.java @@ -0,0 +1,56 @@ +/* + * Options class. + * Copyright (C) 2025 Takayuki Sato. All Rights Reserved. + */ +package com.github.sttk.stringcase; + +/** + * Is a class that represents options which specifies the ways of case conversion of strings. + */ +public class Options { + /** + * Specifies whether to treat the beginning of a sequence of non-alphabetical characters as a + * word boundary. + */ + public final boolean separateBeforeNonAlphabets; + + /** + * Specifies whether to treat the end of a sequence of non-alphabetical characters as a word + * boundary. + */ + public final boolean separateAfterNonAlphabets; + + /** + * Specifies the set of characters to be treated as word separators and removed from the result + * string. + */ + public final String separators; + + /** + * Specifies the set of characters not to be treated as word separators and kept in the result + * string. + */ + public final String keep; + + /** + * The constructor which takes the arguments that specifies the ways of case conversion. + * + * @param separateBeforeNonAlphabets The flag that specifies whether to treat the beginning of + * a sequence of non-alphabetical characters as a word boundary. + * @param separateAfterNonAlphabets The flag that specifies whether to treat the end of a + * sequence of non-alphabetical characters as a word boundary. + * @param separators The symbol characters to be treated as word separators and removed from + * the result string. + * @param keep The symbol characters tobe treated as word separators and kept in the result + * string. + */ + public Options( + boolean separateBeforeNonAlphabets, boolean separateAfterNonAlphabets, + String separators, String keep + ) { + this.separateBeforeNonAlphabets = separateBeforeNonAlphabets; + this.separateAfterNonAlphabets = separateAfterNonAlphabets; + this.separators = separators; + this.keep = keep; + } +} diff --git a/src/main/java/com/github/sttk/stringcase/StringCase.java b/src/main/java/com/github/sttk/stringcase/StringCase.java index aa6b318..777bce3 100644 --- a/src/main/java/com/github/sttk/stringcase/StringCase.java +++ b/src/main/java/com/github/sttk/stringcase/StringCase.java @@ -1,6 +1,6 @@ /* * StringCase class. - * Copyright (C) 2024 Takayuki Sato. All Rights Reserved. + * Copyright (C) 2024-2025 Takayuki Sato. All Rights Reserved. */ package com.github.sttk.stringcase; @@ -9,84 +9,100 @@ import java.util.Arrays; /** - * {@code StringCase} is the class that provides the static methods to convert - * a string to various cases. + * Is the class that provides the static methods to convert a string to following cases. + * + * - camelCase + * - COBOL-CASE + * - kebab-case + * - MACRO_CASE + * - PascalCase + * - snake_case + * - Train-Case */ public final class StringCase { private StringCase() {} + private enum ChIs { + FirstOfStr, + NextOfUpper, + NextOfContdUpper, + NextOfSepMark, + NextOfKeptMark, + Others, + } + /** - * Converts a string to camel case. - * - * This method takes a string as its arguments, then returns a string of - * which the case style is camel case. - * - * This method targets only the upper and lower cases of ASCII alphabets for - * capitalization, and all characters except ASCII alphabets and ASCII - * numbers are eliminated as word separators. + * Converts the input string to camel case with the specified options. * - *
{@code
-   *     String camel = StringCase.camelCase("foo_bar_baz");
-   *     // => "fooBarBaz"
-   * }
- * - * @param input A string to be converted. + * @param input The input string. + * @param opts The options which specifies the ways of case conversion. * @return A string converted to camel case. */ - public static String camelCase(String input) { + public static String camelCaseWithOptions(String input, Options opts) { var result = new CodepointBuffer(input.length()); - enum ChIs { - FirstOfStr, - InFirstWord, - NextOfUpper, - NextOfMark, - Others, - } var flag = ChIs.FirstOfStr; + int[] sepChs = null; + if (opts.separators != null && !opts.separators.isEmpty()) { + sepChs = opts.separators.codePoints().toArray(); + Arrays.sort(sepChs); + } + + int[] keptChs = null; + if (opts.keep != null && !opts.keep.isEmpty()) { + keptChs = opts.keep.codePoints().toArray(); + Arrays.sort(keptChs); + } + for (int ch : input.codePoints().toArray()) { if (Ascii.isUpperCase(ch)) { - switch (flag) { - case ChIs.FirstOfStr: - case ChIs.InFirstWord: + if (flag == ChIs.FirstOfStr) { result.append(Ascii.toLowerCase(ch)); - flag = ChIs.InFirstWord; - break; - case ChIs.NextOfUpper: + flag = ChIs.NextOfUpper; + } else if (flag == ChIs.NextOfUpper || flag == ChIs.NextOfContdUpper || + (!opts.separateAfterNonAlphabets && flag == ChIs.NextOfKeptMark)) { result.append(Ascii.toLowerCase(ch)); - //flag = ChIs.NextOfUpper; - break; - default: + flag = ChIs.NextOfContdUpper; + } else { result.append(ch); flag = ChIs.NextOfUpper; - break; } } else if (Ascii.isLowerCase(ch)) { - switch (flag) { - case ChIs.NextOfUpper: + if (flag == ChIs.NextOfContdUpper) { int prev = result.last(); if (Ascii.isLowerCase(prev)) { prev = Ascii.toUpperCase(prev); } result.replaceLast(prev, ch); - flag = ChIs.Others; - break; - case ChIs.NextOfMark: + } else if (flag == ChIs.NextOfSepMark || + (opts.separateAfterNonAlphabets && flag == ChIs.NextOfKeptMark)) { result.append(Ascii.toUpperCase(ch)); - flag = ChIs.NextOfUpper; - break; - default: + } else { result.append(ch); - flag = ChIs.Others; - break; } - } else if (Ascii.isDigit(ch)) { - result.append(ch); - flag = ChIs.NextOfMark; + flag = ChIs.Others; } else { - if (flag != ChIs.FirstOfStr) { - flag = ChIs.NextOfMark; + var isKeptChar = false; + if (Ascii.isDigit(ch)) { + isKeptChar = true; + } else if (sepChs != null) { + if (Arrays.binarySearch(sepChs, ch) < 0) { + isKeptChar = true; + } + } else if (keptChs != null) { + if (Arrays.binarySearch(keptChs, ch) >= 0) { + isKeptChar = true; + } + } + + if (isKeptChar) { + result.append(ch); + flag = ChIs.NextOfKeptMark; + } else { + if (flag != ChIs.FirstOfStr) { + flag = ChIs.NextOfSepMark; + } } } } @@ -95,174 +111,44 @@ enum ChIs { } /** - * Converts a string to camel case using the specified characters as - * separators. - * - * This method takes a string as its argument, then returns a string of which - * the case style is camel case. - * - * This method targets only the upper and lower cases of ASCII alphabets for - * capitalization, and the characters specified as the second argument of - * this method are regarded as word separators and are eliminated. - * - *
{@code
-   *     String camel = StringCase.camelCaseWithSep("foo-bar100%baz", "- ");
-   *     // => "fooBar100%Baz"
-   * }
+ * Converts the input string to camel case. + *

+ * It treats the end of a sequence of non-alphabetical characters as a word boundary, but not + * the beginning. * - * @param input A string to be converted. - * @param seps A string that consists of characters that are word - * separators. + * @param input The input string. * @return A string converted to camel case. */ - public static String camelCaseWithSep(String input, String seps) { - var result = new CodepointBuffer(input.length()); - - var sepChs = seps.codePoints().toArray(); - Arrays.sort(sepChs); - - enum ChIs { - FirstOfStr, - InFirstWord, - NextOfUpper, - NextOfMark, - Others, - } - var flag = ChIs.FirstOfStr; - - for (int ch : input.codePoints().toArray()) { - if (Arrays.binarySearch(sepChs, ch) >= 0) { - if (flag != ChIs.FirstOfStr) { - flag = ChIs.NextOfMark; - } - } else if (Ascii.isUpperCase(ch)) { - switch (flag) { - case ChIs.FirstOfStr: - case ChIs.InFirstWord: - result.append(Ascii.toLowerCase(ch)); - flag = ChIs.InFirstWord; - break; - case ChIs.NextOfUpper: - result.append(Ascii.toLowerCase(ch)); - //flag = ChIs.NextOfUpper; - break; - default: - result.append(ch); - flag = ChIs.NextOfUpper; - break; - } - } else if (Ascii.isLowerCase(ch)) { - switch (flag) { - case ChIs.NextOfUpper: - int prev = result.last(); - if (Ascii.isLowerCase(prev)) { - prev = Ascii.toUpperCase(prev); - } - result.replaceLast(prev, ch); - flag = ChIs.Others; - break; - case ChIs.NextOfMark: - result.append(Ascii.toUpperCase(ch)); - flag = ChIs.NextOfUpper; - break; - default: - result.append(ch); - flag = ChIs.Others; - break; - } - } else { - result.append(ch); - flag = ChIs.NextOfMark; - } - } - - return result.toString(); + public static String camelCase(String input) { + return camelCaseWithOptions(input, new Options(false, true, null, null)); } /** - * Converts a string to camel case using characters other than the specified - * characters as separators. - * - * This method takes a string as its argument, then returns a string of which - * the case style is camel case. + * Converts the input string to camel case with the specified separator characters. * - * This method targets only the upper and lower cases of ASCII alphabets for - * capitalization, and the characters other than the specified characters as - * the second argument of this method are regarded as word separators and - * are eliminated. + * @param input The input string. + * @param seps The symbol characters to be treated as separators. + * @return A string converted to camel case. * - *

{@code
-   *     String camel = StringCase.camelCaseWithKeep("foo-bar100%baz", "%");
-   *     // => "fooBar100%Baz"
-   * }
+ * @deprecated Should use CamelCaseWithOptions instead + */ + @Deprecated + public static String camelCaseWithSep(String input, String seps) { + return camelCaseWithOptions(input, new Options(false, true, seps, null)); + } + + /** + * Converts the input string to camel case with the specified characters to be kept. * - * @param input A string to be converted. - * @param keeped A string that consists of characters that are not word - * separators. + * @param input The input string. + * @param kept The symbol characters not to be treated as separators. * @return A string converted to camel case. + * + * @deprecated Should use CamelCaseWithOptions instead */ - public static String camelCaseWithKeep(String input, String keeped) { - var result = new CodepointBuffer(input.length()); - - var keepChs = keeped.codePoints().toArray(); - Arrays.sort(keepChs); - - enum ChIs { - FirstOfStr, - InFirstWord, - NextOfUpper, - NextOfMark, - Others, - } - var flag = ChIs.FirstOfStr; - - for (int ch : input.codePoints().toArray()) { - if (Ascii.isUpperCase(ch)) { - switch (flag) { - case ChIs.FirstOfStr: - case ChIs.InFirstWord: - result.append(Ascii.toLowerCase(ch)); - flag = ChIs.InFirstWord; - break; - case ChIs.NextOfUpper: - result.append(Ascii.toLowerCase(ch)); - //flag = ChIs.NextOfUpper; - break; - default: - result.append(ch); - flag = ChIs.NextOfUpper; - break; - } - } else if (Ascii.isLowerCase(ch)) { - switch (flag) { - case ChIs.NextOfUpper: - int prev = result.last(); - if (Ascii.isLowerCase(prev)) { - prev = Ascii.toUpperCase(prev); - } - result.replaceLast(prev, ch); - flag = ChIs.Others; - break; - case ChIs.NextOfMark: - result.append(Ascii.toUpperCase(ch)); - flag = ChIs.NextOfUpper; - break; - default: - result.append(ch); - flag = ChIs.Others; - break; - } - } else if (Ascii.isDigit(ch) || Arrays.binarySearch(keepChs, ch) >= 0 ) { - result.append(ch); - flag = ChIs.NextOfMark; - } else { - if (flag != ChIs.FirstOfStr) { - flag = ChIs.NextOfMark; - } - } - } - - return result.toString(); + @Deprecated + public static String camelCaseWithKeep(String input, String kept) { + return camelCaseWithOptions(input, new Options(false, true, null, kept)); } /** diff --git a/src/test/java/com/github/sttk/stringcase/StringCaseTest.java b/src/test/java/com/github/sttk/stringcase/StringCaseTest.java index 3893f34..47b2790 100644 --- a/src/test/java/com/github/sttk/stringcase/StringCaseTest.java +++ b/src/test/java/com/github/sttk/stringcase/StringCaseTest.java @@ -12,260 +12,6 @@ public class StringCaseTest { private StringCaseTest() {} - // camel case - - @Nested - class CamelCase { - @Test - void fromCamelCase() { - var result = camelCase("abcDefGHIjk"); - assertThat(result).isEqualTo("abcDefGhIjk"); - } - - @Test - void fromPascalCase() { - var result = camelCase("AbcDefGHIjk"); - assertThat(result).isEqualTo("abcDefGhIjk"); - } - - @Test - void fromSnakeCase() { - var result = camelCase("abc_def_ghi"); - assertThat(result).isEqualTo("abcDefGhi"); - } - - @Test - void fromKebabCase() { - var result = camelCase("abc-def-ghi"); - assertThat(result).isEqualTo("abcDefGhi"); - } - - @Test - void fromTrainCase() { - var result = camelCase("Abc-Def-Ghi"); - assertThat(result).isEqualTo("abcDefGhi"); - } - - @Test - void fromMacroCase() { - var result = camelCase("ABC_DEF_GHI"); - assertThat(result).isEqualTo("abcDefGhi"); - } - - @Test - void fromCobolCase() { - var result = camelCase("ABC-DEF-GHI"); - assertThat(result).isEqualTo("abcDefGhi"); - } - - @Test - void keepDigits() { - var result = camelCase("abc123-456defG789HIJklMN12"); - assertThat(result).isEqualTo("abc123456DefG789HiJklMn12"); - } - - @Test - void convertWhenStartingWithDigit() { - var result = camelCase("123abc456def"); - assertThat(result).isEqualTo("123Abc456Def"); - - result = camelCase("123ABC456DEF"); - assertThat(result).isEqualTo("123Abc456Def"); - } - - @Test - void treatMarksAsSeparators() { - var result = camelCase(":.abc~!@def#$ghi%&jk(lm)no/?"); - assertThat(result).isEqualTo("abcDefGhiJkLmNo"); - } - - @Test - void convertEmpty() { - var result = camelCase(""); - assertThat(result).isEqualTo(""); - } - } - - @Nested - class CamelCaseWithSep { - @Test - void fromCamelCase() { - var result = camelCaseWithSep("abcDefGHIjk", "_-"); - assertThat(result).isEqualTo("abcDefGhIjk"); - } - - @Test - void fromPascalCase() { - var result = camelCaseWithSep("AbcDefGHIjk", "_-"); - assertThat(result).isEqualTo("abcDefGhIjk"); - } - - @Test - void fromSnakeCase() { - var result = camelCaseWithSep("abc_def_ghi", "_"); - assertThat(result).isEqualTo("abcDefGhi"); - - result = camelCaseWithSep("abc_def_ghi", "-"); - assertThat(result).isEqualTo("abc_Def_Ghi"); - } - - @Test - void fromKebabCase() { - var result = camelCaseWithSep("abc-def-ghi", "-"); - assertThat(result).isEqualTo("abcDefGhi"); - - result = camelCaseWithSep("abc-def-ghi", "_"); - assertThat(result).isEqualTo("abc-Def-Ghi"); - } - - @Test - void fromTrainCase() { - var result = camelCaseWithSep("Abc-Def-Ghi", "-"); - assertThat(result).isEqualTo("abcDefGhi"); - - result = camelCaseWithSep("Abc-Def-Ghi", "_"); - assertThat(result).isEqualTo("abc-Def-Ghi"); - } - - @Test - void fromMacroCase() { - var result = camelCaseWithSep("ABC_DEF_GHI", "_"); - assertThat(result).isEqualTo("abcDefGhi"); - - result = camelCaseWithSep("ABC_DEF_GHI", "-"); - assertThat(result).isEqualTo("abc_Def_Ghi"); - } - - @Test - void fromCobolCase() { - var result = camelCaseWithSep("ABC-DEF-GHI", "-"); - assertThat(result).isEqualTo("abcDefGhi"); - - result = camelCaseWithSep("ABC-DEF-GHI", "_"); - assertThat(result).isEqualTo("abc-Def-Ghi"); - } - - @Test - void keepDigits() { - var result = camelCaseWithSep("abc123-456defG789HIJklMN12", "_"); - assertThat(result).isEqualTo("abc123-456DefG789HiJklMn12"); - - result = camelCaseWithSep("abc123-456defG789HIJklMN12", "-"); - assertThat(result).isEqualTo("abc123456DefG789HiJklMn12"); - } - - @Test - void convertWhenStartingWithDigit() { - var result = camelCaseWithSep("123abc456def", "-_"); - assertThat(result).isEqualTo("123Abc456Def"); - - result = camelCaseWithSep("123ABC456DEF", "-_"); - assertThat(result).isEqualTo("123Abc456Def"); - } - - @Test - void treatMarksAsSeparators() { - var result = camelCaseWithSep(":.abc~!@def#$ghi%&jk(lm)no/?", ":@$&()/"); - assertThat(result).isEqualTo(".Abc~!Def#Ghi%JkLmNo?"); - } - - @Test - void convertEmpty() { - var result = camelCaseWithSep("", "-_"); - assertThat(result).isEqualTo(""); - } - } - - @Nested - class CamelCaseWithKeep { - @Test - void fromCamelCase() { - var result = camelCaseWithKeep("abcDefGHIjk", "_-"); - assertThat(result).isEqualTo("abcDefGhIjk"); - } - - @Test - void fromPascalCase() { - var result = camelCaseWithKeep("AbcDefGHIjk", "_-"); - assertThat(result).isEqualTo("abcDefGhIjk"); - } - - @Test - void fromSnakeCase() { - var result = camelCaseWithKeep("abc_def_ghi", "-"); - assertThat(result).isEqualTo("abcDefGhi"); - - result = camelCaseWithKeep("abc_def_ghi", "_"); - assertThat(result).isEqualTo("abc_Def_Ghi"); - } - - @Test - void fromKebabCase() { - var result = camelCaseWithKeep("abc-def-ghi", "_"); - assertThat(result).isEqualTo("abcDefGhi"); - - result = camelCaseWithKeep("abc-def-ghi", "-"); - assertThat(result).isEqualTo("abc-Def-Ghi"); - } - - @Test - void fromTrainCase() { - var result = camelCaseWithKeep("Abc-Def-Ghi", "_"); - assertThat(result).isEqualTo("abcDefGhi"); - - result = camelCaseWithKeep("Abc-Def-Ghi", "-"); - assertThat(result).isEqualTo("abc-Def-Ghi"); - } - - @Test - void fromMacroCase() { - var result = camelCaseWithKeep("ABC_DEF_GHI", "-"); - assertThat(result).isEqualTo("abcDefGhi"); - - result = camelCaseWithKeep("ABC_DEF_GHI", "_"); - assertThat(result).isEqualTo("abc_Def_Ghi"); - } - - @Test - void fromCobolCase() { - var result = camelCaseWithKeep("ABC-DEF-GHI", "_"); - assertThat(result).isEqualTo("abcDefGhi"); - - result = camelCaseWithKeep("ABC-DEF-GHI", "-"); - assertThat(result).isEqualTo("abc-Def-Ghi"); - } - - @Test - void keepDigits() { - var result = camelCaseWithKeep("abc123-456defG789HIJklMN12", "-"); - assertThat(result).isEqualTo("abc123-456DefG789HiJklMn12"); - - result = camelCaseWithKeep("abc123-456defG789HIJklMN12", "_"); - assertThat(result).isEqualTo("abc123456DefG789HiJklMn12"); - } - - @Test - void convertWhenStartingWithDigit() { - var result = camelCaseWithKeep("123abc456def", "_"); - assertThat(result).isEqualTo("123Abc456Def"); - - result = camelCaseWithKeep("123ABC456DEF", "-"); - assertThat(result).isEqualTo("123Abc456Def"); - } - - @Test - void treatMarksAsSeparators() { - var result = camelCaseWithKeep(":.abc~!@def#$ghi%&jk(lm)no/?", ".~!#%?"); - assertThat(result).isEqualTo(".Abc~!Def#Ghi%JkLmNo?"); - } - - @Test - void convertEmpty() { - var result = camelCaseWithKeep("", "-_"); - assertThat(result).isEqualTo(""); - } - } - // cobol case @Nested diff --git a/src/test/java/com/github/sttk/stringcase/StringCase_CamelCaseTest.java b/src/test/java/com/github/sttk/stringcase/StringCase_CamelCaseTest.java new file mode 100644 index 0000000..4a44cc5 --- /dev/null +++ b/src/test/java/com/github/sttk/stringcase/StringCase_CamelCaseTest.java @@ -0,0 +1,1344 @@ +package com.github.sttk.stringcase; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.fail; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Nested; + +import static com.github.sttk.stringcase.StringCase.*; + +import static java.lang.Character.codePointAt; + +@SuppressWarnings("missing-explicit-ctor") +public class StringCase_CamelCaseTest { + + @Nested + class CamelCase { + @Test + void convertCamelCase() { + var result = camelCase("abcDefGHIjk"); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var result = camelCase("AbcDefGHIjk"); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var result = camelCase("abc_def_ghi"); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertKebabCase() { + var result = camelCase("abc-def-ghi"); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertTrainCase() { + var result = camelCase("Abc-Def-Ghi"); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertMacroCase() { + var result = camelCase("ABC_DEF_GHI"); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertCobolCase() { + var result = camelCase("ABC-DEF-GHI"); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertWithKeepingDigits() { + var result = camelCase("abc123-456defG89HIJklMN12"); + assertThat(result).isEqualTo("abc123456DefG89HiJklMn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var result = camelCase(":.abc~!@def#$ghi%&jk(lm)no/?"); + assertThat(result).isEqualTo("abcDefGhiJkLmNo"); + } + + @Test + void convertWhenStartingWithDigit() { + var result = camelCase("123abc456def"); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCase("123ABC456DEF"); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCase("123Abc456Def"); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var result = camelCase(""); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class CamelCaseWithOptions { + @Nested + class NonAlphabetsAsHeadOfWord { + @Test + void convertCamelCase() { + var opts = new Options(true, false, null, null); + var result = camelCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, false, null, null); + var result = camelCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, false, null, null); + var result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, false, null, null); + var result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, false, null, null); + var result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, false, null, null); + var result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, false, null, null); + var result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, false, null, null); + var result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123456defG89hiJklMn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(true, false, null, null); + var result = camelCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo("abcDefGhiJkLmNo"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(true, false, null, null); + var result = camelCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = camelCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = camelCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, false, null, null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsTailOfWord { + @Test + void convertCamelCase() { + var opts = new Options(false, true, null, null); + var result = camelCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, true, null, null); + var result = camelCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, true, null, null); + var result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, true, null, null); + var result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, true, null, null); + var result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, true, null, null); + var result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, true, null, null); + var result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, true, null, null); + var result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123456DefG89HiJklMn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, true, null, null); + var result = camelCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo("abcDefGhiJkLmNo"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(false, true, null, null); + var result = camelCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, true, null, null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsWord { + @Test + void convertCamelCase() { + var opts = new Options(true, true, null, null); + var result = camelCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, true, null, null); + var result = camelCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, true, null, null); + var result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, true, null, null); + var result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, true, null, null); + var result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, true, null, null); + var result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, true, null, null); + var result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, true, null, null); + var result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123456DefG89HiJklMn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(true, true, null, null); + var result = camelCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo("abcDefGhiJkLmNo"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(true, true, null, null); + var result = camelCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, true, null, null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsPartAsWord { + @Test + void convertCamelCase() { + var opts = new Options(false, false, null, null); + var result = camelCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, false, null, null); + var result = camelCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, false, null, null); + var result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, false, null, null); + var result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, false, null, null); + var result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, false, null, null); + var result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, false, null, null); + var result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, false, null, null); + var result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123456defG89hiJklMn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, false, null, null); + var result = camelCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo("abcDefGhiJkLmNo"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(false, false, null, null); + var result = camelCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = camelCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = camelCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, false, null, null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsHeadOfWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(true, false, "-_", null); + var result = camelCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, false, "-_", null); + var result = camelCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, false, "_", null); + var result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, false, "-", null); + result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc_def_ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, false, "-", null); + var result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, false, "_", null); + result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, false, "-", null); + var result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, false, "_", null); + result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, false, "_", null); + var result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, false, "-", null); + result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc_def_ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, false, "-", null); + var result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, false, "_", null); + result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, false, "-", null); + var result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123456defG89hiJklMn12"); + + opts = new Options(true, false, "_", null); + result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456defG89hiJklMn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(true, false, ":@$&()/", null); + var result = camelCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo(".abc~!Def#Ghi%JkLmNo?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(true, false, "-", null); + var result = camelCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = camelCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = camelCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, false, null, null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(true, false, "-b2", null); + var result = camelCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("abc123def"); + } + } + + @Nested + class NonAlphabetsAsTailOfWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(false, true, "-_", null); + var result = camelCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, true, "-_", null); + var result = camelCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, true, "_", null); + var result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, true, "-", null); + result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc_Def_Ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, true, "-", null); + var result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, true, "_", null); + result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, true, "-", null); + var result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, true, "_", null); + result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, true, "_", null); + var result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, true, "-", null); + result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc_Def_Ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, true, "-", null); + var result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, true, "_", null); + result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, true, "-", null); + var result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123456DefG89HiJklMn12"); + + opts = new Options(false, true, "_", null); + result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456DefG89HiJklMn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, true, ":@$&()/", null); + var result = camelCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo(".Abc~!Def#Ghi%JkLmNo?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(false, true, "-", null); + var result = camelCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, true, "-_", null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(false, true, "-b2", null); + var result = camelCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("abc123Def"); + } + } + + @Nested + class NonAlphabetsAsWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(true, true, "-_", null); + var result = camelCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, true, "-_", null); + var result = camelCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, true, "_", null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + + opts = new Options(true, true, "-", null); + result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, true, "-", null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + + opts = new Options(true, true, "_", null); + result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, true, "-", null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + + opts = new Options(true, true, "_", null); + result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, true, "_", null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + + opts = new Options(true, true, "-", null); + result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, true, "-", null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + + opts = new Options(true, true, "_", null); + result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, true, "-", null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + + opts = new Options(true, true, "_", null); + result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(true, true, ":@$&()/", null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(true, true, "-_", null); + var result = camelCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, true, "-_", null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(true, true, "-b2", null); + var result = camelCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("abc123Def"); + } + } + + @Nested + class NonAlphabetsAsPartOfWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(false, false, "-_", null); + var result = camelCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, false, "-_", null); + var result = camelCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, false, "_", null); + var result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, false, "-", null); + result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc_def_ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, false, "-", null); + var result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, false, "_", null); + result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, false, "-", null); + var result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, false, "_", null); + result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, false, "_", null); + var result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, false, "-", null); + result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc_def_ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, false, "-", null); + var result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, false, "_", null); + result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, false, "-", null); + var result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123456defG89hiJklMn12"); + + opts = new Options(false, false, "_", null); + result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456defG89hiJklMn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, false, ":@$&()/", null); + var result = camelCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo(".abc~!Def#Ghi%JkLmNo?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(false, false, "-_", null); + var result = camelCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = camelCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = camelCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, false, "-_", null); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(false, false, "-b2", null); + var result = camelCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("abc123def"); + } + } + + @Nested + class NonAlphabetsAsHeadOfWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(true, false, null, "-_"); + var result = camelCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, false, null, "-_"); + var result = camelCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, false, null, "-"); + var result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, false, null, "_"); + result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc_def_ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, false, null, "_"); + var result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, false, null, "-"); + result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, false, null, "_"); + var result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, false, null, "-"); + result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, false, null, "-"); + var result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, false, null, "_"); + result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc_def_ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, false, null, "_"); + var result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, false, null, "-"); + result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, false, null, "_"); + var result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123456defG89hiJklMn12"); + + opts = new Options(true, false, null, "-"); + result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456defG89hiJklMn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(true, false, null, ".~!#%?"); + var result = camelCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo(".abc~!Def#Ghi%JkLmNo?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(true, false, null, "-"); + var result = camelCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = camelCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = camelCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, false, null, "-_"); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsTailOfWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(false, true, null, "-_"); + var result = camelCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, true, null, "-_"); + var result = camelCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, true, null, "-"); + var result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, true, null, "_"); + result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc_Def_Ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, true, null, "_"); + var result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, true, null, "-"); + result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, true, null, "_"); + var result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, true, null, "-"); + result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, true, null, "-"); + var result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, true, null, "_"); + result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc_Def_Ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, true, null, "_"); + var result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, true, null, "-"); + result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, true, null, "_"); + var result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123456DefG89HiJklMn12"); + + opts = new Options(false, true, null, "-"); + result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456DefG89HiJklMn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, true, null, ".~!#%?"); + var result = camelCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo(".Abc~!Def#Ghi%JkLmNo?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(false, true, null, "_"); + var result = camelCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, true, null, "-_"); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(true, true, null, "-_"); + var result = camelCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, true, null, "-_"); + var result = camelCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, true, null, "-"); + var result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, true, null, "_"); + result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc_Def_Ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, true, null, "_"); + var result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, true, null, "-"); + result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, true, null, "_"); + var result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, true, null, "-"); + result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, true, null, "-"); + var result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, true, null, "_"); + result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc_Def_Ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, true, null, "_"); + var result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(true, true, null, "-"); + result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, true, null, "_"); + var result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123456DefG89HiJklMn12"); + + opts = new Options(true, true, null, "-"); + result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456DefG89HiJklMn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(true, true, null, ".~!#%?"); + var result = camelCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo(".Abc~!Def#Ghi%JkLmNo?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(true, true, null, "-_"); + var result = camelCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123Abc456Def"); + + result = camelCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, true, null, "-_"); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsPartOfWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(false, false, null, "-_"); + var result = camelCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, false, null, "-_"); + var result = camelCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abcDefGhIjk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, false, null, "-"); + var result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, false, null, "_"); + result = camelCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc_def_ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, false, null, "_"); + var result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, false, null, "-"); + result = camelCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, false, null, "_"); + var result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, false, null, "-"); + result = camelCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-Def-Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, false, null, "-"); + var result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, false, null, "_"); + result = camelCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc_def_ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, false, null, "_"); + var result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abcDefGhi"); + + opts = new Options(false, false, null, "-"); + result = camelCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, false, null, "_"); + var result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123456defG89hiJklMn12"); + + opts = new Options(false, false, null, "-"); + result = camelCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456defG89hiJklMn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, false, null, ".~!#%?"); + var result = camelCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo(".abc~!Def#Ghi%JkLmNo?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(false, false, null, "-_"); + var result = camelCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = camelCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = camelCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123Abc456Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, false, null, "-_"); + var result = camelCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + } +} From 277c1eea6ff63e136c4c5618709eb7479bf1de6a Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 15 Feb 2025 16:21:49 +0900 Subject: [PATCH 2/2] comment: fixed misspelling found in review --- src/main/java/com/github/sttk/stringcase/Options.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/sttk/stringcase/Options.java b/src/main/java/com/github/sttk/stringcase/Options.java index 027627b..1d6a7db 100644 --- a/src/main/java/com/github/sttk/stringcase/Options.java +++ b/src/main/java/com/github/sttk/stringcase/Options.java @@ -41,7 +41,7 @@ public class Options { * sequence of non-alphabetical characters as a word boundary. * @param separators The symbol characters to be treated as word separators and removed from * the result string. - * @param keep The symbol characters tobe treated as word separators and kept in the result + * @param keep The symbol characters to be treated as word separators and kept in the result * string. */ public Options(