aboutsummaryrefslogtreecommitdiff
path: root/shared/src/test/scala/FieldNameTests.scala
diff options
context:
space:
mode:
Diffstat (limited to 'shared/src/test/scala/FieldNameTests.scala')
-rw-r--r--shared/src/test/scala/FieldNameTests.scala44
1 files changed, 2 insertions, 42 deletions
diff --git a/shared/src/test/scala/FieldNameTests.scala b/shared/src/test/scala/FieldNameTests.scala
index f1b76a9..885dfb6 100644
--- a/shared/src/test/scala/FieldNameTests.scala
+++ b/shared/src/test/scala/FieldNameTests.scala
@@ -2,46 +2,6 @@ package spray.json
import org.scalatest._
-trait SnakeCaseFormats { self: DerivedFormats =>
- override def extractFieldName(paramName: String) =
- FieldNaming.substituteCamel(paramName, '_')
-}
-trait KebabCaseFormats { self: DerivedFormats =>
- override def extractFieldName(paramName: String) =
- FieldNaming.substituteCamel(paramName, '-')
-}
-
-object FieldNaming {
-
- @inline final private def isLower(ch: Char): Boolean =
- ((ch & 0x20) != 0) || (ch == '_')
-
- @inline def substituteCamel(paramName: String, substitute: Char) = {
- val length = paramName.length
- val builder = new StringBuilder(length)
- var i = 0
- while (i < length) {
- val cur = paramName(i)
- if (isLower(cur) && i + 1 < length) {
- builder.append(cur)
- val next = paramName(i + 1)
- if (!isLower(next)) {
- builder.append(substitute)
- builder.append((next ^ 0x20).toChar)
- } else {
- builder.append(next)
- }
- i += 1
- } else {
- builder.append((cur ^ 0x20).toChar)
- }
- i += 1
- }
- builder.result()
- }
-
-}
-
class FieldNameTests extends FlatSpec with FormatTests {
case class A(camelCASE: String, `__a_aB__`: Int, `a-a_B`: Int)
@@ -52,7 +12,7 @@ class FieldNameTests extends FlatSpec with FormatTests {
}
{
- object Protocol extends All with SnakeCaseFormats
+ object Protocol extends All with SnakeCase
import Protocol._
"snake_case" should behave like checkRoundtrip(
B(A("helloWorld", 0, 0)),
@@ -61,7 +21,7 @@ class FieldNameTests extends FlatSpec with FormatTests {
}
{
- object Protocol extends All with KebabCaseFormats
+ object Protocol extends All with KebabCase
import Protocol._
"kebab-case" should behave like checkRoundtrip(
B(A("helloWorld", 0, 0)),