From 61b2debaa00361250fbee05cbb71f2c989ad2c03 Mon Sep 17 00:00:00 2001 From: Burak Emir Date: Fri, 2 Mar 2007 19:07:57 +0000 Subject: * 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 --- test/files/jvm/unittest_xml.scala | 17 ++++++++++++- test/files/jvm/xml02.check | 13 ---------- test/files/jvm/xml02.scala | 51 ++++++++++++++++++--------------------- test/files/neg/xmlcorner.check | 7 ++++++ test/files/neg/xmlcorner.scala | 6 +++++ 5 files changed, 53 insertions(+), 41 deletions(-) delete mode 100644 test/files/jvm/xml02.check create mode 100644 test/files/neg/xmlcorner.check create mode 100644 test/files/neg/xmlcorner.scala (limited to 'test') 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 = + val z2 = + + 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), "", 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 = - Console.println("attributes"); - - Console.println("one"); - assertEquals(ax \ "@foo", "bar") - Console.println("two"); - assertEquals(ax \ "@foo", xml.Text("bar")) - val bx = - 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, "") - - - /* patterns */ - Console.println("patterns"); - assertEquals( match { case => 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", "", bx.toString) + } + } + class XmlPat extends TestCase("patterns") with Assert { + override def run = { + assertTrue( match { case => true; case _ => false; }) + assertTrue( match { case => true; case _ => false; }); /* assertEquals(ax match { case x @ @@ -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 = + ^ +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 = +} -- cgit v1.2.3