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

Lift Framework example source code file (ConversionsSpec.scala)

This example Lift Framework source code file (ConversionsSpec.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Lift Framework tags/keywords

a, bar, hello, int, list, nodeseq, nodeseq, nodeseqfunc, nodeseqfunc, string, string, stringfunc, stringfunc, stringornodeseq

The Lift Framework ConversionsSpec.scala source code

/*
 * Copyright 2010-2011 WorldWide Conferencing, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.liftweb
package common

import xml._

import org.specs.Specification


/**
 * System under specification for Conversions.
 */
object ConversionsSpec extends Specification("Conversions Specification") {

  "A StringOrNodeSeq" should {

    "convert from a String" in {
      val sns: StringOrNodeSeq = "Hello"
      sns.nodeSeq must_== Text("Hello")
    }

    "convert from an Elem" in {
      val sns: StringOrNodeSeq = <b/>
      sns.nodeSeq must ==/ ( <b/> )
    }

    "convert from a Seq[Node]" in {
      val sns: StringOrNodeSeq = List(<a/>, )
      sns.nodeSeq must ==/ (List(<a/>, ) : NodeSeq)
    }
  }

  "A StringFunc" should {

    "be created by a String constant" in {
      val sf: StringFunc = "Foo"

      sf.func() must_== "Foo"
    }

    "be created by a String Function" in {
      val sf: StringFunc = () => "Bar"

      sf.func() must_== "Bar"
    }

    "be created by a constant that can be converted to a String" in {
      implicit def intToString(in: Int): String = in.toString
      val sf: StringFunc = 55

      sf.func() must_== "55"
    }

    "be created by a function that can be converted to a String" in {
      implicit def intToString(in: Int): String = in.toString
      val sf: StringFunc = () => 55

      sf.func() must_== "55"
    }

  }

  "A NodeSeqFunc" should {

    "be created by a NodeSeq constant" in {
      val sf: NodeSeqFunc = <b>Foo

      sf.func() must ==/ (<b>Foo)
    }

    "be created by a NodeSeq Function" in {
      val sf: NodeSeqFunc = () => <i>Bar

      sf.func() must ==/ (<i>Bar)
    }

    "be created by a constant that can be converted to a NodeSeq" in {
      implicit def intToNS(in: Int): NodeSeq = <a>{in}
      val sf: NodeSeqFunc = 55

      sf.func() must ==/ (<a>55)
    }

    "be created by a function that can be converted to a NodeSeq" in {
      implicit def intToNodeSeq(in: Int): NodeSeq = <a>{in}
      val sf: NodeSeqFunc = () => 55

      sf.func() must ==/ (<a>55)
    }

  }

}

Other Lift Framework examples (source code examples)

Here is a short list of links related to this Lift Framework ConversionsSpec.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.