summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-05-26 13:25:35 +0000
committerburaq <buraq@epfl.ch>2004-05-26 13:25:35 +0000
commitca09668e88504786eff94ad778b8c1d23ce9574a (patch)
treef00736aada732b77781c996460a98763c3acd148 /test/files
parentc3168553c4b023ef75210185e4654ea84e16682e (diff)
downloadscala-ca09668e88504786eff94ad778b8c1d23ce9574a.tar.gz
scala-ca09668e88504786eff94ad778b8c1d23ce9574a.tar.bz2
scala-ca09668e88504786eff94ad778b8c1d23ce9574a.zip
fixed tests for new lib things, cleanup
Diffstat (limited to 'test/files')
-rw-r--r--test/files/jvm/xmlLiterals.check34
-rw-r--r--test/files/jvm/xmlLiterals.scala298
-rw-r--r--test/files/jvm/xmlParsing.check0
-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
9 files changed, 241 insertions, 241 deletions
diff --git a/test/files/jvm/xmlLiterals.check b/test/files/jvm/xmlLiterals.check
index 04f0426af9..cf4493ca54 100644
--- a/test/files/jvm/xmlLiterals.check
+++ b/test/files/jvm/xmlLiterals.check
@@ -1,7 +1,11 @@
+Test01Literals
passed ok
passed ok
passed ok
passed ok
+<testTag ab="bkla" value="This is a test."></testTag>
+<testTag bla="foo" value="42"></testTag>
+Test02Embed
passed ok
passed ok
passed ok
@@ -9,8 +13,38 @@ passed ok
passed ok
passed ok
passed ok
+passed ok
+passed ok
+Test03Servlet
+<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>
+Test04
ArrayBuffer(<foo></foo>, <bar>Text</bar>, <foo></foo>)
<foo></foo>
passed ok
passed ok
passed ok
+Test05Ref
+<foo>{</foo>
+<foo>&nbsp;{<bar><baz></baz></bar><bar></bar></foo>
diff --git a/test/files/jvm/xmlLiterals.scala b/test/files/jvm/xmlLiterals.scala
index 1a8d61aca6..6054801bcf 100644
--- a/test/files/jvm/xmlLiterals.scala
+++ b/test/files/jvm/xmlLiterals.scala
@@ -8,152 +8,268 @@ import scala.testing.UnitTest._ ;
import scala.xml._ ;
import scala.collection.immutable ;
-object Test with Application {
- val e = immutable.TreeMap.Empty[String,String];
+object Test {
- 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 )
+ val e = immutable.TreeMap.Empty[String,String];
+
+ /* a helper function to compare up to whitespace */
+
+ 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;
}
- i = i + 1;
+ res.toString();
}
- res.toString();
- }
+ object Test01Literals {
- /* */
- /* === tags, elements === */
- /* */
- val x = <hello></hello>.toString(); /* see neg(1) */
- /* whitespace (ws) handling */
+ /* === tags, elements === */
- val x2 = <hello > </hello>.toString(); /* ws in tags allowed */
+ assertEquals( <hello></hello>.toString(),
+ <hello ></hello>.toString()); /* ws in tags */
- assertEquals( x, noWS( x2 ) );
+ assertEquals( <hello></hello>.toString(),
+ noWS(<hello > </hello>.toString()));
- val x3 = <hello>
- <world></world>
- <test/>
- <mars></mars></hello>.toString(); /* ws in element content */
+ 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() );
+ assertEquals( noWS( x3 ),
+ Elem("hello",e,
+ Elem("world",e),
+ Elem("test",e),
+ Elem("mars",e)).toString() );
- /* */
/* === attributes === */
- /* */
- val z = <html>
+ 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"))
+ 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()
- ));
+ Text("page!"))
+ ) % Pair("background","#FFFFFF")
+ ).toString()
+ ));
- /* todo: better way to deal with whitespace in content */
- /* (Canonical XML or even more aggressive normlization) */
+ /* === attributes are Scala expr === */
- /* */
- /* === embedded Scala blocks === */
- /* */
+ 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() );
- def computeDate() = {
- Elem("date", e,Text("now!"));
}
+ object Test02Embed {
- /* embedding Scala strings as text and elements */
- val sc = <hello>{ "World" }{ Text("42") }{ computeDate() }</hello>;
+ /* === embedded Scala blocks === */
- assertEquals( sc.child.elements.toList,
- List( Text("World"), Text("42"), Elem( "date", e,Text("now!") ) ) );
+ def computeDate() = {
+ Elem("date", e, Text("now!"));
+ }
+ /* embedding Scala strings as text and elements */
+ val sc = <hello>{ "World" }{ Text("42") }{ computeDate() }</hello>;
- assertEquals( sc.toString(),
- Elem("hello",e,Text("World42"),Elem("date",e,Text("now!"))).toString() );
+ assertEquals( sc.child.elements.toList,
+ List( Text("World"), Text("42"), Elem( "date", e,Text("now!") ) ) );
- 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( sc.toString(),
+ Elem("hello",e,Text("World42"),Elem("date",e,Text("now!"))).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() );
+ 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>
+ 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() )
+ 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>;
+ val rows2 = <tr><!-- an XML comment --><?pinotext?><?pi text?></tr>;
+ val rows3 = <tr> a <!-- an XML comment --> b <?pinotext?> c <?pi text?> d </tr>;
+
+ // these are not equal as comments are valid XML Info items.
+ assertEquals( rows2, Elem("tr",e,Comment(" an XML comment "),ProcInstr("pinotext",None),ProcInstr("pi",Some("text"))));
+
+ assertEquals( rows3, Elem("tr",e,Text(" a "),Comment(" an XML comment "),Text(" b "),ProcInstr("pinotext",None),Text(" c "),ProcInstr("pi",Some("text")),Text(" d ")));
+
+ }
+
+object Test03Servlet {
+
+ 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>
- assertEquals( noWS( rows.toList.toString() ), noWS( rows2.toList.toString() ) );
+ case Elem( label, _, xs @ _* ) =>
+ new Elem( label, beautify( xs ):_*)
- val sequence = <foo/>
+ 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() );
+ }
+
+}
+
+
+ object Test04 {
+ val sequence = <foo/>
<bar>Text</bar>
<foo/>;
- Console.println( sequence );
+ Console.println( sequence );
+
+ val onlyOne = <foo/>;
+
+ Console.println( onlyOne );
- val onlyOne = <foo/>;
+ val tryBrace = <try>Now escaped {{ braces } </try>;
+ assertEquals( tryBrace, Elem("try",e,Text("Now escaped { braces }")));
- Console.println( onlyOne );
+ val tryBrace2 = <try myAttrib={ (3+4).toString() }> cool ?</try>;
+ assertEquals( tryBrace2.attribute("myAttrib"), "7" );
- val tryBrace = <try>Now we try escaped {{ braces } </try>;
+ /* 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 */")));
+
+ }
- assertEquals( tryBrace, Elem("try",e,Text("Now we try escaped { braces }")));
- val tryBrace2 = <try myAttrib={ (3+4).toString() }> cool ?</try>;
+ def test05main = {
+ val x1s = <foo>&#0123;</foo>.toString();
+ Console.println( x1s );
+ val x2 = <foo>&nbsp;&#x7b;<bar><baz/></bar><bar/></foo>.toString();
+ Console.println( x2 );
+ }
- assertEquals( tryBrace2.attribute("myAttrib"), "7" );
+ def main( args:Array[String] ):Unit = {
+ Console.println("Test01Literals");
+ Test01Literals;
+ Console.println("Test02Embed");
+ Test02Embed;
+ Console.println("Test03Servlet");
+ Test03Servlet.main( args );
+ Console.println("Test04");
+ Test04;
+ Console.println("Test05Ref");
+ test05main;{
+ }
+ }
- /* 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
deleted file mode 100644
index e69de29bb2..0000000000
--- a/test/files/jvm/xmlParsing.check
+++ /dev/null
diff --git a/test/files/jvm/xmlParsing_attr.check b/test/files/jvm/xmlParsing_attr.check
deleted file mode 100644
index 5ba7cb49b2..0000000000
--- a/test/files/jvm/xmlParsing_attr.check
+++ /dev/null
@@ -1,2 +0,0 @@
-<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
deleted file mode 100644
index ea2eb60bf6..0000000000
--- a/test/files/jvm/xmlParsing_attr.scala
+++ /dev/null
@@ -1,17 +0,0 @@
-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
deleted file mode 100644
index 13e2f4fabc..0000000000
--- a/test/files/jvm/xmlParsing_servlet.check
+++ /dev/null
@@ -1,23 +0,0 @@
-<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
deleted file mode 100644
index e182a06b00..0000000000
--- a/test/files/jvm/xmlParsing_servlet.scala
+++ /dev/null
@@ -1,83 +0,0 @@
-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
deleted file mode 100644
index 049f160175..0000000000
--- a/test/files/jvm/xmlRef.check
+++ /dev/null
@@ -1,2 +0,0 @@
-<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
deleted file mode 100644
index 47bc5dd6dd..0000000000
--- a/test/files/jvm/xmlRef.scala
+++ /dev/null
@@ -1,23 +0,0 @@
-//############################################################################
-// 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 );
-
-}