- Added test files for xml parsing and xml literals
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@2873 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
a4e7c306b7
commit
88a07c37b0
|
@ -32,5 +32,6 @@ neg/overlapping.scala
|
|||
neg/protected.scala
|
||||
neg/seqtest.scala
|
||||
neg/stable.scala
|
||||
neg/xmlParsing001.scala
|
||||
|
||||
##############################################################################
|
||||
|
|
|
@ -30,6 +30,8 @@ run/overloads.scala
|
|||
run/regularpatmat.scala
|
||||
run/runtime.scala
|
||||
run/tailcalls.scala
|
||||
run/xmlLiterals.scala
|
||||
run/xmlParsing.scala
|
||||
|
||||
shl/basic.scala
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
xmlParsing001.scala:13: in XML literal: expected closing tag of hello
|
||||
val y = <hello></hallo>.toString();
|
||||
^
|
||||
xmlParsing001.scala:13: in XML literal: '>' expected instead of '.'
|
||||
val y = <hello></hallo>.toString();
|
||||
^
|
||||
two errors found
|
|
@ -0,0 +1 @@
|
|||
-Xmarkup
|
|
@ -0,0 +1,15 @@
|
|||
//############################################################################
|
||||
// XML Parsing
|
||||
//############################################################################
|
||||
// $Id$
|
||||
|
||||
import scala.testing.UnitTest._ ;
|
||||
|
||||
import scala.xml._ ;
|
||||
|
||||
object Test with Application {
|
||||
|
||||
// error: closing tag of hello not found
|
||||
val y = <hello></hallo>.toString();
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
Seq(<foo></foo>, <bar>Text</bar>, <foo></foo>)
|
||||
<foo></foo>
|
|
@ -0,0 +1 @@
|
|||
-Xmarkup
|
|
@ -0,0 +1,153 @@
|
|||
//############################################################################
|
||||
// XML Literals
|
||||
//############################################################################
|
||||
// $Id$
|
||||
|
||||
import scala.testing.UnitTest._ ;
|
||||
|
||||
import scala.xml._ ;
|
||||
|
||||
object Test with Application {
|
||||
|
||||
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 */
|
||||
|
||||
/* Scala comments are not allowed in XML literals. see neg(2) */
|
||||
|
||||
assertEquals( noWS( x3 ),
|
||||
Elem("hello",
|
||||
Elem("world"),
|
||||
Elem("test"),
|
||||
Elem("mars")).toString() );
|
||||
|
||||
/* examples that MUST fail
|
||||
|
||||
val zzz = <hello>/* no comment */</hello>
|
||||
assertEquals( zzz, Elem("hello", Text("/* no comment */");
|
||||
|
||||
*/
|
||||
|
||||
/* */
|
||||
/* === 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",
|
||||
Elem("body",
|
||||
Elem("h1",Text("Hello World")),
|
||||
Elem("p",Text("Check the "),
|
||||
Elem("a", Text("scala"))
|
||||
% ('href <= "scala.epfl.ch" ),
|
||||
Text("page!"))
|
||||
) %('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", 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", Text("now!") ) ) );
|
||||
|
||||
assertEquals( sc.toString(),
|
||||
Elem("hello",Text("World42"),Elem("date",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",
|
||||
Elem("td",Text("1.1")),Elem("td",Text("1.2"))
|
||||
),
|
||||
Elem("tr",
|
||||
Elem("td",Text("2.1")),Elem("td",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>
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
-Xmarkup
|
|
@ -0,0 +1,42 @@
|
|||
//############################################################################
|
||||
// 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 character entities!
|
||||
welcome   unicode characters!
|
||||
</foo>
|
||||
|
||||
}
|
Loading…
Reference in New Issue