Skip to content

Commit

Permalink
Switch to simplespec 0.4.0-SNAPSHOT.
Browse files Browse the repository at this point in the history
  • Loading branch information
codahale committed Jul 21, 2011
1 parent 51dce64 commit 2c0bc8f
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 309 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<dependency>
<groupId>com.codahale</groupId>
<artifactId>simplespec_${scala.version}</artifactId>
<version>0.3.4</version>
<version>0.4.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
53 changes: 27 additions & 26 deletions src/test/scala/com/codahale/jerkson/tests/ASTTypeSupportSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,121 +3,122 @@ package com.codahale.jerkson.tests
import com.codahale.jerkson.Json._
import com.codahale.jerkson.AST._
import com.codahale.simplespec.Spec
import com.codahale.simplespec.annotation.test

class ASTTypeSupportSpec extends Spec {
class `An AST.JInt` {
def `generates a JSON int` = {
@test def `generates a JSON int` = {
generate(JInt(15)) must beEqualTo("15")
}

def `is parsable from a JSON int` = {
@test def `is parsable from a JSON int` = {
parse[JInt]("15") must beEqualTo(JInt(15))
}

def `is parsable from a JSON int as a JValue` = {
@test def `is parsable from a JSON int as a JValue` = {
parse[JValue]("15") must beEqualTo(JInt(15))
}
}

class `An AST.JFloat` {
def `generates a JSON int` = {
@test def `generates a JSON int` = {
generate(JFloat(15.1)) must beEqualTo("15.1")
}

def `is parsable from a JSON float` = {
@test def `is parsable from a JSON float` = {
parse[JFloat]("15.1") must beEqualTo(JFloat(15.1))
}

def `is parsable from a JSON float as a JValue` = {
@test def `is parsable from a JSON float as a JValue` = {
parse[JValue]("15.1") must beEqualTo(JFloat(15.1))
}
}


class `An AST.JString` {
def `generates a JSON string` = {
@test def `generates a JSON string` = {
generate(JString("woo")) must beEqualTo("\"woo\"")
}

def `is parsable from a JSON string` = {
@test def `is parsable from a JSON string` = {
parse[JString]("\"woo\"") must beEqualTo(JString("woo"))
}

def `is parsable from a JSON string as a JValue` = {
@test def `is parsable from a JSON string as a JValue` = {
parse[JValue]("\"woo\"") must beEqualTo(JString("woo"))
}
}

class `An AST.JNull` {
def `generates a JSON null` = {
@test def `generates a JSON null` = {
generate(JNull) must beEqualTo("null")
}

def `is parsable from a JSON null` = {
@test def `is parsable from a JSON null` = {
parse[JNull.type]("null") must beEqualTo(JNull)
}

def `is parsable from a JSON null as a JValue` = {
@test def `is parsable from a JSON null as a JValue` = {
parse[JValue]("null") must beEqualTo(JNull)
}
}

class `An AST.JBoolean` {
def `generates a JSON true` = {
@test def `generates a JSON true` = {
generate(JBoolean(true)) must beEqualTo("true")
}

def `generates a JSON false` = {
@test def `generates a JSON false` = {
generate(JBoolean(false)) must beEqualTo("false")
}

def `is parsable from a JSON true` = {
@test def `is parsable from a JSON true` = {
parse[JBoolean]("true") must beEqualTo(JBoolean(true))
}

def `is parsable from a JSON false` = {
@test def `is parsable from a JSON false` = {
parse[JBoolean]("false") must beEqualTo(JBoolean(false))
}

def `is parsable from a JSON true as a JValue` = {
@test def `is parsable from a JSON true as a JValue` = {
parse[JValue]("true") must beEqualTo(JBoolean(true))
}

def `is parsable from a JSON false as a JValue` = {
@test def `is parsable from a JSON false as a JValue` = {
parse[JValue]("false") must beEqualTo(JBoolean(false))
}
}

class `An AST.JArray of JInts` {
def `generates a JSON array of ints` = {
@test def `generates a JSON array of ints` = {
generate(JArray(List(JInt(1), JInt(2), JInt(3)))) must beEqualTo("[1,2,3]")
}

def `is parsable from a JSON array of ints` = {
@test def `is parsable from a JSON array of ints` = {
parse[JArray]("[1,2,3]") must beEqualTo(JArray(List(JInt(1), JInt(2), JInt(3))))
}

def `is parsable from a JSON array of ints as a JValue` = {
@test def `is parsable from a JSON array of ints as a JValue` = {
parse[JValue]("[1,2,3]") must beEqualTo(JArray(List(JInt(1), JInt(2), JInt(3))))
}
}

class `An AST.JObject` {
private val obj = JObject(List(JField("id", JInt(1)), JField("name", JString("Coda"))))
val obj = JObject(List(JField("id", JInt(1)), JField("name", JString("Coda"))))

def `generates a JSON object with matching field values` = {
@test def `generates a JSON object with matching field values` = {
generate(obj) must beEqualTo("""{"id":1,"name":"Coda"}""")
}

def `is parsable from a JSON object` = {
@test def `is parsable from a JSON object` = {
parse[JObject]("""{"id":1,"name":"Coda"}""") must beEqualTo(obj)
}

def `is parsable from a JSON object as a JValue` = {
@test def `is parsable from a JSON object as a JValue` = {
parse[JValue]("""{"id":1,"name":"Coda"}""") must beEqualTo(obj)
}

def `is parsable from an empty JSON object` = {
@test def `is parsable from an empty JSON object` = {
parse[JObject]("""{}""") must beEqualTo(JObject(Nil))
}
}
Expand Down
Loading

0 comments on commit 2c0bc8f

Please sign in to comment.