summaryrefslogtreecommitdiff
path: root/test/files/jvm
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-05-26 10:44:15 +0000
committerburaq <buraq@epfl.ch>2004-05-26 10:44:15 +0000
commit1f7970f3c60575d1715d1c5dd022dfa0d08bb51a (patch)
treee941181649de5c3d1bc52e621014a70f312ead24 /test/files/jvm
parentbab61a5c3f2eada77158b217ab7e318c19fdbb64 (diff)
downloadscala-1f7970f3c60575d1715d1c5dd022dfa0d08bb51a.tar.gz
scala-1f7970f3c60575d1715d1c5dd022dfa0d08bb51a.tar.bz2
scala-1f7970f3c60575d1715d1c5dd022dfa0d08bb51a.zip
moved to jvm, interpreter too brittle
Diffstat (limited to 'test/files/jvm')
-rw-r--r--test/files/jvm/matching.check2
-rw-r--r--test/files/jvm/xmlLiterals.check16
-rw-r--r--test/files/jvm/xmlLiterals.scala159
-rw-r--r--test/files/jvm/xmlParsing.check0
-rw-r--r--test/files/jvm/xmlParsing.scala52
-rw-r--r--test/files/jvm/xmlParsing_attr.check2
-rw-r--r--test/files/jvm/xmlParsing_attr.scala17
-rw-r--r--test/files/jvm/xmlParsing_servlet.check23
-rw-r--r--test/files/jvm/xmlParsing_servlet.scala83
-rw-r--r--test/files/jvm/xmlRef.check2
-rw-r--r--test/files/jvm/xmlRef.scala23
-rw-r--r--test/files/jvm/xmlstuff.scala141
12 files changed, 449 insertions, 71 deletions
diff --git a/test/files/jvm/matching.check b/test/files/jvm/matching.check
index 5a60ffb236..e2ccb0cd9b 100644
--- a/test/files/jvm/matching.check
+++ b/test/files/jvm/matching.check
@@ -1,4 +1,4 @@
<<< bug Test1
-0
+List(t2)
>>> bug Test1
diff --git a/test/files/jvm/xmlLiterals.check b/test/files/jvm/xmlLiterals.check
new file mode 100644
index 0000000000..04f0426af9
--- /dev/null
+++ b/test/files/jvm/xmlLiterals.check
@@ -0,0 +1,16 @@
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
+passed ok
+ArrayBuffer(<foo></foo>, <bar>Text</bar>, <foo></foo>)
+<foo></foo>
+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..1a8d61aca6
--- /dev/null
+++ b/test/files/jvm/xmlLiterals.scala
@@ -0,0 +1,159 @@
+//############################################################################
+// XML Literals
+//############################################################################
+// $Id$
+
+import scala.testing.UnitTest._ ;
+
+import scala.xml._ ;
+import scala.collection.immutable ;
+
+object Test with Application {
+
+ val e = immutable.TreeMap.Empty[String,String];
+
+ def noWS(x:String):String = {
+ val res = new StringBuffer();
+ var i = 0; while( i < x.length() ) {
+ val c = x.charAt( i );
+ c match {
+ case ' ' | '\n' | '\t' =>
+ case _ => res.append( c )
+ }
+ i = i + 1;
+ }
+ res.toString();
+ }
+
+
+
+ /* */
+ /* === tags, elements === */
+ /* */
+
+ val x = <hello></hello>.toString(); /* see neg(1) */
+
+ /* whitespace (ws) handling */
+
+ val x2 = <hello > </hello>.toString(); /* ws in tags allowed */
+
+ assertEquals( x, noWS( x2 ) );
+
+ val x3 = <hello>
+ <world></world>
+ <test/>
+ <mars></mars></hello>.toString(); /* ws in element content */
+
+
+ assertEquals( noWS( x3 ),
+ Elem("hello",e,
+ Elem("world",e),
+ Elem("test",e),
+ Elem("mars",e)).toString() );
+
+
+ /* */
+ /* === 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>.toString();
+
+ assertEquals( noWS( z ), noWS(
+ Elem("html",e,
+ Elem("body",e,
+ Elem("h1",e,Text("Hello World")),
+ Elem("p",e,Text("Check the "),
+ Elem("a", e,Text("scala"))
+ % Pair("href","scala.epfl.ch"),
+ Text("page!"))
+ ) % Pair("background","#FFFFFF")
+ ).toString()
+ ));
+
+ /* todo: better way to deal with whitespace in content */
+ /* (Canonical XML or even more aggressive normlization) */
+
+ /* */
+ /* === embedded Scala blocks === */
+ /* */
+
+ def computeDate() = {
+ Elem("date", e,Text("now!"));
+ }
+
+
+ /* embedding Scala strings as text and elements */
+ val sc = <hello>{ "World" }{ Text("42") }{ computeDate() }</hello>;
+
+ assertEquals( sc.child.elements.toList,
+ List( Text("World"), Text("42"), Elem( "date", e,Text("now!") ) ) );
+
+ assertEquals( sc.toString(),
+ Elem("hello",e,Text("World42"),Elem("date",e,Text("now!"))).toString() );
+
+ def foo( m:Node ):String = m match {
+ case <hello/> => "hello node"
+ case <hallo ></hallo > => "hallo node"
+ case <test>{ z }</test> => "test node:"+z
+ case <list>{ e1:Node }{ e2:Node }{ _* }</list> => e1.toString() + e2.toString();
+ }
+
+ assertEquals( foo(<hello/>), "hello node" );
+ assertEquals( foo(<hallo/>), "hallo node" );
+ assertEquals( foo(<test>42</test>), "test node:42" );
+ assertEquals( foo(<list><a/><b><c/></b><d/><d/></list>),
+ <a/>.toString() + <b><c/></b>.toString() );
+
+ val rows = <tr>
+ <td>1.1</td><td>1.2</td>
+ </tr>
+ <tr>
+ <td>2.1</td><td>2.2</td>
+ </tr>;
+
+ assertEquals( noWS( rows.toList.toString() ),
+ noWS( List(Elem("tr",e,
+ Elem("td",e,Text("1.1")),Elem("td",e,Text("1.2"))
+ ),
+ Elem("tr",e,
+ Elem("td",e,Text("2.1")),Elem("td",e,Text("2.2"))
+ )
+ ).toString() )
+ );
+ val rows2 = <tr><!-- an XML comment --><td>1.1</td><td>1.2</td>
+ </tr>
+ <tr>
+ <td>2.1</td><td>2.2</td>
+ </tr>;
+
+ assertEquals( noWS( rows.toList.toString() ), noWS( rows2.toList.toString() ) );
+
+ val sequence = <foo/>
+ <bar>Text</bar>
+ <foo/>;
+
+ Console.println( sequence );
+
+ val onlyOne = <foo/>;
+
+ Console.println( onlyOne );
+
+ val tryBrace = <try>Now we try escaped {{ braces } </try>;
+
+ assertEquals( tryBrace, Elem("try",e,Text("Now we try escaped { braces }")));
+
+ val tryBrace2 = <try myAttrib={ (3+4).toString() }> cool ?</try>;
+
+ assertEquals( tryBrace2.attribute("myAttrib"), "7" );
+
+ /* Scala comments are not allowed in XML literals. see neg(2) */
+ val zzz = <hello>/* no comment */</hello>;
+ assertEquals( zzz, Elem("hello", e, Text("/* no comment */")));
+
+}
+
diff --git a/test/files/jvm/xmlParsing.check b/test/files/jvm/xmlParsing.check
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/files/jvm/xmlParsing.check
diff --git a/test/files/jvm/xmlParsing.scala b/test/files/jvm/xmlParsing.scala
new file mode 100644
index 0000000000..e4270f8877
--- /dev/null
+++ b/test/files/jvm/xmlParsing.scala
@@ -0,0 +1,52 @@
+//############################################################################
+// XML Parsing
+//############################################################################
+// $Id$
+
+import scala.testing.UnitTest._ ;
+
+import scala.xml._ ;
+
+/** this file test just succesful run of the parser. There are no checks whether
+ * the encoding to Scala expressions is done correctly
+ */
+object Test with Application {
+
+ val x0 = <hello/>;
+ val x1s = <foo></foo>.toString();
+ val x2 = <foo><bar><baz/></bar><bar/></foo>.toString();
+
+ /* whitespace (ws) handling */
+
+ val x3 = <hello > </hello>.toString(); /* ws in tags allowed */
+
+ val x4 = <hello>
+ <world></world>
+ <test/>
+ <mars></mars></hello>.toString(); /* ws in element content */
+
+ /* 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>.toString();
+
+ val ent = <foo>
+ hello &nbsp; character entities!
+ welcome &#0160; unicode characters!
+ </foo>;
+
+
+ val foo = <a/><b/><c/>;
+
+
+ val foo2 = foo match {
+ case <a/><b/> => 1
+ case <a></a><b></b><c></c> => 2
+ case Seq(Elem("a",_),Elem("b",_),Elem("c",_)) => 3
+ };
+
+}
diff --git a/test/files/jvm/xmlParsing_attr.check b/test/files/jvm/xmlParsing_attr.check
new file mode 100644
index 0000000000..5ba7cb49b2
--- /dev/null
+++ b/test/files/jvm/xmlParsing_attr.check
@@ -0,0 +1,2 @@
+<testTag ab="bkla" value="This is a test."></testTag>
+<testTag bla="foo" value="42"></testTag>
diff --git a/test/files/jvm/xmlParsing_attr.scala b/test/files/jvm/xmlParsing_attr.scala
new file mode 100644
index 0000000000..ea2eb60bf6
--- /dev/null
+++ b/test/files/jvm/xmlParsing_attr.scala
@@ -0,0 +1,17 @@
+import scala.xml._ ;
+
+object Test with Application {
+
+ val testValue = "This is a test.";
+
+ val testValue2 = 42;
+
+ val page = <testTag value={ testValue } ab="bkla" />;
+
+ val page2 = <testTag value={testValue2.toString()} bla="foo"></testTag>;
+
+ Console.println( page.toString() );
+
+ Console.println( page2.toString() );
+
+}
diff --git a/test/files/jvm/xmlParsing_servlet.check b/test/files/jvm/xmlParsing_servlet.check
new file mode 100644
index 0000000000..13e2f4fabc
--- /dev/null
+++ b/test/files/jvm/xmlParsing_servlet.check
@@ -0,0 +1,23 @@
+<html>
+ <head>
+ <title>ModularFormatting</title>
+ </head>
+ <body>
+ <h2>Welcome</h2>
+ <p>
+ What follows is an example of modular formatting.
+ </p>
+ <p>
+ <table align="center">
+ <tr>
+ <td bgcolor="#AAAAFF" color="#222255"><h1> message </h1></td>
+ </tr>
+ </table>
+ </p>
+ <hr></hr>
+ <p>
+ Complicated layout tasks can be encapsulated and outsourced.
+ </p>
+ <h2>Bye!</h2>
+ </body>
+ </html>
diff --git a/test/files/jvm/xmlParsing_servlet.scala b/test/files/jvm/xmlParsing_servlet.scala
new file mode 100644
index 0000000000..e182a06b00
--- /dev/null
+++ b/test/files/jvm/xmlParsing_servlet.scala
@@ -0,0 +1,83 @@
+import scala.xml._ ;
+
+object Test {
+
+ val headerMsg = Text("What follows is an example of modular formatting.");
+ val footerMsg = Text("Complicated layout tasks can be encapsulated and outsourced.");
+
+ /** helper function for the main page, provides header and a footer
+ */
+ def page( ns:Seq[Node] ) = {
+ <html>
+ <head>
+ <title>ModularFormatting</title>
+ </head>
+ <body>
+ <h2>Welcome</h2>
+ <p>
+ { headerMsg }
+ </p>
+ <p>
+ { ns:_* }
+ </p>
+ <hr/>
+ <p>
+ { footerMsg }
+ </p>
+ <h2>Bye!</h2>
+ </body>
+ </html>
+ }
+
+ /** applies beautify to every element in a sequence
+ */
+ def beautify( xs:Seq[Node] ):Seq[Node] = xs.toList.map { beautify }
+
+ /** this is a recursive procedure that adds some attributes to the tree
+ */
+ def beautify( n:Node ):Node = n match {
+ case <td>{ xs @ _* }</td> =>
+ <td bgcolor="#AAAAFF" color="#222255">{ xs:_* }</td>
+
+ case <table>{ xs @ _* }</table> =>
+ <table align="center">{ beautify( xs ):_* }</table>
+
+ case Elem( label, _, xs @ _* ) =>
+ new Elem( label, beautify( xs ):_*)
+
+ case _ => n
+ }
+
+ /** this function will take a node and put it in a table
+ */
+ def format( msg:Node ):Node = {
+ <table>
+ <tr>
+ <td>{ msg }</td>
+ </tr>
+ </table>
+ }
+
+ /** returns a highlighted text node with the string given as arguemnt. if it
+ * is null, supplies a default string.
+ */
+ def getMessage( x:String ) = {
+ if( x == null )
+ <h1> This could be YOUR message ! </h1>
+ else
+ <h1> { Text( x ) } </h1>
+ }
+
+ /** the entry method
+ */
+ def doGetXML() = {
+ beautify( page( List( format( getMessage( "message" ) )) ));
+ /* page( List( format( theMessage ))); */
+
+ }
+
+ def main( args:Array[String] ) = {
+ Console.println( doGetXML() );
+ }
+
+}
diff --git a/test/files/jvm/xmlRef.check b/test/files/jvm/xmlRef.check
new file mode 100644
index 0000000000..049f160175
--- /dev/null
+++ b/test/files/jvm/xmlRef.check
@@ -0,0 +1,2 @@
+<foo>{</foo>
+<foo>&nbsp;{<bar><baz></baz></bar><bar></bar></foo>
diff --git a/test/files/jvm/xmlRef.scala b/test/files/jvm/xmlRef.scala
new file mode 100644
index 0000000000..47bc5dd6dd
--- /dev/null
+++ b/test/files/jvm/xmlRef.scala
@@ -0,0 +1,23 @@
+//############################################################################
+// XML Parsing
+//############################################################################
+// $Id$
+
+import scala.testing.UnitTest._ ;
+
+import scala.xml._ ;
+
+/** this file test just succesful run of the parser. There are no checks whether
+ * the encoding to Scala expressions is done correctly
+ */
+object Test with Application {
+
+ val x1s = <foo>&#0123;</foo>.toString();
+
+ Console.println( x1s );
+
+ val x2 = <foo>&nbsp;&#x7b;<bar><baz/></bar><bar/></foo>.toString();
+
+ Console.println( x2 );
+
+}
diff --git a/test/files/jvm/xmlstuff.scala b/test/files/jvm/xmlstuff.scala
index aa6bc95d8d..c7c0e5da93 100644
--- a/test/files/jvm/xmlstuff.scala
+++ b/test/files/jvm/xmlstuff.scala
@@ -5,6 +5,9 @@ import scala.testing.UnitTest._ ;
import scala.xml.{Node,NodeSeq,Elem,Text};
object Test with Application {
+
+ val e = scala.collection.immutable.TreeMap.Empty[String,String];
+
/*
def eq( a:Seq[Node], b:Seq[Node] ):boolean = {
(a.length == b.length) && eq(a.elements,b.elements)
@@ -25,8 +28,8 @@ object Test with Application {
val c = new Node {
def label = "hello";
- def child = List(Elem("world"));
- def attribute = List();
+ def child = List(Elem("world",e));
+ def attribute = e;
};
assertSameElements( List( 3 ), List( 3 ));
@@ -42,10 +45,10 @@ object Test with Application {
val i = new InputSource( new StringReader( x2 ));
val x2p = XML.load( i );
- assertEquals(x2p, Elem("book",
- Elem("author",Text("Peter Buneman")),
- Elem("author",Text("Dan Suciu")),
- Elem("title",Text("Data on ze web"))));
+ assertEquals(x2p, Elem("book",e,
+ Elem("author",e,Text("Peter Buneman")),
+ Elem("author",e,Text("Dan Suciu")),
+ Elem("title",e,Text("Data on ze web"))));
val xmlFile2 = "<bib><book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book><book><author>John Mitchell</author><title>Foundations of Programming Languages</title></book></bib>";
val isrc2 = new InputSource( new StringReader( xmlFile2 ) );
@@ -55,117 +58,115 @@ object Test with Application {
Console.println("xpath \\");
- //assertSameElements( parsedxml1 \ '_ , List( 'world() ) );
- assertSameElements( parsedxml1 \ '_ , List( Elem("world") ) );
+ assertSameElements( parsedxml1 \ "_" , List( Elem("world",e) ) );
- //assertSameElements( parsedxml1 \ 'world, List( 'world() ) );
- assertSameElements( parsedxml1 \ 'world, List( Elem("world") ) );
+ assertSameElements( parsedxml1 \ "world", List( Elem("world",e) ) );
/*
- Console.println( parsedxml2 \ '_ );
- Console.println( (parsedxml2 \ '_).elements);
- for( val i <- (parsedxml2 \ '_).elements) {
+ Console.println( parsedxml2 \ "_" );
+ Console.println( (parsedxml2 \ "_" ).elements);
+ for( val i <- (parsedxml2 \ "_" ).elements) {
Console.println( i );
};
*/
assertSameElements(
- parsedxml2 \ '_ ,
+ parsedxml2 \ "_" ,
List(
- Elem("book",
- Elem("author",Text("Peter Buneman")),
- Elem("author",Text("Dan Suciu")),
- Elem("title",Text("Data on ze web"))),
- Elem("book",
- Elem("author",Text("John Mitchell")),
- Elem("title",Text("Foundations of Programming Languages"))))
+ Elem("book", e,
+ Elem("author",e,Text("Peter Buneman")),
+ Elem("author",e,Text("Dan Suciu")),
+ Elem("title",e,Text("Data on ze web"))),
+ Elem("book",e,
+ Elem("author",e,Text("John Mitchell")),
+ Elem("title",e,Text("Foundations of Programming Languages"))))
);
- assertEquals( (parsedxml2 \ 'author).length, 0 );
+ assertEquals( (parsedxml2 \ "author").length, 0 );
assertSameElements(
- parsedxml2 \ 'book,
+ parsedxml2 \ "book",
List(
- Elem("book",
- Elem("author",Text("Peter Buneman")),
- Elem("author",Text("Dan Suciu")),
- Elem("title",Text("Data on ze web"))),
- Elem("book",
- Elem("author",Text("John Mitchell")),
- Elem("title",Text("Foundations of Programming Languages")))
+ Elem("book",e,
+ Elem("author",e,Text("Peter Buneman")),
+ Elem("author",e,Text("Dan Suciu")),
+ Elem("title",e,Text("Data on ze web"))),
+ Elem("book",e,
+ Elem("author",e,Text("John Mitchell")),
+ Elem("title",e,Text("Foundations of Programming Languages")))
)
);
assertSameElements(
- parsedxml2 \ '_ \ '_,
+ parsedxml2 \ "_" \ "_",
List(
- Elem("author",Text("Peter Buneman")),
- Elem("author",Text("Dan Suciu")),
- Elem("title",Text("Data on ze web")),
- Elem("author",Text("John Mitchell")),
- Elem("title",Text("Foundations of Programming Languages"))
+ Elem("author",e,Text("Peter Buneman")),
+ Elem("author",e,Text("Dan Suciu")),
+ Elem("title",e,Text("Data on ze web")),
+ Elem("author",e,Text("John Mitchell")),
+ Elem("title",e,Text("Foundations of Programming Languages"))
)
);
assertSameElements(
- parsedxml2 \ '_ \ 'author,
+ parsedxml2 \ "_" \ "author",
List(
- Elem("author",Text("Peter Buneman")),
- Elem("author",Text("Dan Suciu")),
- Elem("author",Text("John Mitchell"))
+ Elem("author",e,Text("Peter Buneman")),
+ Elem("author",e,Text("Dan Suciu")),
+ Elem("author",e,Text("John Mitchell"))
)
);
- assertSameElements( (parsedxml2 \ '_ \ '_ \ 'author), List() );
+ assertSameElements( (parsedxml2 \ "_" \ "_" \ "author"), List() );
Console.println("xpath \\\\ DESCENDANTS");
assertSameElements(
- parsedxml2 \\ 'author,
+ parsedxml2 \\ "author",
List(
- Elem("author",Text("Peter Buneman")),
- Elem("author",Text("Dan Suciu")),
- Elem("author",Text("John Mitchell"))
+ Elem("author",e,Text("Peter Buneman")),
+ Elem("author",e,Text("Dan Suciu")),
+ Elem("author",e,Text("John Mitchell"))
)
);
assertSameElements(
- new NodeSeq(List( parsedxml2 ))\\ '_,
+ new NodeSeq(List( parsedxml2 )) \\ "_",
List(
- Elem("bib",
- Elem("book",
- Elem("author",Text("Peter Buneman")),
- Elem("author",Text("Dan Suciu")),
- Elem("title",Text("Data on ze web"))),
- Elem("book",
- Elem("author",Text("John Mitchell")),
- Elem("title",Text("Foundations of Programming Languages")))),
- Elem("book",
- Elem("author",Text("Peter Buneman")),
- Elem("author",Text("Dan Suciu")),
- Elem("title",Text("Data on ze web"))),
- Elem("author",Text("Peter Buneman")),
+ Elem("bib",e,
+ Elem("book",e,
+ Elem("author",e,Text("Peter Buneman")),
+ Elem("author",e,Text("Dan Suciu")),
+ Elem("title",e,Text("Data on ze web"))),
+ Elem("book",e,
+ Elem("author",e,Text("John Mitchell")),
+ Elem("title",e,Text("Foundations of Programming Languages")))),
+ Elem("book",e,
+ Elem("author",e,Text("Peter Buneman")),
+ Elem("author",e,Text("Dan Suciu")),
+ Elem("title",e,Text("Data on ze web"))),
+ Elem("author",e,Text("Peter Buneman")),
Text("Peter Buneman"),
- Elem("author",Text("Dan Suciu")),
+ Elem("author",e,Text("Dan Suciu")),
Text("Dan Suciu"),
- Elem("title",Text("Data on ze web")),
+ Elem("title",e,Text("Data on ze web")),
Text("Data on ze web"),
- Elem("book",
- Elem("author",Text("John Mitchell")),
- Elem("title",Text("Foundations of Programming Languages"))),
- Elem("author",Text("John Mitchell")),
+ Elem("book",e,
+ Elem("author",e,Text("John Mitchell")),
+ Elem("title",e,Text("Foundations of Programming Languages"))),
+ Elem("author",e,Text("John Mitchell")),
Text("John Mitchell"),
- Elem("title",Text("Foundations of Programming Languages")),
+ Elem("title",e,Text("Foundations of Programming Languages")),
Text("Foundations of Programming Languages")
)
);
@@ -173,10 +174,10 @@ object Test with Application {
assertSameElements(
- parsedxml2 \\ 'title,
+ parsedxml2 \\ "title",
List(
- Elem("title",Text("Data on ze web")),
- Elem("title",Text("Foundations of Programming Languages")))
-);
+ Elem("title",e,Text("Data on ze web")),
+ Elem("title",e,Text("Foundations of Programming Languages")))
+ );
}