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

Lift Framework example source code file (Html5ParserSpec.scala)

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

full, htm5, html5parser, html5parser, html5parserspec, html5writer, none, parse, parse, pendinguntilfixed, specification, specification, todo, write

The Lift Framework Html5ParserSpec.scala source code

/*
 * Copyright 2006-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.Elem

import org.specs.Specification
import org.specs.specification.PendingUntilFixed

import common._
import Helpers._


/**
 * Systems under specification for Html5 Parser.
 */
object Html5ParserSpec extends Specification("Html5Parser Specification") with PendingUntilFixed with Html5Parser with Html5Writer {

  "Htm5 Writer" should {
    "Write &" in {
      toString(<foo baz="&dog"/>) must_== """"""
    }

    "ignore attributes that are null" in {
      toString(<foo id={None}/>) must_== """"""
    }
  }

  "Html5 Parser" should {
    val pages = for {
      page1 <- tryo(readWholeStream(getClass.getResourceAsStream("Html5ParserSpec.page1.html"))).filter(_ ne null)
      page2 <- tryo(readWholeStream(getClass.getResourceAsStream("Html5ParserSpec.page2.html"))).filter(_ ne null)
      page3 <- tryo(readWholeStream(getClass.getResourceAsStream("Html5ParserSpec.page3.html"))).filter(_ ne null)
    } yield (page1, page2, page3)

    pages match {
      case Full(p) =>
        val (page1, page2, page3) = (new String(p._1), new String(p._2), new String(p._3))

        "parse valid page type1" in {
          val parsed = parse(page1).open_!
          (parsed \\ "script").length must be >= 4
        }

        "parse valid page type2" in {
          val parsed = parse(page2).open_!
          (parsed \\ "script").length must be >= 4
        }

        "fail to parse invalid page type3" in {
          val parsed = parse(page3)
          parsed match {
            case _: Failure => true must_== true
            case _          => fail("succeeded parsing invalid page")
          }
        } pendingUntilFixed

      case _ =>
        fail("Failed loading test files") // TODO: Improve error message
    }

    "change <lift:head> to " in {
      val parsed = parse("<div>123
").open_! val heads = parsed \\ "head" heads.length must_== 1 heads.text must_== "123" (heads(0).asInstanceOf[Elem].prefix == null) must_== true } pendingUntilFixed "Parse stuff with lift: namespace" in { val parsed = parse("""<lift:surround with="dog">
""") val e = parsed.open_!.asInstanceOf[Elem] e.prefix must_== "lift" e.label must_== "surround" (parsed.open_! \ "@with").text must_== "dog" } "Parse stuff without lift: namespace" in { val parsed = parse("""<div with="dog">
""") val e = parsed.open_!.asInstanceOf[Elem] e.label must_== "div" (parsed.open_! \ "@with").text must_== "dog" } } }

Other Lift Framework examples (source code examples)

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