summaryrefslogtreecommitdiff
path: root/test/files/jvm
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-02-13 16:58:37 +0000
committerburaq <buraq@epfl.ch>2004-02-13 16:58:37 +0000
commit7861176c228e2384088d2cf45afec140364d1c3e (patch)
tree0756aa8cd44da4d29a2426078bf23cc0662dee49 /test/files/jvm
parent14ea14e71b63cc590f312246146c42da4fe94e94 (diff)
downloadscala-7861176c228e2384088d2cf45afec140364d1c3e.tar.gz
scala-7861176c228e2384088d2cf45afec140364d1c3e.tar.bz2
scala-7861176c228e2384088d2cf45afec140364d1c3e.zip
test cases for xml literal parsing
Diffstat (limited to 'test/files/jvm')
-rw-r--r--test/files/jvm/xmlLiterals.check5
-rw-r--r--test/files/jvm/xmlLiterals.scala75
2 files changed, 80 insertions, 0 deletions
diff --git a/test/files/jvm/xmlLiterals.check b/test/files/jvm/xmlLiterals.check
new file mode 100644
index 0000000000..bd0b0c1bc5
--- /dev/null
+++ b/test/files/jvm/xmlLiterals.check
@@ -0,0 +1,5 @@
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
diff --git a/test/files/jvm/xmlLiterals.scala b/test/files/jvm/xmlLiterals.scala
new file mode 100644
index 0000000000..320fc995c0
--- /dev/null
+++ b/test/files/jvm/xmlLiterals.scala
@@ -0,0 +1,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>
+
+ */
+
+
+}
+