diff --git a/src/main/java/com/github/sttk/stringcase/StringCase.java b/src/main/java/com/github/sttk/stringcase/StringCase.java index 5d0c34e..678c015 100644 --- a/src/main/java/com/github/sttk/stringcase/StringCase.java +++ b/src/main/java/com/github/sttk/stringcase/StringCase.java @@ -414,80 +414,88 @@ public static String kebabCaseWithKeep(String input, String kept) { } /** - * Converts a string to macro case. + * Converts the input string to macro case with the specified options. * - * This method takes a string as its argument, then returns a string of which - * the case style is macro case. - * - * This method targets the upper and lower cases of ASCII alphabets for - * capitalization, and all characters except ASCII alphabets and ASCII - * numbers are eliminated as word separators. - * - *
{@code - * String macro = StringCase.macroCase("fooBarBaz"); - * // => "FOO_BAR_BAZ" - * }- * - * @param input A string to be converted. + * @param input The input string. + * @param opts The options with specifies the ways of case conversion. * @return A string converted to macro case. */ - public static String macroCase(String input) { - var result = new CodepointBuffer(input.length() + input.length() / 2); + public static String macroCaseWithOptions(String input, Options opts) { + var result = new CodepointBuffer(input.length()); final int UNDERSCORE = 0x5f; - enum ChIs { - FirstOfStr, - NextOfUpper, - NextOfContdUpper, - NextOfSepMark, - NextOfKeepedMark, - 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: + if (flag == ChIs.FirstOfStr) { result.append(ch); flag = ChIs.NextOfUpper; - break; - case ChIs.NextOfUpper: - case ChIs.NextOfContdUpper: + } else if (flag == ChIs.NextOfUpper || flag == ChIs.NextOfContdUpper || + (!opts.separateAfterNonAlphabets && flag == ChIs.NextOfKeptMark)) { result.append(ch); flag = ChIs.NextOfContdUpper; - break; - default: + } else { result.append(UNDERSCORE, ch); flag = ChIs.NextOfUpper; - break; } } else if (Ascii.isLowerCase(ch)) { - switch (flag) { - case ChIs.NextOfContdUpper: + if (flag == ChIs.NextOfContdUpper) { int prev = result.last(); result.replaceLast(UNDERSCORE, prev, Ascii.toUpperCase(ch)); - break; - case ChIs.NextOfSepMark: - case ChIs.NextOfKeepedMark: + } else if (flag == ChIs.NextOfSepMark || + (opts.separateAfterNonAlphabets && flag == ChIs.NextOfKeptMark)) { result.append(UNDERSCORE, Ascii.toUpperCase(ch)); - break; - default: + } else { result.append(Ascii.toUpperCase(ch)); - break; } flag = ChIs.Others; - } else if (Ascii.isDigit(ch)) { - if (flag == ChIs.NextOfSepMark) { - result.append(UNDERSCORE, ch); - } else { - result.append(ch); - } - flag = ChIs.NextOfKeepedMark; } else { - if (flag != ChIs.FirstOfStr) { - flag = ChIs.NextOfSepMark; + 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) { + if (opts.separateBeforeNonAlphabets) { + if (flag == ChIs.FirstOfStr || flag == ChIs.NextOfKeptMark) { + result.append(ch); + } else { + result.append(UNDERSCORE, ch); + } + } else { + if (flag != ChIs.NextOfSepMark) { + result.append(ch); + } else { + result.append(UNDERSCORE, ch); + } + } + flag = ChIs.NextOfKeptMark; + } else { + if (flag != ChIs.FirstOfStr) { + flag = ChIs.NextOfSepMark; + } } } } @@ -496,181 +504,44 @@ enum ChIs { } /** - * Converts a string to macro 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 macro 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 replaced to - * underscores. - * - *
{@code - * String macro = StringCase.macroCaseWithSep("foo-Bar100%Baz", "- "); - * // => "FOO_BAR100%_BAZ" - * }+ * Converts the input string to macro 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 macro case. */ - public static String macroCaseWithSep(String input, String seps) { - var result = new CodepointBuffer(input.length() + input.length() / 2); - - final int UNDERSCORE = 0x5f; - - var sepChs = seps.codePoints().toArray(); - Arrays.sort(sepChs); - - enum ChIs { - FirstOfStr, - NextOfUpper, - NextOfContdUpper, - NextOfSepMark, - NextOfKeepedMark, - Others, - } - var flag = ChIs.FirstOfStr; - - for (int ch : input.codePoints().toArray()) { - if (Arrays.binarySearch(sepChs, ch) >= 0) { - if (flag != ChIs.FirstOfStr) { - flag = ChIs.NextOfSepMark; - } - } else if (Ascii.isUpperCase(ch)) { - switch (flag) { - case ChIs.FirstOfStr: - result.append(ch); - flag = ChIs.NextOfUpper; - break; - case ChIs.NextOfUpper: - case ChIs.NextOfContdUpper: - result.append(ch); - flag = ChIs.NextOfContdUpper; - break; - default: - result.append(UNDERSCORE, ch); - flag = ChIs.NextOfUpper; - break; - } - } else if (Ascii.isLowerCase(ch)) { - switch (flag) { - case ChIs.NextOfContdUpper: - int prev = result.last(); - result.replaceLast(UNDERSCORE, prev, Ascii.toUpperCase(ch)); - break; - case ChIs.NextOfSepMark: - case ChIs.NextOfKeepedMark: - result.append(UNDERSCORE, Ascii.toUpperCase(ch)); - break; - default: - result.append(Ascii.toUpperCase(ch)); - break; - } - flag = ChIs.Others; - } else { - if (flag == ChIs.NextOfSepMark) { - result.append(UNDERSCORE, ch); - } else { - result.append(ch); - } - flag = ChIs.NextOfKeepedMark; - } - } - - return result.toString(); + public static String macroCase(String input) { + return macroCaseWithOptions(input, new Options(false, true, null, null)); } /** - * Converts a string to macro case using characters other than the specified - * characters as separators. + * Converts the input string to macro case with the specified separator characters. * - * This mthod takes a string slice as its argument, then returns a `String` - * of which the case style is macro case. - * - * 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 replaced to underscores. + * @param input The input string. + * @param seps The symbol characters to be treated as separators. + * @return A string converted to macro case. * - *
{@code - * String macro = StringCase.macroCaseWithKeep("foo-bar100%baz", "%"); - * // => "FOO_BAR100%_BAZ; - * }+ * @deprecated Should use {@link #macroCaseWithOptions} instead + */ + @Deprecated + public static String macroCaseWithSep(String input, String seps) { + return macroCaseWithOptions(input, new Options(false, true, seps, null)); + } + + /** + * Converts the input string to macro 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 macro case. + * + * @deprecated Should use {@link #macroCaseWithOptions} instead */ - public static String macroCaseWithKeep(String input, String keeped) { - var result = new CodepointBuffer(input.length() + input.length() / 2); - - final int UNDERSCORE = 0x5f; - - var keepChs = keeped.codePoints().toArray(); - Arrays.sort(keepChs); - - enum ChIs { - FirstOfStr, - NextOfUpper, - NextOfContdUpper, - NextOfSepMark, - NextOfKeepedMark, - Others, - } - var flag = ChIs.FirstOfStr; - - for (int ch : input.codePoints().toArray()) { - if (Ascii.isUpperCase(ch)) { - switch (flag) { - case ChIs.FirstOfStr: - result.append(ch); - flag = ChIs.NextOfUpper; - break; - case ChIs.NextOfUpper: - case ChIs.NextOfContdUpper: - result.append(ch); - flag = ChIs.NextOfContdUpper; - break; - default: - result.append(UNDERSCORE, ch); - flag = ChIs.NextOfUpper; - break; - } - } else if (Ascii.isLowerCase(ch)) { - switch (flag) { - case ChIs.NextOfContdUpper: - int prev = result.last(); - result.replaceLast(UNDERSCORE, prev, Ascii.toUpperCase(ch)); - break; - case ChIs.NextOfSepMark: - case ChIs.NextOfKeepedMark: - result.append(UNDERSCORE, Ascii.toUpperCase(ch)); - break; - default: - result.append(Ascii.toUpperCase(ch)); - break; - } - flag = ChIs.Others; - } else if (Ascii.isDigit(ch) || Arrays.binarySearch(keepChs, ch) >= 0) { - if (flag == ChIs.NextOfSepMark) { - result.append(UNDERSCORE, ch); - } else { - result.append(ch); - } - flag = ChIs.NextOfKeepedMark; - } else { - if (flag != ChIs.FirstOfStr) { - flag = ChIs.NextOfSepMark; - } - } - } - - return result.toString(); + @Deprecated + public static String macroCaseWithKeep(String input, String kept) { + return macroCaseWithOptions(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 dcda9ec..1a321b0 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() {} - // macro case - - @Nested - class MacroCase { - @Test - void fromCamelCase() { - var result = macroCase("abcDefGHIjk"); - assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); - } - - @Test - void fromPascalCase() { - var result = macroCase("AbcDefGHIjk"); - assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); - } - - @Test - void fromSnakeCase() { - var result = macroCase("abc_def_ghi"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - } - - @Test - void fromKebabCase() { - var result = macroCase("abc-def-ghi"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - } - - @Test - void fromTrainCase() { - var result = macroCase("Abc-Def-Ghi"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - } - - @Test - void fromMacroCase() { - var result = macroCase("ABC_DEF_GHI"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - } - - @Test - void fromCobolCase() { - var result = macroCase("ABC-DEF-GHI"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - } - - @Test - void keepDigits() { - var result = macroCase("abc123-456defG789HIJklMN12"); - assertThat(result).isEqualTo("ABC123_456_DEF_G789_HI_JKL_MN12"); - } - - @Test - void convertWhenStartingWithDigit() { - var result = macroCase("123abc456def"); - assertThat(result).isEqualTo("123_ABC456_DEF"); - - result = macroCase("123ABC456DEF"); - assertThat(result).isEqualTo("123_ABC456_DEF"); - } - - @Test - void treatMarksAsSeparators() { - var result = macroCase(":.abc~!@def#$ghi%&jk(lm)no/?"); - assertThat(result).isEqualTo("ABC_DEF_GHI_JK_LM_NO"); - } - - @Test - void convertEmpty() { - var result = macroCase(""); - assertThat(result).isEqualTo(""); - } - } - - @Nested - class MacroCaseWithSep { - @Test - void fromCamelCase() { - var result = macroCaseWithSep("abcDefGHIjk", "_-"); - assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); - } - - @Test - void fromPascalCase() { - var result = macroCaseWithSep("AbcDefGHIjk", "_-"); - assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); - } - - @Test - void fromSnakeCase() { - var result = macroCaseWithSep("abc_def_ghi", "_"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - - result = macroCaseWithSep("abc_def_ghi", "-"); - assertThat(result).isEqualTo("ABC__DEF__GHI"); - } - - @Test - void fromKebabCase() { - var result = macroCaseWithSep("abc-def-ghi", "-"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - - result = macroCaseWithSep("abc-def-ghi", "_"); - assertThat(result).isEqualTo("ABC-_DEF-_GHI"); - } - - @Test - void fromTrainCase() { - var result = macroCaseWithSep("Abc-Def-Ghi", "-"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - - result = macroCaseWithSep("Abc-Def-Ghi", "_"); - assertThat(result).isEqualTo("ABC-_DEF-_GHI"); - } - - @Test - void fromMacroCase() { - var result = macroCaseWithSep("ABC_DEF_GHI", "_"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - - result = macroCaseWithSep("ABC_DEF_GHI", "-"); - assertThat(result).isEqualTo("ABC__DEF__GHI"); - } - - @Test - void fromCobolCase() { - var result = macroCaseWithSep("ABC-DEF-GHI", "-"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - - result = macroCaseWithSep("ABC-DEF-GHI", "_"); - assertThat(result).isEqualTo("ABC-_DEF-_GHI"); - } - - @Test - void keepDigits() { - var result = macroCaseWithSep("abc123-456defG789HIJklMN12", "-"); - assertThat(result).isEqualTo("ABC123_456_DEF_G789_HI_JKL_MN12"); - - result = macroCaseWithSep("abc123-456defG789HIJklMN12", "_"); - assertThat(result).isEqualTo("ABC123-456_DEF_G789_HI_JKL_MN12"); - } - - @Test - void convertWhenStartingWithDigit() { - var result = macroCaseWithSep("123abc456def", "-_"); - assertThat(result).isEqualTo("123_ABC456_DEF"); - - result = macroCaseWithSep("123ABC456DEF", "-_"); - assertThat(result).isEqualTo("123_ABC456_DEF"); - } - - @Test - void treatMarksAsSeparators() { - var result = macroCaseWithSep(":.abc~!@def#$ghi%&jk(lm)no/?", ":@$&()/"); - assertThat(result).isEqualTo("._ABC~!_DEF#_GHI%_JK_LM_NO_?"); - } - - @Test - void convertEmpty() { - var result = macroCaseWithSep("", "-_"); - assertThat(result).isEqualTo(""); - } - } - - @Nested - class MacroCaseWithKeep { - @Test - void fromCamelCase() { - var result = macroCaseWithKeep("abcDefGHIjk", "_-"); - assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); - } - - @Test - void fromPascalCase() { - var result = macroCaseWithKeep("AbcDefGHIjk", "_-"); - assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); - } - - @Test - void fromSnakeCase() { - var result = macroCaseWithKeep("abc_def_ghi", "-"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - - result = macroCaseWithKeep("abc_def_ghi", "_"); - assertThat(result).isEqualTo("ABC__DEF__GHI"); - } - - @Test - void fromKebabCase() { - var result = macroCaseWithKeep("abc-def-ghi", "_"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - - result = macroCaseWithKeep("abc-def-ghi", "-"); - assertThat(result).isEqualTo("ABC-_DEF-_GHI"); - } - - @Test - void fromTrainCase() { - var result = macroCaseWithKeep("Abc-Def-Ghi", "_"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - - result = macroCaseWithKeep("Abc-Def-Ghi", "-"); - assertThat(result).isEqualTo("ABC-_DEF-_GHI"); - } - - @Test - void fromMacroCase() { - var result = macroCaseWithKeep("ABC_DEF_GHI", "-"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - - result = macroCaseWithKeep("ABC_DEF_GHI", "_"); - assertThat(result).isEqualTo("ABC__DEF__GHI"); - } - - @Test - void fromCobolCase() { - var result = macroCaseWithKeep("ABC-DEF-GHI", "_"); - assertThat(result).isEqualTo("ABC_DEF_GHI"); - - result = macroCaseWithKeep("ABC-DEF-GHI", "-"); - assertThat(result).isEqualTo("ABC-_DEF-_GHI"); - } - - @Test - void keepDigits() { - var result = macroCaseWithKeep("abc123-456defG789HIJklMN12", "-"); - assertThat(result).isEqualTo("ABC123-456_DEF_G789_HI_JKL_MN12"); - - result = macroCaseWithKeep("abc123-456defG789HIJklMN12", "_"); - assertThat(result).isEqualTo("ABC123_456_DEF_G789_HI_JKL_MN12"); - } - - @Test - void convertWhenStartingWithDigit() { - var result = macroCaseWithKeep("123abc456def", "_"); - assertThat(result).isEqualTo("123_ABC456_DEF"); - - result = macroCaseWithKeep("123ABC456DEF", "-"); - assertThat(result).isEqualTo("123_ABC456_DEF"); - } - - @Test - void treatMarksAsSeparators() { - var result = macroCaseWithKeep(":.abc~!@def#$ghi%&jk(lm)no/?", ".~!#%?"); - assertThat(result).isEqualTo("._ABC~!_DEF#_GHI%_JK_LM_NO_?"); - } - - @Test - void convertEmpty() { - var result = macroCaseWithKeep("", "-_"); - assertThat(result).isEqualTo(""); - } - } - // pascal case @Nested diff --git a/src/test/java/com/github/sttk/stringcase/StringCase_MacroCaseTest.java b/src/test/java/com/github/sttk/stringcase/StringCase_MacroCaseTest.java new file mode 100644 index 0000000..3fb050d --- /dev/null +++ b/src/test/java/com/github/sttk/stringcase/StringCase_MacroCaseTest.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_MacroCaseTest { + + @Nested + class MacroCase { + @Test + void convertCamelCase() { + var result = macroCase("abcDefGHIjk"); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var result = macroCase("AbcDefGHIjk"); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var result = macroCase("abc_def_ghi"); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertKebabCase() { + var result = macroCase("abc-def-ghi"); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertTrainCase() { + var result = macroCase("Abc-Def-Ghi"); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertMacroCase() { + var result = macroCase("ABC_DEF_GHI"); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertCobolCase() { + var result = macroCase("ABC-DEF-GHI"); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertWithKeepingDigits() { + var result = macroCase("abc123-456defG89HIJklMN12"); + assertThat(result).isEqualTo("ABC123_456_DEF_G89_HI_JKL_MN12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var result = macroCase(":.abc~!@def#$ghi%&jk(lm)no/?"); + assertThat(result).isEqualTo("ABC_DEF_GHI_JK_LM_NO"); + } + + @Test + void convertWhenStartingWithDigit() { + var result = macroCase("123abc456def"); + assertThat(result).isEqualTo("123_ABC456_DEF"); + + result = macroCase("123ABC456DEF"); + assertThat(result).isEqualTo("123_ABC456_DEF"); + + result = macroCase("123Abc456Def"); + assertThat(result).isEqualTo("123_ABC456_DEF"); + } + + @Test + void convertAnEmptyString() { + var result = macroCase(""); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class MacroCaseWithOptions { + @Nested + class NonAlphabetsAsHeadOfWord { + @Test + void convertCamelCase() { + var opts = new Options(true, false, null, null); + var result = macroCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, false, "", ""); + var result = macroCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, false, null, null); + var result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, false, null, null); + var result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, false, null, null); + var result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, false, null, null); + var result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, false, null, null); + var result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, false, null, null); + var result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC_123_456DEF_G_89HI_JKL_MN_12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(true, false, null, null); + var result = macroCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI_JK_LM_NO"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(true, false, null, null); + var result = macroCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123ABC_456DEF"); + + result = macroCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123ABC_456DEF"); + + result = macroCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123_ABC_456_DEF"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, false, null, null); + var result = macroCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsTailOfWord { + @Test + void convertCamelCase() { + var opts = new Options(false, true, null, null); + var result = macroCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, true, "", ""); + var result = macroCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, true, null, null); + var result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, true, null, null); + var result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, true, null, null); + var result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, true, null, null); + var result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, true, null, null); + var result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, true, null, null); + var result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC123_456_DEF_G89_HI_JKL_MN12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, true, null, null); + var result = macroCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI_JK_LM_NO"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(false, true, null, null); + var result = macroCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123_ABC456_DEF"); + + result = macroCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123_ABC456_DEF"); + + result = macroCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123_ABC456_DEF"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, true, null, null); + var result = macroCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsWord { + @Test + void convertCamelCase() { + var opts = new Options(true, true, null, null); + var result = macroCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, true, "", ""); + var result = macroCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, true, null, null); + var result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, true, null, null); + var result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, true, null, null); + var result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, true, null, null); + var result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, true, null, null); + var result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, true, null, null); + var result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC_123_456_DEF_G_89_HI_JKL_MN_12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(true, true, null, null); + var result = macroCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI_JK_LM_NO"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(true, true, null, null); + var result = macroCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123_ABC_456_DEF"); + + result = macroCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123_ABC_456_DEF"); + + result = macroCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123_ABC_456_DEF"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, true, null, null); + var result = macroCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsPartAsWord { + @Test + void convertCamelCase() { + var opts = new Options(false, false, null, null); + var result = macroCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, false, "", ""); + var result = macroCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, false, null, null); + var result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, false, null, null); + var result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, false, null, null); + var result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, false, null, null); + var result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, false, null, null); + var result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, false, null, null); + var result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC123_456DEF_G89HI_JKL_MN12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, false, null, null); + var result = macroCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI_JK_LM_NO"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(false, false, null, null); + var result = macroCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123ABC456DEF"); + + result = macroCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123ABC456DEF"); + + result = macroCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123_ABC456_DEF"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, false, null, null); + var result = macroCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsHeadOfWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(true, false, "-_", null); + var result = macroCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, false, "-_", ""); + var result = macroCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, false, "_", null); + var result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, false, "-", null); + result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC__DEF__GHI"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, false, "-", null); + var result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, false, "_", null); + result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_-DEF_-GHI"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, false, "-", null); + var result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, false, "_", null); + result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_-_DEF_-_GHI"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, false, "_", null); + var result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, false, "-", null); + result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC__DEF__GHI"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, false, "-", null); + var result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, false, "_", null); + result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_-DEF_-GHI"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, false, "-", null); + var result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC_123_456DEF_G_89HI_JKL_MN_12"); + + opts = new Options(true, false, "_", null); + result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC_123-456DEF_G_89HI_JKL_MN_12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(true, false, ":@$&()/", null); + var result = macroCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo(".ABC_~!_DEF_#_GHI_%_JK_LM_NO_?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(true, false, "-", null); + var result = macroCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123ABC_456DEF"); + + result = macroCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123ABC_456DEF"); + + result = macroCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123_ABC_456_DEF"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, false, null, null); + var result = macroCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(true, false, "-b2", null); + var result = macroCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("ABC_123DEF"); + } + } + + @Nested + class NonAlphabetsAsTailOfWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(false, true, "-_", null); + var result = macroCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, true, "-_", ""); + var result = macroCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, true, "_", null); + var result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, true, "-", null); + result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC__DEF__GHI"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, true, "-", null); + var result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, true, "_", null); + result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC-_DEF-_GHI"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, true, "-", null); + var result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, true, "_", null); + result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC-_DEF-_GHI"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, true, "_", null); + var result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, true, "-", null); + result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC__DEF__GHI"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, true, "-", null); + var result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, true, "_", null); + result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC-_DEF-_GHI"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, true, "-", null); + var result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC123_456_DEF_G89_HI_JKL_MN12"); + + opts = new Options(false, true, "_", null); + result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC123-456_DEF_G89_HI_JKL_MN12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, true, ":@$&()/", null); + var result = macroCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo("._ABC~!_DEF#_GHI%_JK_LM_NO_?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(false, true, "-", null); + var result = macroCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123_ABC456_DEF"); + + result = macroCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123_ABC456_DEF"); + + result = macroCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123_ABC456_DEF"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, true, "-_", null); + var result = macroCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(false, true, "-b2", null); + var result = macroCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("ABC123_DEF"); + } + } + + @Nested + class NonAlphabetsAsWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(true, true, "-_", null); + var result = macroCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, true, "-_", ""); + var result = macroCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, true, "_", null); + var result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, true, "-", null); + result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC___DEF___GHI"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, true, "-", null); + var result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, true, "_", null); + result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_-_DEF_-_GHI"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, true, "-", null); + var result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, true, "_", null); + result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_-_DEF_-_GHI"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, true, "_", null); + var result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, true, "-", null); + result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC___DEF___GHI"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, true, "-", null); + var result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, true, "_", null); + result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_-_DEF_-_GHI"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, true, "-", null); + var result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC_123_456_DEF_G_89_HI_JKL_MN_12"); + + opts = new Options(true, true, "_", null); + result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC_123-456_DEF_G_89_HI_JKL_MN_12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(true, true, ":@$&()/", null); + var result = macroCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo("._ABC_~!_DEF_#_GHI_%_JK_LM_NO_?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(true, true, "-_", null); + var result = macroCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123_ABC_456_DEF"); + + result = macroCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123_ABC_456_DEF"); + + result = macroCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123_ABC_456_DEF"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, true, "-_", null); + var result = macroCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(true, true, "-b2", null); + var result = macroCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("ABC_123_DEF"); + } + } + + @Nested + class NonAlphabetsAsPartOfWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(false, false, "-_", null); + var result = macroCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, false, "-_", ""); + var result = macroCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, false, "_", null); + var result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, false, "-", null); + result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, false, "-", null); + var result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, false, "_", null); + result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC-DEF-GHI"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, false, "-", null); + var result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, false, "_", null); + result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC-_DEF-_GHI"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, false, "_", null); + var result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, false, "-", null); + result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, false, "-", null); + var result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, false, "_", null); + result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC-DEF-GHI"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, false, "-", null); + var result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC123_456DEF_G89HI_JKL_MN12"); + + opts = new Options(false, false, "_", null); + result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC123-456DEF_G89HI_JKL_MN12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, false, ":@$&()/", null); + var result = macroCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo(".ABC~!_DEF#_GHI%_JK_LM_NO_?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(false, false, "-_", null); + var result = macroCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123ABC456DEF"); + + result = macroCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123ABC456DEF"); + + result = macroCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123_ABC456_DEF"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, false, "-_", null); + var result = macroCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(false, false, "-b2", null); + var result = macroCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("ABC123DEF"); + } + } + + @Nested + class NonAlphabetsAsHeadOfWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(true, false, null, "-_"); + var result = macroCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, false, "", "-_"); + var result = macroCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, false, null, "-"); + var result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, false, null, "_"); + result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC__DEF__GHI"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, false, null, "_"); + var result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, false, null, "-"); + result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_-DEF_-GHI"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, false, null, "_"); + var result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, false, null, "-"); + result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_-_DEF_-_GHI"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, false, null, "-"); + var result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, false, null, "_"); + result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC__DEF__GHI"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, false, null, "_"); + var result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, false, null, "-"); + result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_-DEF_-GHI"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, false, null, "_"); + var result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC_123_456DEF_G_89HI_JKL_MN_12"); + + opts = new Options(true, false, null, "-"); + result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC_123-456DEF_G_89HI_JKL_MN_12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(true, false, null, ".~!#%?"); + var result = macroCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo(".ABC_~!_DEF_#_GHI_%_JK_LM_NO_?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(true, false, null, "-"); + var result = macroCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123ABC_456DEF"); + + result = macroCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123ABC_456DEF"); + + result = macroCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123_ABC_456_DEF"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, false, null, "-_"); + var result = macroCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsTailOfWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(false, true, null, "-_"); + var result = macroCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, true, "", "-_"); + var result = macroCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, true, null, "-"); + var result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, true, null, "_"); + result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC__DEF__GHI"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, true, null, "_"); + var result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, true, null, "-"); + result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC-_DEF-_GHI"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, true, null, "_"); + var result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, true, null, "-"); + result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC-_DEF-_GHI"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, true, null, "-"); + var result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, true, null, "_"); + result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC__DEF__GHI"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, true, null, "_"); + var result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, true, null, "-"); + result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC-_DEF-_GHI"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, true, null, "_"); + var result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC123_456_DEF_G89_HI_JKL_MN12"); + + opts = new Options(false, true, null, "-"); + result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC123-456_DEF_G89_HI_JKL_MN12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, true, null, ".~!#%?"); + var result = macroCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo("._ABC~!_DEF#_GHI%_JK_LM_NO_?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(false, true, null, "_"); + var result = macroCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123_ABC456_DEF"); + + result = macroCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123_ABC456_DEF"); + + result = macroCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123_ABC456_DEF"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, true, null, "-_"); + var result = macroCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(true, true, null, "-_"); + var result = macroCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, true, "", "-_"); + var result = macroCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, true, null, "-"); + var result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, true, null, "_"); + result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC___DEF___GHI"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, true, null, "_"); + var result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, true, null, "-"); + result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_-_DEF_-_GHI"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, true, null, "_"); + var result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, true, null, "-"); + result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_-_DEF_-_GHI"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, true, null, "-"); + var result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, true, null, "_"); + result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC___DEF___GHI"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, true, null, "_"); + var result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(true, true, null, "-"); + result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_-_DEF_-_GHI"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, true, null, "_"); + var result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC_123_456_DEF_G_89_HI_JKL_MN_12"); + + opts = new Options(true, true, null, "-"); + result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC_123-456_DEF_G_89_HI_JKL_MN_12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(true, true, null, ".~!#%?"); + var result = macroCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo("._ABC_~!_DEF_#_GHI_%_JK_LM_NO_?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(true, true, null, "-_"); + var result = macroCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123_ABC_456_DEF"); + + result = macroCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123_ABC_456_DEF"); + + result = macroCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123_ABC_456_DEF"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, true, null, "-_"); + var result = macroCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsPartOfWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(false, false, null, "-_"); + var result = macroCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, false, "", "-_"); + var result = macroCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("ABC_DEF_GH_IJK"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, false, null, "-"); + var result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, false, null, "_"); + result = macroCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, false, null, "_"); + var result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, false, null, "-"); + result = macroCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("ABC-DEF-GHI"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, false, null, "_"); + var result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, false, null, "-"); + result = macroCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("ABC-_DEF-_GHI"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, false, null, "-"); + var result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, false, null, "_"); + result = macroCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, false, null, "_"); + var result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC_DEF_GHI"); + + opts = new Options(false, false, null, "-"); + result = macroCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("ABC-DEF-GHI"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, false, null, "_"); + var result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC123_456DEF_G89HI_JKL_MN12"); + + opts = new Options(false, false, null, "-"); + result = macroCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("ABC123-456DEF_G89HI_JKL_MN12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, false, null, ".~!#%?"); + var result = macroCaseWithOptions(":.abc~!@def#$ghi%&jk(lm)no/?", opts); + assertThat(result).isEqualTo(".ABC~!_DEF#_GHI%_JK_LM_NO_?"); + } + + @Test + void convertWhenStartingWithDigit() { + var opts = new Options(false, false, null, "-_"); + var result = macroCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123ABC456DEF"); + + result = macroCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123ABC456DEF"); + + result = macroCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123_ABC456_DEF"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, false, null, "-_"); + var result = macroCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + } +}