From 79c74ef9a094e6223824e5c345e58adf0d9fbced Mon Sep 17 00:00:00 2001 From: sttk Date: Sun, 16 Feb 2025 23:48:10 +0900 Subject: [PATCH] new!: added trainCaseWithOptions, updated trainCase to use it, and deprecated trainCaseWithSep/Keep --- .../github/sttk/stringcase/StringCase.java | 311 ++-- .../sttk/stringcase/StringCaseTest.java | 268 ---- .../stringcase/StringCase_TrainCaseTest.java | 1344 +++++++++++++++++ 3 files changed, 1429 insertions(+), 494 deletions(-) delete mode 100644 src/test/java/com/github/sttk/stringcase/StringCaseTest.java create mode 100644 src/test/java/com/github/sttk/stringcase/StringCase_TrainCaseTest.java diff --git a/src/main/java/com/github/sttk/stringcase/StringCase.java b/src/main/java/com/github/sttk/stringcase/StringCase.java index 87742cc..0168560 100644 --- a/src/main/java/com/github/sttk/stringcase/StringCase.java +++ b/src/main/java/com/github/sttk/stringcase/StringCase.java @@ -795,86 +795,93 @@ public static String snakeCaseWithKeep(String input, String kept) { } /** - * Converts a string to train case. + * Converts the input string to train case with the specified options. * - * This method takes a string as its argument, then returns a string of which - * the case style is train 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 train = StringCase.trainCase("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 train case. */ - public static String trainCase(String input) { - var result = new CodepointBuffer(input.length() * 2); + public static String trainCaseWithOptions(String input, Options opts) { + var result = new CodepointBuffer(input.length()); final int HYPHEN = 0x2d; - 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(Ascii.toLowerCase(ch)); flag = ChIs.NextOfContdUpper; - break; - default: + } else { result.append(HYPHEN, ch); flag = ChIs.NextOfUpper; - break; } } else if (Ascii.isLowerCase(ch)) { - switch (flag) { - case ChIs.FirstOfStr: + if (flag == ChIs.FirstOfStr) { result.append(Ascii.toUpperCase(ch)); - break; - case ChIs.NextOfContdUpper: + } else if (flag == ChIs.NextOfContdUpper) { int prev = result.last(); if (Ascii.isLowerCase(prev)) { prev = Ascii.toUpperCase(prev); } result.replaceLast(HYPHEN, prev, ch); - break; - case ChIs.NextOfSepMark: - case ChIs.NextOfKeepedMark: + } else if (flag == ChIs.NextOfSepMark || + (opts.separateAfterNonAlphabets && flag == ChIs.NextOfKeptMark)) { result.append(HYPHEN, Ascii.toUpperCase(ch)); - break; - default: - result.append(ch); - break; - } - flag = ChIs.Others; - } else if (Ascii.isDigit(ch)) { - if (flag == ChIs.NextOfSepMark) { - result.append(HYPHEN, ch); } else { result.append(ch); } - flag = ChIs.NextOfKeepedMark; + flag = ChIs.Others; } 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(HYPHEN, ch); + } + } else { + if (flag != ChIs.NextOfSepMark) { + result.append(ch); + } else { + result.append(HYPHEN, ch); + } + } + flag = ChIs.NextOfKeptMark; + } else { + if (flag != ChIs.FirstOfStr) { + flag = ChIs.NextOfSepMark; + } } } } @@ -883,191 +890,43 @@ enum ChIs { } /** - * Converts a string to train 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 train 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 hyphens. - * - *
{@code
-   *     String train = StringCase.trainCaseWithSep("foo-Bar100%Baz", "- ");
-   *     // => "Foo-Bar100%-Baz"
-   * }
+ * Converts the input string to train 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 train case. */ - public static String trainCaseWithSep(String input, String seps) { - var result = new CodepointBuffer(input.length() * 2); - - final int HYPHEN = 0x2d; - - 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(Ascii.toLowerCase(ch)); - flag = ChIs.NextOfContdUpper; - break; - default: - result.append(HYPHEN, ch); - flag = ChIs.NextOfUpper; - break; - } - } else if (Ascii.isLowerCase(ch)) { - switch (flag) { - case ChIs.FirstOfStr: - result.append(Ascii.toUpperCase(ch)); - break; - case ChIs.NextOfContdUpper: - int prev = result.last(); - if (Ascii.isLowerCase(prev)) { - prev = Ascii.toUpperCase(prev); - } - result.replaceLast(HYPHEN, prev, ch); - break; - case ChIs.NextOfSepMark: - case ChIs.NextOfKeepedMark: - result.append(HYPHEN, Ascii.toUpperCase(ch)); - break; - default: - result.append(ch); - break; - } - flag = ChIs.Others; - } else { - if (flag == ChIs.NextOfSepMark) { - result.append(HYPHEN, ch); - } else { - result.append(ch); - } - flag = ChIs.NextOfKeepedMark; - } - } - - return result.toString(); + public static String trainCase(String input) { + return trainCaseWithOptions(input, new Options(false, true, null, null)); } /** - * Converts a string to train 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 train case. + * Converts the input string to train 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 - * replaced to hyphens. + * @param input The input string. + * @param seps The symbol characters to be treated as separators. + * @return A string converted to train case. * - *

{@code
-   *     String train = StringCase.trainCaseWithKeep("foo-bar100%baz", "%");
-   *     // => "Foo-Bar100%-Baz"
-   * }
+ * @deprecated Should use {@link #trainCaseWithOptions} instead + */ + @Deprecated + public static String trainCaseWithSep(String input, String seps) { + return trainCaseWithOptions(input, new Options(false, true, seps, null)); + } + + /** + * Converts the input string to train 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 train case. + * + * @deprecated Should use {@link #trainCaseWithOptions} instead */ - public static String trainCaseWithKeep(String input, String keeped) { - var result = new CodepointBuffer(input.length() * 2); - - final int HYPHEN = 0x2d; - - 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(Ascii.toLowerCase(ch)); - flag = ChIs.NextOfContdUpper; - break; - default: - result.append(HYPHEN, ch); - flag = ChIs.NextOfUpper; - break; - } - } else if (Ascii.isLowerCase(ch)) { - switch (flag) { - case ChIs.FirstOfStr: - result.append(Ascii.toUpperCase(ch)); - break; - case ChIs.NextOfContdUpper: - int prev = result.last(); - if (Ascii.isLowerCase(prev)) { - prev = Ascii.toUpperCase(prev); - } - result.replaceLast(HYPHEN, prev, ch); - break; - case ChIs.NextOfSepMark: - case ChIs.NextOfKeepedMark: - result.append(HYPHEN, Ascii.toUpperCase(ch)); - break; - default: - result.append(ch); - break; - } - flag = ChIs.Others; - } else if (Ascii.isDigit(ch) || Arrays.binarySearch(keepChs, ch) >= 0) { - if (flag == ChIs.NextOfSepMark) { - result.append(HYPHEN, ch); - } else { - result.append(ch); - } - flag = ChIs.NextOfKeepedMark; - } else { - if (flag != ChIs.FirstOfStr) { - flag = ChIs.NextOfSepMark; - } - } - } - - return result.toString(); + @Deprecated + public static String trainCaseWithKeep(String input, String kept) { + return trainCaseWithOptions(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 deleted file mode 100644 index 481de05..0000000 --- a/src/test/java/com/github/sttk/stringcase/StringCaseTest.java +++ /dev/null @@ -1,268 +0,0 @@ -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; - -public class StringCaseTest { - private StringCaseTest() {} - - // train case - - @Nested - class TrainCase { - @Test - void fromCamelCase() { - var result = trainCase("abcDefGHIjk"); - assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); - } - - @Test - void fromPascalCase() { - var result = trainCase("AbcDefGHIjk"); - assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); - } - - @Test - void fromSnakeCase() { - var result = trainCase("abc_def_ghi"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - } - - @Test - void fromKebabCase() { - var result = trainCase("abc-def-ghi"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - } - - @Test - void fromTrainCase() { - var result = trainCase("Abc-Def-Ghi"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - } - - @Test - void fromMacroCase() { - var result = trainCase("ABC_DEF_GHI"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - } - - @Test - void fromCobolCase() { - var result = trainCase("ABC-DEF-GHI"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - } - - @Test - void keepDigits() { - var result = trainCase("abc123-456defG789HIJklMN12"); - assertThat(result).isEqualTo("Abc123-456-Def-G789-Hi-Jkl-Mn12"); - } - - @Test - void convertWhenStartingWithDigit() { - var result = trainCase("123abc456def"); - assertThat(result).isEqualTo("123-Abc456-Def"); - - result = trainCase("123ABC456DEF"); - assertThat(result).isEqualTo("123-Abc456-Def"); - } - - @Test - void treatMarksAsSeparators() { - var result = trainCase(":.abc~!@def#$ghi%&jk(lm)no/?"); - assertThat(result).isEqualTo("Abc-Def-Ghi-Jk-Lm-No"); - } - - @Test - void convertEmpty() { - var result = trainCase(""); - assertThat(result).isEqualTo(""); - } - } - - @Nested - class TrainCaseWithSep { - @Test - void fromCamelCase() { - var result = trainCaseWithSep("abcDefGHIjk", "_-"); - assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); - } - - @Test - void fromPascalCase() { - var result = trainCaseWithSep("AbcDefGHIjk", "_-"); - assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); - } - - @Test - void fromSnakeCase() { - var result = trainCaseWithSep("abc_def_ghi", "_"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - - result = trainCaseWithSep("abc_def_ghi", "-"); - assertThat(result).isEqualTo("Abc_-Def_-Ghi"); - } - - @Test - void fromKebabCase() { - var result = trainCaseWithSep("abc-def-ghi", "-"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - - result = trainCaseWithSep("abc-def-ghi", "_"); - assertThat(result).isEqualTo("Abc--Def--Ghi"); - } - - @Test - void fromTrainCase() { - var result = trainCaseWithSep("Abc-Def-Ghi", "-"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - - result = trainCaseWithSep("Abc-Def-Ghi", "_"); - assertThat(result).isEqualTo("Abc--Def--Ghi"); - } - - @Test - void fromMacroCase() { - var result = trainCaseWithSep("ABC_DEF_GHI", "_"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - - result = trainCaseWithSep("ABC_DEF_GHI", "-"); - assertThat(result).isEqualTo("Abc_-Def_-Ghi"); - } - - @Test - void fromCobolCase() { - var result = trainCaseWithSep("ABC-DEF-GHI", "-"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - - result = trainCaseWithSep("ABC-DEF-GHI", "_"); - assertThat(result).isEqualTo("Abc--Def--Ghi"); - } - - @Test - void keepDigits() { - var result = trainCaseWithSep("abc123-456defG789HIJklMN12", "-"); - assertThat(result).isEqualTo("Abc123-456-Def-G789-Hi-Jkl-Mn12"); - - result = trainCaseWithSep("abc123-456defG789HIJklMN12", "_"); - assertThat(result).isEqualTo("Abc123-456-Def-G789-Hi-Jkl-Mn12"); - } - - @Test - void convertWhenStartingWithDigit() { - var result = trainCaseWithSep("123abc456def", "-_"); - assertThat(result).isEqualTo("123-Abc456-Def"); - - result = trainCaseWithSep("123ABC456DEF", "-_"); - assertThat(result).isEqualTo("123-Abc456-Def"); - } - - @Test - void treatMarksAsSeparators() { - var result = trainCaseWithSep(":.abc~!@def#$ghi%&jk(lm)no/?", ":@$&()/"); - assertThat(result).isEqualTo(".-Abc~!-Def#-Ghi%-Jk-Lm-No-?"); - } - - @Test - void convertEmpty() { - var result = trainCaseWithSep("", "-_"); - assertThat(result).isEqualTo(""); - } - } - - @Nested - class TrainCaseWithKeep { - @Test - void fromCamelCase() { - var result = trainCaseWithKeep("abcDefGHIjk", "_-"); - assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); - } - - @Test - void fromPascalCase() { - var result = trainCaseWithKeep("AbcDefGHIjk", "_-"); - assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); - } - - @Test - void fromSnakeCase() { - var result = trainCaseWithKeep("abc_def_ghi", "-"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - - result = trainCaseWithKeep("abc_def_ghi", "_"); - assertThat(result).isEqualTo("Abc_-Def_-Ghi"); - } - - @Test - void fromKebabCase() { - var result = trainCaseWithKeep("abc-def-ghi", "_"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - - result = trainCaseWithKeep("abc-def-ghi", "-"); - assertThat(result).isEqualTo("Abc--Def--Ghi"); - } - - @Test - void fromTrainCase() { - var result = trainCaseWithKeep("Abc-Def-Ghi", "_"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - - result = trainCaseWithKeep("Abc-Def-Ghi", "-"); - assertThat(result).isEqualTo("Abc--Def--Ghi"); - } - - @Test - void fromMacroCase() { - var result = trainCaseWithKeep("ABC_DEF_GHI", "-"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - - result = trainCaseWithKeep("ABC_DEF_GHI", "_"); - assertThat(result).isEqualTo("Abc_-Def_-Ghi"); - } - - @Test - void fromCobolCase() { - var result = trainCaseWithKeep("ABC-DEF-GHI", "_"); - assertThat(result).isEqualTo("Abc-Def-Ghi"); - - result = trainCaseWithKeep("ABC-DEF-GHI", "-"); - assertThat(result).isEqualTo("Abc--Def--Ghi"); - } - - @Test - void keepDigits() { - var result = trainCaseWithKeep("abc123-456defG789HIJklMN12", "-"); - assertThat(result).isEqualTo("Abc123-456-Def-G789-Hi-Jkl-Mn12"); - - result = trainCaseWithKeep("abc123-456defG789HIJklMN12", "_"); - assertThat(result).isEqualTo("Abc123-456-Def-G789-Hi-Jkl-Mn12"); - } - - @Test - void convertWhenStartingWithDigit() { - var result = trainCaseWithKeep("123abc456def", "_"); - assertThat(result).isEqualTo("123-Abc456-Def"); - - result = trainCaseWithKeep("123ABC456DEF", "-"); - assertThat(result).isEqualTo("123-Abc456-Def"); - } - - @Test - void treatMarksAsSeparators() { - var result = trainCaseWithKeep(":.abc~!@def#$ghi%&jk(lm)no/?", ".~!#%?"); - assertThat(result).isEqualTo(".-Abc~!-Def#-Ghi%-Jk-Lm-No-?"); - } - - @Test - void convertEmpty() { - var result = trainCaseWithKeep("", "-_"); - assertThat(result).isEqualTo(""); - } - } -} diff --git a/src/test/java/com/github/sttk/stringcase/StringCase_TrainCaseTest.java b/src/test/java/com/github/sttk/stringcase/StringCase_TrainCaseTest.java new file mode 100644 index 0000000..166e1b4 --- /dev/null +++ b/src/test/java/com/github/sttk/stringcase/StringCase_TrainCaseTest.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_TrainCaseTest { + + @Nested + class TrainCase { + @Test + void convertCamelCase() { + var result = trainCase("abcDefGHIjk"); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var result = trainCase("AbcDefGHIjk"); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var result = trainCase("abc_def_ghi"); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertKebabCase() { + var result = trainCase("abc-def-ghi"); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertTrainCase() { + var result = trainCase("Abc-Def-Ghi"); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertMacroCase() { + var result = trainCase("ABC_DEF_GHI"); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertCobolCase() { + var result = trainCase("ABC-DEF-GHI"); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertWithKeepingDigits() { + var result = trainCase("abc123-456defG89HIJklMN12"); + assertThat(result).isEqualTo("Abc123-456-Def-G89-Hi-Jkl-Mn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var result = trainCase(":.abc~!@def#$ghi%&jk(lm)no/?"); + assertThat(result).isEqualTo("Abc-Def-Ghi-Jk-Lm-No"); + } + + @Test + void convertWhenStartingWithDigit() { + var result = trainCase("123abc456def"); + assertThat(result).isEqualTo("123-Abc456-Def"); + + result = trainCase("123ABC456DEF"); + assertThat(result).isEqualTo("123-Abc456-Def"); + + result = trainCase("123Abc456Def"); + assertThat(result).isEqualTo("123-Abc456-Def"); + } + + @Test + void convertAnEmptyString() { + var result = trainCase(""); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class TrainCaseWithOptions { + @Nested + class NonAlphabetsAsHeadOfWord { + @Test + void convertCamelCase() { + var opts = new Options(true, false, null, null); + var result = trainCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, false, "", ""); + var result = trainCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, false, null, null); + var result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, false, null, null); + var result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, false, null, null); + var result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, false, null, null); + var result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, false, null, null); + var result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, false, null, null); + var result = trainCaseWithOptions("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 = trainCaseWithOptions(":.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 = trainCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc-456def"); + + result = trainCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc-456def"); + + result = trainCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-Abc-456-Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, false, null, null); + var result = trainCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsTailOfWord { + @Test + void convertCamelCase() { + var opts = new Options(false, true, null, null); + var result = trainCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, true, "", ""); + var result = trainCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, true, null, null); + var result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, true, null, null); + var result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, true, null, null); + var result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, true, null, null); + var result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, true, null, null); + var result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, true, null, null); + var result = trainCaseWithOptions("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 = trainCaseWithOptions(":.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 = trainCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123-Abc456-Def"); + + result = trainCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123-Abc456-Def"); + + result = trainCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-Abc456-Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, true, null, null); + var result = trainCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsWord { + @Test + void convertCamelCase() { + var opts = new Options(true, true, null, null); + var result = trainCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, true, "", ""); + var result = trainCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, true, null, null); + var result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, true, null, null); + var result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, true, null, null); + var result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, true, null, null); + var result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, true, null, null); + var result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, true, null, null); + var result = trainCaseWithOptions("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 = trainCaseWithOptions(":.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 = trainCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123-Abc-456-Def"); + + result = trainCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123-Abc-456-Def"); + + result = trainCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-Abc-456-Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, true, null, null); + var result = trainCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsPartAsWord { + @Test + void convertCamelCase() { + var opts = new Options(false, false, null, null); + var result = trainCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, false, "", ""); + var result = trainCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, false, null, null); + var result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, false, null, null); + var result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, false, null, null); + var result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, false, null, null); + var result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, false, null, null); + var result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, false, null, null); + var result = trainCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("Abc123-456def-G89hi-Jkl-Mn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, false, null, null); + var result = trainCaseWithOptions(":.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 = trainCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = trainCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = trainCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-Abc456-Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, false, null, null); + var result = trainCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsHeadOfWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(true, false, "-_", null); + var result = trainCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, false, "-_", ""); + var result = trainCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, false, "_", null); + var result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, false, "-", null); + result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-_def-_ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, false, "-", null); + var result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, false, "_", null); + result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc--def--ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, false, "-", null); + var result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, false, "_", null); + result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc---Def---Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, false, "_", null); + var result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, false, "-", null); + result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-_def-_ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, false, "-", null); + var result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, false, "_", null); + result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc--def--ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, false, "-", null); + var result = trainCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("Abc-123-456def-G-89hi-Jkl-Mn-12"); + + opts = new Options(true, false, "_", null); + result = trainCaseWithOptions("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 = trainCaseWithOptions(":.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 = trainCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc-456def"); + + result = trainCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc-456def"); + + result = trainCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-Abc-456-Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, false, null, null); + var result = trainCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(true, false, "-b2", null); + var result = trainCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("Abc-123def"); + } + } + + @Nested + class NonAlphabetsAsTailOfWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(false, true, "-_", null); + var result = trainCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, true, "-_", ""); + var result = trainCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, true, "_", null); + var result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, true, "-", null); + result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc_-Def_-Ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, true, "-", null); + var result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, true, "_", null); + result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc--Def--Ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, true, "-", null); + var result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, true, "_", null); + result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc--Def--Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, true, "_", null); + var result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, true, "-", null); + result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc_-Def_-Ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, true, "-", null); + var result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, true, "_", null); + result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc--Def--Ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, true, "-", null); + var result = trainCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("Abc123-456-Def-G89-Hi-Jkl-Mn12"); + + opts = new Options(false, true, "_", null); + result = trainCaseWithOptions("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 = trainCaseWithOptions(":.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 = trainCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123-Abc456-Def"); + + result = trainCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123-Abc456-Def"); + + result = trainCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-Abc456-Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, true, "-_", null); + var result = trainCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(false, true, "-b2", null); + var result = trainCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("Abc123-Def"); + } + } + + @Nested + class NonAlphabetsAsWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(true, true, "-_", null); + var result = trainCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, true, "-_", ""); + var result = trainCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, true, "_", null); + var result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, true, "-", null); + result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-_-Def-_-Ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, true, "-", null); + var result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, true, "_", null); + result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc---Def---Ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, true, "-", null); + var result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, true, "_", null); + result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc---Def---Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, true, "_", null); + var result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, true, "-", null); + result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-_-Def-_-Ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, true, "-", null); + var result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, true, "_", null); + result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc---Def---Ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, true, "-", null); + var result = trainCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("Abc-123-456-Def-G-89-Hi-Jkl-Mn-12"); + + opts = new Options(true, true, "_", null); + result = trainCaseWithOptions("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 = trainCaseWithOptions(":.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 = trainCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123-Abc-456-Def"); + + result = trainCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123-Abc-456-Def"); + + result = trainCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-Abc-456-Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, true, "-_", null); + var result = trainCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(true, true, "-b2", null); + var result = trainCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("Abc-123-Def"); + } + } + + @Nested + class NonAlphabetsAsPartOfWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(false, false, "-_", null); + var result = trainCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, false, "-_", ""); + var result = trainCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, false, "_", null); + var result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, false, "-", null); + result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc_def_ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, false, "-", null); + var result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, false, "_", null); + result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, false, "-", null); + var result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, false, "_", null); + result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc--Def--Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, false, "_", null); + var result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, false, "-", null); + result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc_def_ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, false, "-", null); + var result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, false, "_", null); + result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, false, "-", null); + var result = trainCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("Abc123-456def-G89hi-Jkl-Mn12"); + + opts = new Options(false, false, "_", null); + result = trainCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("Abc123-456def-G89hi-Jkl-Mn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, false, ":@$&()/", null); + var result = trainCaseWithOptions(":.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 = trainCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = trainCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = trainCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-Abc456-Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, false, "-_", null); + var result = trainCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(false, false, "-b2", null); + var result = trainCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("Abc123def"); + } + } + + @Nested + class NonAlphabetsAsHeadOfWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(true, false, null, "-_"); + var result = trainCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, false, "", "-_"); + var result = trainCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, false, null, "-"); + var result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, false, null, "_"); + result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-_def-_ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, false, null, "_"); + var result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, false, null, "-"); + result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc--def--ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, false, null, "_"); + var result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, false, null, "-"); + result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc---Def---Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, false, null, "-"); + var result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, false, null, "_"); + result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-_def-_ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, false, null, "_"); + var result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, false, null, "-"); + result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc--def--ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, false, null, "_"); + var result = trainCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("Abc-123-456def-G-89hi-Jkl-Mn-12"); + + opts = new Options(true, false, null, "-"); + result = trainCaseWithOptions("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 = trainCaseWithOptions(":.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 = trainCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc-456def"); + + result = trainCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc-456def"); + + result = trainCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-Abc-456-Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, false, null, "-_"); + var result = trainCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsTailOfWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(false, true, null, "-_"); + var result = trainCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, true, "", "-_"); + var result = trainCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, true, null, "-"); + var result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, true, null, "_"); + result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc_-Def_-Ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, true, null, "_"); + var result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, true, null, "-"); + result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc--Def--Ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, true, null, "_"); + var result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, true, null, "-"); + result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc--Def--Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, true, null, "-"); + var result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, true, null, "_"); + result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc_-Def_-Ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, true, null, "_"); + var result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, true, null, "-"); + result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc--Def--Ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, true, null, "_"); + var result = trainCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("Abc123-456-Def-G89-Hi-Jkl-Mn12"); + + opts = new Options(false, true, null, "-"); + result = trainCaseWithOptions("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 = trainCaseWithOptions(":.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 = trainCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123-Abc456-Def"); + + result = trainCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123-Abc456-Def"); + + result = trainCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-Abc456-Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, true, null, "-_"); + var result = trainCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(true, true, null, "-_"); + var result = trainCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, true, "", "-_"); + var result = trainCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, true, null, "-"); + var result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, true, null, "_"); + result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-_-Def-_-Ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, true, null, "_"); + var result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, true, null, "-"); + result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc---Def---Ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, true, null, "_"); + var result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, true, null, "-"); + result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc---Def---Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, true, null, "-"); + var result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, true, null, "_"); + result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-_-Def-_-Ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, true, null, "_"); + var result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(true, true, null, "-"); + result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc---Def---Ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, true, null, "_"); + var result = trainCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("Abc-123-456-Def-G-89-Hi-Jkl-Mn-12"); + + opts = new Options(true, true, null, "-"); + result = trainCaseWithOptions("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 = trainCaseWithOptions(":.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 = trainCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123-Abc-456-Def"); + + result = trainCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123-Abc-456-Def"); + + result = trainCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-Abc-456-Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, true, null, "-_"); + var result = trainCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsPartOfWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(false, false, null, "-_"); + var result = trainCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, false, "", "-_"); + var result = trainCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("Abc-Def-Gh-Ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, false, null, "-"); + var result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, false, null, "_"); + result = trainCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("Abc_def_ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, false, null, "_"); + var result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, false, null, "-"); + result = trainCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("Abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, false, null, "_"); + var result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, false, null, "-"); + result = trainCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("Abc--Def--Ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, false, null, "-"); + var result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, false, null, "_"); + result = trainCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("Abc_def_ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, false, null, "_"); + var result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-Def-Ghi"); + + opts = new Options(false, false, null, "-"); + result = trainCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("Abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, false, null, "_"); + var result = trainCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("Abc123-456def-G89hi-Jkl-Mn12"); + + opts = new Options(false, false, null, "-"); + result = trainCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("Abc123-456def-G89hi-Jkl-Mn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, false, null, ".~!#%?"); + var result = trainCaseWithOptions(":.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 = trainCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = trainCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = trainCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-Abc456-Def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, false, null, "-_"); + var result = trainCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + } +}