diff options
author | Jakob Odersky <jakob@odersky.com> | 2018-04-19 20:56:27 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2018-04-19 20:56:27 -0700 |
commit | f57e5f96d657c422836f69faf55d8df3992ab3be (patch) | |
tree | a350049ef863479d62238d3b02b405dee2460ba0 /shared/src/test/scala/FieldNameTests.scala | |
parent | 4f239025c6185f551fc15ed34e2ddbcf0e0948e0 (diff) | |
download | spray-json-derivation-f57e5f96d657c422836f69faf55d8df3992ab3be.tar.gz spray-json-derivation-f57e5f96d657c422836f69faf55d8df3992ab3be.tar.bz2 spray-json-derivation-f57e5f96d657c422836f69faf55d8df3992ab3be.zip |
Add utility formats for modifying parameter name extraction
Diffstat (limited to 'shared/src/test/scala/FieldNameTests.scala')
-rw-r--r-- | shared/src/test/scala/FieldNameTests.scala | 44 |
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)), |