Skip to content

Commit

Permalink
Close #448 - [extras-string] Add case conversion - Seq[String].mkCame…
Browse files Browse the repository at this point in the history
…lCaseString
  • Loading branch information
kevin-lee committed Oct 23, 2023
1 parent 9aea450 commit 6126b76
Show file tree
Hide file tree
Showing 4 changed files with 580 additions and 3 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ lazy val extrasCoreJs = extrasCore.js.settings(Test / fork := false)
lazy val extrasString = crossSubProject("string", crossProject(JVMPlatform, JSPlatform))
.settings(
crossScalaVersions := props.CrossScalaVersions,
libraryDependencies += libs.cats % Test,
libraryDependencies := removeScala3Incompatible(scalaVersion.value, libraryDependencies.value),
)
lazy val extrasStringJvm = extrasString.jvm
Expand Down Expand Up @@ -1119,7 +1120,7 @@ lazy val props = new {
val isScala3Incompatible: ModuleID => Boolean =
m =>
m.name == "wartremover" ||
m.name == "ammonite" ||
m.name == "ammonite" ||
m.name == "kind-projector" ||
m.name == "better-monadic-for"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ object cases extends cases {
} yield pascal).mkString
}.mkString

def mkCamelCaseString: String =
ss.headOption.fold("")(_.toCamelCase) +
ss.drop(1).mkPascalCaseString

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package extras.strings.syntax.casesSpec

import cats.syntax.all._
import hedgehog._

/** @author Kevin Lee
Expand All @@ -13,7 +14,23 @@ object Gens {
tail <- Gen.string(Gen.lower, Range.linear(min - 1, max - 1))
} yield head +: tail

def genCamelCaseList(range: Range[Int]): Gen[List[String]] =
Gen.string(Gen.lower, Range.linear(1, 5)).list(range)
def genFirstLowerCasesThenAllPascalCases(maxLength: Int)(min: Int, max: Int): Gen[List[String]] = {
if (maxLength < 2) {
sys.error(show"maxLength should not be less than 2. maxLength=$maxLength")
} else if (min > max) {
sys.error(show"min should not be greater than max. min=$min, max=$max")
} else if (min <= 0) {
sys.error(show"min should be greater than 0. min=$min")
} else {
for {
first <- Gen.string(Gen.lower, Range.linear(1, 5))
rest <- if ((max - 1) === 0)
Gen.constant(List.empty)
else
genPascalCase(2, 5).list(Range.linear(min - 1, max - 1))
} yield first :: rest

}
}

}
Loading

0 comments on commit 6126b76

Please sign in to comment.