Skip to content

Commit 8b2e8e0

Browse files
committed
Migrate a few partest jvm tests to JUnit tests.
Migrated to JUnit the following tests (from test/files/jvm): * t0632.scala * t1118.scala * unittest_xml.scala None of those tests were dependent on anything jvm specific.
1 parent 1d66533 commit 8b2e8e0

File tree

11 files changed

+228
-167
lines changed

11 files changed

+228
-167
lines changed

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ pomExtra := (
8181
// default value must be set here
8282
TestKeys.includeTestDependencies := true
8383

84+
libraryDependencies ++= Seq("junit" % "junit" % "4.11" % "test", "com.novocode" % "junit-interface" % "0.10" % "test")
85+
8486
// default
8587
TestKeys.partestVersion := "1.0.0-RC6"
8688

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package scala.xml
2+
3+
object JUnitAssertsForXML {
4+
5+
private[xml] def assertEquals(expected: String, actual: NodeSeq): Unit =
6+
org.junit.Assert.assertEquals(expected, actual.toString)
7+
8+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package scala.xml
2+
3+
import org.junit.Test
4+
import org.junit.Ignore
5+
import org.junit.runner.RunWith
6+
import org.junit.runners.JUnit4
7+
import org.junit.Assert.assertEquals
8+
9+
class MetaDataTest {
10+
11+
@Test
12+
def absentElementPrefixed1: Unit = {
13+
// type ascription to help overload resolution pick the right variant
14+
assertEquals(null: Object, Null("za://foo.com", TopScope, "bar"))
15+
assertEquals(null, Null("bar"))
16+
}
17+
18+
@Test
19+
def absentElementPrefixed2: Unit = {
20+
assertEquals(None, Null.get("za://foo.com", TopScope, "bar" ))
21+
assertEquals(None, Null.get("bar"))
22+
}
23+
24+
@Test
25+
def presentElement1: Unit = {
26+
val x = new PrefixedAttribute("zo","bar", new Atom(42), Null)
27+
val s = new NamespaceBinding("zo","za://foo.com", TopScope)
28+
assertEquals(new Atom(42), x("za://foo.com", s, "bar" ))
29+
assertEquals(null, x("bar"))
30+
assertEquals(Some(new Atom(42)), x.get("za://foo.com", s, "bar"))
31+
assertEquals(None, x.get("bar"))
32+
}
33+
34+
@Test
35+
def presentElement2: Unit = {
36+
val s = new NamespaceBinding("zo","za://foo.com", TopScope)
37+
val x1 = new PrefixedAttribute("zo","bar", new Atom(42), Null)
38+
val x = new UnprefixedAttribute("bar","meaning", x1)
39+
assertEquals(null, x(null, s, "bar"))
40+
assertEquals(Text("meaning"), x("bar"))
41+
assertEquals(None, x.get(null, s, "bar" ))
42+
assertEquals(Some(Text("meaning")), x.get("bar"))
43+
}
44+
45+
@Test
46+
def attributeExtractor: Unit = {
47+
def domatch(x:Node): Node = {
48+
x match {
49+
case Node("foo", md @ UnprefixedAttribute(_, value, _), _*) if !value.isEmpty =>
50+
md("bar")(0)
51+
case _ => new Atom(3)
52+
}
53+
}
54+
val z = <foo bar="gar"/>
55+
val z2 = <foo/>
56+
assertEquals(Text("gar"), domatch(z))
57+
assertEquals(new Atom(3), domatch(z2))
58+
}
59+
60+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package scala.xml
2+
3+
import org.junit.Test
4+
import org.junit.Ignore
5+
import org.junit.runner.RunWith
6+
import org.junit.runners.JUnit4
7+
import JUnitAssertsForXML.assertEquals
8+
9+
class PrintEmptyElementsTest {
10+
11+
@Test
12+
def representEmptyXMLElementsInShortForm: Unit = {
13+
val expected: String =
14+
"""|
15+
|<hi/> <!-- literal short -->
16+
|<there></there> <!-- literal long -->
17+
|<guys who="you all"></guys> <!-- literal long with attribute-->
18+
|<hows it="going"/> <!-- literal short with attribute -->
19+
|<this>is pretty cool</this> <!-- literal not empty -->
20+
|""".stripMargin
21+
// the xml snippet is not indented because indentation affects pretty printing
22+
// results
23+
val actual: NodeSeq =
24+
<xml:group>
25+
<hi/> <!-- literal short -->
26+
<there></there> <!-- literal long -->
27+
<guys who="you all"></guys> <!-- literal long with attribute-->
28+
<hows it="going"/> <!-- literal short with attribute -->
29+
<this>is pretty cool</this> <!-- literal not empty -->
30+
</xml:group>
31+
assertEquals(expected, actual)
32+
}
33+
34+
@Test
35+
def programmaticLong: Unit = {
36+
assertEquals("<emptiness></emptiness> <!--programmatic long-->",
37+
Elem(null, "emptiness", Null, TopScope, false) ++ Text(" ") ++ Comment("programmatic long"))
38+
}
39+
40+
@Test
41+
def programmaticShort: Unit = {
42+
assertEquals("<vide/> <!--programmatic short-->",
43+
Elem(null, "vide", Null, TopScope, true) ++ Text(" ") ++ Comment("programmatic short"))
44+
}
45+
46+
@Test
47+
def programmaticShortWithAttribute: Unit = {
48+
assertEquals("""<elem attr="value"/> <!--programmatic short with attribute-->""",
49+
Elem(null, "elem", Attribute("attr", Text("value"), Null), TopScope, true) ++ Text(" ") ++ Comment ("programmatic short with attribute"))
50+
}
51+
52+
@Test
53+
def programmaticLongWithAttribute: Unit = {
54+
assertEquals("""<elem2 attr2="value2"></elem2> <!--programmatic long with attribute-->""",
55+
Elem(null, "elem2", Attribute("attr2", Text("value2"), Null), TopScope, false) ++ Text(" ") ++ Comment ("programmatic long with attribute"))
56+
}
57+
58+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package scala.xml
2+
3+
import org.junit.Test
4+
import org.junit.Ignore
5+
import org.junit.runner.RunWith
6+
import org.junit.runners.JUnit4
7+
import org.junit.Assert.assertTrue
8+
import org.junit.Assert.assertFalse
9+
import org.junit.Assert.assertEquals
10+
11+
class UtilityTest {
12+
13+
@Test
14+
def isNameStart: Unit = {
15+
assertTrue(Utility.isNameStart('b'))
16+
assertFalse(Utility.isNameStart(':'))
17+
}
18+
19+
@Test
20+
def trim: Unit = {
21+
val x = <foo>
22+
<toomuchws/>
23+
</foo>
24+
val y = xml.Utility.trim(x)
25+
assertEquals(1, y match { case <foo><toomuchws/></foo> => 1 })
26+
27+
val x2 = <foo>
28+
<toomuchws> a b b a </toomuchws>
29+
</foo>
30+
val y2 = xml.Utility.trim(x2)
31+
assertEquals(2, y2 match { case <foo><toomuchws>a b b a</toomuchws></foo> => 2 })
32+
}
33+
34+
@Test
35+
def aposEscaping: Unit = {
36+
val z = <bar>''</bar>
37+
val z1 = z.toString
38+
assertEquals("<bar>''</bar>", z1)
39+
}
40+
41+
@Test
42+
def sort: Unit = {
43+
val q = xml.Utility.sort(<a g='3' j='2' oo='2' a='2'/>)
44+
assertEquals(" a=\"2\" g=\"3\" j=\"2\" oo=\"2\"", xml.Utility.sort(q.attributes).toString)
45+
val pp = new xml.PrettyPrinter(80,5)
46+
assertEquals("<a a=\"2\" g=\"3\" j=\"2\" oo=\"2\"/>", pp.format(q))
47+
}
48+
49+
@Test
50+
def issue777: Unit = {
51+
<hi>
52+
<there/>
53+
<guys/>
54+
</hi>.hashCode // Bug #777
55+
}
56+
57+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package scala.xml.parsing
2+
3+
import org.junit.Test
4+
import org.junit.Ignore
5+
import org.junit.runner.RunWith
6+
import org.junit.runners.JUnit4
7+
import scala.xml.JUnitAssertsForXML.assertEquals
8+
9+
class Ticket0632Test {
10+
11+
import scala.io.Source.fromString
12+
import scala.xml.parsing.ConstructingParser.fromSource
13+
import scala.xml.{NodeSeq, TopScope}
14+
private def parse(s:String) = fromSource(fromString(s), false).element(TopScope)
15+
16+
@Test
17+
def singleAmp: Unit = {
18+
val expected = "<foo x=\"&amp;\"/>"
19+
assertEquals(expected, parse("<foo x='&amp;'/>"))
20+
assertEquals(expected, xml.XML.loadString("<foo x='&amp;'/>"))
21+
assertEquals(expected, <foo x="&amp;"/>)
22+
assertEquals(expected, <foo x={ "&" }/>)
23+
}
24+
25+
@Test
26+
def oneAndHalfAmp: Unit = {
27+
val expected = "<foo x=\"&amp;amp;\"/>"
28+
assertEquals(expected, xml.XML.loadString("<foo x='&amp;amp;'/>"))
29+
assertEquals(expected, parse("<foo x='&amp;amp;'/>"))
30+
assertEquals(expected, <foo x="&amp;amp;"/>)
31+
assertEquals(expected, <foo x={ "&amp;" }/>)
32+
}
33+
34+
@Test
35+
def doubleAmp: Unit = {
36+
val expected = "<foo x=\"&amp;&amp;\"/>"
37+
assertEquals(expected, xml.XML.loadString("<foo x='&amp;&amp;'/>"))
38+
assertEquals(expected, parse("<foo x='&amp;&amp;'/>"))
39+
assertEquals(expected, <foo x="&amp;&amp;"/>)
40+
assertEquals(expected, <foo x={ "&&" }/>)
41+
}
42+
43+
}

test/files/jvm/t0632.check

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/files/jvm/t0632.scala

Lines changed: 0 additions & 22 deletions
This file was deleted.

test/files/jvm/t1118.check

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/files/jvm/t1118.scala

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)