Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SimpleParserSpec extends FlatSpec with Matchers {
- val parser = new SimpleParser
- "SimpleParser" should "work with basic tweet" in {
- val tweet = """{"id":1,"text":"foo"}"""
- parser parse tweet match {
- case Some(parsed) => {
- parsed.text should be ("foo")
- parsed.id should be (1)
- }
- case _ => fail("didn't parse tweet")
- }
- }
- "SimpleParser" should "reject a non-JSON tweet" in {
- val tweet = """ "id":1,"text":"foo" """
- parser parse tweet match {
- case Some(parsed) => fail("didn't reject a non-JSON tweet")
- case e => e should be (None)
- }
- }
- "SimpleParser" should "ignore nested content" in {
- val tweet = """{"id":1,"text":"foo","nested":{"id":2}}"""
- parser parse tweet match {
- case Some(parsed) => {
- parsed.text should be ("foo")
- parsed.id should be (1)
- }
- case _ => fail("didn't parse tweet")
- }
- }
- "SimpleParser" should "fail on partial content" in {
- val tweet = """{"id":1}"""
- parser parse tweet match {
- case Some(parsed) => fail("Didn't reject a partial tweet")
- case e => e should be (None)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement