Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

json, json-scalaz, json-ext

  • Loading branch information...
commit 6d7ef24ea4927c4b07da0b74a188011299f185e1 1 parent 357844a
@nafg nafg authored
Showing with 106 additions and 76 deletions.
  1. +3 −2 core/json-ext/src/test/scala/net/liftweb/json/ext/JodaTimeSerializerSpec.scala
  2. +3 −2 core/json-ext/src/test/scala/net/liftweb/json/ext/JsonBoxSerializerSpec.scala
  3. +1 −1  core/json-scalaz/src/test/scala/net/lifweb/json/scalaz/Example.scala
  4. +1 −1  core/json-scalaz/src/test/scala/net/lifweb/json/scalaz/LottoExample.scala
  5. +1 −1  core/json-scalaz/src/test/scala/net/lifweb/json/scalaz/TupleExample.scala
  6. +4 −4 core/json-scalaz/src/test/scala/net/lifweb/json/scalaz/ValidationExample.scala
  7. +4 −2 core/json/src/test/scala/net/liftweb/json/DiffExamples.scala
  8. +1 −1  core/json/src/test/scala/net/liftweb/json/Examples.scala
  9. +6 −4 core/json/src/test/scala/net/liftweb/json/ExtractionBugs.scala
  10. +4 −2 core/json/src/test/scala/net/liftweb/json/ExtractionExamplesSpec.scala
  11. +1 −1  core/json/src/test/scala/net/liftweb/json/FieldSerializerBugs.scala
  12. +4 −4 core/json/src/test/scala/net/liftweb/json/FieldSerializerExamples.scala
  13. +21 −18 core/json/src/test/scala/net/liftweb/json/JsonAstSpec.scala
  14. +4 −2 core/json/src/test/scala/net/liftweb/json/JsonFormatsSpec.scala
  15. +7 −4 core/json/src/test/scala/net/liftweb/json/JsonParserSpec.scala
  16. +6 −3 core/json/src/test/scala/net/liftweb/json/JsonPrintingSpec.scala
  17. +4 −2 core/json/src/test/scala/net/liftweb/json/JsonQueryExamples.scala
  18. +7 −4 core/json/src/test/scala/net/liftweb/json/JsonXmlSpec.scala
  19. +4 −2 core/json/src/test/scala/net/liftweb/json/LottoExample.scala
  20. +4 −2 core/json/src/test/scala/net/liftweb/json/MergeExamples.scala
  21. +3 −3 core/json/src/test/scala/net/liftweb/json/ParserBugs.scala
  22. +3 −2 core/json/src/test/scala/net/liftweb/json/PullParserExamples.scala
  23. +2 −2 core/json/src/test/scala/net/liftweb/json/SerializationBugs.scala
  24. +4 −4 core/json/src/test/scala/net/liftweb/json/SerializationExamples.scala
  25. +1 −1  core/json/src/test/scala/net/liftweb/json/XmlBugs.scala
  26. +3 −2 core/json/src/test/scala/net/liftweb/json/XmlExamples.scala
View
5 core/json-ext/src/test/scala/net/liftweb/json/ext/JodaTimeSerializerSpec.scala
@@ -20,7 +20,7 @@ package ext
import org.joda.time._
-import org.specs.Specification
+import org.specs2.mutable.Specification
import common._
import json.Serialization.{read, write => swrite}
@@ -29,7 +29,8 @@ import json.Serialization.{read, write => swrite}
/**
* System under specification for JodaTimeSerializer.
*/
-object JodaTimeSerializerSpec extends Specification("JodaTimeSerializer Specification") {
+object JodaTimeSerializerSpec extends Specification {
+ "JodaTimeSerializer Specification".title
implicit val formats = Serialization.formats(NoTypeHints) ++ JodaTimeSerializers.all
View
5 core/json-ext/src/test/scala/net/liftweb/json/ext/JsonBoxSerializerSpec.scala
@@ -18,7 +18,7 @@ package net.liftweb
package json
package ext
-import org.specs.Specification
+import org.specs2.mutable.Specification
import common._
import json.Serialization.{read, write => swrite}
@@ -27,7 +27,8 @@ import json.Serialization.{read, write => swrite}
/**
* System under specification for JsonBoxSerializer.
*/
-object JsonBoxSerializerSpec extends Specification("JsonBoxSerializer Specification") {
+object JsonBoxSerializerSpec extends Specification {
+ "JsonBoxSerializer Specification".title
implicit val formats = net.liftweb.json.DefaultFormats + new JsonBoxSerializer
View
2  core/json-scalaz/src/test/scala/net/lifweb/json/scalaz/Example.scala
@@ -5,7 +5,7 @@ import Scalaz._
import JsonScalaz._
import net.liftweb.json._
-import org.specs.Specification
+import org.specs2.mutable.Specification
object Example extends Specification {
View
2  core/json-scalaz/src/test/scala/net/lifweb/json/scalaz/LottoExample.scala
@@ -5,7 +5,7 @@ import Scalaz._
import JsonScalaz._
import net.liftweb.json._
-import org.specs.Specification
+import org.specs2.mutable.Specification
object LottoExample extends Specification {
case class Winner(winnerId: Long, numbers: List[Int])
View
2  core/json-scalaz/src/test/scala/net/lifweb/json/scalaz/TupleExample.scala
@@ -5,7 +5,7 @@ import Scalaz._
import JsonScalaz._
import net.liftweb.json._
-import org.specs.Specification
+import org.specs2.mutable.Specification
object TupleExample extends Specification {
"Parse tuple from List" in {
View
8 core/json-scalaz/src/test/scala/net/lifweb/json/scalaz/ValidationExample.scala
@@ -5,7 +5,7 @@ import Scalaz._
import JsonScalaz._
import net.liftweb.json._
-import org.specs.Specification
+import org.specs2.mutable.Specification
object ValidationExample extends Specification {
@@ -30,9 +30,9 @@ object ValidationExample extends Specification {
"pass when age within limits" in {
// Age must be between 16 an 60
-// FIXME enable when 2.8 no longer supported, 2.9 needs: import Validation.Monad._
-// val person = Person.applyJSON(field("name"), validate[Int]("age") >=> min(16) >=> max(60) apply _)
-// person(json) mustEqual Success(Person("joe", 17))
+ import Validation.Monad._
+ val person = Person.applyJSON(field("name"), validate[Int]("age") >=> min(16) >=> max(60) apply _)
+ person(json) mustEqual Success(Person("joe", 17))
}
}
View
6 core/json/src/test/scala/net/liftweb/json/DiffExamples.scala
@@ -17,13 +17,15 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
/**
* System under specification for Diff Examples.
*/
-object DiffExamples extends Specification("Diff Examples") {
+object DiffExamples extends Specification {
+ "Diff Examples".title
+
import MergeExamples.{scala1, scala2, lotto1, lotto2, mergedLottoResult}
"Diff example" in {
View
2  core/json/src/test/scala/net/liftweb/json/Examples.scala
@@ -17,7 +17,7 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
object Examples extends Specification {
View
10 core/json/src/test/scala/net/liftweb/json/ExtractionBugs.scala
@@ -17,13 +17,15 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
+
+object ExtractionBugs extends Specification {
+ "Extraction bugs Specification".title
-object ExtractionBugs extends Specification("Extraction bugs Specification") {
implicit val formats = DefaultFormats
-
+
"ClassCastException (BigInt) regression 2 must pass" in {
- val opt = OptionOfInt(Some(39))
+ val opt = OptionOfInt(Some(39))
Extraction.decompose(opt).extract[OptionOfInt].opt.get mustEqual 39
}
View
6 core/json/src/test/scala/net/liftweb/json/ExtractionExamplesSpec.scala
@@ -18,9 +18,11 @@ package net.liftweb
package json
import java.util.Date
-import org.specs.Specification
+import org.specs2.mutable.Specification
+
+object ExtractionExamples extends Specification {
+ "Extraction Examples Specification".title
-object ExtractionExamples extends Specification("Extraction Examples Specification") {
implicit val formats = DefaultFormats
"Extraction example" in {
View
2  core/json/src/test/scala/net/liftweb/json/FieldSerializerBugs.scala
@@ -17,7 +17,7 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
object FieldSerializerBugs extends Specification {
import Serialization.{read, write => swrite}
View
8 core/json/src/test/scala/net/liftweb/json/FieldSerializerExamples.scala
@@ -17,9 +17,9 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
-object FieldSerializerExamples extends Specification {
+object FieldSerializerExamples extends Specification {
import Serialization.{read, write => swrite}
import FieldSerializer._
@@ -33,7 +33,7 @@ object FieldSerializerExamples extends Specification {
"All fields are serialized by default" in {
implicit val formats = DefaultFormats + FieldSerializer[WildDog]()
val ser = swrite(dog)
- val dog2 = read[WildDog](ser)
+ val dog2 = read[WildDog](ser)
dog2.name mustEqual dog.name
dog2.color mustEqual dog.color
dog2.owner mustEqual dog.owner
@@ -49,7 +49,7 @@ object FieldSerializerExamples extends Specification {
implicit val formats = DefaultFormats + dogSerializer
val ser = swrite(dog)
- val dog2 = read[WildDog](ser)
+ val dog2 = read[WildDog](ser)
dog2.name mustEqual dog.name
dog2.color mustEqual dog.color
dog2.owner must beNull
View
39 core/json/src/test/scala/net/liftweb/json/JsonAstSpec.scala
@@ -17,7 +17,8 @@
package net.liftweb
package json
-import org.specs.{ScalaCheck, Specification}
+import org.specs2.mutable.Specification
+import org.specs2.ScalaCheck
import org.scalacheck._
import org.scalacheck.Prop.{forAll, forAllNoShrink}
@@ -25,37 +26,39 @@ import org.scalacheck.Prop.{forAll, forAllNoShrink}
/**
* System under specification for JSON AST.
*/
-object JsonAstSpec extends Specification("JSON AST Specification") with JValueGen with ScalaCheck {
+object JsonAstSpec extends Specification with JValueGen with ScalaCheck {
+ "JSON AST Specification".title
+
"Functor identity" in {
val identityProp = (json: JValue) => json == (json map identity)
- forAll(identityProp) must pass
+ check(forAll(identityProp))
}
"Functor composition" in {
val compositionProp = (json: JValue, fa: JValue => JValue, fb: JValue => JValue) =>
json.map(fb).map(fa) == json.map(fa compose fb)
- forAll(compositionProp) must pass
+ check(forAll(compositionProp))
}
"Monoid identity" in {
val identityProp = (json: JValue) => (json ++ JNothing == json) && (JNothing ++ json == json)
- forAll(identityProp) must pass
+ check(forAll(identityProp))
}
"Monoid associativity" in {
val assocProp = (x: JValue, y: JValue, z: JValue) => x ++ (y ++ z) == (x ++ y) ++ z
- forAll(assocProp) must pass
+ check(forAll(assocProp))
}
"Merge identity" in {
val identityProp = (json: JValue) => (json merge JNothing) == json && (JNothing merge json) == json
- forAll(identityProp) must pass
+ check(forAll(identityProp))
}
"Merge idempotency" in {
val idempotencyProp = (x: JValue) => (x merge x) == x
- forAll(idempotencyProp) must pass
+ check(forAll(idempotencyProp))
}
"Diff identity" in {
@@ -63,12 +66,12 @@ object JsonAstSpec extends Specification("JSON AST Specification") with JValueGe
(json diff JNothing) == Diff(JNothing, JNothing, json) &&
(JNothing diff json) == Diff(JNothing, json, JNothing)
- forAll(identityProp) must pass
+ check(forAll(identityProp))
}
"Diff with self is empty" in {
val emptyProp = (x: JValue) => (x diff x) == Diff(JNothing, JNothing, JNothing)
- forAll(emptyProp) must pass
+ check(forAll(emptyProp))
}
"Diff is subset of originals" in {
@@ -76,25 +79,25 @@ object JsonAstSpec extends Specification("JSON AST Specification") with JValueGe
val Diff(c, a, d) = x diff y
y == (y merge (c merge a))
}
- forAll(subsetProp) must pass
+ check(forAll(subsetProp))
}
"Diff result is same when fields are reordered" in {
val reorderProp = (x: JObject) => (x diff reorderFields(x)) == Diff(JNothing, JNothing, JNothing)
- forAll(reorderProp) must pass
+ check(forAll(reorderProp))
}
"Remove all" in {
val removeAllProp = (x: JValue) => (x remove { _ => true }) == JNothing
- forAll(removeAllProp) must pass
+ check(forAll(removeAllProp))
}
"Remove nothing" in {
val removeNothingProp = (x: JValue) => (x remove { _ => false }) == x
- forAll(removeNothingProp) must pass
+ check(forAll(removeNothingProp))
}
- "Remove removes only matching elements (in case of a field, its value is set to JNothing)" in {
+ "Remove removes only matching elements (in case of a field, its value is set to JNothing)" in check {
forAllNoShrink(genJValue, genJValueClass) { (json: JValue, x: Class[_ <: JValue]) => {
val removed = json remove typePredicate(x)
val Diff(c, a, d) = json diff removed
@@ -103,7 +106,7 @@ object JsonAstSpec extends Specification("JSON AST Specification") with JValueGe
case _ => true
}
c == JNothing && a == JNothing && elemsLeft.forall(_.getClass != x)
- }} must pass
+ }}
}
"Replace one" in {
@@ -142,8 +145,8 @@ object JsonAstSpec extends Specification("JSON AST Specification") with JValueGe
// ensure that we test some JObject instances
val fieldReplacement = (x: JObject, replacement: JObject) => anyReplacement(x, replacement)
- forAll(fieldReplacement) must pass
- forAll(anyReplacement) must pass
+ check(forAll(fieldReplacement))
+ check(forAll(anyReplacement))
}
private def reorderFields(json: JValue) = json map {
View
6 core/json/src/test/scala/net/liftweb/json/JsonFormatsSpec.scala
@@ -17,12 +17,14 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
/**
* System under specification for JSON Formats.
*/
-object JsonFormatsSpec extends Specification("JsonFormats Specification") with TypeHintExamples {
+object JsonFormatsSpec extends Specification with TypeHintExamples {
+ "JsonFormats Specification".title
+
implicit val formats = ShortTypeHintExamples.formats + FullTypeHintExamples.formats.typeHints
val hintsForFish = ShortTypeHintExamples.formats.typeHints.hintFor(classOf[Fish])
View
11 core/json/src/test/scala/net/liftweb/json/JsonParserSpec.scala
@@ -17,7 +17,8 @@
package net.liftweb
package json
-import org.specs.{ScalaCheck, Specification}
+import org.specs2.mutable.Specification
+import org.specs2.ScalaCheck
import org.scalacheck.{Arbitrary, Gen}
import org.scalacheck.Prop._
@@ -25,16 +26,18 @@ import org.scalacheck.Prop._
/**
* System under specification for JSON Parser.
*/
-object JsonParserSpec extends Specification("JSON Parser Specification") with JValueGen with ScalaCheck {
+object JsonParserSpec extends Specification with JValueGen with ScalaCheck {
+ "JSON Parser Specification".title
+
"Any valid json can be parsed" in {
val parsing = (json: JValue) => { parse(Printer.pretty(render(json))); true }
- forAll(parsing) must pass
+ check(forAll(parsing))
}
"Buffer size does not change parsing result" in {
val bufSize = Gen.choose(2, 64)
val parsing = (x: JValue, s1: Int, s2: Int) => { parseVal(x, s1) == parseVal(x, s2) }
- forAll(genObject, bufSize, bufSize)(parsing) must pass
+ check(forAll(genObject, bufSize, bufSize)(parsing))
}
"Parsing is thread safe" in {
View
9 core/json/src/test/scala/net/liftweb/json/JsonPrintingSpec.scala
@@ -17,7 +17,8 @@
package net.liftweb
package json
-import org.specs.{ScalaCheck, Specification}
+import org.specs2.mutable.Specification
+import org.specs2.ScalaCheck
import org.scalacheck.Arbitrary
import org.scalacheck.Prop.forAll
@@ -25,12 +26,14 @@ import org.scalacheck.Prop.forAll
/**
* System under specification for JSON Printing.
*/
-object JsonPrintingSpec extends Specification("JSON Printing Specification") with JValueGen with ScalaCheck {
+object JsonPrintingSpec extends Specification with JValueGen with ScalaCheck {
+ "JSON Printing Specification".title
+
import scala.text.Document
"rendering does not change semantics" in {
val rendering = (json: Document) => parse(Printer.pretty(json)) == parse(Printer.compact(json))
- forAll(rendering) must pass
+ check(forAll(rendering))
}
private def parse(json: String) = scala.util.parsing.json.JSON.parse(json)
View
6 core/json/src/test/scala/net/liftweb/json/JsonQueryExamples.scala
@@ -17,13 +17,15 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
/**
* System under specification for JSON Query Examples.
*/
-object JsonQueryExamples extends Specification("JSON Query Examples") {
+object JsonQueryExamples extends Specification {
+ "JSON Query Examples".title
+
"List of IPs" in {
val ips = for { JString(ip) <- json \\ "ip" } yield ip
ips mustEqual List("192.168.1.125", "192.168.1.126", "192.168.1.127", "192.168.2.125", "192.168.2.126")
View
11 core/json/src/test/scala/net/liftweb/json/JsonXmlSpec.scala
@@ -17,7 +17,8 @@
package net.liftweb
package json
-import org.specs.{ScalaCheck, Specification}
+import org.specs2.mutable.Specification
+import org.specs2.ScalaCheck
import org.scalacheck.Arbitrary
import org.scalacheck.Prop.forAll
@@ -25,18 +26,20 @@ import org.scalacheck.Prop.forAll
/**
* System under specification for JSON XML.
*/
-object JsonXmlSpec extends Specification("JSON XML Specification") with NodeGen with JValueGen with ScalaCheck {
+object JsonXmlSpec extends Specification with NodeGen with JValueGen with ScalaCheck {
+ "JSON XML Specification".title
+
import Xml._
import scala.xml.Node
"Valid XML can be converted to JSON and back (symmetric op)" in {
val conversion = (xml: Node) => { toXml(toJson(xml)).head == xml }
- forAll(conversion) must pass
+ check(forAll(conversion))
}
"JSON can be converted to XML, and back to valid JSON (non symmetric op)" in {
val conversion = (json: JValue) => { parse(compact(render(toJson(toXml(json))))); true }
- forAll(conversion) must pass
+ check(forAll(conversion))
}
implicit def arbXml: Arbitrary[Node] = Arbitrary(genXml)
View
6 core/json/src/test/scala/net/liftweb/json/LottoExample.scala
@@ -17,13 +17,15 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
/**
* System under specification for Lotto Examples.
*/
-object LottoExample extends Specification("Lotto Examples") {
+object LottoExample extends Specification {
+ "Lotto Examples".title
+
import JsonDSL._
implicit val formats = DefaultFormats
View
6 core/json/src/test/scala/net/liftweb/json/MergeExamples.scala
@@ -17,11 +17,13 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
-object MergeExamples extends Specification("Merge Examples") {
+object MergeExamples extends Specification {
+ "Merge Examples".title
+
"Merge example" in {
(scala1 merge scala2) mustEqual expectedMergeResult
}
View
6 core/json/src/test/scala/net/liftweb/json/ParserBugs.scala
@@ -19,7 +19,7 @@ package json
import util.control.Exception._
-import org.specs.Specification
+import org.specs2.mutable.Specification
object ParserBugs extends Specification {
"Unicode ffff is a valid char in string literal" in {
@@ -40,8 +40,8 @@ object ParserBugs extends Specification {
}
"Solo quote mark should fail cleanly (not StringIndexOutOfBoundsException) (1041)" in {
- JsonParser.parse("\"", discardParser) must throwA(new Exception()).like {
- case e: JsonParser.ParseException => e.getMessage.startsWith("unexpected eof")
+ JsonParser.parse("\"", discardParser) must throwA[JsonParser.ParseException].like {
+ case e => e.getMessage must startWith("unexpected eof")
}
}
View
5 core/json/src/test/scala/net/liftweb/json/PullParserExamples.scala
@@ -17,13 +17,14 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
/**
* System under specification for JSON Pull Parser.
*/
-object PullParserExamples extends Specification("JSON Pull Parser Examples") {
+object PullParserExamples extends Specification {
+ "JSON Pull Parser Examples".title
import JsonParser._
"Pull parsing example" in {
View
4 core/json/src/test/scala/net/liftweb/json/SerializationBugs.scala
@@ -17,7 +17,7 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
import java.util.UUID
object SerializationBugs extends Specification {
@@ -100,7 +100,7 @@ object SerializationBugs extends Specification {
case (TypeInfo(SeqClass, parameterizedType), JArray(xs)) =>
val typeInfo = TypeInfo(parameterizedType
.map(_.getActualTypeArguments()(0))
- .getOrElse(fail("No type parameter info for type Seq")).asInstanceOf[Class[_]], None)
+ .getOrElse(failure("No type parameter info for type Seq")).asInstanceOf[Class[_]], None)
xs.map(x => Extraction.extract(x, typeInfo))
}
}
View
8 core/json/src/test/scala/net/liftweb/json/SerializationExamples.scala
@@ -18,7 +18,7 @@ package net.liftweb
package json
import java.util.Date
-import org.specs.Specification
+import org.specs2.mutable.Specification
object SerializationExamples extends Specification {
import Serialization.{read, write => swrite}
@@ -288,10 +288,10 @@ object CustomSerializerExamples extends Specification {
i2.startTime mustEqual i.startTime
i2.endTime mustEqual i.endTime
- val p = Pattern.compile("^Curly")
- val pser = swrite(p)
+ val pat = Pattern.compile("^Curly")
+ val pser = swrite(pat)
pser mustEqual """{"$pattern":"^Curly"}"""
- read[Pattern](pser).pattern mustEqual p.pattern
+ read[Pattern](pser).pattern mustEqual pat.pattern
val d = new Date(0)
val dser = swrite(d)
View
2  core/json/src/test/scala/net/liftweb/json/XmlBugs.scala
@@ -17,7 +17,7 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
object XmlBugs extends Specification {
View
5 core/json/src/test/scala/net/liftweb/json/XmlExamples.scala
@@ -17,13 +17,14 @@
package net.liftweb
package json
-import org.specs.Specification
+import org.specs2.mutable.Specification
/**
* System under specification for Xml Examples.
*/
-object XmlExamples extends Specification("XML Examples") {
+object XmlExamples extends Specification {
+ "XML Examples".title
import JsonDSL._
import Xml._
import scala.xml.{Group, Text}

1 comment on commit 6d7ef24

@fmpwizard
Owner

+1

Please sign in to comment.
Something went wrong with that request. Please try again.