This repository has been archived by the owner on May 15, 2019. It is now read-only.
/
NodeSeqSpecs.scala
47 lines (38 loc) · 1.95 KB
/
NodeSeqSpecs.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
package com.codecommit.antixml
import org.specs._
object NodeSeqSpecs extends Specification {
import XML._
"shallow selector" should {
"find an immediate descendant" in {
val ns = fromString("<parent><parent/></parent>")
ns \ "parent" mustEqual NodeSeq(elem("parent"))
}
"be referentially transparent" in {
val ns = fromString("<parent><parent/></parent>")
ns \ "parent" mustEqual NodeSeq(elem("parent"))
ns \ "parent" mustEqual NodeSeq(elem("parent"))
}
"find a subset of nodes" in {
val ns = fromString("<parent>Some<a/>text<b/>to\nreally<c/>confuse<a/><b/><d/>things<e/><a/><f/></parent>")
val result = NodeSeq(elem("a"), elem("a"), elem("a"))
ns \ "a" mustEqual result
}
}
"deep selector" should {
"find an immediate descendant" in {
val ns = fromString("<parent><parent/></parent>")
ns \\ "parent" mustEqual NodeSeq(elem("parent"))
}
"find a subset of nodes" in {
val ns = fromString("<parent>Some<a/>text<b/>to\nreally<c/>confuse<a/><b/><d/>things<e/><a/><f/></parent>")
val result = NodeSeq(elem("a"), elem("a"), elem("a"))
ns \\ "a" mustEqual result
}
"find and linearize a deep subset of nodes" in {
val ns = fromString("<parent>Some text<sub1><target>sub1</target></sub1><target>top<sub1><target>top1</target><target>top2</target></sub1><target>top3-outer</target></target><phoney><target>phoney</target></phoney>More text<target>outside</target></parent>")
val result = fromString("<parent><target>top<sub1><target>top1</target><target>top2</target></sub1><target>top3-outer</target></target><target>outside</target><target>sub1</target><target>top3-outer</target><target>phoney</target><target>top1</target><target>top2</target></parent>")
ns \\ "target" mustEqual result.head.asInstanceOf[Elem].children
}
}
def elem(name: String, children: Node*) = Elem(None, name, Map(), NodeSeq(children: _*))
}