diff options
author | Burak Emir <emir@epfl.ch> | 2007-03-02 19:07:57 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2007-03-02 19:07:57 +0000 |
commit | 61b2debaa00361250fbee05cbb71f2c989ad2c03 (patch) | |
tree | 7e4ed39511700f88f7b68a695fcf18ef67366ecf /test | |
parent | a1c87639762b2b9172c1a775fbd3cfaa66536ab0 (diff) | |
download | scala-61b2debaa00361250fbee05cbb71f2c989ad2c03.tar.gz scala-61b2debaa00361250fbee05cbb71f2c989ad2c03.tar.bz2 scala-61b2debaa00361250fbee05cbb71f2c989ad2c03.zip |
* small lib addition to testing.SUnit, made Uni...
* small lib addition to testing.SUnit, made UnitTest @deprecated added
* xml pattern matching on prefixes (in SymbolicXMLBuilder) xml name
* parsing ensures that names do not end in a colon (namespaces) rewrote
* xml02 to use SUnit
Diffstat (limited to 'test')
-rw-r--r-- | test/files/jvm/unittest_xml.scala | 17 | ||||
-rw-r--r-- | test/files/jvm/xml02.check | 13 | ||||
-rw-r--r-- | test/files/jvm/xml02.scala | 51 | ||||
-rw-r--r-- | test/files/neg/xmlcorner.check | 7 | ||||
-rw-r--r-- | test/files/neg/xmlcorner.scala | 6 |
5 files changed, 53 insertions, 41 deletions
diff --git a/test/files/jvm/unittest_xml.scala b/test/files/jvm/unittest_xml.scala index c302ef1e24..b6d3da00f5 100644 --- a/test/files/jvm/unittest_xml.scala +++ b/test/files/jvm/unittest_xml.scala @@ -7,12 +7,20 @@ object Test { class ParsingTest extends TestCase("scala.xml.Parsing") with Assert { override def runTest = { assertTrue(Parsing.isNameStart('b')) + assertTrue(Parsing.isNameStart(':')) } } class MetaDataTest extends TestCase("scala.xml.MetaData") with Assert { - import scala.xml.{TopScope, NamespaceBinding, Atom, Text } + import scala.xml.{HasKeyValue, TopScope, NamespaceBinding, Node, Atom, Text } + def domatch(x:Node): Node = { + val hasBar = new HasKeyValue("bar") + x match { + case Node("foo", hasBar(z), _*) => z + case _ => new Atom(3) + } + } override def runTest = { var x: MetaData = Null @@ -44,6 +52,12 @@ object Test { assertEquals("present element (prefixed) 6", None, x.get(null, s, "bar" )) assertEquals("present element (unprefix) 6", Some(Text("meaning")), x.get("bar")) + val z = <foo bar="gar"/> + val z2 = <foo/> + + assertEquals("attribute extractor 1", Text("gar"), domatch(z)) + assertEquals("attribute extractor 2", new Atom(3), domatch(z2)) + } } @@ -74,6 +88,7 @@ object Test { assertEquals("sort attrib"+xml.Utility.sort(q.attributes).toString, " a=\"2\" g=\"3\" j=\"2\" oo=\"2\"", xml.Utility.sort(q.attributes).toString) val pp = new xml.PrettyPrinter(80,5) assertEquals("pretty print sorted attrib:"+pp.format(q), "<a a=\"2\" g=\"3\" j=\"2\" oo=\"2\"></a>", pp.format(q)) + } def main(args:Array[String]) = { diff --git a/test/files/jvm/xml02.check b/test/files/jvm/xml02.check deleted file mode 100644 index dc9e15dd2b..0000000000 --- a/test/files/jvm/xml02.check +++ /dev/null @@ -1,13 +0,0 @@ -attributes -one -passed ok -two -passed ok -three -passed ok -four -passed ok -five -passed ok -patterns -passed ok diff --git a/test/files/jvm/xml02.scala b/test/files/jvm/xml02.scala index d0d97e64eb..ac400d7adf 100644 --- a/test/files/jvm/xml02.scala +++ b/test/files/jvm/xml02.scala @@ -1,39 +1,32 @@ -object Test { -def main(args:Array[String]) = { +import testing.SUnit._ + +object Test extends TestConsoleMain { + import scala.xml.NodeSeq import NodeSeq.view - import testing.UnitTest._ - val ax = <hello foo="bar"> <world/> </hello> - Console.println("attributes"); - - Console.println("one"); - assertEquals(ax \ "@foo", "bar") - Console.println("two"); - assertEquals(ax \ "@foo", xml.Text("bar")) - val bx = <hello foo="bar&x"></hello> - Console.println("three"); - assertEquals(bx \ "@foo", "bar&x") - Console.println("four"); - assertSameElements(bx \ "@foo", List(xml.Text("bar&x"))) - //assertSameElements(bx \ "@foo", List(xml.Text("bar"),xml.EntityRef("amp"),xml.Text("x"))) - - Console.println("five"); - assertEquals(bx.toString, "<hello foo=\"bar&x\"></hello>") - - - /* patterns */ - Console.println("patterns"); - assertEquals(<hello/> match { case <hello/> => true; case _ => false; }, - true); + class XmlEx extends TestCase("attributes") with Assert { + override def run = { + assertEquals("@one", "bar", ax \ "@foo") + assertEquals("@two", xml.Text("bar"), ax \ "@foo") + assertEquals("@three", "bar&x", bx \ "@foo") + assertTrue ("@four", (bx \ "@foo") sameElements List(xml.Text("bar&x"))) + //assertTrue("@four", (bx \ "@foo") sameElements List(xml.Text("bar"),xml.EntityRef("amp"),xml.Text("x"))) + assertEquals("@five", "<hello foo=\"bar&x\"></hello>", bx.toString) + } + } + class XmlPat extends TestCase("patterns") with Assert { + override def run = { + assertTrue(<hello/> match { case <hello/> => true; case _ => false; }) + assertTrue(<x:ga xmlns:x="z"/> match { case <x:ga/> => true; case _ => false; }); /* assertEquals(ax match { case x @ <hello> @@ -51,6 +44,10 @@ def main(args:Array[String]) = { case _ => false; }, true); */ -} - + } + } + def suite = new TestSuite( + new XmlEx, + new XmlPat + ) } diff --git a/test/files/neg/xmlcorner.check b/test/files/neg/xmlcorner.check new file mode 100644 index 0000000000..8791829e50 --- /dev/null +++ b/test/files/neg/xmlcorner.check @@ -0,0 +1,7 @@ +xmlcorner.scala:2: error: illegal start of simple expression + val wrong = <:bla/> + ^ +xmlcorner.scala:5: error: in XML literal: name cannot end in ':' + val wrong = <bla: /> + ^ +two errors found diff --git a/test/files/neg/xmlcorner.scala b/test/files/neg/xmlcorner.scala new file mode 100644 index 0000000000..9f1c55bce4 --- /dev/null +++ b/test/files/neg/xmlcorner.scala @@ -0,0 +1,6 @@ +class foo { + val wrong = <:bla/> +} +class bar { + val wrong = <bla: /> +} |