summaryrefslogtreecommitdiff
path: root/test/files/jvm/xml03syntax.scala
blob: fd3fbfaf8fe8272dc9bc401949fea5a53c0f5a7d (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
import scala.testing.SUnit._
import scala.xml._

object Test extends AnyRef with Assert {

  private def handle[A](x: Node): A = {
    println(x)
    x.child(0).asInstanceOf[Atom[A]].data
  }

  def main(args: Array[String]) {

    val xNull = <hello>{null}</hello> // these used to be Atom(unit), changed to empty children

    assertSameElements(xNull.child, Nil)

    val x0 = <hello>{}</hello> // these used to be Atom(unit), changed to empty children
    val x00 = <hello>{ }</hello> //  dto.

    val xa = <hello>{ "world" }</hello>


    assertSameElements(x0.child,  Nil)
    assertSameElements(x00.child, Nil)
    assertEquals(handle[String](xa), "world")

    val xb = <hello>{ 1.5 }</hello>

    assertEquals(handle[Double](xb), 1.5)

    val xc = <hello>{ 5 }</hello>

    assertEquals(handle[Int](xc), 5)

    val xd = <hello>{ true }</hello>

    assertEquals(handle[Boolean](xd), true)

    val xe = <hello>{ 5:short }</hello>

    assertEquals(handle[Short](xe), 5:short)

    val xf = <hello>{ val x = 27; x }</hello>

    assertEquals(handle[Int](xf), 27)

    val xg = <hello>{ List(1,2,3,4) }</hello>

    println(xg)
    for (z <- xg.child) {
      println(z.toString() + {if (z.isInstanceOf[Text]) "(is text node ' ')" else ""})
    }

    val xh = <hello>{ for(val x <- List(1,2,3,4); x % 2 == 0) yield x }</hello>

    println(xh)
    for (z <- xh.child) {
      println(z.toString() + {if (z.isInstanceOf[Text]) "(is text node ' ')" else ""})
    }

  }

}