summaryrefslogtreecommitdiff
path: root/test/files/jvm/xmlLiterals.scala
blob: 320fc995c02706b9788f4ae50eddb4622ded16fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import scala.testing.UnitTest._ ;

object Test with Application {

  /*                                                                    */
  /*                                             === tags, elements === */
  /*                                                                    */

  val x = <hello></hello>.toXML; /* see neg(1) */

  /* whitespace (ws) handling */

  val x2 = <hello  >  </hello>.toXML;       /* ws in tags allowed */

  assertEquals( x, x2 );

  val x3 = <hello>
             <world> </world>
             <test/>
             <mars></mars></hello>.toXML;   /* ws in element content */

  /* Scala comments are not allowed in XML literals. see neg(2) */

  assertEquals( x3, 'hello('world,'test,'mars).toXML );

  /*                                                                   */
  /*                                                === attributes === */
  /*                                                                   */

  val z = <html>
            <body background="#FFFFFF">
              <h1>Hello World</h1>
              <p>Check the <a href="scala.epfl.ch">scala</a> page!</p>
            </body>
          </html>.toXML;

  assertEquals( z, 'html(
                      'body(
                          'h1("Hello World"),
                          'p("Check the ",
                             'a("scala") % ('href <= "scala.epfl.ch" ),
                             "page!")) %('background <= "#FFFFFF")).toXML);

  /*  todo: better way to deal with whitespace in content              */
  /*      (Canonical XML or even more aggressive normlization)         */

  /*                                                                   */
  /*                                    === embedded Scala blocks  === */
  /*                                                                   */

  def computeDate() = {
    'date("now!")
  }


  /* embedding Scala strings as text and elements  */
  val sc = <hello> { "World" }{ 7*6 }{ computeDate() }</hello>;

  assertEquals( sc.children.toList, List(Text("World"),Text("42"), 'date("now!")) );
  assertEquals( sc.toXML, 'hello("World42",'date("now!")).toXML );

  /* examples that MUST fail

  neg(1)
  val y = <hello></hallo>.toXML; // error: closing tag of hello

  neg(2)
  val z = <hello> // my hello comment      <--- this will be parsed as text !!
          </hello>

  */


}