/
Html5ParserSpec.scala
101 lines (83 loc) · 3.19 KB
/
Html5ParserSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* 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_== """<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"
}
}
}