Skip to content

Add tests removed from scalac #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions jvm/src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,115 @@ class XMLTestJVM {
assertEquals("""<a a:b="1" a:c="2" a:d="3" a:e="4" a:f="5"/>""", sort(<a a:b="1" a:c="2" a:d="3" a:e="4" a:f="5"/>) toString)
}

@UnitTest
def t8253: Unit = {
// `identity(foo)` used to match the overly permissive match in SymbolXMLBuilder
// which was intended to more specifically match `_root_.scala.xml.Text(...)`

import reflect.runtime.universe._ // not using the XML library in compiler tests

val ns1 = "ns1"
assertEquals(reify(ns1).tree.toString, q"ns1".toString)
assertEquals("<sample xmlns='ns1'/>",
"""|{
| var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
| $tmpscope = new _root_.scala.xml.NamespaceBinding(null, "ns1", $tmpscope);
| {
| val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
| new _root_.scala.xml.Elem(null, "sample", _root_.scala.xml.Null, $scope, true)
| }
|}""".stripMargin,
q"<sample xmlns='ns1'/>".toString)
assertEquals("<sample xmlns={identity(ns1)}/>",
"""|{
| var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
| $tmpscope = new _root_.scala.xml.NamespaceBinding(null, ns1, $tmpscope);
| {
| val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
| new _root_.scala.xml.Elem(null, "sample", _root_.scala.xml.Null, $scope, true)
| }
|}""".stripMargin,
q"<sample xmlns={ns1}/>".toString)
assertEquals("<sample xmlns:foo='ns1'/>",
"""|{
| var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
| $tmpscope = new _root_.scala.xml.NamespaceBinding("foo", "ns1", $tmpscope);
| {
| val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
| new _root_.scala.xml.Elem(null, "sample", _root_.scala.xml.Null, $scope, true)
| }
|}""".stripMargin,
q"<sample xmlns:foo='ns1'/>".toString)
assertEquals("<sample xmlns:foo={identity(ns1)}/>",
"""|{
| var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
| $tmpscope = new _root_.scala.xml.NamespaceBinding("foo", ns1, $tmpscope);
| {
| val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
| new _root_.scala.xml.Elem(null, "sample", _root_.scala.xml.Null, $scope, true)
| }
|}""".stripMargin,
q"<sample xmlns:foo={ns1}/>".toString)
}

@UnitTest
def t8466lift: Unit = {
import scala.reflect.runtime.universe._

implicit val liftXmlComment = Liftable[Comment] { comment =>
q"new _root_.scala.xml.Comment(${comment.commentText})"
}
liftXmlComment(Comment("foo"))
assertEquals(q"${Comment("foo")}".toString, q"<!--foo-->".toString)
}

@UnitTest
def t8466unlift: Unit = {
import scala.reflect.runtime.universe._

implicit val unliftXmlComment = Unliftable[Comment] {
case q"new _root_.scala.xml.Comment(${value: String})" => Comment(value)
}
unliftXmlComment.unapply(q"<!--foo-->")
val q"${comment: Comment}" = q"<!--foo-->"
assertEquals(comment.commentText, "foo")
}

@UnitTest
def t9027: Unit = {
// used to be parsed as .println

import reflect.runtime._, universe._

assertEquals(
"""|{
| {
| val $buf = new _root_.scala.xml.NodeBuffer();
| $buf.$amp$plus(new _root_.scala.xml.Elem(null, "a", _root_.scala.xml.Null, $scope, true));
| $buf.$amp$plus(new _root_.scala.xml.Elem(null, "b", _root_.scala.xml.Null, $scope, true));
| $buf
| };
| println("hello, world.")
|}""".stripMargin,
q"""<a/><b/>
println("hello, world.")""".toString)
assertEquals(
"""|{
| {
| val $buf = new _root_.scala.xml.NodeBuffer();
| $buf.$amp$plus(new _root_.scala.xml.Elem(null, "a", _root_.scala.xml.Null, $scope, true));
| $buf.$amp$plus(new _root_.scala.xml.Elem(null, "b", _root_.scala.xml.Null, $scope, true));
| $buf.$amp$plus(new _root_.scala.xml.Elem(null, "c", _root_.scala.xml.Null, $scope, true));
| $buf
| };
| println("hello, world.")
|}""".stripMargin,
q"""<a/>
<b/>
<c/>
println("hello, world.")""".toString)
}

@UnitTest
def t9060 = {
val expected = """<a xmlns:b·="http://example.com"/>"""
Expand Down
44 changes: 44 additions & 0 deletions shared/src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ Ours is the portal of hope, come as you are."
</wsdl:definitions>""", wsdlTemplate4("service4", () => "target4") toString)
}

@UnitTest
def t547: Unit = {
// ambiguous toString problem from #547
val atom: scala.xml.Atom[Unit] = new scala.xml.Atom(())
assertEquals(().toString, atom.toString)
}

@UnitTest
def t1079 = assertFalse(<t user:tag=""/> == <t user:tag="X"/>)

Expand Down Expand Up @@ -416,6 +423,30 @@ Ours is the portal of hope, come as you are."
assertTrue(<k a="1" b="2"/> != <k b="2"/>)
}

@UnitTest
def t4124: Unit = {
val body: Node = <elem>hi</elem>
assertEquals("hi", ((body: AnyRef, "foo"): @unchecked) match {
case (node: Node, "bar") => "bye"
case (ser: Serializable, "foo") => "hi"
})

assertEquals("hi", ((body, "foo"): @unchecked) match {
case (node: Node, "bar") => "bye"
case (ser: Serializable, "foo") => "hi"
})

assertEquals("bye", ((body: AnyRef, "foo"): @unchecked) match {
case (node: Node, "foo") => "bye"
case (ser: Serializable, "foo") => "hi"
})

assertEquals("bye", ((body: AnyRef, "foo"): @unchecked) match {
case (node: Node, "foo") => "bye"
case (ser: Serializable, "foo") => "hi"
})
}

@UnitTest
def t5052: Unit = {
assertTrue(<elem attr={ null: String }/> xml_== <elem/>)
Expand All @@ -438,6 +469,19 @@ Ours is the portal of hope, come as you are."
assertHonorsIterableContract(<a a="" y={ null: String }/>.attributes)
}

@UnitTest
def t5154: Unit = {

// extra space made the pattern OK
def f = <z> {{3}}</z> match { case <z> {{3}}</z> => true }

// lack of space used to error: illegal start of simple pattern
def g = <z>{{3}}</z> match { case <z>{{3}}</z> => true }

assertTrue(f)
assertTrue(g)
}

@UnitTest
def t5843: Unit = {
val foo = scala.xml.Attribute(null, "foo", "1", scala.xml.Null)
Expand Down