From e9778d25a89c6642a39e941d8f9c158b9f6ed2d0 Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Thu, 26 Apr 2018 14:07:07 -0400 Subject: [PATCH] Add tests removed from scalac --- jvm/src/test/scala/scala/xml/XMLTest.scala | 109 ++++++++++++++++++ shared/src/test/scala/scala/xml/XMLTest.scala | 44 +++++++ 2 files changed, 153 insertions(+) diff --git a/jvm/src/test/scala/scala/xml/XMLTest.scala b/jvm/src/test/scala/scala/xml/XMLTest.scala index 64813c732..ba204d0e1 100644 --- a/jvm/src/test/scala/scala/xml/XMLTest.scala +++ b/jvm/src/test/scala/scala/xml/XMLTest.scala @@ -480,6 +480,115 @@ class XMLTestJVM { assertEquals("""""", sort() 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("", + """|{ + | 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"".toString) + assertEquals("", + """|{ + | 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"".toString) + assertEquals("", + """|{ + | 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"".toString) + assertEquals("", + """|{ + | 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"".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"".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"") + val q"${comment: Comment}" = q"" + 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""" + 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""" + + + println("hello, world.")""".toString) + } + @UnitTest def t9060 = { val expected = """""" diff --git a/shared/src/test/scala/scala/xml/XMLTest.scala b/shared/src/test/scala/scala/xml/XMLTest.scala index 6147f56b4..998b06dcd 100644 --- a/shared/src/test/scala/scala/xml/XMLTest.scala +++ b/shared/src/test/scala/scala/xml/XMLTest.scala @@ -369,6 +369,13 @@ Ours is the portal of hope, come as you are." """, 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( == ) @@ -416,6 +423,30 @@ Ours is the portal of hope, come as you are." assertTrue( != ) } + @UnitTest + def t4124: Unit = { + val body: Node = hi + 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( xml_== ) @@ -438,6 +469,19 @@ Ours is the portal of hope, come as you are." assertHonorsIterableContract(.attributes) } + @UnitTest + def t5154: Unit = { + + // extra space made the pattern OK + def f = {{3}} match { case {{3}} => true } + + // lack of space used to error: illegal start of simple pattern + def g = {{3}} match { case {{3}} => true } + + assertTrue(f) + assertTrue(g) + } + @UnitTest def t5843: Unit = { val foo = scala.xml.Attribute(null, "foo", "1", scala.xml.Null)