Skip to content

Commit b7fcbeb

Browse files
authored
Merge pull request #213 from ashawley/scalac-tests
Add tests removed from scalac
2 parents 390bd11 + e9778d2 commit b7fcbeb

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

Diff for: jvm/src/test/scala/scala/xml/XMLTest.scala

+109
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,115 @@ class XMLTestJVM {
480480
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)
481481
}
482482

483+
@UnitTest
484+
def t8253: Unit = {
485+
// `identity(foo)` used to match the overly permissive match in SymbolXMLBuilder
486+
// which was intended to more specifically match `_root_.scala.xml.Text(...)`
487+
488+
import reflect.runtime.universe._ // not using the XML library in compiler tests
489+
490+
val ns1 = "ns1"
491+
assertEquals(reify(ns1).tree.toString, q"ns1".toString)
492+
assertEquals("<sample xmlns='ns1'/>",
493+
"""|{
494+
| var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
495+
| $tmpscope = new _root_.scala.xml.NamespaceBinding(null, "ns1", $tmpscope);
496+
| {
497+
| val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
498+
| new _root_.scala.xml.Elem(null, "sample", _root_.scala.xml.Null, $scope, true)
499+
| }
500+
|}""".stripMargin,
501+
q"<sample xmlns='ns1'/>".toString)
502+
assertEquals("<sample xmlns={identity(ns1)}/>",
503+
"""|{
504+
| var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
505+
| $tmpscope = new _root_.scala.xml.NamespaceBinding(null, ns1, $tmpscope);
506+
| {
507+
| val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
508+
| new _root_.scala.xml.Elem(null, "sample", _root_.scala.xml.Null, $scope, true)
509+
| }
510+
|}""".stripMargin,
511+
q"<sample xmlns={ns1}/>".toString)
512+
assertEquals("<sample xmlns:foo='ns1'/>",
513+
"""|{
514+
| var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
515+
| $tmpscope = new _root_.scala.xml.NamespaceBinding("foo", "ns1", $tmpscope);
516+
| {
517+
| val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
518+
| new _root_.scala.xml.Elem(null, "sample", _root_.scala.xml.Null, $scope, true)
519+
| }
520+
|}""".stripMargin,
521+
q"<sample xmlns:foo='ns1'/>".toString)
522+
assertEquals("<sample xmlns:foo={identity(ns1)}/>",
523+
"""|{
524+
| var $tmpscope: _root_.scala.xml.NamespaceBinding = $scope;
525+
| $tmpscope = new _root_.scala.xml.NamespaceBinding("foo", ns1, $tmpscope);
526+
| {
527+
| val $scope: _root_.scala.xml.NamespaceBinding = $tmpscope;
528+
| new _root_.scala.xml.Elem(null, "sample", _root_.scala.xml.Null, $scope, true)
529+
| }
530+
|}""".stripMargin,
531+
q"<sample xmlns:foo={ns1}/>".toString)
532+
}
533+
534+
@UnitTest
535+
def t8466lift: Unit = {
536+
import scala.reflect.runtime.universe._
537+
538+
implicit val liftXmlComment = Liftable[Comment] { comment =>
539+
q"new _root_.scala.xml.Comment(${comment.commentText})"
540+
}
541+
liftXmlComment(Comment("foo"))
542+
assertEquals(q"${Comment("foo")}".toString, q"<!--foo-->".toString)
543+
}
544+
545+
@UnitTest
546+
def t8466unlift: Unit = {
547+
import scala.reflect.runtime.universe._
548+
549+
implicit val unliftXmlComment = Unliftable[Comment] {
550+
case q"new _root_.scala.xml.Comment(${value: String})" => Comment(value)
551+
}
552+
unliftXmlComment.unapply(q"<!--foo-->")
553+
val q"${comment: Comment}" = q"<!--foo-->"
554+
assertEquals(comment.commentText, "foo")
555+
}
556+
557+
@UnitTest
558+
def t9027: Unit = {
559+
// used to be parsed as .println
560+
561+
import reflect.runtime._, universe._
562+
563+
assertEquals(
564+
"""|{
565+
| {
566+
| val $buf = new _root_.scala.xml.NodeBuffer();
567+
| $buf.$amp$plus(new _root_.scala.xml.Elem(null, "a", _root_.scala.xml.Null, $scope, true));
568+
| $buf.$amp$plus(new _root_.scala.xml.Elem(null, "b", _root_.scala.xml.Null, $scope, true));
569+
| $buf
570+
| };
571+
| println("hello, world.")
572+
|}""".stripMargin,
573+
q"""<a/><b/>
574+
println("hello, world.")""".toString)
575+
assertEquals(
576+
"""|{
577+
| {
578+
| val $buf = new _root_.scala.xml.NodeBuffer();
579+
| $buf.$amp$plus(new _root_.scala.xml.Elem(null, "a", _root_.scala.xml.Null, $scope, true));
580+
| $buf.$amp$plus(new _root_.scala.xml.Elem(null, "b", _root_.scala.xml.Null, $scope, true));
581+
| $buf.$amp$plus(new _root_.scala.xml.Elem(null, "c", _root_.scala.xml.Null, $scope, true));
582+
| $buf
583+
| };
584+
| println("hello, world.")
585+
|}""".stripMargin,
586+
q"""<a/>
587+
<b/>
588+
<c/>
589+
println("hello, world.")""".toString)
590+
}
591+
483592
@UnitTest
484593
def t9060 = {
485594
val expected = """<a xmlns:b·="http://example.com"/>"""

Diff for: shared/src/test/scala/scala/xml/XMLTest.scala

+44
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,13 @@ Ours is the portal of hope, come as you are."
369369
</wsdl:definitions>""", wsdlTemplate4("service4", () => "target4") toString)
370370
}
371371

372+
@UnitTest
373+
def t547: Unit = {
374+
// ambiguous toString problem from #547
375+
val atom: scala.xml.Atom[Unit] = new scala.xml.Atom(())
376+
assertEquals(().toString, atom.toString)
377+
}
378+
372379
@UnitTest
373380
def t1079 = assertFalse(<t user:tag=""/> == <t user:tag="X"/>)
374381

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

426+
@UnitTest
427+
def t4124: Unit = {
428+
val body: Node = <elem>hi</elem>
429+
assertEquals("hi", ((body: AnyRef, "foo"): @unchecked) match {
430+
case (node: Node, "bar") => "bye"
431+
case (ser: Serializable, "foo") => "hi"
432+
})
433+
434+
assertEquals("hi", ((body, "foo"): @unchecked) match {
435+
case (node: Node, "bar") => "bye"
436+
case (ser: Serializable, "foo") => "hi"
437+
})
438+
439+
assertEquals("bye", ((body: AnyRef, "foo"): @unchecked) match {
440+
case (node: Node, "foo") => "bye"
441+
case (ser: Serializable, "foo") => "hi"
442+
})
443+
444+
assertEquals("bye", ((body: AnyRef, "foo"): @unchecked) match {
445+
case (node: Node, "foo") => "bye"
446+
case (ser: Serializable, "foo") => "hi"
447+
})
448+
}
449+
419450
@UnitTest
420451
def t5052: Unit = {
421452
assertTrue(<elem attr={ null: String }/> xml_== <elem/>)
@@ -438,6 +469,19 @@ Ours is the portal of hope, come as you are."
438469
assertHonorsIterableContract(<a a="" y={ null: String }/>.attributes)
439470
}
440471

472+
@UnitTest
473+
def t5154: Unit = {
474+
475+
// extra space made the pattern OK
476+
def f = <z> {{3}}</z> match { case <z> {{3}}</z> => true }
477+
478+
// lack of space used to error: illegal start of simple pattern
479+
def g = <z>{{3}}</z> match { case <z>{{3}}</z> => true }
480+
481+
assertTrue(f)
482+
assertTrue(g)
483+
}
484+
441485
@UnitTest
442486
def t5843: Unit = {
443487
val foo = scala.xml.Attribute(null, "foo", "1", scala.xml.Null)

0 commit comments

Comments
 (0)