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

Lift Framework example source code file (ToHeadSpec.scala)

This example Lift Framework source code file (ToHeadSpec.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

failed, failed, full, full, improve, improve, specification, todo, todo, tohead, toheadspec

The Lift Framework ToHeadSpec.scala source code

/*
 * Copyright 2007-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 util

import xml.XML._

import org.specs.Specification

import common._
import ControlHelpers._
import HeadHelper._


/**
 * Systems under specification for ToHead.
 */
object ToHeadSpec extends Specification("ToHead Specification") {

  "lift <head> merger" should {
    "merge /html/body//head into existing /html/head section" in {
      val susfiles = for {
        act <- tryo(getClass.getResource("ToHeadSpec.actual1.html")).filter(_ ne null)
        exp <- tryo(getClass.getResource("ToHeadSpec.expected1.html")).filter(_ ne null)
      } yield (act, exp)

      susfiles match {
        case Full(sus) =>
          val actual = load(sus._1)
          val expected = load(sus._2)
          mergeToHtmlHead(actual).toString.replaceAll("\\s", "") must_==
          (expected.toString.replaceAll("\\s", ""))
        case _         =>
          fail("Failed loading test files") // TODO: Improve error message
      }
    }

    "merge <head> from real example" in {
      val susfiles = for {
        act <- tryo(getClass.getResource("ToHeadSpec.actual2.html")).filter(_ ne null)
        exp <- tryo(getClass.getResource("ToHeadSpec.expected2.html")).filter(_ ne null)
      } yield (act, exp)

      susfiles match {
        case Full(sus) =>
          val actual = load(sus._1)
          val expected = load(sus._2)
          mergeToHtmlHead(actual) must ==/(expected)
        case _         =>
          fail("Failed loading test files") // TODO: Improve error message
      }
    }

    "merge <lift:tohead> into a new head if not previously exist" in {
      val susfiles = for {
        act <- tryo(getClass.getResource("ToHeadSpec.actual3.html")).filter(_ ne null)
        exp <- tryo(getClass.getResource("ToHeadSpec.expected3.html")).filter(_ ne null)
      } yield (act, exp)

      susfiles match {
        case Full(sus) =>
          val actual = load(sus._1)
          val expected = load(sus._2)
          mergeToHtmlHead(actual).toString.replaceAll("\\s", "") must_==
          (expected.toString.replaceAll("\\s", ""))
        case _         =>
          fail("Failed loading test files") // TODO: Improve error message
      }
    }
   }

  /*
   "lift head cleaner" should {
     "remove duplicate title tag" >> {
       val actual = (<title>hellohello2hello3)

       val expected = (<title>hello)

       HeadHelper.cleanHead(actual) must equalIgnoreSpace(expected)
     }
     "remove script tag with same id as previous script tag" >> {
       val invariant = (<script type="text/javascript" id="sc1" src="foo1.js">)
       HeadHelper.cleanHead(invariant) must equalIgnoreSpace(invariant)

       val actual = (<script type="text/javascript" id="sc1" src="foo1.js">)
       val expected = (<script type="text/javascript" id="sc1" src="foo1.js">)
       HeadHelper.cleanHead(actual) must equalIgnoreSpace(expected)
     }
     "remove script tag with src attributes if src attributes are equals to previous script" >> {
       val actual = (<script type="text/javascript" id="sc1" src="foo1.js">)
       val expected = (<script type="text/javascript" id="sc1" src="foo1.js">)
       HeadHelper.cleanHead(actual) must equalIgnoreSpace(expected)

       val actual2 = (<script type="text/javascript" id="sc1" src="foo1.js">)
       val expected2 = (<script type="text/javascript" id="sc1" src="foo1.js">)
       HeadHelper.cleanHead(actual2) must equalIgnoreSpace(expected2)
     }
     "remove script tag if content are equals to previous script (need to trim each line ?)" >> {
       val actual = (<script type="text/javascript">alert("hello");)
       val expected = (<script type="text/javascript" >alert("hello");)
       HeadHelper.cleanHead(actual) must equalIgnoreSpace(expected)
     }
     "remove link to css with same id as previous link tag" >> {
       val invariant = (<link id="css1" rel="stylesheet" type="text/css" href="style1.css"/>)
       HeadHelper.cleanHead(invariant) must equalIgnoreSpace(invariant)

       val actual = (<link id="css1" rel="stylesheet" type="text/css" href="style1.css"/>)
       val expected = (<link id="css1" rel="stylesheet" type="text/css" href="style1.css"/>)
       HeadHelper.cleanHead(actual) must equalIgnoreSpace(expected)
     }
     "remove link tag with href attributes if href attributes are equals to previous link" >> {
       val invariant = (<link rel="stylesheet" type="text/css" href="style1.css"/>)
       HeadHelper.cleanHead(invariant) must equalIgnoreSpace(invariant)

       val actual = (<link rel="stylesheet" type="text/css" href="style1.css"/>)
       val expected = (<link rel="stylesheet" type="text/css" href="style1.css"/>)
       HeadHelper.cleanHead(actual) must equalIgnoreSpace(expected)
     }
     "remove style tag with same id as previous style tag" >> {
       val invariant = (<style id="st1">.foo{{...}})
       HeadHelper.cleanHead(invariant) must equalIgnoreSpace(invariant)

       val actual = (<style id="st1">.foo{{...}})
       val expected = (<style id="st1">.foo{{...}})
       HeadHelper.cleanHead(actual) must equalIgnoreSpace(expected)
     }
     "remove style tag if content are equals to previous style (need to trim each line ?)" >> {
       val invariant = (<style>.foo{{...}})
       HeadHelper.cleanHead(invariant) must equalIgnoreSpace(invariant)

       val actual = (<style>.foo{{...}})
       val expected = (<style>.foo{{...}})
       HeadHelper.cleanHead(actual) must equalIgnoreSpace(expected)
     }
   }
*/
}

Other Lift Framework examples (source code examples)

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