diff options
Diffstat (limited to 'test/files/jvm')
-rw-r--r-- | test/files/jvm/bigints.check | 9 | ||||
-rw-r--r-- | test/files/jvm/bigints.scala | 49 | ||||
-rw-r--r-- | test/files/jvm/stringbuilder.check | 17 | ||||
-rw-r--r-- | test/files/jvm/stringbuilder.scala | 84 | ||||
-rw-r--r-- | test/files/jvm/unittest_io_Jvm.check | 6 | ||||
-rw-r--r-- | test/files/jvm/unittest_io_Jvm.scala | 31 | ||||
-rw-r--r-- | test/files/jvm/unittest_xml.scala | 119 | ||||
-rw-r--r-- | test/files/jvm/xml01.scala | 169 | ||||
-rw-r--r-- | test/files/jvm/xml02.check | 0 | ||||
-rw-r--r-- | test/files/jvm/xml02.scala | 62 | ||||
-rw-r--r-- | test/files/jvm/xml03syntax.check | 9 | ||||
-rw-r--r-- | test/files/jvm/xml03syntax.scala | 33 | ||||
-rw-r--r-- | test/files/jvm/xml04embed.check | 3 | ||||
-rw-r--r-- | test/files/jvm/xml04embed.scala | 13 | ||||
-rw-r--r-- | test/files/jvm/xmlattr.check | 18 | ||||
-rw-r--r-- | test/files/jvm/xmlattr.scala | 65 | ||||
-rw-r--r-- | test/files/jvm/xmlstuff.scala | 292 |
17 files changed, 463 insertions, 516 deletions
diff --git a/test/files/jvm/bigints.check b/test/files/jvm/bigints.check new file mode 100644 index 0000000000..7952a044df --- /dev/null +++ b/test/files/jvm/bigints.check @@ -0,0 +1,9 @@ +int_add_bigint = (3,3) +int_sub_bigint = (-1,-1) +int_mul_bigint = (4,4) +z <= 3 = true +3 < z = false +z <= 3 = true +3 < z = false +c > MAX_LONG = false +c <= MAX_LONG = true diff --git a/test/files/jvm/bigints.scala b/test/files/jvm/bigints.scala index f4ca2d17a3..4f6a06b7e1 100644 --- a/test/files/jvm/bigints.scala +++ b/test/files/jvm/bigints.scala @@ -1,41 +1,32 @@ -//############################################################################ -// BigInt, BigDecimal -//############################################################################ - -//############################################################################ - -import testing.SUnit._ - -/** Test the Scala implementation of class <code>scala.BigDecimal</code>. +/** Test the Scala implementation of classes <code>scala.BigInt</code> +* and <code>scala.BigDecimal</code>. * * @author Stephane Micheloud */ -object Test extends TestConsoleMain { - def suite = new TestSuite( - Test_BigInt, - Test_BigDecimal - ) +object Test { + def main(args: Array[String]) { + Test_BigInt.runTest() + Test_BigDecimal.runTest() + } } -object Test_BigInt extends TestCase("BigInt") with Assert { - override def enableStackTrace = false - override def runTest { +object Test_BigInt { + def runTest() { import BigInt._ val x: BigInt = 1 val y = x + 1 val z = 1 + y - assertEquals("int_add_bigint", 1+y, y+1) - assertEquals("int_sub_bigint", 1-y, -(y-1)) - assertEquals("int_mul_bigint", 2*x*y, y*x*2) - assertTrue("z_<=_3", z <= 3) - assertFalse("3_<_z", 3 < z) + println("int_add_bigint = " + (1+y, y+1)) + println("int_sub_bigint = " + (1-y,-(y-1))) + println("int_mul_bigint = " + (2*x*y, y*x*2)) + println("z <= 3 = " + (z <= 3)) + println("3 < z = " + (3 < z)) } } -object Test_BigDecimal extends TestCase("BigDecimal") with Assert { - override def enableStackTrace = false - override def runTest { +object Test_BigDecimal { + def runTest() { import scala.BigDecimal, BigDecimal._ val xi: BigDecimal = 1 @@ -47,14 +38,14 @@ object Test_BigDecimal extends TestCase("BigDecimal") with Assert { val x: BigDecimal = 1 val y = x + 1 val z = 1 + y - assertTrue("z_<=_3", z <= 3) - assertFalse("3_<_z", 3 < z) + println("z <= 3 = " + (z <= 3)) + println("3 < z = " + (3 < z)) val a: BigDecimal= Math.MAX_LONG val b: BigDecimal = 1 val c = a - b - assertFalse("c_>_MAX_LONG", c > Math.MAX_LONG) - assertTrue("c_<=_MAX_LONG", c <= Math.MAX_LONG) + println("c > MAX_LONG = " + (c > Math.MAX_LONG)) + println("c <= MAX_LONG = " + (c <= Math.MAX_LONG)) } } diff --git a/test/files/jvm/stringbuilder.check b/test/files/jvm/stringbuilder.check new file mode 100644 index 0000000000..c9b44990b7 --- /dev/null +++ b/test/files/jvm/stringbuilder.check @@ -0,0 +1,17 @@ +s0 equals j0 = false +s0.toString equals j0.toString = true +s1.toString equals j1.toString = true +j2=cba, s2=cba +s2.toString equals j2.toString = true +j3=aba, s3=aba +s3.toString equals j3.toString = true +s0.toString equals j0.toString = true +s1.toString equals j1.toString = true +j0=-1988a1trueabc, s0=-1988a1trueabc +s0.toString equals j0.toString = true +j1=xyz012###, s1=xyz012### +s1.toString equals j1.toString = true +j1=2, s1=2 +s1 == j1 = true +j2=8, s2=8 +s2 == j2 = true diff --git a/test/files/jvm/stringbuilder.scala b/test/files/jvm/stringbuilder.scala index c86a8a7713..54951d657b 100644 --- a/test/files/jvm/stringbuilder.scala +++ b/test/files/jvm/stringbuilder.scala @@ -1,98 +1,88 @@ -import testing.SUnit._ - /** Test the Scala implementation of class <code>scala.StringBuilder</code>. * * @author Stephane Micheloud */ -object Test extends TestConsoleMain { - def suite = new TestSuite( - Test1, //ctor, reverse - Test2, //append - Test3, //insert - Test4 //indexOf, lastIndexOf - ) +object Test { + def main(args: Array[String]) { + Test1.run() //ctor, reverse + Test2.run() //append + Test3.run() //insert + Test4.run() //indexOf, lastIndexOf + } } -object Test1 extends TestCase("ctor") with Assert { - override def enableStackTrace = false - override def runTest { - val j0 = new java.lang.StringBuilder("abc") // Java 1.5+ +object Test1 { + def run() { + val j0 = new java.lang.StringBuilder("abc") val s0 = new StringBuilder("abc") - assertEquals("s0 equals j0", false, s0 equals j0) - assertEquals("s0.toString equals j0.toString", true, s0.toString equals j0.toString) + println("s0 equals j0 = " + (s0 equals j0)) + println("s0.toString equals j0.toString = " + (s0.toString equals j0.toString)) val str = """ Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages. It is also fully interoperable with Java.""" val j1 = new java.lang.StringBuilder(100) append str val s1 = new java.lang.StringBuilder(100) append str - assertEquals("s1.toString equals j1.toString", true, s1.toString equals j1.toString) + println("s1.toString equals j1.toString = " + (s1.toString equals j1.toString)) val j2 = j0 reverse val s2 = s0 reverse; - //println("j2="+j2+", s2="+s2)//debug - assertEquals("s2.toString equals j2.toString", true, s2.toString equals j2.toString) + println("j2="+j2+", s2="+s2) + println("s2.toString equals j2.toString = " + (s2.toString equals j2.toString)) val j3 = j2; j3 setCharAt (0, j3 charAt 2) val s3 = s2; s3(0) = s3(2) - //println("j3="+j3+", s3="+s3)//debug - assertEquals("s3.toString equals j3.toString", true, s3.toString equals j3.toString) + println("j3="+j3+", s3="+s3) + println("s3.toString equals j3.toString = " + (s3.toString equals j3.toString)) } } -object Test2 extends TestCase("append") with Assert { - override def enableStackTrace = false - override def runTest { - val j0 = new java.lang.StringBuilder("abc") // Java 1.5+ +object Test2 { + def run() { + val j0 = new java.lang.StringBuilder("abc") val s0 = new StringBuilder("abc") - j0 append true append (1.toByte) append 'a' append 9 append -1L append 1.2e-10f append -2.1e+100d s0 append true append (1.toByte) append 'a' append 9 append -1L append 1.2e-10f append -2.1e+100d + println("s0.toString equals j0.toString = " + (s0.toString equals j0.toString)) - assertEquals("s0.toString equals j0.toString", true, s0.toString equals j0.toString) - - val j1 = new java.lang.StringBuilder // Java 1.5+ + val j1 = new java.lang.StringBuilder val s1 = new StringBuilder j1 append "###" append Array('0', '1', '2') append "xyz".subSequence(0, 3) s1 append "###" appendAll Array('0', '1', '2') appendAll List('x', 'y', 'z') - assertEquals("s1.toString equals j1.toString", true, s1.toString equals j1.toString) + println("s1.toString equals j1.toString = " + (s1.toString equals j1.toString)) } } -object Test3 extends TestCase("insert") with Assert { - override def enableStackTrace = false - override def runTest { - val j0 = new java.lang.StringBuilder("abc") // Java 1.5+ +object Test3 { + def run() { + val j0 = new java.lang.StringBuilder("abc") val s0 = new StringBuilder("abc") - j0 insert (0, true) insert (0, 1.toByte) insert (0, 'a') insert (0, 88.toShort) insert (0, 9) insert (0, -1L) s0 insert (0, true) insert (0, 1.toByte) insert (0, 'a') insert (0, 88.toShort) insert (0, 9) insert (0, -1L) - //println("j0="+j0+", s0="+s0)//debug - assertEquals("s0.toString equals j0.toString", true, s0.toString equals j0.toString) + println("j0="+j0+", s0="+s0) + println("s0.toString equals j0.toString = " + (s0.toString equals j0.toString)) - val j1 = new java.lang.StringBuilder // Java 1.5+ + val j1 = new java.lang.StringBuilder val s1 = new StringBuilder j1 insert (0, "###") insert (0, Array('0', '1', '2')) insert (0, "xyz".subSequence(0, 3)) s1 insert (0, "###") insertAll (0, Array('0', '1', '2')) insertAll (0, List('x', 'y', 'z')) - //println("j1="+j1+", s1="+s1)//debug - assertEquals("s1.toString equals j1.toString", true, s1.toString equals j1.toString) - + println("j1="+j1+", s1="+s1) + println("s1.toString equals j1.toString = " + (s1.toString equals j1.toString)) } } -object Test4 extends TestCase("indefOf") with Assert { - override def enableStackTrace = false - override def runTest { +object Test4 { + def run() { val j0 = new java.lang.StringBuilder("abc") // Java 1.5+ val s0 = new StringBuilder("abc") val j1 = j0 indexOf("c") val s1 = s0 indexOf("c") - //println("j1="+j1+", s1="+s1)//debug - assertEquals("s1 == j1", true, s1 == j1) + println("j1="+j1+", s1="+s1) + println("s1 == j1 = " + (s1 == j1)) val j2 = j0 append "123abc" lastIndexOf("c") val s2 = s0 append "123abc" lastIndexOf("c") - //println("j2="+j2+", s2="+s2)//debug - assertEquals("s2 == j2", true, s2 == j2) + println("j2="+j2+", s2="+s2) + println("s2 == j2 = " + (s2 == j2)) } } diff --git a/test/files/jvm/unittest_io_Jvm.check b/test/files/jvm/unittest_io_Jvm.check new file mode 100644 index 0000000000..d6e855f939 --- /dev/null +++ b/test/files/jvm/unittest_io_Jvm.check @@ -0,0 +1,6 @@ +lines.size = 5 + +This is a file +it is split on several lines. + +isn't it? diff --git a/test/files/jvm/unittest_io_Jvm.scala b/test/files/jvm/unittest_io_Jvm.scala index fd5889cb86..7c8ef131bc 100644 --- a/test/files/jvm/unittest_io_Jvm.scala +++ b/test/files/jvm/unittest_io_Jvm.scala @@ -1,24 +1,15 @@ -import scala.testing.SUnit._ import scala.io.Source -object Test extends TestConsoleMain { - - def suite = new TestSuite( - new ReadlinesTest - ) - - class ReadlinesTest extends TestCase("scala.io.Source method getLines()") { - - val src = Source.fromString(""" -This is a file -it is split on several lines. - -isn't it? -""") - def runTest() = assertEquals("wrong number of lines",src.getLines.toList.length,5) // five new lines in there - //for (line <- src.getLines) { - // Console.print(line) - //} +object Test { + def main(args: Array[String]) { + val lines = Source.fromString( + """| + |This is a file + |it is split on several lines. + | + |isn't it? + |""".stripMargin).getLines.toList + println("lines.size = " + lines.size) + lines.foreach(println) } - } diff --git a/test/files/jvm/unittest_xml.scala b/test/files/jvm/unittest_xml.scala index 1569bb13af..e3d69115bc 100644 --- a/test/files/jvm/unittest_xml.scala +++ b/test/files/jvm/unittest_xml.scala @@ -1,23 +1,26 @@ +import scala.xml.{ MetaData, Null, Utility, PrefixedAttribute, UnprefixedAttribute } object Test { - import scala.testing.SUnit._ - import scala.xml.{MetaData, Null, Utility, PrefixedAttribute, UnprefixedAttribute } + def main(args:Array[String]) = { + MetaDataTest.run() + UtilityTest.run() + } - class MetaDataTest extends TestCase("scala.xml.MetaData") with Assert { + object MetaDataTest { - import scala.xml.{HasKeyValue, TopScope, NamespaceBinding, Node, Atom, Text } + import scala.xml.{ HasKeyValue, TopScope, NamespaceBinding, Node, Atom, Text } - def domatch(x:Node): Node = { + def domatch(x:Node): Node = { val hasBar = new HasKeyValue("bar") - x match { - //case Node("foo", hasBar(z), _*) => z + x match { + //case Node("foo", hasBar(z), _*) => z case Node("foo", md, _*) if !hasBar.unapplySeq(md).isEmpty => md("bar")(0) - case _ => new Atom(3) - } - } - override def runTest = { + case _ => new Atom(3) + } + } + def run() { var x: MetaData = Null var s: NamespaceBinding = TopScope @@ -25,85 +28,75 @@ object Test { // testing method def apply(uri:String, scp:NamespaceBinding, k:String): Seq[Node] // def apply(k:String): Seq[Node] - assertEquals("absent element (prefixed) 1", null, x("za://foo.com", s, "bar" )) - assertEquals("absent element (unprefix) 1", null, x("bar")) + assert(null == x("za://foo.com", s, "bar" ), "absent element (prefixed) 1") + assert(null == x("bar"), "absent element (unprefix) 1") - assertEquals("absent element (prefixed) 2", None, x.get("za://foo.com", s, "bar" )) - assertEquals("absent element (unprefix) 2", None, x.get("bar")) + assert(None == x.get("za://foo.com", s, "bar" ), "absent element (prefixed) 2") + assert(None == x.get("bar"), "absent element (unprefix) 2") x = new PrefixedAttribute("zo","bar", new Atom(42), x) s = new NamespaceBinding("zo","za://foo.com",s) - assertEquals("present element (prefixed) 3", new Atom(42), x("za://foo.com", s, "bar" )) - assertEquals("present element (unprefix) 3", null, x("bar")) + assert(new Atom(42) == x("za://foo.com", s, "bar" ), "present element (prefixed) 3") + assert(null == x("bar"), "present element (unprefix) 3") - assertEquals("present element (prefixed) 4", Some(new Atom(42)), x.get("za://foo.com", s, "bar" )) - assertEquals("present element (unprefix) 4", None, x.get("bar")) + assert(Some(new Atom(42)) == x.get("za://foo.com", s, "bar" ), "present element (prefixed) 4") + assert(None == x.get("bar"), "present element (unprefix) 4") x = new UnprefixedAttribute("bar","meaning", x) - assertEquals("present element (prefixed) 5", null, x(null, s, "bar" )) - assertEquals("present element (unprefix) 5", Text("meaning"), x("bar")) + assert(null == x(null, s, "bar"), "present element (prefixed) 5") + assert(Text("meaning") == x("bar"), "present element (unprefix) 5") - assertEquals("present element (prefixed) 6", None, x.get(null, s, "bar" )) - assertEquals("present element (unprefix) 6", Some(Text("meaning")), x.get("bar")) + assert(None == x.get(null, s, "bar" ), "present element (prefixed) 6") + assert(Some(Text("meaning")) == x.get("bar"), "present element (unprefix) 6") - val z = <foo bar="gar"/> - val z2 = <foo/> + 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)) + assert(Text("gar") == domatch(z), "attribute extractor 1") + assert(new Atom(3) == domatch(z2), "attribute extractor 2") } } - class UtilityTest extends TestCase("scala.xml.Utility") with Assert { - def runTest() = { - assertTrue(Utility.isNameStart('b')) - assertFalse(Utility.isNameStart(':')) - + object UtilityTest { + def run() { + assert(Utility.isNameStart('b')) + assert(!Utility.isNameStart(':')) - val x = <foo> - <toomuchws/> - </foo> + val x = <foo> + <toomuchws/> + </foo> - val y = xml.Utility.trim(x) + val y = xml.Utility.trim(x) - assertEquals("trim 1 ", 1, y match { case <foo><toomuchws/></foo> => 1 }) + assert(1 == (y match { case <foo><toomuchws/></foo> => 1 }), "trim 1") - val x2 = <foo> - <toomuchws> a b b a </toomuchws> - </foo> + val x2 = <foo> + <toomuchws> a b b a </toomuchws> + </foo> - val y2 = xml.Utility.trim(x2) + val y2 = xml.Utility.trim(x2) - assertEquals("trim 2 ", 2, y2 match { case <foo><toomuchws>a b b a</toomuchws></foo> => 2 }) + assert(2 == (y2 match { case <foo><toomuchws>a b b a</toomuchws></foo> => 2 }), "trim 2") + val z = <bar>''</bar> + val z1 = z.toString - val z = <bar>''</bar> - val z1 = z.toString + assert("<bar>''</bar>" == z1, "apos unescaped") - assertEquals("apos unescaped", "<bar>''</bar>", z1) + val q = xml.Utility.sort(<a g='3' j='2' oo='2' a='2'/>) + assert(" a=\"2\" g=\"3\" j=\"2\" oo=\"2\"" == xml.Utility.sort(q.attributes).toString) - val q = xml.Utility.sort(<a g='3' j='2' oo='2' a='2'/>) - 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)) + val pp = new xml.PrettyPrinter(80,5) + assert("<a a=\"2\" g=\"3\" j=\"2\" oo=\"2\"></a>" == pp.format(q)) - <hi> - <there/> - <guys/> - </hi>.hashCode // Bug #777 - } + <hi> + <there/> + <guys/> + </hi>.hashCode // Bug #777 + } } - def main(args:Array[String]) = { - val ts = new TestSuite( - new MetaDataTest, - new UtilityTest - ) - val tr = new TestResult() - ts.run(tr) - tr.failures foreach Console.println - } } diff --git a/test/files/jvm/xml01.scala b/test/files/jvm/xml01.scala index bb6f98bacc..ef320e218b 100644 --- a/test/files/jvm/xml01.scala +++ b/test/files/jvm/xml01.scala @@ -1,12 +1,10 @@ import java.io.StringReader import org.xml.sax.InputSource -import scala.testing.SUnit._ import scala.util.logging._ import scala.xml._ - -object Test extends App with Assert { +object Test extends App { val e: scala.xml.MetaData = Null //Node.NoAttributes val sc: scala.xml.NamespaceBinding = TopScope @@ -26,45 +24,33 @@ object Test extends App with Assert { } println("equality") - assertEqualsXML(c, parsedxml11) - assertEqualsXML(parsedxml1, parsedxml11) - assertSameElementsXML(List(parsedxml1), List(parsedxml11)) - assertSameElementsXML(Array(parsedxml1).toList, List(parsedxml11)) + assert(c == parsedxml11) + assert(parsedxml1 == parsedxml11) + assert(List(parsedxml1) sameElements List(parsedxml11)) + assert(Array(parsedxml1).toList sameElements List(parsedxml11)) val x2 = "<book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book>"; val i = new InputSource(new StringReader(x2)) val x2p = XML.load(i) - assertEqualsXML(x2p, Elem(null, "book" , e, sc, - Elem(null, "author", e, sc,Text("Peter Buneman")), - Elem(null, "author", e, sc,Text("Dan Suciu")), - Elem(null, "title" , e, sc,Text("Data on ze web")))); + assert(x2p == Elem(null, "book" , e, sc, + Elem(null, "author", e, sc,Text("Peter Buneman")), + Elem(null, "author", e, sc,Text("Dan Suciu")), + Elem(null, "title" , e, sc,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)) val parsedxml2 = XML.load(isrc2) - // xmlFile2/book -> book,book println("xpath \\") + assert(parsedxml1 \ "_" sameElements List(Elem(null,"world", e, sc))) - assertSameElementsXML(parsedxml1 \ "_" , List(Elem(null,"world", e, sc))) - - assertSameElementsXML(parsedxml1 \ "world", List(Elem(null,"world", e, sc))) - -/* - Console.println( parsedxml2 \ "_" ); - Console.println( (parsedxml2 \ "_" ).iterator); - for( val i <- (parsedxml2 \ "_" ).iterator) { - Console.println( i ); - }; - */ + assert(parsedxml1 \ "world" sameElements List(Elem(null,"world", e, sc))) - assertSameElementsXML( - parsedxml2 \ "_" , - - List( + assert( + (parsedxml2 \ "_") sameElements List( Elem(null,"book", e, sc, Elem(null,"author", e, sc, Text("Peter Buneman")), Elem(null,"author", e, sc, Text("Dan Suciu")), @@ -72,13 +58,11 @@ object Test extends App with Assert { Elem(null,"book",e,sc, Elem(null,"author",e,sc,Text("John Mitchell")), Elem(null,"title",e,sc,Text("Foundations of Programming Languages")))) - ); - assertEquals( (parsedxml2 \ "author").length, 0 ); - - assertSameElementsXML( - parsedxml2 \ "book", + ) + assert((parsedxml2 \ "author").isEmpty) - List( + assert( + (parsedxml2 \ "book") sameElements List( Elem(null,"book",e,sc, Elem(null,"author", e, sc, Text("Peter Buneman")), Elem(null,"author", e, sc, Text("Dan Suciu")), @@ -87,69 +71,51 @@ object Test extends App with Assert { Elem(null,"author", e, sc, Text("John Mitchell")), Elem(null,"title" , e, sc, Text("Foundations of Programming Languages"))) ) - ); - - assertSameElementsXML( + ) - parsedxml2 \ "_" \ "_", - - List( + assert( + (parsedxml2 \ "_" \ "_") sameElements List( Elem(null,"author", e, sc, Text("Peter Buneman")), Elem(null,"author", e, sc, Text("Dan Suciu")), Elem(null,"title" , e, sc, Text("Data on ze web")), Elem(null,"author", e, sc, Text("John Mitchell")), Elem(null,"title" , e, sc, Text("Foundations of Programming Languages")) ) - ); - - assertSameElementsXML( - - parsedxml2 \ "_" \ "author", + ) - List( + assert( + (parsedxml2 \ "_" \ "author") sameElements List( Elem(null,"author", e, sc, Text("Peter Buneman")), Elem(null,"author", e, sc, Text("Dan Suciu")), Elem(null,"author", e, sc, Text("John Mitchell")) ) + ) - ); - - assertSameElementsXML( (parsedxml2 \ "_" \ "_" \ "author"), List() ); + assert((parsedxml2 \ "_" \ "_" \ "author").isEmpty) Console.println("xpath \\\\ DESCENDANTS"); - assertSameElementsXML( - - parsedxml2 \\ "author", - - List( + assert( + (parsedxml2 \\ "author") sameElements List( Elem(null,"author", e, sc, Text("Peter Buneman")), Elem(null,"author", e, sc, Text("Dan Suciu")), Elem(null,"author", e, sc, Text("John Mitchell")) ) + ) - ); - - - assertSameElementsXML( - - parsedxml2 \\ "title", - - List( + assert( + (parsedxml2 \\ "title") sameElements List( Elem(null,"title", e, sc, Text("Data on ze web")), Elem(null,"title", e, sc, Text("Foundations of Programming Languages"))) - ); + ) println( (parsedxml2 \\ "book" ){ n:Node => (n \ "title") xml_== "Data on ze web" } - ); + ) - assertEqualsXML( - - (new NodeSeq { val theSeq = List( parsedxml2 ) }) \\ "_", - - List( + assert( + ((new NodeSeq { val theSeq = List( parsedxml2 ) }) \\ "_") sameElements List( Elem(null,"bib",e,sc, Elem(null,"book",e,sc, Elem(null, "author", e, sc, Text("Peter Buneman")), @@ -163,64 +129,53 @@ object Test extends App with Assert { Elem(null,"author",e,sc,Text("Dan Suciu")), Elem(null,"title",e,sc,Text("Data on ze web"))), Elem(null,"author",e,sc,Text("Peter Buneman")), - //Text("Peter Buneman"), Elem(null,"author",e,sc,Text("Dan Suciu")), - //Text("Dan Suciu"), Elem(null,"title",e,sc,Text("Data on ze web")), - //Text("Data on ze web"), Elem(null,"book",e,sc, Elem(null,"author",e,sc,Text("John Mitchell")), Elem(null,"title",e,sc,Text("Foundations of Programming Languages"))), Elem(null,"author",e,sc,Text("John Mitchell")), - //Text("John Mitchell"), Elem(null,"title",e,sc,Text("Foundations of Programming Languages")) - //Text("Foundations of Programming Languages") ) - ); - - // test group node - Console println "-- group nodes" - val zx1: Node = Group { <a/><b/><c/> } - val zy1 = <f>{zx1}</f> - Console println zy1.toString() + ) - val zx2: Node = Group { List(<a/>,zy1,zx1) } - Console println zx2.toString() + // test group node + Console println "-- group nodes" + val zx1: Node = Group { <a/><b/><c/> } + val zy1 = <f>{zx1}</f> + Console println zy1.toString() - val zz1 = <xml:group><a/><b/><c/></xml:group> + val zx2: Node = Group { List(<a/>,zy1,zx1) } + Console println zx2.toString() - assertTrue(zx1 xml_== zz1) - assertTrue(zz1.length == 3) + val zz1 = <xml:group><a/><b/><c/></xml:group> - // unparsed + assert(zx1 xml_== zz1) + assert(zz1.length == 3) - // val uup = <xml:unparsed>&<<>""^%@$!#</xml:unparsed> - // assertTrue(uup == "&<<>\"\"^%@$!#") - // test unicode escapes backslash u + // unparsed println("attribute value normalization") val xmlAttrValueNorm = "<personne id='p0003' nom='Şahingöz' />"; - { - val isrcA = new InputSource( new StringReader(xmlAttrValueNorm) ); - val parsedxmlA = XML.load(isrcA); - val c = (parsedxmlA \ "@nom").text.charAt(0); - //Console.println("char '"+c+"' \u015e"); - assertTrue(c == '\u015e'); - } - // buraq: if the following test fails with 'character x not allowed', it is - // related to the mutable variable in a closures in MarkupParser.parsecharref - { - val isr = scala.io.Source.fromString(xmlAttrValueNorm); - val pxmlB = scala.xml.parsing.ConstructingParser.fromSource(isr,false); - val parsedxmlB = pxmlB.element(TopScope); - val c = (parsedxmlB \ "@nom").text.charAt(0); - //Console.println("char '"+c+"' \u015e"); - assertTrue(c == '\u015e'); - } + { + val isrcA = new InputSource( new StringReader(xmlAttrValueNorm) ); + val parsedxmlA = XML.load(isrcA); + val c = (parsedxmlA \ "@nom").text.charAt(0); + assert(c == '\u015e'); + } + // buraq: if the following test fails with 'character x not allowed', it is + // related to the mutable variable in a closures in MarkupParser.parsecharref + { + val isr = scala.io.Source.fromString(xmlAttrValueNorm); + val pxmlB = scala.xml.parsing.ConstructingParser.fromSource(isr,false); + val parsedxmlB = pxmlB.element(TopScope); + val c = (parsedxmlB \ "@nom").text.charAt(0); + assert(c == '\u015e'); + } // #60 test by round trip val p = scala.xml.parsing.ConstructingParser.fromSource(scala.io.Source.fromString("<foo bar:attr='&'/>"),true) val n = p.element(new scala.xml.NamespaceBinding("bar","BAR",scala.xml.TopScope))(0) - assertFalse( n.attributes.get("BAR", n, "attr").isEmpty) + assert( n.attributes.get("BAR", n, "attr").nonEmpty) } diff --git a/test/files/jvm/xml02.check b/test/files/jvm/xml02.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/jvm/xml02.check diff --git a/test/files/jvm/xml02.scala b/test/files/jvm/xml02.scala index 11f77cc90f..fb790d5926 100644 --- a/test/files/jvm/xml02.scala +++ b/test/files/jvm/xml02.scala @@ -1,6 +1,11 @@ -import testing.SUnit._ +object Test { -object Test extends TestConsoleMain { + def main(args: Array[String]) { + XmlEx.run() + XmlEy.run() + XmlPat.run() + DodgyNamespace.run() + } import scala.xml.{NodeSeq, Utility} import NodeSeq.seqToNodeSeq @@ -15,38 +20,38 @@ object Test extends TestConsoleMain { val bx = <hello foo="bar&x"></hello> - object XmlEx extends TestCase("attributes") with Assert { + object XmlEx { - override def runTest = { - assertTrue("@one", (ax \ "@foo") xml_== "bar") // uses NodeSeq.view! - assertTrue("@two", (ax \ "@foo") xml_== xml.Text("bar")) // dto. - assertTrue("@three", (bx \ "@foo") xml_== "bar&x") // dto. - assertTrue ("@four", (bx \ "@foo") xml_sameElements List(xml.Text("bar&x"))) - assertEquals("@five", "<hello foo=\"bar&x\"></hello>", bx.toString) + def run() { + assert((ax \ "@foo") xml_== "bar") // uses NodeSeq.view! + assert((ax \ "@foo") xml_== xml.Text("bar")) // dto. + assert((bx \ "@foo") xml_== "bar&x") // dto. + assert((bx \ "@foo") xml_sameElements List(xml.Text("bar&x"))) + assert("<hello foo=\"bar&x\"></hello>" == bx.toString) } } - object XmlEy extends TestCase("attributes with namespace") with Assert { - override def runTest = { + object XmlEy { + def run() { val z = ax \ "@{the namespace from outer space}foo" - assertTrue("@six", (ax \ "@{the namespace from outer space}foo") xml_== "baz") - assertTrue("@eight", (cx \ "@{the namespace from outer space}foo") xml_== "baz") + assert((ax \ "@{the namespace from outer space}foo") xml_== "baz") + assert((cx \ "@{the namespace from outer space}foo") xml_== "baz") try { ax \ "@" - assertTrue("wrong1", false) + assert(false) } catch { case _: IllegalArgumentException => } try { ax \ "@{" - assertTrue("wrong2", false) + assert(false) } catch { case _: IllegalArgumentException => } try { ax \ "@{}" - assertTrue("wrong3", false) + assert(false) } catch { case _: IllegalArgumentException => } @@ -54,25 +59,20 @@ object Test extends TestConsoleMain { } } - object XmlPat extends TestCase("patterns") with Assert { - override def runTest = { - assertTrue(<hello/> match { case <hello/> => true; case _ => false; }) - assertTrue(<x:ga xmlns:x="z"/> match { case <x:ga/> => true; case _ => false; }); - assertTrue(Utility.trim(cx) match { case n @ <hello>crazy text world</hello> if (n \ "@foo") xml_== "bar" => true; }) - assertTrue(Utility.trim(cx) match { case n @ <z:hello>crazy text world</z:hello> if (n \ "@foo") xml_== "bar" => true; }) + object XmlPat { + def run() { + assert(<hello/> match { case <hello/> => true; case _ => false; }) + assert(<x:ga xmlns:x="z"/> match { case <x:ga/> => true; case _ => false; }); + assert(Utility.trim(cx) match { case n @ <hello>crazy text world</hello> if (n \ "@foo") xml_== "bar" => true; }) + assert(Utility.trim(cx) match { case n @ <z:hello>crazy text world</z:hello> if (n \ "@foo") xml_== "bar" => true; }) } } - object DodgyNamespace extends TestCase("DodgyNamespace") with Assert { - override def runTest = { + object DodgyNamespace { + def run() { val x = <flog xmlns:ee="http://ee.com"><foo xmlns:dog="http://dog.com"><dog:cat/></foo></flog> - assertTrue(x.toString.matches(".*xmlns:dog=\"http://dog.com\".*")); + assert(x.toString.matches(".*xmlns:dog=\"http://dog.com\".*")); } } - def suite = new TestSuite( - XmlEx, - XmlEy, - XmlPat, - DodgyNamespace - ) + } diff --git a/test/files/jvm/xml03syntax.check b/test/files/jvm/xml03syntax.check index fd1e10cac9..75dc539137 100644 --- a/test/files/jvm/xml03syntax.check +++ b/test/files/jvm/xml03syntax.check @@ -1,9 +1,18 @@ +true +true +true <hello>world</hello> +true <hello>1.5</hello> +true <hello>5</hello> +true <hello>true</hello> +true <hello>5</hello> +true <hello>27</hello> +true <hello>1 2 3 4</hello> 1 2 diff --git a/test/files/jvm/xml03syntax.scala b/test/files/jvm/xml03syntax.scala index 2fee0243a6..2c93f7c176 100644 --- a/test/files/jvm/xml03syntax.scala +++ b/test/files/jvm/xml03syntax.scala @@ -1,7 +1,6 @@ -import scala.testing.SUnit._ import scala.xml._ -object Test extends AnyRef with Assert { +object Test { private def handle[A](x: Node): A = { println(x) @@ -9,15 +8,15 @@ object Test extends AnyRef with Assert { } def main(args: Array[String]) { - test1 - test2 - test3 + test1() + test2() + test3() } - private def test1 { + private def test1() { val xNull = <hello>{null}</hello> // these used to be Atom(unit), changed to empty children - assertSameElements(xNull.child, Nil) + println(xNull.child sameElements Nil) val x0 = <hello>{}</hello> // these used to be Atom(unit), changed to empty children val x00 = <hello>{ }</hello> // dto. @@ -25,29 +24,29 @@ object Test extends AnyRef with Assert { val xa = <hello>{ "world" }</hello> - assertSameElements(x0.child, Nil) - assertSameElements(x00.child, Nil) - assertEquals(handle[String](xa), "world") + println(x0.child sameElements Nil) + println(x00.child sameElements Nil) + println(handle[String](xa) == "world") val xb = <hello>{ 1.5 }</hello> - assertEquals(handle[Double](xb), 1.5) + println(handle[Double](xb) == 1.5) val xc = <hello>{ 5 }</hello> - assertEquals(handle[Int](xc), 5) + println(handle[Int](xc) == 5) val xd = <hello>{ true }</hello> - assertEquals(handle[Boolean](xd), true) + println(handle[Boolean](xd) == true) val xe = <hello>{ 5:Short }</hello> - assertEquals(handle[Short](xe), 5:Short) + println(handle[Short](xe) == (5:Short)) val xf = <hello>{ val x = 27; x }</hello> - assertEquals(handle[Int](xf), 27) + println(handle[Int](xf) == 27) val xg = <hello>{ List(1,2,3,4) }</hello> @@ -68,7 +67,7 @@ object Test extends AnyRef with Assert { /** see SVN r13821 (emir): support for <elem key={x:Option[Seq[Node]]} />, * so that Options can be used for optional attributes. */ - private def test2 { + private def test2() { val x1: Option[Seq[Node]] = Some(<b>hello</b>) val n1 = <elem key={x1} />; println("node="+n1+", key="+n1.attribute("key")) @@ -78,7 +77,7 @@ object Test extends AnyRef with Assert { println("node="+n2+", key="+n2.attribute("key")) } - private def test3 { + private def test3() { // this demonstrates how to handle entities val s = io.Source.fromString("<a> </a>") object parser extends xml.parsing.ConstructingParser(s, false /*ignore ws*/) { diff --git a/test/files/jvm/xml04embed.check b/test/files/jvm/xml04embed.check index e69de29bb2..e71e645149 100644 --- a/test/files/jvm/xml04embed.check +++ b/test/files/jvm/xml04embed.check @@ -0,0 +1,3 @@ +{ +} +{}{}{} diff --git a/test/files/jvm/xml04embed.scala b/test/files/jvm/xml04embed.scala index 249e8ceb06..fa453e4295 100644 --- a/test/files/jvm/xml04embed.scala +++ b/test/files/jvm/xml04embed.scala @@ -1,15 +1,10 @@ -import scala.testing.SUnit._ - -object Test extends AnyRef with Assert { +object Test { def main(args: Array[String]) { val ya = <x>{{</x> - assertEquals(ya.text, "{") - + println(ya.text) val ua = <x>}}</x> - assertEquals(ua.text, "}") - + println(ua.text) val za = <x>{{}}{{}}{{}}</x> - assertEquals(za.text, "{}{}{}") - + println(za.text) } } diff --git a/test/files/jvm/xmlattr.check b/test/files/jvm/xmlattr.check index e69de29bb2..af80b60fb2 100644 --- a/test/files/jvm/xmlattr.check +++ b/test/files/jvm/xmlattr.check @@ -0,0 +1,18 @@ +true +true +true +true +true +true +removal of duplicates for unprefixed attributes in append = 1 +true +true +true +true +true +true +true +true +true +<b x="&"></b> +<b x="&"></b> diff --git a/test/files/jvm/xmlattr.scala b/test/files/jvm/xmlattr.scala index a947adf231..2668819c9d 100644 --- a/test/files/jvm/xmlattr.scala +++ b/test/files/jvm/xmlattr.scala @@ -1,60 +1,63 @@ -import testing.SUnit.{Assert, TestCase, TestConsoleMain, TestSuite} -import xml.{NodeSeq, Null, Text, UnprefixedAttribute} +import xml.{ NodeSeq, Null, Text, UnprefixedAttribute } -object Test extends TestConsoleMain { - def suite = new TestSuite(UnprefixedAttributeTest, AttributeWithOptionTest) +object Test { - object UnprefixedAttributeTest extends TestCase("UnprefixedAttribute") with Assert { - override def runTest { - var x = new UnprefixedAttribute("foo","bar", Null) + def main(args: Array[String]) { + UnprefixedAttributeTest() + AttributeWithOptionTest() + AttributeOutputTest() + } - // always assertX(expected, actual) - assertEquals(Some(Text("bar")), x.get("foo")); - assertEquals(Text("bar"), x("foo")) - assertEquals(None, x.get("no_foo")) - assertEquals(null, x("no_foo")) + object UnprefixedAttributeTest { + def apply() { + val x = new UnprefixedAttribute("foo","bar", Null) + println(Some(Text("bar")) == x.get("foo")) + println(Text("bar") == x("foo")) + println(None == x.get("no_foo")) + println(null == x("no_foo")) val y = x.remove("foo") - assertEquals(Null, y) + println(Null == y) val z = new UnprefixedAttribute("foo", null:NodeSeq, x) - assertEquals(None, z.get("foo")) + println(None == z.get("foo")) var appended = x append x append x append x var len = 0; while (appended ne Null) { appended = appended.next len = len + 1 } - assertEquals("removal of duplicates for unprefixed attributes in append", 1, len) + println("removal of duplicates for unprefixed attributes in append = " + len) } } - object AttributeWithOptionTest extends TestCase("AttributeWithOption") with Assert { - override def runTest { - var x = new UnprefixedAttribute("foo", Some(Text("bar")), Null) + object AttributeWithOptionTest { + def apply() { + val x = new UnprefixedAttribute("foo", Some(Text("bar")), Null) - assertEquals(Some(Text("bar")), x.get("foo")); - assertEquals(Text("bar"), x("foo")) - assertEquals(None, x.get("no_foo")) - assertEquals(null, x("no_foo")) + println(Some(Text("bar")) == x.get("foo")) + println(Text("bar") == x("foo")) + println(None == x.get("no_foo")) + println(null == x("no_foo")) val attr1 = Some(Text("foo value")) val attr2 = None val y = <b foo={attr1} bar={attr2} /> - assertEquals(Some(Text("foo value")), y.attributes.get("foo")); - assertEquals(Text("foo value"), y.attributes("foo")) - assertEquals(None, y.attributes.get("bar")) - assertEquals(null, y.attributes("bar")) + println(Some(Text("foo value")) == y.attributes.get("foo")); + println(Text("foo value") == y.attributes("foo")) + println(None == y.attributes.get("bar")) + println(null == y.attributes("bar")) val z = new UnprefixedAttribute("foo", None, x) - assertEquals(None, z.get("foo")) // None + println(None == z.get("foo")) } } - object AttributeOutputTest extends TestCase("AttributeOutput") with Assert { - override def runTest { - assertEquals(<b x="&"/>.toString, "<b x=\"&\"></b>") - assertEquals( <b x={"&"}/>.toString, "<b x=\"&\"></b>") + object AttributeOutputTest { + def apply() { + println(<b x="&"/>) + println(<b x={"&"}/>) } } + } diff --git a/test/files/jvm/xmlstuff.scala b/test/files/jvm/xmlstuff.scala index 6e711a0f86..08aa716352 100644 --- a/test/files/jvm/xmlstuff.scala +++ b/test/files/jvm/xmlstuff.scala @@ -1,10 +1,8 @@ import java.io.StringReader import org.xml.sax.InputSource - -import scala.testing.SUnit.Assert import scala.xml.{Node, NodeSeq, Elem, Text, XML} -object Test extends AnyRef with Assert { +object Test { /** returns true if exception was thrown */ def catcher(att: Function1[Unit, scala.xml.MetaData]): Boolean = { @@ -21,193 +19,163 @@ object Test extends AnyRef with Assert { def main(args: Array[String]) { - //val e: scala.xml.MetaData = null; //Node.NoAttributes; - //val sc: scala.xml.NamespaceBinding = null; - - // ------------------------------------------ tests for class NodeSeq - - /** - println("checking wellformed attributes"); - { - import scala.xml.{ UnprefixedAttribute, Null } - assertTrue(catcher {x:Unit => new UnprefixedAttribute("key", "<", Null)}); // < illegal - assertTrue(catcher(x:Unit => new UnprefixedAttribute("key", "&", Null))); // & illegal - assertTrue(catcher(x:Unit => new UnprefixedAttribute("key", "a&a", Null))); // & illegal - assertTrue(catcher(x:Unit => new UnprefixedAttribute("key", "a&a;&", Null))); // 2nd & - - assertFalse(catcher(x:Unit => new UnprefixedAttribute("key", "a&a; <<", Null))); - } -*/ - -/* -checking wellformed attributes -< not allowed in attribute value -passed ok -malformed entity reference in attribute value [&] -passed ok -malformed entity reference in attribute value [a&a] -passed ok -malformed entity reference in attribute value [a&a;&] -passed ok -passed ok -*/ - - println("NodeSeq") + println("NodeSeq") val p = <foo> - <bar gt='ga' value="3"/> - <baz bazValue="8"/> - <bar value="5" gi='go'/> - </foo>; + <bar gt='ga' value="3"/> + <baz bazValue="8"/> + <bar value="5" gi='go'/> + </foo>; val pelems_1 = for( val x <- p \ "bar"; val y <- p \ "baz" ) yield { Text(x.attributes("value").toString + y.attributes("bazValue").toString+ "!") }; val pelems_2 = new NodeSeq { val theSeq = List(Text("38!"),Text("58!")) }; - assertSameElementsXML(pelems_1, pelems_2) + assert(pelems_1 sameElements pelems_2) - assertEqualsXML(p \\ "@bazValue", Text("8")) + assert(Text("8") sameElements (p \\ "@bazValue")) val books = - <bks> - <book><title>Blabla</title></book> - <book><title>Blubabla</title></book> - <book><title>Baaaaaaalabla</title></book> + <bks> + <book><title>Blabla</title></book> + <book><title>Blubabla</title></book> + <book><title>Baaaaaaalabla</title></book> </bks>; - val reviews = - <reviews> - <entry><title>Blabla</title> - <remarks> - Hallo Welt. - </remarks> + val reviews = + <reviews> + <entry><title>Blabla</title> + <remarks> + Hallo Welt. + </remarks> + </entry> + <entry><title>Blubabla</title> + <remarks> + Hello Blu + </remarks> + </entry> + <entry><title>Blubabla</title> + <remarks> + rem 2 + </remarks> </entry> - <entry><title>Blubabla</title> - <remarks> - Hello Blu - </remarks> - </entry> - <entry><title>Blubabla</title> - <remarks> - rem 2 - </remarks> - </entry> </reviews>; - println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( - for (t <- books \\ "title"; - r <- reviews \\ "entry" - if (r \ "title") xml_== t) yield - <result> - { t } - { r \ "remarks" } - </result> - )); - - // example - println( - for (t @ <book><title>Blabla</title></book> <- new NodeSeq { val theSeq = books.child }.toList) - yield t - ); -val phoneBook = - <phonebook> - <descr> - This is the <b>phonebook</b> of the - <a href="http://acme.org">ACME</a> corporation. - </descr> - <entry> - <name>John</name> - <phone where="work"> +41 21 693 68 67</phone> - <phone where="mobile">+41 79 602 23 23</phone> - </entry> + println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( + for (t <- books \\ "title"; + r <- reviews \\ "entry" + if (r \ "title") xml_== t) yield + <result> + { t } + { r \ "remarks" } + </result> + )); + + // example + println( + for (t @ <book><title>Blabla</title></book> <- new NodeSeq { val theSeq = books.child }.toList) + yield t + ); + val phoneBook = + <phonebook> + <descr> + This is the <b>phonebook</b> of the + <a href="http://acme.org">ACME</a> corporation. + </descr> + <entry> + <name>John</name> + <phone where="work"> +41 21 693 68 67</phone> + <phone where="mobile">+41 79 602 23 23</phone> + </entry> </phonebook>; -val addrBook = - <addrbook> - <descr> - This is the <b>addressbook</b> of the - <a href="http://acme.org">ACME</a> corporation. - </descr> - <entry> - <name>John</name> - <street> Elm Street</street> - <city>Dolphin City</city> - </entry> + val addrBook = + <addrbook> + <descr> + This is the <b>addressbook</b> of the + <a href="http://acme.org">ACME</a> corporation. + </descr> + <entry> + <name>John</name> + <street> Elm Street</street> + <city>Dolphin City</city> + </entry> </addrbook>; - println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( - for (t <- addrBook \\ "entry"; - r <- phoneBook \\ "entry" - if (t \ "name") xml_== (r \ "name")) yield - <result> - { t.child } - { r \ "phone" } - </result> - )); - - - /* namespaces */ - // begin tmp - println("namespaces") - val cuckoo = <cuckoo xmlns="http://cuckoo.com"> + println( new scala.xml.PrettyPrinter(80, 5).formatNodes ( + for (t <- addrBook \\ "entry"; + r <- phoneBook \\ "entry" + if (t \ "name") xml_== (r \ "name")) yield + <result> + { t.child } + { r \ "phone" } + </result> + )); + + + /* namespaces */ + // begin tmp + println("namespaces") + val cuckoo = <cuckoo xmlns="http://cuckoo.com"> <foo/> <bar/> - </cuckoo>; - assertEquals(cuckoo.namespace, "http://cuckoo.com") - for (n <- cuckoo \ "_" ) { - //println("n = "+n); - //println("n.prefix = "+n.prefix); - //.println("n.scope = "+n.scope); - assertEquals( n.namespace, "http://cuckoo.com") - } + </cuckoo>; + assert(cuckoo.namespace == "http://cuckoo.com") + for (n <- cuckoo \ "_" ) { + //println("n = "+n); + //println("n.prefix = "+n.prefix); + //.println("n.scope = "+n.scope); + assert( n.namespace == "http://cuckoo.com") + } - println("validation - elements") - val vtor = new scala.xml.dtd.ElementValidator(); - { - import scala.xml.dtd.ELEMENTS - import scala.xml.dtd.ContentModel._ - vtor.setContentModel( - ELEMENTS( - Sequ( - Letter(ElemName("bar")), - Star(Letter(ElemName("baz"))) ))); + println("validation - elements") + val vtor = new scala.xml.dtd.ElementValidator(); + { + import scala.xml.dtd.ELEMENTS + import scala.xml.dtd.ContentModel._ + vtor.setContentModel( + ELEMENTS( + Sequ( + Letter(ElemName("bar")), + Star(Letter(ElemName("baz"))) ))); - } - assertEquals(vtor( <foo><bar/><baz/><baz/></foo> ), true); - { - import scala.xml.dtd.MIXED - import scala.xml.dtd.ContentModel._ - - vtor.setContentModel( - MIXED( - Alt(Letter(ElemName("bar")), - Letter(ElemName("baz")), - Letter(ElemName("bal"))))); - } + } + assert(vtor( <foo><bar/><baz/><baz/></foo> )) - assertEquals(vtor(<foo><bar/><baz/><baz/></foo> ), true) - assertEquals(vtor(<foo>ab<bar/>cd<baz/>ed<baz/>gh</foo> ), true) - assertEquals(vtor(<foo> <ugha/> <bugha/> </foo> ), false) + { + import scala.xml.dtd.MIXED + import scala.xml.dtd.ContentModel._ + + vtor.setContentModel( + MIXED( + Alt(Letter(ElemName("bar")), + Letter(ElemName("baz")), + Letter(ElemName("bal"))))); + } - println("validation - attributes") - vtor.setContentModel(null) - vtor.setMetaData(List()) - assertEquals(vtor( <foo bar="hello"/> ), false) + assert(vtor(<foo><bar/><baz/><baz/></foo> )) + assert(vtor(<foo>ab<bar/>cd<baz/>ed<baz/>gh</foo> )) + assert(!vtor(<foo> <ugha/> <bugha/> </foo> )) - { - import scala.xml.dtd._ - vtor setMetaData List(AttrDecl("bar", "CDATA", IMPLIED)) - } - assertEquals(vtor(<foo href="http://foo.com" bar="hello"/>), false) - assertEquals(vtor(<foo bar="hello"/>), true) + println("validation - attributes") + vtor.setContentModel(null) + vtor.setMetaData(List()) + assert(!vtor( <foo bar="hello"/> )) - { - import scala.xml.dtd._ - vtor.setMetaData(List(AttrDecl("bar","CDATA",REQUIRED))) - } - assertEquals( vtor( <foo href="http://foo.com" /> ), false ) - assertEquals( vtor( <foo bar="http://foo.com" /> ), true ) + { + import scala.xml.dtd._ + vtor setMetaData List(AttrDecl("bar", "CDATA", IMPLIED)) + } + assert(!vtor(<foo href="http://foo.com" bar="hello"/>)) + assert(vtor(<foo bar="hello"/>)) + + { + import scala.xml.dtd._ + vtor.setMetaData(List(AttrDecl("bar","CDATA",REQUIRED))) + } + assert(!vtor( <foo href="http://foo.com" /> )) + assert( vtor( <foo bar="http://foo.com" /> )) } } |