@@ -480,6 +480,115 @@ class XMLTestJVM {
480
480
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)
481
481
}
482
482
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
+
483
592
@ UnitTest
484
593
def t9060 = {
485
594
val expected = """ <a xmlns:b·="http://example.com"/>"""
0 commit comments