<commit_before>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.twitter.bijection.json4s

import org.scalacheck.Properties
import com.twitter.bijection.{Injection, BaseProperties}
import Json4sInjections._
import org.json4s.JsonAST._
import org.json4s.JsonAST.JString

/**
 * @author <NAME>
 * @since 1/10/14
 */
object Json4sInjectionLaws extends Properties("Json4sInjection")
with BaseProperties {
  case class Twit(name: String, id: Int, id_str: String, indices: List[Int], screen_name: String)

  def createTwit(i: (String, Int, String, List[Int], String)): Twit = Twit(i._1, i._2, i._3, i._4, i._5)

  implicit val testCaseClassToJson = arbitraryViaFn {
    in: (String, Int, String, List[Int], String) => createTwit(in)
  }

  implicit val testJValueToJson = arbitraryViaFn[(String, Int, String, List[Int], String),JValue] {
    in: (String, Int, String, List[Int], String) => JObject(
      List(
        JField("name", JString(in._1)),
        JField("id", JInt(in._2)),
        JField("id_String", JString(in._3)),
        JField("indices", JArray(in._4.map(JInt(_)))),
        JField("screen_name", JString(in._5))
      ))
  }

  def roundTripCaseClassToJson(implicit inj: Injection[Twit, String], mn: Manifest[Twit]) = isLooseInjection[Twit, String]

  def roundTripCaseClassToJValue(implicit inj: Injection[Twit, JValue], mn: Manifest[Twit]) = isLooseInjection[Twit, JValue]

  def roundTripJValueToString(implicit inj: Injection[JValue, String]) = isLooseInjection[JValue, String]

  property("round trip Case Class to Json") = roundTripCaseClassToJson
  property("round trip Case Class to JValue") = roundTripCaseClassToJValue
  property("round trip JValue to String") = roundTripJValueToString
}<commit_msg>fixed the build on scala 2.10<commit_after>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.twitter.bijection.json4s

import org.scalacheck.Properties
import com.twitter.bijection.{Injection, BaseProperties}

import org.json4s.JsonAST._
import org.json4s.JsonAST.JString

/**
 * @author <NAME>
 * @since 1/10/14
 */
object Json4sInjectionLaws extends Properties("Json4sInjection")
with BaseProperties {
  case class Twit(name: String, id: Int, id_str: String, indices: List[Int], screen_name: String)

  def createTwit(i: (String, Int, String, List[Int], String)): Twit = Twit(i._1, i._2, i._3, i._4, i._5)

  implicit val testCaseClassToJson = arbitraryViaFn {
    in: (String, Int, String, List[Int], String) => createTwit(in)
  }

  implicit val testJValueToJson = arbitraryViaFn[(String, Int, String, List[Int], String),JValue] {
    in: (String, Int, String, List[Int], String) => JObject(
      List(
        JField("name", JString(in._1)),
        JField("id", JInt(in._2)),
        JField("id_String", JString(in._3)),
        JField("indices", JArray(in._4.map(JInt(_)))),
        JField("screen_name", JString(in._5))
      ))
  }

  def roundTripCaseClassToJson(implicit inj: Injection[Twit, String], mn: Manifest[Twit]) = isLooseInjection[Twit, String]

  def roundTripCaseClassToJValue(implicit inj: Injection[Twit, JValue], mn: Manifest[Twit]) = isLooseInjection[Twit, JValue]

  def roundTripJValueToString(implicit inj: Injection[JValue, String]) = isLooseInjection[JValue, String]

  property("round trip Case Class to Json") = {
    import Json4sInjections.caseClass2Json
    roundTripCaseClassToJson
  }
  property("round trip Case Class to JValue") = {
    import Json4sInjections.caseClass2JValue
    roundTripCaseClassToJValue
  }
  property("round trip JValue to String") = {
    import Json4sInjections.jvalue2Json
    roundTripJValueToString
  }
}
{'fraction_non_alphanumeric': 0.11395101171458999, 'fraction_numerical': 0.01235356762513312, 'mean_word_length': 4.241071428571429, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5715208', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1496, 'n_words': 427}