Skip to content

Commit 06f38a3

Browse files
committed
Merge pull request #14 from adriaanm/junitify
turn remainder of the pos/run/jvm partest tests into JUnit ones
2 parents d2e3480 + 4670d66 commit 06f38a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+986
-1571
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package scala.xml
2+
3+
import org.junit.Test
4+
import org.junit.Assert.assertTrue
5+
import org.junit.Assert.assertEquals
6+
7+
class PatternMatching extends {
8+
@Test
9+
def unprefixedAttribute: Unit = {
10+
val li = List("1", "2", "3", "4")
11+
assertTrue(matchSeq(li))
12+
assertTrue(matchList(li))
13+
}
14+
15+
def matchSeq(args: Seq[String]) = args match {
16+
case Seq(a, b, c, d @ _*) => true
17+
}
18+
19+
def matchList(args: List[String]) =
20+
Elem(null, "bla", Null, TopScope, minimizeEmpty = true, (args map { x => Text(x) }): _*) match {
21+
case Elem(_, _, _, _, Text("1"), _*) => true
22+
}
23+
24+
@Test
25+
def simpleNode =
26+
assertTrue(<hello/> match {
27+
case <hello/> => true
28+
})
29+
30+
@Test
31+
def nameSpaced =
32+
assertTrue(<x:ga xmlns:x="z"/> match {
33+
case <x:ga/> => true
34+
})
35+
36+
val cx = <z:hello foo="bar" xmlns:z="z" x:foo="baz" xmlns:x="the namespace from outer space">
37+
crazy text world
38+
</z:hello>
39+
40+
@Test
41+
def nodeContents = {
42+
assertTrue(Utility.trim(cx) match {
43+
case n @ <hello>crazy text world</hello> if (n \ "@foo") xml_== "bar" => true
44+
})
45+
assertTrue(Utility.trim(cx) match {
46+
case n @ <z:hello>crazy text world</z:hello> if (n \ "@foo") xml_== "bar" => true
47+
})
48+
assertTrue(<x:foo xmlns:x="gaga"/> match {
49+
case scala.xml.QNode("gaga", "foo", md, child @ _*) => true
50+
})
51+
52+
assertTrue(<x:foo xmlns:x="gaga"/> match {
53+
case scala.xml.Node("foo", md, child @ _*) => true
54+
})
55+
56+
}
57+
58+
object SafeNodeSeq {
59+
def unapplySeq(any: Any): Option[Seq[Node]] = any match {
60+
case s: Seq[_] => Some(s flatMap (_ match {
61+
case n: Node => n case _ => NodeSeq.Empty
62+
})) case _ => None
63+
}
64+
}
65+
66+
@Test
67+
def nodeSeq = { // t0646
68+
import scala.xml.NodeSeq
69+
70+
val books =
71+
<bks>
72+
<title>Blabla</title>
73+
<title>Blubabla</title>
74+
<title>Baaaaaaalabla</title>
75+
</bks>;
76+
77+
assertTrue(new NodeSeq { val theSeq = books.child } match {
78+
case t @ Seq(<title>Blabla</title>) => false
79+
case _ => true
80+
})
81+
82+
// SI-1059
83+
var m: PartialFunction[Any, Any] = { case SafeNodeSeq(s @ _*) => s }
84+
85+
assertEquals(m(<a/> ++ <b/>), List(<a/>, <b/>))
86+
assertTrue(m.isDefinedAt(<a/> ++ <b/>))
87+
}
88+
89+
@Test
90+
def SI_4124 = {
91+
val body: Node = <elem>hi</elem>
92+
93+
assertTrue((body: AnyRef, "foo") match {
94+
case (node: Node, "bar") => false
95+
case (ser: Serializable, "foo") => true
96+
})
97+
98+
assertTrue((body, "foo") match {
99+
case (node: Node, "bar") => false
100+
case (ser: Serializable, "foo") => true
101+
})
102+
103+
assertTrue((body: AnyRef, "foo") match {
104+
case (node: Node, "foo") => true
105+
case (ser: Serializable, "foo") => false
106+
})
107+
108+
assertTrue((body: AnyRef, "foo") match {
109+
case (node: Node, "foo") => true
110+
case (ser: Serializable, "foo") => false
111+
})
112+
}
113+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package scala.xml
2+
3+
// these tests depend on xml, so they ended up here,
4+
// though really they are compiler tests
5+
6+
import scala.collection._
7+
import scala.collection.mutable.ArrayBuffer
8+
9+
// t1626
10+
object o {
11+
val n = <a xmlns=""/>
12+
n.namespace == null
13+
}
14+
15+
// t1761
16+
class Foo {
17+
val elements: Seq[Node] = Nil
18+
val innerTransform: PartialFunction[Elem, String] = {
19+
case Elem(_, l: String, _, _, _@ _*) if elements.exists(_.label == l) =>
20+
l
21+
}
22+
}
23+
24+
// t2281
25+
class A {
26+
def f(x: Boolean) = if (x) <br/><br/> else <br/>
27+
}
28+
29+
class B {
30+
def splitSentences(text: String): ArrayBuffer[String] = {
31+
val outarr = new ArrayBuffer[String]
32+
var outstr = new StringBuffer
33+
var prevspace = false
34+
val ctext = text.replaceAll("\n+", "\n")
35+
ctext foreach { c =>
36+
outstr append c
37+
if (c == '.' || c == '!' || c == '?' || c == '\n' || c == ':' || c == ';' || (prevspace && c == '-')) {
38+
outarr += outstr.toString
39+
outstr = new StringBuffer
40+
}
41+
if (c == '\n') {
42+
outarr += "\n\n"
43+
}
44+
prevspace = c == ' '
45+
}
46+
if (outstr.length > 0) {
47+
outarr += outstr.toString
48+
}
49+
outarr
50+
}
51+
52+
def spanForSentence(x: String, picktext: String) =
53+
if (x == "\n\n") {
54+
<br/><br/>
55+
} else {
56+
<span class='clicksentence' style={ if (x == picktext) "background-color: yellow" else "" }>{ x }</span>
57+
}
58+
59+
def selectableSentences(text: String, picktext: String) = {
60+
val sentences = splitSentences(text)
61+
sentences.map(x => spanForSentence(x, picktext))
62+
}
63+
}
64+
65+
// SI-5858
66+
object Test {
67+
new Elem(null, null, Null, TopScope, Nil: _*) // was ambiguous
68+
}
69+
70+
class Floozy {
71+
def fooz(x: Node => String) = {}
72+
def foo(m: Node): Unit = fooz {
73+
case Elem(_, _, _, _, n, _*) if (n == m) => "gaga"
74+
}
75+
}
76+
77+
object guardedMatch { // SI-3705
78+
// guard caused verifyerror in oldpatmat -- TODO: move this to compiler test suite
79+
def updateNodes(ns: Seq[Node]): Seq[Node] =
80+
for (subnode <- ns) yield subnode match {
81+
case <d>{ _ }</d> if true => <d>abc</d>
82+
case Elem(prefix, label, attribs, scope, children @ _*) =>
83+
Elem(prefix, label, attribs, scope, minimizeEmpty = true, updateNodes(children): _*)
84+
case other => other
85+
}
86+
updateNodes(<b/>)
87+
}
88+
89+
// SI-6897
90+
object shouldCompile {
91+
val html = (null: Any) match {
92+
case 1 => <xml:group></xml:group>
93+
case 2 => <p></p>
94+
}
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package scala.xml
2+
3+
import scala.xml.transform._
4+
5+
import org.junit.Test
6+
import org.junit.Assert.assertTrue
7+
import org.junit.Assert.assertEquals
8+
9+
class Transformers {
10+
11+
12+
def transformer = new RuleTransformer(new RewriteRule {
13+
override def transform(n: Node): NodeSeq = n match {
14+
case <t>{ _* }</t> => <q/>
15+
case n => n
16+
}
17+
})
18+
19+
@Test
20+
def transform = // SI-2124
21+
assertEquals(transformer.transform(<p><lost/><t><s><r></r></s></t></p>),
22+
<p><lost/><q/></p>)
23+
24+
@Test
25+
def transformNamespaced = // SI-2125
26+
assertEquals(transformer.transform(<xml:group><p><lost/><t><s><r></r></s></t></p></xml:group>),
27+
Group(<p><lost/><q/></p>))
28+
29+
@Test
30+
def rewriteRule = { // SI-2276
31+
val inputXml: Node =
32+
<root>
33+
<subnode>
34+
<version>1</version>
35+
</subnode>
36+
<contents>
37+
<version>1</version>
38+
</contents>
39+
</root>
40+
41+
object t1 extends RewriteRule {
42+
override def transform(n: Node): Seq[Node] = n match {
43+
case <version>{ x }</version> if x.toString.toInt < 4 => <version>{ x.toString.toInt + 1 }</version>
44+
case other => other
45+
}
46+
}
47+
48+
val ruleTransformer = new RuleTransformer(t1)
49+
JUnitAssertsForXML.assertEquals(ruleTransformer(inputXml).toString, // TODO: why do we need toString?
50+
<root>
51+
<subnode>
52+
<version>2</version>
53+
</subnode>
54+
<contents>
55+
<version>2</version>
56+
</contents>
57+
</root>)
58+
}
59+
}

0 commit comments

Comments
 (0)