Advertisement
Guest User

Untitled

a guest
Jun 5th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.09 KB | None | 0 0
  1. class SimpleParserSpec extends FlatSpec with Matchers {
  2.     val parser = new SimpleParser
  3.  
  4.     "SimpleParser" should "work with basic tweet" in {
  5.         val tweet = """{"id":1,"text":"foo"}"""
  6.         parser parse tweet match {
  7.             case Some(parsed) => {
  8.                 parsed.text should be ("foo")
  9.                 parsed.id should be (1)
  10.             }
  11.             case _ => fail("didn't parse tweet")
  12.         }
  13.     }
  14.  
  15.     "SimpleParser" should "reject a non-JSON tweet" in {
  16.         val tweet = """ "id":1,"text":"foo" """
  17.         parser parse tweet match {
  18.             case Some(parsed) => fail("didn't reject a non-JSON tweet")
  19.             case e => e should be (None)
  20.         }
  21.     }
  22.  
  23.     "SimpleParser" should "ignore nested content" in {
  24.         val tweet = """{"id":1,"text":"foo","nested":{"id":2}}"""
  25.         parser parse tweet match {
  26.             case Some(parsed) => {
  27.                 parsed.text should be ("foo")
  28.                 parsed.id should be (1)
  29.             }
  30.             case _ => fail("didn't parse tweet")
  31.         }
  32.     }
  33.  
  34.     "SimpleParser" should "fail on partial content" in {
  35.         val tweet = """{"id":1}"""
  36.         parser parse tweet match {
  37.             case Some(parsed) => fail("Didn't reject a partial tweet")
  38.             case e => e should be (None)
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement