diff --git a/src/main/java/com/github/sttk/stringcase/StringCase.java b/src/main/java/com/github/sttk/stringcase/StringCase.java index 4bacb3d..5d0c34e 100644 --- a/src/main/java/com/github/sttk/stringcase/StringCase.java +++ b/src/main/java/com/github/sttk/stringcase/StringCase.java @@ -283,83 +283,88 @@ public static String cobolCaseWithKeep(String input, String kept) { } /** - * Converts a string to kebab case. + * Converts the input string to kebab case with the specified options. * - * This method takes a string as its argument, then returns a string of which - * the case style is kebab 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 kebab = StringCase.kebabCase("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 kebab case. */ - public static String kebabCase(String input) { - var result = new CodepointBuffer(input.length() + input.length() / 2); + public static String kebabCaseWithOptions(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(Ascii.toLowerCase(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, Ascii.toLowerCase(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(HYPHEN, prev, ch); - break; - case ChIs.NextOfSepMark: - case ChIs.NextOfKeepedMark: + } else if (flag == ChIs.NextOfSepMark || + (opts.separateAfterNonAlphabets && flag == ChIs.NextOfKeptMark)) { result.append(HYPHEN, ch); - break; - default: + } else { result.append(ch); - break; } flag = ChIs.Others; - } else if (Ascii.isDigit(ch)) { - switch (flag) { - case ChIs.NextOfSepMark: - result.append(HYPHEN, ch); - break; - default: - result.append(ch); - break; - } - 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(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; + } } } } @@ -368,180 +373,44 @@ enum ChIs { } /** - * Converts a string to kebab 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 kebab 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 kebab = StringCase.kebabCaseWithSep("foo-Bar100%Baz", "- ");
-   *     // => "foo-bar100%-baz"
-   * }
+ * Converts the input string to kebab 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 kebab case. */ - public static String kebabCaseWithSep(String input, String seps) { - var result = new CodepointBuffer(input.length() + 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(Ascii.toLowerCase(ch)); - flag = ChIs.NextOfUpper; - break; - case ChIs.NextOfUpper: - case ChIs.NextOfContdUpper: - result.append(Ascii.toLowerCase(ch)); - flag = ChIs.NextOfContdUpper; - break; - default: - result.append(HYPHEN, Ascii.toLowerCase(ch)); - flag = ChIs.NextOfUpper; - break; - } - } else if (Ascii.isLowerCase(ch)) { - switch (flag) { - case ChIs.NextOfContdUpper: - int prev = result.last(); - result.replaceLast(HYPHEN, prev, ch); - break; - case ChIs.NextOfSepMark: - case ChIs.NextOfKeepedMark: - result.append(HYPHEN, 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 kebabCase(String input) { + return kebabCaseWithOptions(input, new Options(false, true, null, null)); } /** - * Converts a string to kebab 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 kebab case. + * Converts the input string to kebab 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 kebab case. * - *

{@code
-   *     String kebab = StringCase.kebabCaseWithKeep("foo-Bar100%Baz", "%");
-   *     // => "foo-bar100%-baz"
-   * }
+ * @deprecated Should use {@link #kebabCaseWithOptions} instead + */ + @Deprecated + public static String kebabCaseWithSep(String input, String seps) { + return kebabCaseWithOptions(input, new Options(false, true, seps, null)); + } + + /** + * Converts the input string to kebab 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 kebab case. + * + * @deprecated Should use {@link #kebabCaseWithOptions} instead */ - public static String kebabCaseWithKeep(String input, String keeped) { - var result = new CodepointBuffer(input.length() + 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(Ascii.toLowerCase(ch)); - flag = ChIs.NextOfUpper; - break; - case ChIs.NextOfUpper: - case ChIs.NextOfContdUpper: - result.append(Ascii.toLowerCase(ch)); - flag = ChIs.NextOfContdUpper; - break; - default: - result.append(HYPHEN, Ascii.toLowerCase(ch)); - flag = ChIs.NextOfUpper; - break; - } - } else if (Ascii.isLowerCase(ch)) { - switch (flag) { - case ChIs.NextOfContdUpper: - int prev = result.last(); - result.replaceLast(HYPHEN, prev, ch); - break; - case ChIs.NextOfSepMark: - case ChIs.NextOfKeepedMark: - result.append(HYPHEN, 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 kebabCaseWithKeep(String input, String kept) { + return kebabCaseWithOptions(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 af5d5d8..dcda9ec 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() {} - // kebab case - - @Nested - class KebabCase { - @Test - void fromCamelCase() { - var result = kebabCase("abcDefGHIjk"); - assertThat(result).isEqualTo("abc-def-gh-ijk"); - } - - @Test - void fromPascalCase() { - var result = kebabCase("AbcDefGHIjk"); - assertThat(result).isEqualTo("abc-def-gh-ijk"); - } - - @Test - void fromSnakeCase() { - var result = kebabCase("abc_def_ghi"); - assertThat(result).isEqualTo("abc-def-ghi"); - } - - @Test - void fromKebabCase() { - var result = kebabCase("abc-def-ghi"); - assertThat(result).isEqualTo("abc-def-ghi"); - } - - @Test - void fromTrainCase() { - var result = kebabCase("Abc-Def-Ghi"); - assertThat(result).isEqualTo("abc-def-ghi"); - } - - @Test - void fromMacroCase() { - var result = kebabCase("ABC_DEF_GHI"); - assertThat(result).isEqualTo("abc-def-ghi"); - } - - @Test - void fromCobolCase() { - var result = kebabCase("ABC-DEF-GHI"); - assertThat(result).isEqualTo("abc-def-ghi"); - } - - @Test - void keepDigits() { - var result = kebabCase("abc123-456defG789HIJklMN12"); - assertThat(result).isEqualTo("abc123-456-def-g789-hi-jkl-mn12"); - } - - @Test - void convertWhenStartingWithDigit() { - var result = kebabCase("123abc456def"); - assertThat(result).isEqualTo("123-abc456-def"); - - result = kebabCase("123ABC456DEF"); - assertThat(result).isEqualTo("123-abc456-def"); - } - - @Test - void treatMarksAsSeparators() { - var result = kebabCase(":.abc~!@def#$ghi%&jk(lm)no/?"); - assertThat(result).isEqualTo("abc-def-ghi-jk-lm-no"); - } - - @Test - void convertEmpty() { - var result = kebabCase(""); - assertThat(result).isEqualTo(""); - } - } - - @Nested - class KebabCaseWithSep { - @Test - void fromCamelCase() { - var result = kebabCaseWithSep("abcDefGHIjk", "_-"); - assertThat(result).isEqualTo("abc-def-gh-ijk"); - } - - @Test - void fromPascalCase() { - var result = kebabCaseWithSep("AbcDefGHIjk", "_-"); - assertThat(result).isEqualTo("abc-def-gh-ijk"); - } - - @Test - void fromSnakeCase() { - var result = kebabCaseWithSep("abc_def_ghi", "_"); - assertThat(result).isEqualTo("abc-def-ghi"); - - result = kebabCaseWithSep("abc_def_ghi", "-"); - assertThat(result).isEqualTo("abc_-def_-ghi"); - } - - @Test - void fromKebabCase() { - var result = kebabCaseWithSep("abc-def-ghi", "-"); - assertThat(result).isEqualTo("abc-def-ghi"); - - result = kebabCaseWithSep("abc-def-ghi", "_"); - assertThat(result).isEqualTo("abc--def--ghi"); - } - - @Test - void fromTrainCase() { - var result = kebabCaseWithSep("Abc-Def-Ghi", "-"); - assertThat(result).isEqualTo("abc-def-ghi"); - - result = kebabCaseWithSep("Abc-Def-Ghi", "_"); - assertThat(result).isEqualTo("abc--def--ghi"); - } - - @Test - void fromMacroCase() { - var result = kebabCaseWithSep("ABC_DEF_GHI", "_"); - assertThat(result).isEqualTo("abc-def-ghi"); - - result = kebabCaseWithSep("ABC_DEF_GHI", "-"); - assertThat(result).isEqualTo("abc_-def_-ghi"); - } - - @Test - void fromCobolCase() { - var result = kebabCaseWithSep("ABC-DEF-GHI", "-"); - assertThat(result).isEqualTo("abc-def-ghi"); - - result = kebabCaseWithSep("ABC-DEF-GHI", "_"); - assertThat(result).isEqualTo("abc--def--ghi"); - } - - @Test - void keepDigits() { - var result = kebabCaseWithSep("abc123-456defG789HIJklMN12", "-"); - assertThat(result).isEqualTo("abc123-456-def-g789-hi-jkl-mn12"); - - result = kebabCaseWithSep("abc123-456defG789HIJklMN12", "_"); - assertThat(result).isEqualTo("abc123-456-def-g789-hi-jkl-mn12"); - } - - @Test - void convertWhenStartingWithDigit() { - var result = kebabCaseWithSep("123abc456def", "-_"); - assertThat(result).isEqualTo("123-abc456-def"); - - result = kebabCaseWithSep("123ABC456DEF", "-_"); - assertThat(result).isEqualTo("123-abc456-def"); - } - - @Test - void treatMarksAsSeparators() { - var result = kebabCaseWithSep(":.abc~!@def#$ghi%&jk(lm)no/?", ":@$&()/"); - assertThat(result).isEqualTo(".-abc~!-def#-ghi%-jk-lm-no-?"); - } - - @Test - void convertEmpty() { - var result = kebabCaseWithSep("", "-_"); - assertThat(result).isEqualTo(""); - } - } - - @Nested - class KebabCaseWithKeep { - @Test - void fromCamelCase() { - var result = kebabCaseWithKeep("abcDefGHIjk", "_-"); - assertThat(result).isEqualTo("abc-def-gh-ijk"); - } - - @Test - void fromPascalCase() { - var result = kebabCaseWithKeep("AbcDefGHIjk", "_-"); - assertThat(result).isEqualTo("abc-def-gh-ijk"); - } - - @Test - void fromSnakeCase() { - var result = kebabCaseWithKeep("abc_def_ghi", "-"); - assertThat(result).isEqualTo("abc-def-ghi"); - - result = kebabCaseWithKeep("abc_def_ghi", "_"); - assertThat(result).isEqualTo("abc_-def_-ghi"); - } - - @Test - void fromKebabCase() { - var result = kebabCaseWithKeep("abc-def-ghi", "_"); - assertThat(result).isEqualTo("abc-def-ghi"); - - result = kebabCaseWithKeep("abc-def-ghi", "-"); - assertThat(result).isEqualTo("abc--def--ghi"); - } - - @Test - void fromTrainCase() { - var result = kebabCaseWithKeep("Abc-Def-Ghi", "_"); - assertThat(result).isEqualTo("abc-def-ghi"); - - result = kebabCaseWithKeep("Abc-Def-Ghi", "-"); - assertThat(result).isEqualTo("abc--def--ghi"); - } - - @Test - void fromMacroCase() { - var result = kebabCaseWithKeep("ABC_DEF_GHI", "-"); - assertThat(result).isEqualTo("abc-def-ghi"); - - result = kebabCaseWithKeep("ABC_DEF_GHI", "_"); - assertThat(result).isEqualTo("abc_-def_-ghi"); - } - - @Test - void fromCobolCase() { - var result = kebabCaseWithKeep("ABC-DEF-GHI", "_"); - assertThat(result).isEqualTo("abc-def-ghi"); - - result = kebabCaseWithKeep("ABC-DEF-GHI", "-"); - assertThat(result).isEqualTo("abc--def--ghi"); - } - - @Test - void keepDigits() { - var result = kebabCaseWithKeep("abc123-456defG789HIJklMN12", "-"); - assertThat(result).isEqualTo("abc123-456-def-g789-hi-jkl-mn12"); - - result = kebabCaseWithKeep("abc123-456defG789HIJklMN12", "_"); - assertThat(result).isEqualTo("abc123-456-def-g789-hi-jkl-mn12"); - } - - @Test - void convertWhenStartingWithDigit() { - var result = kebabCaseWithKeep("123abc456def", "_"); - assertThat(result).isEqualTo("123-abc456-def"); - - result = kebabCaseWithKeep("123ABC456DEF", "-"); - assertThat(result).isEqualTo("123-abc456-def"); - } - - @Test - void treatMarksAsSeparators() { - var result = kebabCaseWithKeep(":.abc~!@def#$ghi%&jk(lm)no/?", ".~!#%?"); - assertThat(result).isEqualTo(".-abc~!-def#-ghi%-jk-lm-no-?"); - } - - @Test - void convertEmpty() { - var result = kebabCaseWithKeep("", "-_"); - assertThat(result).isEqualTo(""); - } - } - // macro case @Nested diff --git a/src/test/java/com/github/sttk/stringcase/StringCase_CobolCaseTest.java b/src/test/java/com/github/sttk/stringcase/StringCase_CobolCaseTest.java index 2f7167b..9f2f16d 100644 --- a/src/test/java/com/github/sttk/stringcase/StringCase_CobolCaseTest.java +++ b/src/test/java/com/github/sttk/stringcase/StringCase_CobolCaseTest.java @@ -14,6 +14,7 @@ public class StringCase_CobolCaseTest { @Nested class CobolCase { + @Test void convertCamelCase() { var result = cobolCase("abcDefGHIjk"); assertThat(result).isEqualTo("ABC-DEF-GH-IJK"); diff --git a/src/test/java/com/github/sttk/stringcase/StringCase_KebabCaseTest.java b/src/test/java/com/github/sttk/stringcase/StringCase_KebabCaseTest.java new file mode 100644 index 0000000..9697d85 --- /dev/null +++ b/src/test/java/com/github/sttk/stringcase/StringCase_KebabCaseTest.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_KebabCaseTest { + + @Nested + class KebabCase { + @Test + void convertCamelCase() { + var result = kebabCase("abcDefGHIjk"); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var result = kebabCase("AbcDefGHIjk"); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var result = kebabCase("abc_def_ghi"); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertKebabCase() { + var result = kebabCase("abc-def-ghi"); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var result = kebabCase("Abc-Def-Ghi"); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertMacroCase() { + var result = kebabCase("ABC_DEF_GHI"); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertCobolCase() { + var result = kebabCase("ABC-DEF-GHI"); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var result = kebabCase("abc123-456defG89HIJklMN12"); + assertThat(result).isEqualTo("abc123-456-def-g89-hi-jkl-mn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var result = kebabCase(":.abc~!@def#$ghi%&jk(lm)no/?"); + assertThat(result).isEqualTo("abc-def-ghi-jk-lm-no"); + } + + @Test + void convertWhenStartingWithDigit() { + var result = kebabCase("123abc456def"); + assertThat(result).isEqualTo("123-abc456-def"); + + result = kebabCase("123ABC456DEF"); + assertThat(result).isEqualTo("123-abc456-def"); + + result = kebabCase("123Abc456Def"); + assertThat(result).isEqualTo("123-abc456-def"); + } + + @Test + void convertAnEmptyString() { + var result = kebabCase(""); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class KebabCaseWithOptions { + @Nested + class NonAlphabetsAsHeadOfWord { + @Test + void convertCamelCase() { + var opts = new Options(true, false, null, null); + var result = kebabCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, false, "", ""); + var result = kebabCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, false, null, null); + var result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, false, null, null); + var result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, false, null, null); + var result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, false, null, null); + var result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, false, null, null); + var result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, false, null, null); + var result = kebabCaseWithOptions("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 = kebabCaseWithOptions(":.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 = kebabCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc-456def"); + + result = kebabCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc-456def"); + + result = kebabCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-abc-456-def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, false, null, null); + var result = kebabCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsTailOfWord { + @Test + void convertCamelCase() { + var opts = new Options(false, true, null, null); + var result = kebabCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, true, "", ""); + var result = kebabCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, true, null, null); + var result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, true, null, null); + var result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, true, null, null); + var result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, true, null, null); + var result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, true, null, null); + var result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, true, null, null); + var result = kebabCaseWithOptions("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 = kebabCaseWithOptions(":.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 = kebabCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123-abc456-def"); + + result = kebabCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123-abc456-def"); + + result = kebabCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-abc456-def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, true, null, null); + var result = kebabCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsWord { + @Test + void convertCamelCase() { + var opts = new Options(true, true, null, null); + var result = kebabCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, true, "", ""); + var result = kebabCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, true, null, null); + var result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, true, null, null); + var result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, true, null, null); + var result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, true, null, null); + var result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, true, null, null); + var result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, true, null, null); + var result = kebabCaseWithOptions("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 = kebabCaseWithOptions(":.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 = kebabCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123-abc-456-def"); + + result = kebabCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123-abc-456-def"); + + result = kebabCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-abc-456-def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, true, null, null); + var result = kebabCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsPartAsWord { + @Test + void convertCamelCase() { + var opts = new Options(false, false, null, null); + var result = kebabCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, false, "", ""); + var result = kebabCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, false, null, null); + var result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, false, null, null); + var result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, false, null, null); + var result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, false, null, null); + var result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, false, null, null); + var result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, false, null, null); + var result = kebabCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456def-g89hi-jkl-mn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, false, null, null); + var result = kebabCaseWithOptions(":.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 = kebabCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = kebabCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = kebabCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-abc456-def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, false, null, null); + var result = kebabCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsHeadOfWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(true, false, "-_", null); + var result = kebabCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, false, "-_", ""); + var result = kebabCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, false, "_", null); + var result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, false, "-", null); + result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-_def-_ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, false, "-", null); + var result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, false, "_", null); + result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc--def--ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, false, "-", null); + var result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, false, "_", null); + result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc---def---ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, false, "_", null); + var result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, false, "-", null); + result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-_def-_ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, false, "-", null); + var result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, false, "_", null); + result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc--def--ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, false, "-", null); + var result = kebabCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc-123-456def-g-89hi-jkl-mn-12"); + + opts = new Options(true, false, "_", null); + result = kebabCaseWithOptions("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 = kebabCaseWithOptions(":.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 = kebabCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc-456def"); + + result = kebabCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc-456def"); + + result = kebabCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-abc-456-def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, false, null, null); + var result = kebabCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(true, false, "-b2", null); + var result = kebabCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("abc-123def"); + } + } + + @Nested + class NonAlphabetsAsTailOfWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(false, true, "-_", null); + var result = kebabCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, true, "-_", ""); + var result = kebabCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, true, "_", null); + var result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, true, "-", null); + result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc_-def_-ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, true, "-", null); + var result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, true, "_", null); + result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc--def--ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, true, "-", null); + var result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, true, "_", null); + result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc--def--ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, true, "_", null); + var result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, true, "-", null); + result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc_-def_-ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, true, "-", null); + var result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, true, "_", null); + result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc--def--ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, true, "-", null); + var result = kebabCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456-def-g89-hi-jkl-mn12"); + + opts = new Options(false, true, "_", null); + result = kebabCaseWithOptions("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 = kebabCaseWithOptions(":.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 = kebabCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123-abc456-def"); + + result = kebabCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123-abc456-def"); + + result = kebabCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-abc456-def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, true, "-_", null); + var result = kebabCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(false, true, "-b2", null); + var result = kebabCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("abc123-def"); + } + } + + @Nested + class NonAlphabetsAsWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(true, true, "-_", null); + var result = kebabCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, true, "-_", ""); + var result = kebabCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, true, "_", null); + var result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, true, "-", null); + result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-_-def-_-ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, true, "-", null); + var result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, true, "_", null); + result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc---def---ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, true, "-", null); + var result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, true, "_", null); + result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc---def---ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, true, "_", null); + var result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, true, "-", null); + result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-_-def-_-ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, true, "-", null); + var result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, true, "_", null); + result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc---def---ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, true, "-", null); + var result = kebabCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc-123-456-def-g-89-hi-jkl-mn-12"); + + opts = new Options(true, true, "_", null); + result = kebabCaseWithOptions("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 = kebabCaseWithOptions(":.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 = kebabCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123-abc-456-def"); + + result = kebabCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123-abc-456-def"); + + result = kebabCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-abc-456-def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, true, "-_", null); + var result = kebabCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(true, true, "-b2", null); + var result = kebabCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("abc-123-def"); + } + } + + @Nested + class NonAlphabetsAsPartOfWordAndWithSeparators { + @Test + void convertCamelCase() { + var opts = new Options(false, false, "-_", null); + var result = kebabCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, false, "-_", ""); + var result = kebabCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, false, "_", null); + var result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, false, "-", null); + result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc_def_ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, false, "-", null); + var result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, false, "_", null); + result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, false, "-", null); + var result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, false, "_", null); + result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc--def--ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, false, "_", null); + var result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, false, "-", null); + result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc_def_ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, false, "-", null); + var result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, false, "_", null); + result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, false, "-", null); + var result = kebabCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456def-g89hi-jkl-mn12"); + + opts = new Options(false, false, "_", null); + result = kebabCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456def-g89hi-jkl-mn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, false, ":@$&()/", null); + var result = kebabCaseWithOptions(":.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 = kebabCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = kebabCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = kebabCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-abc456-def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, false, "-_", null); + var result = kebabCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + + @Test + void alphabetsAndNumbersInSeparatorsAreNoEffect() { + var opts = new Options(false, false, "-b2", null); + var result = kebabCaseWithOptions("abc123def", opts); + assertThat(result).isEqualTo("abc123def"); + } + } + + @Nested + class NonAlphabetsAsHeadOfWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(true, false, null, "-_"); + var result = kebabCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, false, "", "-_"); + var result = kebabCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, false, null, "-"); + var result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, false, null, "_"); + result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-_def-_ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, false, null, "_"); + var result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, false, null, "-"); + result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc--def--ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, false, null, "_"); + var result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, false, null, "-"); + result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc---def---ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, false, null, "-"); + var result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, false, null, "_"); + result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-_def-_ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, false, null, "_"); + var result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, false, null, "-"); + result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc--def--ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, false, null, "_"); + var result = kebabCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc-123-456def-g-89hi-jkl-mn-12"); + + opts = new Options(true, false, null, "-"); + result = kebabCaseWithOptions("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 = kebabCaseWithOptions(":.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 = kebabCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc-456def"); + + result = kebabCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc-456def"); + + result = kebabCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-abc-456-def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, false, null, "-_"); + var result = kebabCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsTailOfWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(false, true, null, "-_"); + var result = kebabCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, true, "", "-_"); + var result = kebabCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, true, null, "-"); + var result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, true, null, "_"); + result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc_-def_-ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, true, null, "_"); + var result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, true, null, "-"); + result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc--def--ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, true, null, "_"); + var result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, true, null, "-"); + result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc--def--ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, true, null, "-"); + var result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, true, null, "_"); + result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc_-def_-ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, true, null, "_"); + var result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, true, null, "-"); + result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc--def--ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, true, null, "_"); + var result = kebabCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456-def-g89-hi-jkl-mn12"); + + opts = new Options(false, true, null, "-"); + result = kebabCaseWithOptions("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 = kebabCaseWithOptions(":.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 = kebabCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123-abc456-def"); + + result = kebabCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123-abc456-def"); + + result = kebabCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-abc456-def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, true, null, "-_"); + var result = kebabCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(true, true, null, "-_"); + var result = kebabCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(true, true, "", "-_"); + var result = kebabCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(true, true, null, "-"); + var result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, true, null, "_"); + result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-_-def-_-ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(true, true, null, "_"); + var result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, true, null, "-"); + result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc---def---ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(true, true, null, "_"); + var result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, true, null, "-"); + result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc---def---ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(true, true, null, "-"); + var result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, true, null, "_"); + result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-_-def-_-ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(true, true, null, "_"); + var result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(true, true, null, "-"); + result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc---def---ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(true, true, null, "_"); + var result = kebabCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc-123-456-def-g-89-hi-jkl-mn-12"); + + opts = new Options(true, true, null, "-"); + result = kebabCaseWithOptions("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 = kebabCaseWithOptions(":.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 = kebabCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123-abc-456-def"); + + result = kebabCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123-abc-456-def"); + + result = kebabCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-abc-456-def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(true, true, null, "-_"); + var result = kebabCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + + @Nested + class NonAlphabetsAsPartOfWordAndWithKeptCharacters { + @Test + void convertCamelCase() { + var opts = new Options(false, false, null, "-_"); + var result = kebabCaseWithOptions("abcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertPascalCase() { + var opts = new Options(false, false, "", "-_"); + var result = kebabCaseWithOptions("AbcDefGHIjk", opts); + assertThat(result).isEqualTo("abc-def-gh-ijk"); + } + + @Test + void convertSnakeCase() { + var opts = new Options(false, false, null, "-"); + var result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, false, null, "_"); + result = kebabCaseWithOptions("abc_def_ghi", opts); + assertThat(result).isEqualTo("abc_def_ghi"); + } + + @Test + void convertKebabCase() { + var opts = new Options(false, false, null, "_"); + var result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, false, null, "-"); + result = kebabCaseWithOptions("abc-def-ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertTrainCase() { + var opts = new Options(false, false, null, "_"); + var result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, false, null, "-"); + result = kebabCaseWithOptions("Abc-Def-Ghi", opts); + assertThat(result).isEqualTo("abc--def--ghi"); + } + + @Test + void convertMacroCase() { + var opts = new Options(false, false, null, "-"); + var result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, false, null, "_"); + result = kebabCaseWithOptions("ABC_DEF_GHI", opts); + assertThat(result).isEqualTo("abc_def_ghi"); + } + + @Test + void convertCobolCase() { + var opts = new Options(false, false, null, "_"); + var result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + + opts = new Options(false, false, null, "-"); + result = kebabCaseWithOptions("ABC-DEF-GHI", opts); + assertThat(result).isEqualTo("abc-def-ghi"); + } + + @Test + void convertWithKeepingDigits() { + var opts = new Options(false, false, null, "_"); + var result = kebabCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456def-g89hi-jkl-mn12"); + + opts = new Options(false, false, null, "-"); + result = kebabCaseWithOptions("abc123-456defG89HIJklMN12", opts); + assertThat(result).isEqualTo("abc123-456def-g89hi-jkl-mn12"); + } + + @Test + void convertWithSymbolsAsSeparators() { + var opts = new Options(false, false, null, ".~!#%?"); + var result = kebabCaseWithOptions(":.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 = kebabCaseWithOptions("123abc456def", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = kebabCaseWithOptions("123ABC456DEF", opts); + assertThat(result).isEqualTo("123abc456def"); + + result = kebabCaseWithOptions("123Abc456Def", opts); + assertThat(result).isEqualTo("123-abc456-def"); + } + + @Test + void convertAnEmptyString() { + var opts = new Options(false, false, null, "-_"); + var result = kebabCaseWithOptions("", opts); + assertThat(result).isEqualTo(""); + } + } + } +}