Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f2410f6a95
Fetching contributors…

Cannot retrieve contributors at this time

102 lines (83 sloc) 3.262 kb
/*
* 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="&amp;dog"/>) must_== """<foo baz="&dog"></foo>"""
}
"ignore attributes that are null" in {
toString(<foo id={None}/>) must_== """<foo></foo>"""
}
}
"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 <head>" in {
val parsed = parse("<div><lift:head>123</lift:head></div>").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"><div/></lift:surround>""")
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"><div/></div>""")
val e = parsed.open_!.asInstanceOf[Elem]
e.label must_== "div"
(parsed.open_! \ "@with").text must_== "dog"
}
}
}
Jump to Line
Something went wrong with that request. Please try again.