alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Play Framework/Scala example source code file (EventSourceSpec.scala)

This example Play Framework source code file (EventSourceSpec.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Play Framework (and Scala) source code examples by using tags.

All credit for the original source code belongs to Play Framework; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Play Framework tags/keywords

api, event, eventsource, eventsourcespec, lib, library, none, play, play framework, some, specification

The EventSourceSpec.scala Play Framework example source code

package play.api.libs

import org.specs2.mutable.Specification

object EventSourceSpec extends Specification {

  import EventSource.Event

  "EventSource event formatter" should {

    "format an event" in {
      Event("foo", None, None).formatted must equalTo ("data: foo\n\n")
    }

    "format an event with an id" in {
      Event("foo", Some("42"), None).formatted must equalTo ("id: 42\ndata: foo\n\n")
    }

    "format an event with a name" in {
      Event("foo", None, Some("message")).formatted must equalTo ("event: message\ndata: foo\n\n")
    }

    "split data by lines" in {
      Event("a\nb").formatted must equalTo ("data: a\ndata: b\n\n")
    }

    "support '\\r' as an end of line" in {
      Event("a\rb").formatted must equalTo ("data: a\ndata: b\n\n")
    }

    "support '\\r\\n' as an end of line" in {
      Event("a\r\nb").formatted must equalTo ("data: a\ndata: b\n\n")
    }

  }

}

Other Play Framework source code examples

Here is a short list of links related to this Play Framework EventSourceSpec.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.