summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/files/jvm/bigints.check9
-rw-r--r--test/files/jvm/bigints.scala49
-rw-r--r--test/files/jvm/stringbuilder.check17
-rw-r--r--test/files/jvm/stringbuilder.scala84
-rw-r--r--test/files/jvm/unittest_io_Jvm.check6
-rw-r--r--test/files/jvm/unittest_io_Jvm.scala31
-rw-r--r--test/files/jvm/unittest_xml.scala119
-rw-r--r--test/files/jvm/xml01.scala169
-rw-r--r--test/files/jvm/xml02.check0
-rw-r--r--test/files/jvm/xml02.scala62
-rw-r--r--test/files/jvm/xml03syntax.check9
-rw-r--r--test/files/jvm/xml03syntax.scala33
-rw-r--r--test/files/jvm/xml04embed.check3
-rw-r--r--test/files/jvm/xml04embed.scala13
-rw-r--r--test/files/jvm/xmlattr.check18
-rw-r--r--test/files/jvm/xmlattr.scala65
-rw-r--r--test/files/jvm/xmlstuff.scala292
-rw-r--r--test/files/neg/bug1183.check8
-rw-r--r--test/files/neg/bug1183.scala14
-rw-r--r--test/files/pos/patmat.scala163
-rw-r--r--test/files/run/lists-run.scala171
-rw-r--r--test/files/run/patmatnew.scala858
-rw-r--r--test/files/run/unapply.scala77
-rw-r--r--test/files/run/unittest_collection.scala123
-rw-r--r--test/files/run/unittest_io.scala41
25 files changed, 1141 insertions, 1293 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='&#x015e;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='&amp;'/>"),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&amp;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&amp;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&amp;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>&nbsp;</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="&amp;"></b>
+<b x="&amp;"></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="&amp;"/>.toString, "<b x=\"&amp;\"></b>")
- assertEquals( <b x={"&"}/>.toString, "<b x=\"&amp;\"></b>")
+ object AttributeOutputTest {
+ def apply() {
+ println(<b x="&amp;"/>)
+ 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; &lt;&lt;", 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" /> ))
}
}
diff --git a/test/files/neg/bug1183.check b/test/files/neg/bug1183.check
index ebbf8aca23..9e20592d08 100644
--- a/test/files/neg/bug1183.check
+++ b/test/files/neg/bug1183.check
@@ -1,16 +1,16 @@
-bug1183.scala:10: error: name clash: class Foo defines object Baz
+bug1183.scala:6: error: name clash: class Foo defines object Baz
and its companion object Foo also defines class Baz
object Baz
^
-bug1183.scala:11: error: name clash: class Foo defines class Bam
+bug1183.scala:7: error: name clash: class Foo defines class Bam
and its companion object Foo also defines object Bam
class Bam
^
-bug1183.scala:12: error: name clash: class Foo defines object Bar
+bug1183.scala:8: error: name clash: class Foo defines object Bar
and its companion object Foo also defines class Bar
object Bar
^
-bug1183.scala:13: error: name clash: class Foo defines class Bar
+bug1183.scala:9: error: name clash: class Foo defines class Bar
and its companion object Foo also defines class Bar
case class Bar(i:Int)
^
diff --git a/test/files/neg/bug1183.scala b/test/files/neg/bug1183.scala
index a845126488..23868ab401 100644
--- a/test/files/neg/bug1183.scala
+++ b/test/files/neg/bug1183.scala
@@ -1,10 +1,6 @@
-import scala.testing.SUnit._
+// bug 1183 from in the old tracker, not in Trac
-object Test extends TestConsoleMain {
-
- def suite = new TestSuite(
- new Test717
- )
+object Test {
class Foo(j:Int) {
object Baz
@@ -14,14 +10,14 @@ object Test extends TestConsoleMain {
}
- class Test717 extends TestCase("#717 test path of case classes") {
+ class Test717 {
val foo1 = new Foo(1)
- override def runTest() = {
+ def runTest() = {
val res = (foo1.Bar(2):Any) match {
case foo1.Bar(2) => true // (1)
}
- assertTrue("ok", res);
+ require(res)
}
}
diff --git a/test/files/pos/patmat.scala b/test/files/pos/patmat.scala
new file mode 100644
index 0000000000..8131a044fa
--- /dev/null
+++ b/test/files/pos/patmat.scala
@@ -0,0 +1,163 @@
+// these used to be in test/files/run/patmatnew.scala
+// the ticket numbers are from the old tracker, not Trac
+
+object ZipFun {
+ //just compilation
+ def zipFun[a, b](xs: List[a], ys: List[b]): List[Pair[a, b]] = (Pair(xs, ys): @unchecked) match {
+ // !!! case Pair(List(), _), Pair(_, List()) => List()
+ case (x :: xs1, y :: ys1) => (x, y) :: zipFun(xs1, ys1)
+ }
+}
+
+object Test1253 { // compile-only
+ def foo(t: (Int, String)) = t match {
+ case (1, "") => throw new Exception
+ case (r, _) => throw new Exception(r.toString)
+ }
+}
+
+object Foo1258 {
+ case object baz
+ def foo(bar: AnyRef) = {
+ val Baz = baz
+ bar match {
+ case Baz => ()
+ }
+ }
+}
+
+object Bug1261 {
+ sealed trait Elem
+ case class Foo() extends Elem
+ case class Bar() extends Elem
+ trait Row extends Elem
+ object Row {
+ def unapply(r: Row) = true
+
+ def f(elem: Elem) {
+ elem match {
+ case Bar() => ;
+ case Row() => ;
+ case Foo() => ; // used to give ERROR (unreachable code)
+ }
+ }
+ }
+}
+
+sealed abstract class Tree
+case class Node(l: Tree, v: Int, r: Tree) extends Tree
+case object EmptyTree extends Tree
+
+object Ticket335 { // compile-only
+ def runTest() {
+ (EmptyTree: Tree @unchecked) match {
+ case Node(_, v, _) if (v == 0) => 0
+ case EmptyTree => 2
+ }
+ }
+}
+
+object TestIfOpt { //compile-only "test EqualsPatternClass in combination with MixTypes opt, bug #1278"
+ trait Token {
+ val offset: Int
+ def matching: Option[Token]
+ }
+ def go(tok: Token) = (tok.matching: @unchecked) match {
+ case Some(other) if true => Some(other)
+ case _ if true => tok.matching match {
+ case Some(other) => Some(other)
+ case _ => None
+ }
+ }
+}
+
+object Go { // bug #1277 compile-only
+ trait Core { def next: Position = null }
+ trait Dir
+ val NEXT = new Dir {}
+
+ trait Position extends Core
+
+ (null: Core, null: Dir) match {
+ case (_, NEXT) if true => false // no matter whether NEXT test succeed, cannot throw column because of guard
+ case (at2: Position, dir) => true
+ }
+}
+
+trait Outer { // bug #1282 compile-only
+ object No
+ trait File {
+ (null: AnyRef) match {
+ case No => false
+ }
+ }
+}
+
+class Test806_818 { // #806, #811 compile only -- type of bind
+ // bug811
+ trait Core {
+ trait NodeImpl
+ trait OtherImpl extends NodeImpl
+ trait DoubleQuoteImpl extends NodeImpl
+ def asDQ(node: OtherImpl) = node match {
+ case dq: DoubleQuoteImpl => dq
+ }
+ }
+
+ trait IfElseMatcher {
+ type Node <: NodeImpl
+ trait NodeImpl
+ trait IfImpl
+ private def coerceIf(node: Node) = node match {
+ case node: IfImpl => node // var node is of type Node with IfImpl!
+ case _ => null
+ }
+ }
+}
+
+object Ticket495bis {
+ def signum(x: Int): Int =
+ x match {
+ case 0 => 0
+ case _ if x < 0 => -1
+ case _ if x > 0 => 1
+ }
+ def pair_m(x: Int, y: Int) =
+ (x, y) match {
+ case (_, 0) => 0
+ case (-1, _) => -1
+ case (_, _) => 1
+ }
+}
+
+object Ticket522 {
+ class Term[X]
+ object App {
+ // i'm hidden
+ case class InternalApply[Y, Z](fun: Y => Z, arg: Y) extends Term[Z]
+
+ def apply[Y, Z](fun: Y => Z, arg: Y): Term[Z] =
+ new InternalApply[Y, Z](fun, arg)
+
+ def unapply[X](arg: Term[X]): Option[(Y => Z, Y)] forSome { type Y; type Z } =
+ arg match {
+ case i: InternalApply[y, z] => Some(i.fun, i.arg)
+ case _ => None
+ }
+ }
+
+ App({ x: Int => x }, 5) match {
+ case App(arg, a) =>
+ }
+}
+
+object Ticket710 {
+ def method {
+ sealed class Parent()
+ case object Child extends Parent()
+ val x: Parent = Child
+ x match {
+ case Child => ()
+ }
+ }
+}
diff --git a/test/files/run/lists-run.scala b/test/files/run/lists-run.scala
index 6871a96183..9e9e49e818 100644
--- a/test/files/run/lists-run.scala
+++ b/test/files/run/lists-run.scala
@@ -1,99 +1,84 @@
-//############################################################################
-// Lists
-//############################################################################
-
-//############################################################################
-
-import testing.SUnit._
-
/** Test the Scala implementation of class <code>scala.List</code>.
*
* @author Stephane Micheloud
*/
-object Test extends TestConsoleMain {
- def suite = new TestSuite(
- Test_multiset, // multiset operations: union, intersect, diff
- Test1, //count, exists, filter, ..
- Test2, //#468
- Test3, //#1691
- Test4, //#1721
- Test5
- )
+object Test {
+ def main(args: Array[String]) {
+ Test_multiset.run() // multiset operations: union, intersect, diff
+ Test1.run() //count, exists, filter, ..
+ Test2.run() //#468
+ Test3.run() //#1691
+ Test4.run() //#1721
+ Test5.run()
+ }
}
-object Test_multiset extends TestCase("multiset") with Assert {
- override def enableStackTrace = false
- override def runTest {
+object Test_multiset {
+ def run() {
def isSubListOf[A](thiz: List[A], that: List[A]): Boolean =
thiz forall (that contains _)
val xs = List(1, 1, 2)
val ys = List(1, 2, 2, 3)
- assertEquals("xs_union_ys", List(1, 1, 2, 1, 2, 2, 3), xs union ys)
- assertEquals("ys_union_xs", List(1, 2, 2, 3, 1, 1, 2), ys union xs)
- assertEquals("xs_intersect_ys", List(1, 2), xs intersect ys)
- assertEquals("ys_intersect_xs", List(1, 2), ys intersect xs)
- assertEquals("xs_diff_ys", List(1), xs diff ys)
- assertEquals("ys_diff_xs", List(2, 3), ys diff xs)
- assertTrue("xs_subset_ys", isSubListOf(xs -- ys, xs diff ys))
+ assert(List(1, 1, 2, 1, 2, 2, 3) == (xs union ys), "xs_union_ys")
+ assert(List(1, 2, 2, 3, 1, 1, 2) == (ys union xs), "ys_union_xs")
+ assert(List(1, 2) == (xs intersect ys), "xs_intersect_ys")
+ assert(List(1, 2) == (ys intersect xs), "ys_intersect_xs")
+ assert(List(1) == (xs diff ys), "xs_diff_ys")
+ assert(List(2, 3) == (ys diff xs), "ys_diff_xs")
+ assert(isSubListOf(xs -- ys, xs diff ys), "xs_subset_ys")
val zs = List(0, 1, 1, 2, 2, 2)
- assertEquals("zs_union_ys", List(0, 1, 1, 2, 2, 2, 1, 2, 2, 3), zs union ys)
- assertEquals("ys_union_zs", List(1, 2, 2, 3, 0, 1, 1, 2, 2, 2), ys union zs)
- assertEquals("zs_intersect_ys", List(1, 2, 2), zs intersect ys)
- assertEquals("ys_intersect_zs", List(1, 2, 2), ys intersect zs)
- assertEquals("zs_diff_ys", List(0, 1, 2), zs diff ys)
- assertEquals("ys_diff_zs", List(3), ys diff zs)
- assertTrue("xs_subset_ys", isSubListOf(zs -- ys, zs diff ys))
+ assert(List(0, 1, 1, 2, 2, 2, 1, 2, 2, 3) == (zs union ys), "zs_union_ys")
+ assert(List(1, 2, 2, 3, 0, 1, 1, 2, 2, 2) == (ys union zs), "ys_union_zs")
+ assert(List(1, 2, 2) == (zs intersect ys), "zs_intersect_ys")
+ assert(List(1, 2, 2) == (ys intersect zs), "ys_intersect_zs")
+ assert(List(0, 1, 2) == (zs diff ys), "zs_diff_ys")
+ assert(List(3) == (ys diff zs), "ys_diff_zs")
+ assert(isSubListOf(zs -- ys, zs diff ys), "xs_subset_ys")
val ws = List(2)
- assertEquals("ws_union_ys", List(2, 1, 2, 2, 3), ws union ys)
- assertEquals("ys_union_ws", List(1, 2, 2, 3, 2), ys union ws)
- assertEquals("ws_intersect_ys", List(2), ws intersect ys)
- assertEquals("ys_intersect_ws", List(2), ys intersect ws)
- assertEquals("ws_diff_ys", List(), ws diff ys)
- assertEquals("ys_diff_ws", List(1, 2, 3), ys diff ws)
- assertTrue("ws_subset_ys", isSubListOf(ws -- ys, ws diff ys))
+ assert(List(2, 1, 2, 2, 3) == (ws union ys), "ws_union_ys")
+ assert(List(1, 2, 2, 3, 2) == (ys union ws), "ys_union_ws")
+ assert(List(2) == (ws intersect ys), "ws_intersect_ys")
+ assert(List(2) == (ys intersect ws), "ys_intersect_ws")
+ assert(List() == (ws diff ys), "ws_diff_ys")
+ assert(List(1, 2, 3) == (ys diff ws), "ys_diff_ws")
+ assert(isSubListOf(ws -- ys, ws diff ys), "ws_subset_ys")
val vs = List(3, 2, 2, 1)
- assertEquals("xs_union_vs", List(1, 1, 2, 3, 2, 2, 1), xs union vs)
- assertEquals("vs_union_xs", List(3, 2, 2, 1, 1, 1, 2), vs union xs)
- assertEquals("xs_intersect_vs", List(1, 2), xs intersect vs)
- assertEquals("vs_intersect_xs", List(2, 1), vs intersect xs)
- assertEquals("xs_diff_vs", List(1), xs diff vs)
- assertEquals("vs_diff_xs", List(3, 2), vs diff xs)
- assertTrue("xs_subset_vs", isSubListOf(xs -- vs, xs diff vs))
+ assert(List(1, 1, 2, 3, 2, 2, 1) == (xs union vs), "xs_union_vs")
+ assert(List(3, 2, 2, 1, 1, 1, 2) == (vs union xs), "vs_union_xs")
+ assert(List(1, 2) == (xs intersect vs), "xs_intersect_vs")
+ assert(List(2, 1) == (vs intersect xs), "vs_intersect_xs")
+ assert(List(1) == (xs diff vs), "xs_diff_vs")
+ assert(List(3, 2) == (vs diff xs), "vs_diff_xs")
+ assert(isSubListOf(xs -- vs, xs diff vs), "xs_subset_vs")
// tests adapted from Thomas Jung
- assertTrue(
- "be symmetric after sorting", {
+ assert({
def sort(zs: List[Int]) = zs sort ( _ > _ )
sort(xs intersect ys) == sort(ys intersect xs)
- })
- assertTrue(
- "obey min cardinality", {
+ }, "be symmetric after sorting")
+ assert({
def cardinality[A](zs: List[A], e: A): Int = zs count (e == _)
val intersection = xs intersect ys
xs forall (e => cardinality(intersection, e) == (cardinality(xs, e)
min cardinality(ys, e)))
- })
- assertTrue(
- "maintain order", {
+ }, "obey min cardinality")
+ assert({
val intersection = xs intersect ys
val unconsumed = xs.foldLeft(intersection){(rest, e) =>
if (! rest.isEmpty && e == rest.head) rest.tail else rest
}
unconsumed.isEmpty
- })
- assertTrue(
- "has the list as again intersection",
- xs == (xs intersect xs)
- )
+ }, "maintain order")
+ assert(xs == (xs intersect xs),
+ "has the list as again intersection")
}
}
-object Test1 extends TestCase("ctor") with Assert {
- override def enableStackTrace = false
- override def runTest {
+object Test1 {
+ def run() {
val xs1 = List(1, 2, 3)
val xs2 = List('a', 'b')
val xs3 = List(List(1, 2), List(4, 5))
@@ -103,100 +88,96 @@ object Test1 extends TestCase("ctor") with Assert {
{
val n1 = xs1 count { e => e % 2 != 0 }
val n2 = xs4 count { e => e < 5 }
- assertEquals("check_count", 4, n1 + n2)
+ assert(4 == (n1 + n2), "check_count")
}
{
val b1 = xs1 exists { e => e % 2 == 0 }
val b2 = xs4 exists { e => e == 5 }
- assertEquals("check_exists", false , b1 & b2)
+ assert(!(b1 & b2), "check_exists")
}
{
val ys1 = xs1 filter { e => e % 2 == 0 }
val ys2 = xs4 filter { e => e < 5 }
- assertEquals("check_filter", 3, ys1.length + ys2.length)
+ assert(3 == ys1.length + ys2.length, "check_filter")
}
{
val n1 = xs1.foldLeft(0)((e1, e2) => e1 + e2)
val ys1 = xs4.foldLeft(List[Int]())((e1, e2) => e2 :: e1)
- assertEquals("check_foldLeft", 10, n1 + ys1.length)
+ assert(10 == n1 + ys1.length, "check_foldLeft")
}
{
val b1 = xs1 forall { e => e < 10}
val b2 = xs4 forall { e => e % 2 == 0 }
- assertEquals("check_forall", true, b1 & b2)
+ assert(b1 & b2, "check_forall")
}
{
val ys1 = xs1 filterNot { e => e % 2 != 0 }
val ys2 = xs4 filterNot { e => e < 5 }
- assertEquals("check_remove", 3, ys1.length + ys2.length)
+ assert(3 == ys1.length + ys2.length, "check_remove")
}
{
val ys1 = xs1 zip xs2
val ys2 = xs1 zip xs3
- assertEquals("check_zip", 4, ys1.length + ys2.length)
+ assert(4 == ys1.length + ys2.length, "check_zip")
}
{
val ys1 = xs1.zipAll(xs2, 0, '_')
val ys2 = xs2.zipAll(xs1, '_', 0)
val ys3 = xs1.zipAll(xs3, 0, List(-1))
- assertEquals("check_zipAll", 9, ys1.length + ys2.length + ys3.length)
+ assert(9 == ys1.length + ys2.length + ys3.length, "check_zipAll")
}
}
}
-object Test2 extends TestCase("t0468") with Assert {
- override def enableStackTrace = false
- override def runTest {
+object Test2 {
+ def run() {
val xs1 = List(1, 2, 3)
val xs2 = List(0)
val ys1 = xs1 ::: List(4)
- assertEquals("check_:::", List(1, 2, 3, 4), ys1)
+ assert(List(1, 2, 3, 4) == ys1, "check_:::")
val ys2 = ys1 - 4
- assertEquals("check_-", xs1, ys2)
+ assert(xs1 == ys2, "check_-")
val n2 = (xs1 ++ ys1).length
val n3 = (xs1 ++ Nil).length
val n4 = (xs1 ++ ((new collection.mutable.ArrayBuffer[Int]) + 0)).length
- assertEquals("check_++", 14, n2 + n3 + n4)
+ assert(14 == n2 + n3 + n4, "check_++")
}
}
-object Test3 extends TestCase("t1691") with Assert {
- override def enableStackTrace = false
- override def runTest {
+object Test3 {
+ def run() {
try {
List.range(1, 10, 0)
} catch {
case e: IllegalArgumentException => ()
case _ => throw new Error("List.range(1, 10, 0)")
}
- assertEquals(List.range(10, 0, -2),
- List(10, 8, 6, 4, 2))
+ assert(List.range(10, 0, -2) == List(10, 8, 6, 4, 2))
}
}
-object Test4 extends TestCase("t1721") with Assert {
- override def enableStackTrace = false
- override def runTest {
- assertTrue(List(1,2,3).endsWith(List(2,3)))
- assertFalse(List(1,2,3).endsWith(List(1,3)))
- assertTrue(List(1,2,3).endsWith(List()))
- assertFalse(List(1,2,3).endsWith(List(0,1,2,3)))
- assertTrue(List(1,2,3).endsWith(List(1,2,3)))
- assertFalse(List().endsWith(List(1,2,3)))
- assertTrue(List().endsWith(List()))
+object Test4 {
+ def run() {
+ assert(List(1,2,3).endsWith(List(2,3)))
+ assert(!List(1,2,3).endsWith(List(1,3)))
+ assert(List(1,2,3).endsWith(List()))
+ assert(!List(1,2,3).endsWith(List(0,1,2,3)))
+ assert(List(1,2,3).endsWith(List(1,2,3)))
+ assert(!List().endsWith(List(1,2,3)))
+ assert(List().endsWith(List()))
}
}
-object Test5 extends TestCase("list pattern matching") {
+object Test5 {
def show(xs: List[String]) = xs match {
case "foo" :: args => args.toString
case List(x) => x.toString
case Nil => "Nil"
}
- override def runTest {
+ def run() {
assert(show(List()) == "Nil")
assert(show(List("a")) == "a")
assert(show(List("foo", "b")) == "List(b)")
diff --git a/test/files/run/patmatnew.scala b/test/files/run/patmatnew.scala
index 025d6bf2ef..9e91a48258 100644
--- a/test/files/run/patmatnew.scala
+++ b/test/files/run/patmatnew.scala
@@ -1,102 +1,81 @@
-trait Treez { self: Shmeez =>
- abstract class Tree
- case class Beez(i:Int) extends Tree
- case object HagbardCeline extends Tree
-}
-
-trait Shmeez extends AnyRef with Treez {
- val tree: Tree
-
- def foo = tree match {
- case Beez(2) => 1
- case HagbardCeline => 0
- }
-}
-
-import scala.testing.SUnit._
-
-object Test extends TestConsoleMain {
-
- //just compilation
- def zipFun[a,b](xs:List[a], ys:List[b]):List[Pair[a,b]] = (Pair(xs,ys): @unchecked) match {
- // !!! case Pair(List(), _), Pair(_, List()) => List()
- case (x :: xs1, y :: ys1) => (x, y) :: zipFun(xs1, ys1)
- }
-
- def suite = new TestSuite(
- new TestSimpleIntSwitch,
- new SimpleUnapply,
- SeqUnapply,
- applyFromJcl,
- new Test717,
- TestGuards,
- TestEqualsPatternOpt,
- TestSequence01,
- TestSequence02,
- TestSequence03,
- TestSequence04,
- TestSequence05,
- TestSequence06,
- TestSequence07,
- TestSequence08,
- TestStream,
- new Test903,
- new Test1163_Order,
- new TestUnbox,
- Bug457,
- Bug508,
- Bug789,
- Bug995,
- Bug1093,
- Bug1094,
- ClassDefInGuard,
- Ticket2,
- Ticket11,
- Ticket37,
- Ticket44,
- Ticket346
- )
-
- class Foo(j:Int) {
- case class Bar(i:Int)
- }
- class SimpleUnapply extends TestCase("simpleUnapply") {
- override def runTest() { // from sortedmap, old version
+object Test {
+
+ def main(args: Array[String]) {
+ ApplyFromJcl.run()
+ Bug1093.run()
+ Bug1094.run()
+ Bug1270.run()
+ Bug1281.run()
+ Bug457.run()
+ Bug508.run()
+ Bug789.run()
+ Bug881.run()
+ Bug995.run()
+ ClassDefInGuard.run()
+ SeqUnapply.run()
+ SimpleUnapply.run()
+ Test1163_Order.run()
+ Test717.run()
+ Test903.run()
+ TestEqualsPatternOpt.run()
+ TestGuards.run()
+ TestSequence01.run()
+ TestSequence02.run()
+ TestSequence03.run()
+ TestSequence04.run()
+ TestSequence05.run()
+ TestSequence06.run()
+ TestSequence07.run()
+ TestSequence08.run()
+ TestSimpleIntSwitch.run()
+ TestStream.run()
+ TestUnbox.run()
+ Ticket11.run()
+ Ticket2.run()
+ Ticket346.run()
+ Ticket37.run()
+ Ticket44.run()
+ }
+
+ def assertEquals(a: Any, b: Any) { assert(a == b) }
+ def assertEquals(msg: String, a: Any, b: Any) { assert(a == b, msg) }
+
+ object SimpleUnapply {
+ def run() { // from sortedmap, old version
List((1, 2)).head match {
- case kv @ Pair(key, _) => kv.toString + " " + key.toString
+ case kv@Pair(key, _) => kv.toString + " " + key.toString
}
-
}
}
- object SeqUnapply extends TestCase("seqUnapply") {
+ object SeqUnapply {
case class SFB(i: Int, xs: List[Int])
- override def runTest() {
- List(1,2) match {
+ def run() {
+ List(1, 2) match {
case List(1) => assert(false, "wrong case")
- case List(1,2,xs @ _*) => assert(xs.isEmpty, "not empty")
+ case List(1, 2, xs@_*) => assert(xs.isEmpty, "not empty")
case Nil => assert(false, "wrong case")
}
- SFB(1,List(1)) match {
+ SFB(1, List(1)) match {
case SFB(_, List(x)) => assert(x == 1)
case SFB(_, _) => assert(false)
}
}
}
- object applyFromJcl extends TestCase("applyFromJcl") {
- override def runTest {
- val p = (1,2)
- Some(2) match {
- case Some(p._2) =>
- case _ => assert(false)
- }
+ object ApplyFromJcl {
+ def run() {
+ val p = (1, 2)
+ Some(2) match {
+ case Some(p._2) =>
+ case _ => assert(false)
+ }
}
}
- class TestSimpleIntSwitch extends TestCase("SimpleIntSwitch") {
- override def runTest() = {
+ object TestSimpleIntSwitch {
+ def run() {
assertEquals("s1", 1, 1 match {
case 3 => 3
case 2 => 2
@@ -107,12 +86,12 @@ object Test extends TestConsoleMain {
case 1 => 1
case _ => 0
})
- assertEquals("s2boxed", 1, (1:Any) match {
+ assertEquals("s2boxed", 1, (1: Any) match {
case 1 => 1
case _ => 0
})
assertEquals("s3", 1, ("hello") match {
- case s:String => 1
+ case s: String => 1
//case _ => 0 // unreachable!
})
val xyz: (Int, String, Boolean) = (1, "abc", true);
@@ -122,69 +101,93 @@ object Test extends TestConsoleMain {
})
}
}
- class Test717 extends TestCase("#717 test path of case classes") {
+
+ // #717 test path of case classes
+ object Test717 {
+ class Foo(j: Int) {
+ case class Bar(i: Int)
+ }
val foo1 = new Foo(1)
val foo2 = new Foo(2)
-
- override def runTest() = {
- val res = (foo1.Bar(2):Any) match {
- case foo2.Bar(2) => false
- case foo1.Bar(2) => true
+ def run() {
+ val res = (foo1.Bar(2): Any) match {
+ case foo2.Bar(2) => false
+ case foo1.Bar(2) => true
}
- assertTrue("ok", res);
+ assert(res)
}
}
- object TestGuards extends TestCase("multiple guards for same pattern") with Shmeez {
- val tree:Tree = Beez(2)
- override def runTest = {
+ ///
+
+ trait Treez { self: Shmeez =>
+ abstract class Tree
+ case class Beez(i: Int) extends Tree
+ case object HagbardCeline extends Tree
+ }
+
+ trait Shmeez extends AnyRef with Treez {
+ val tree: Tree
+
+ def foo = tree match {
+ case Beez(2) => 1
+ case HagbardCeline => 0
+ }
+ }
+
+ // multiple guards for same pattern
+ object TestGuards extends Shmeez {
+ val tree: Tree = Beez(2)
+ def run() {
val res = tree match {
case Beez(x) if x == 3 => false
case Beez(x) if x == 2 => true
}
- assertTrue("ok", res);
- val ret = (Beez(3):Tree) match {
+ assert(res)
+ val ret = (Beez(3): Tree) match {
case Beez(x) if x == 3 => true
case Beez(x) if x == 2 => false
}
- assertTrue("ok", ret);
+ assert(ret)
}
}
- object TestEqualsPatternOpt extends TestCase("test EqualsPatternClass in combination with MixTypes opt, bug #1276") {
+ // test EqualsPatternClass in combination with MixTypes opt, bug #1276
+ object TestEqualsPatternOpt {
val NoContext = new Object
- override def runTest {
- assertEquals(1,((NoContext:Any) match {
- case that : AnyRef if this eq that => 0
+ def run() {
+ assertEquals(1, ((NoContext: Any) match {
+ case that: AnyRef if this eq that => 0
case NoContext => 1
case _ => 2
}))
}
}
- object TestSequence01 extends TestCase("uno (all ignoring patterns on List)") {
+ // all ignoring patterns on List
+ object TestSequence01 {
def doMatch(xs: List[String]): String = xs match {
case List(_*) => "ok"
}
def doMatch2(xs: List[String]): List[String] = xs match {
- case List(_, rest @ _*) => rest.toList
+ case List(_, rest@_*) => rest.toList
}
- override def runTest() {
+ def run() {
val list1 = List()
assertEquals(doMatch(list1), "ok")
- val list2 = List("1","2","3")
+ val list2 = List("1", "2", "3")
assertEquals(doMatch(list2), "ok")
- val list3 = List("1","2","3")
- assertEquals(doMatch2(list3), List("2","3"))
+ val list3 = List("1", "2", "3")
+ assertEquals(doMatch2(list3), List("2", "3"))
}
}
-
- object TestSequence02 extends TestCase("due (all ignoring patterns on Seq)") {
+ // all ignoring patterns on Seq
+ object TestSequence02 {
def doMatch(l: Seq[String]): String = l match {
case Seq(_*) => "ok"
}
- override def runTest() {
+ def run() {
val list1 = List()
assertEquals(doMatch(list1), "ok")
val list2 = List("1", "2", "3")
@@ -196,112 +199,104 @@ object Test extends TestConsoleMain {
}
}
- object TestSequence03 extends TestCase("tre (right-ignoring patterns on List, defaults)") {
+ // right-ignoring patterns on List, defaults
+ object TestSequence03 {
def doMatch(xs: List[String]): String = xs match {
- case List(_,_,_,_*) => "ok"
+ case List(_, _, _, _*) => "ok"
case _ => "not ok"
}
- override def runTest() {
+ def run() {
val list1 = List()
assertEquals(doMatch(list1), "not ok")
- val list2 = List("1","2","3")
+ val list2 = List("1", "2", "3")
assertEquals(doMatch(list2), "ok")
- val list3 = List("1","2","3","4")
+ val list3 = List("1", "2", "3", "4")
assertEquals(doMatch(list3), "ok")
}
}
-
- object TestSequence04 extends TestCase("quattro (all- and right-ignoring pattern on case class w/ seq param)") {
+ // all- and right-ignoring pattern on case class w/ seq param
+ object TestSequence04 {
case class Foo(i: Int, chars: Char*)
- override def runTest() = {
+ def run() {
val a = Foo(0, 'a') match {
- case Foo(i, c, chars @ _*) => c
+ case Foo(i, c, chars@_*) => c
case _ => null
}
assertEquals(a, 'a')
val b = Foo(0, 'a') match {
- case Foo(i, chars @ _*) => 'b'
+ case Foo(i, chars@_*) => 'b'
case _ => null
}
assertEquals(b, 'b')
}
}
- object TestSequence05 extends TestCase("cinque (sealed case class with ignoring seq patterns)") {
+ // sealed case class with ignoring seq patterns
+ object TestSequence05 {
sealed abstract class Con;
case class Foo() extends Con
- case class Bar(xs:Con*) extends Con
+ case class Bar(xs: Con*) extends Con
- override def runTest() {
- val res = (Bar(Foo()):Con) match {
+ def run() {
+ val res = (Bar(Foo()): Con) match {
case Bar(xs@_*) => xs // this should be optimized away to a pattern Bar(xs)
case _ => Nil
}
- assertEquals("res instance"+res.isInstanceOf[Seq[Con] forSome { type Con }]+" res(0)="+res(0), true, res.isInstanceOf[Seq[Foo] forSome { type Foo}] && res(0) == Foo() )
+ assertEquals("res instance" + res.isInstanceOf[Seq[Con] forSome { type Con }] + " res(0)=" + res(0), true, res.isInstanceOf[Seq[Foo] forSome { type Foo }] && res(0) == Foo())
}
}
- object TestSequence06 extends TestCase("sei (not regular) fancy guards / bug#644 ") {
+ // (not regular) fancy guards / bug#644
+ object TestSequence06 {
case class A(i: Any)
def doMatch(x: Any, bla: Int) = x match {
- case x:A if (bla==1) => 0
+ case x: A if (bla == 1) => 0
case A(1) => 1
case A(A(1)) => 2
}
- override def runTest() {
- assertEquals(doMatch(A(null),1), 0)
- assertEquals(doMatch(A(1),2), 1)
- assertEquals(doMatch(A(A(1)),2), 2)
+ def run() {
+ assertEquals(doMatch(A(null), 1), 0)
+ assertEquals(doMatch(A(1), 2), 1)
+ assertEquals(doMatch(A(A(1)), 2), 2)
}
}
- object TestSequence07 extends TestCase("sette List of chars") {
+ // List of chars
+ object TestSequence07 {
def doMatch1(xs: List[Char]) = xs match {
- case List(x, y, _*) => x::y::Nil
+ case List(x, y, _*) => x :: y :: Nil
}
def doMatch2(xs: List[Char]) = xs match {
- case List(x, y, z, w) => List(z,w)
- }
- //def doMatch3(xs:List[char]) = xs match {
- // case List(_*, z, w) => w::Nil
- //}
- //
- // Since the second case should have been unreachable all along,
- // let's just comment this one out.
- //
- // def doMatch4(xs:Seq[Char]) = xs match {
- // case Seq(x, y, _*) => x::y::Nil
- // case Seq(x, y, z, w) => List(z,w) // redundant!
- // }
- def doMatch5(xs:Seq[Char]) = xs match {
- case Seq(x, y, 'c', w @ _*) => x::y::Nil
- case Seq(x, y, z @ _*) => z
- }
- def doMatch6(xs:Seq[Char]) = xs match {
- case Seq(x, 'b') => x::'b'::Nil
- case Seq(x, y, z @ _*) => z.toList
- }
-
- override def runTest() {
- assertEquals(List('a','b'), doMatch1(List('a','b','c','d')))
- assertEquals(List('c','d'), doMatch2(List('a','b','c','d')))
- // assertEquals(doMatch3(List('a','b','c','d')), List('d'))
- // assertEquals(List('a','b'), doMatch4(List('a','b','c','d')))
- assertEquals(List('a','b'), doMatch5(List('a','b','c','d')))
- assertEquals(List('c','d'), doMatch6(List('a','b','c','d')))
- }
- }
-
- object TestSequence08 extends TestCase("backquoted identifiers in pattern") {
- override def runTest() {
+ case List(x, y, z, w) => List(z, w)
+ }
+ def doMatch3(xs: Seq[Char]) = xs match {
+ case Seq(x, y, 'c', w@_*) => x :: y :: Nil
+ case Seq(x, y, z@_*) => z
+ }
+ def doMatch4(xs: Seq[Char]) = xs match {
+ case Seq(x, 'b') => x :: 'b' :: Nil
+ case Seq(x, y, z@_*) => z.toList
+ }
+
+ def run() {
+ assertEquals(List('a', 'b'), doMatch1(List('a', 'b', 'c', 'd')))
+ assertEquals(List('c', 'd'), doMatch2(List('a', 'b', 'c', 'd')))
+ assertEquals(List('a', 'b'), doMatch3(List('a', 'b', 'c', 'd')))
+ assertEquals(List('c', 'd'), doMatch4(List('a', 'b', 'c', 'd')))
+ }
+ }
+
+ // backquoted identifiers in pattern
+ object TestSequence08 {
+ def run() {
val xs = List(2, 3)
val ys = List(1, 2, 3) match {
case x :: `xs` => xs
@@ -311,20 +306,21 @@ object Test extends TestConsoleMain {
}
}
-
- object TestStream extends TestCase("unapply for Streams") {
+ // unapply for Streams
+ object TestStream {
def sum(stream: Stream[Int]): Int =
stream match {
case Stream.Empty => 0
case Stream.cons(hd, tl) => hd + sum(tl)
}
- val str: Stream[Int] = List(1,2,3).iterator.toStream
+ val str: Stream[Int] = List(1, 2, 3).iterator.toStream
- def runTest() = assertEquals(sum(str), 6)
+ def run() { assertEquals(sum(str), 6) }
}
- class Test1163_Order extends TestCase("bug#1163 order of temps must be preserved") {
+ // bug#1163 order of temps must be preserved
+ object Test1163_Order {
abstract class Function
case class Var(n: String) extends Function
case class Const(v: Double) extends Function
@@ -342,11 +338,11 @@ object Test extends TestConsoleMain {
case n :: ls => flips((l take n reverse) ::: (l drop n)) + 1
}
- def runTest() = assertEquals("both", (Var("x"),Var("y")), f)
+ def run() { assertEquals("both", (Var("x"), Var("y")), f) }
}
- class TestUnbox extends TestCase("unbox") {
- override def runTest() {
+ object TestUnbox {
+ def run() {
val xyz: (Int, String, Boolean) = (1, "abc", true)
xyz._1 match {
case 1 => "OK"
@@ -356,82 +352,41 @@ object Test extends TestConsoleMain {
}
}
- class Test806_818 { // #806, #811 compile only -- type of bind
- // bug811
- trait Core {
- trait NodeImpl
- trait OtherImpl extends NodeImpl
- trait DoubleQuoteImpl extends NodeImpl
- def asDQ(node : OtherImpl) = node match {
- case dq : DoubleQuoteImpl => dq
- }
+ object Test903 {
+ class Person(_name: String, _father: Person) {
+ def name = _name
+ def father = _father
}
- trait IfElseMatcher {
- type Node <: NodeImpl
- trait NodeImpl
- trait IfImpl
- private def coerceIf(node: Node) = node match {
- case node : IfImpl => node // var node is of type Node with IfImpl!
- case _ => null
- }
+ object PersonFather {
+ def unapply(p: Person): Option[Person] =
+ if (p.father == null)
+ None
+ else
+ Some(p.father)
+ }
+ def run() {
+ val p1 = new Person("p1", null)
+ val p2 = new Person("p2", p1)
+ assertEquals((p2.name, p1.name), p2 match {
+ case aPerson@PersonFather(f) => (aPerson.name, f.name)
+ case _ => "No father"
+ })
}
}
+ object Bug881 {
+ object Foo1 {
+ class Bar1(val x: String)
+ def p(b: Bar1) = b.x
- class Person(_name : String, _father : Person) {
- def name = _name
- def father = _father
- }
-
- object PersonFather {
- def unapply(p : Person) : Option[Person] =
- if (p.father == null)
- None
- else
- Some(p.father)
- }
-
- class Test903 extends TestCase("bug903") {
-
- override def runTest = {
- val p1 = new Person("p1",null)
- val p2 = new Person("p2",p1)
- assertEquals((p2.name, p1.name), p2 match {
- case aPerson@PersonFather(f) => (aPerson.name,f.name)
- case _ => "No father"
- })
- }
- }
-
-
- object Test1253 { // compile-only
- def foo(t : (Int, String)) = t match {
- case (1, "") => throw new Exception
- case (r, _) => throw new Exception(r.toString)
+ def unapply(s: String): Option[Bar1] =
+ Some(new Bar1(s))
}
- }
-
- object Foo1258 {
- case object baz
- def foo(bar : AnyRef) = {
- val Baz = baz
- bar match {
- case Baz => ()
- }
+ class Foo(j: Int) {
+ case class Bar(i: Int)
}
- }
-
- object Foo1 {
- class Bar1(val x : String)
- def p(b : Bar1) = Console.println(b.x)
-
- def unapply(s : String) : Option[Bar1] =
- Some(new Bar1(s))
- }
-
- object bug881 extends TestCase("881") {
- override def runTest = {
+ def run() {
"baz" match {
case Foo1(x) =>
Foo1.p(x)
@@ -439,32 +394,31 @@ object Test extends TestConsoleMain {
}
}
-
// these are exhaustive matches
// should not generate any warnings
- def f[A](z:(Option[A],Option[A])) = z match {
- case Pair(None,Some(x)) => 1
- case Pair(Some(x),None ) => 2
- case Pair(Some(x),Some(y)) => 3
+ def f[A](z: (Option[A], Option[A])) = z match {
+ case Pair(None, Some(x)) => 1
+ case Pair(Some(x), None) => 2
+ case Pair(Some(x), Some(y)) => 3
case _ => 4
}
- def g1[A](z:Option[List[A]]) = z match {
+ def g1[A](z: Option[List[A]]) = z match {
case Some(Nil) => true
- case Some(x::Nil) => true
+ case Some(x :: Nil) => true
case _ => true
}
- def g2[A](z:Option[List[A]]) = z match {
- case Some(x::Nil) => true
+ def g2[A](z: Option[List[A]]) = z match {
+ case Some(x :: Nil) => true
case Some(_) => false
case _ => true
}
- def h[A](x: (Option[A],Option[A])) = x match {
- case Pair(None,_:Some[_]) => 1
- case Pair(_:Some[_],None ) => 2
- case Pair(_:Some[_],_:Some[_]) => 3
+ def h[A](x: (Option[A], Option[A])) = x match {
+ case Pair(None, _: Some[_]) => 1
+ case Pair(_: Some[_], None) => 2
+ case Pair(_: Some[_], _: Some[_]) => 3
case _ => 4
}
@@ -474,7 +428,7 @@ object Test extends TestConsoleMain {
case (h1 :: t1, h2 :: t2) => 'c'
}
- def k (x:AnyRef) = x match {
+ def k(x: AnyRef) = x match {
case null => 1
case _ => 2
}
@@ -484,13 +438,11 @@ object Test extends TestConsoleMain {
case FooBar => true
}
- object Bug1270 { // unapply13
-
+ object Bug1270 { // unapply13
class Sync {
def apply(x: Int): Int = 42
def unapply(scrut: Any): Option[Int] = None
}
-
class Buffer {
object Get extends Sync
@@ -498,111 +450,47 @@ object Test extends TestConsoleMain {
case Get(y) if y > 4 => // y gets a wildcard type for some reason?! hack
}
}
-
- println((new Buffer).ps.isDefinedAt(42))
- }
-
- object Bug1261 {
- sealed trait Elem
- case class Foo() extends Elem
- case class Bar() extends Elem
- trait Row extends Elem
- object Row {
- def unapply(r: Row) = true
-
- def f(elem: Elem) {
- elem match {
- case Bar() => ;
- case Row() => ;
- case Foo() => ; // used to give ERROR (unreachable code)
- }}}
- }
-/*
- object Feature1196 {
- def f(l: List[Int]) { }
-
- val l: Seq[Int] = List(1, 2, 3)
-
- l match {
- case x @ List(1, _) => f(x) // x needs to get better type List[int] here
- }
- }
-*/
- object TestIfOpt { //compile-only "test EqualsPatternClass in combination with MixTypes opt, bug #1278"
- trait Token {
- val offset : Int
- def matching : Option[Token]
- }
- def go(tok : Token) = (tok.matching: @unchecked) match {
- case Some(other) if true => Some(other)
- case _ if true => tok.matching match {
- case Some(other) => Some(other)
- case _ => None
- }
+ def run() {
+ assert(!(new Buffer).ps.isDefinedAt(42))
}
}
- object Go { // bug #1277 compile-only
- trait Core { def next : Position = null }
- trait Dir
- val NEXT = new Dir{}
-
- trait Position extends Core
-
- (null:Core, null:Dir) match {
- case (_, NEXT) if true => false // no matter whether NEXT test succeed, cannot throw column because of guard
- case (at2:Position,dir) => true
- }
- }
-
- trait Outer { // bug #1282 compile-only
- object No
- trait File {
- (null:AnyRef) match {
- case No => false
- }
- }
- }
-
- object cast2 { // #1281
-
+ object Bug1281 {
class Sync {
def unapplySeq(scrut: Int): Option[Seq[Int]] = {
- println("unapplySeq: "+scrut)
if (scrut == 42) Some(List(1, 2))
else None
}
}
-
class Buffer {
val Get = new Sync
-
val jp: PartialFunction[Any, Any] = {
- case Get(xs) => println(xs) // the argDummy <unapply-selector> should have proper arg.tpe (Int in this case)
+ case Get(xs) => // the argDummy <unapply-selector> should have proper arg.tpe (Int in this case)
}
}
-
- println((new Buffer).jp.isDefinedAt(40))
- println((new Buffer).jp.isDefinedAt(42))
+ def run() {
+ assert(!(new Buffer).jp.isDefinedAt(40))
+ assert(!(new Buffer).jp.isDefinedAt(42))
+ }
}
- object ClassDefInGuard extends TestCase("classdef in guard") { // compile-and-load only
- val z:PartialFunction[Any,Any] = {
- case x::xs if xs.forall { y => y.hashCode() > 0 } => 1
+ object ClassDefInGuard {
+ val z: PartialFunction[Any, Any] = {
+ case x :: xs if xs.forall { y => y.hashCode() > 0 } => 1
}
- override def runTest {
- val s:PartialFunction[Any,Any] = {
- case List(4::xs) => 1
- case List(5::xs) => 1
- case _ if false =>
- case List(3::xs) if List(3:Any).forall { g => g.hashCode() > 0 } => 1
- }
+ def run() {
+ val s: PartialFunction[Any, Any] = {
+ case List(4 :: xs) => 1
+ case List(5 :: xs) => 1
+ case _ if false =>
+ case List(3 :: xs) if List(3: Any).forall { g => g.hashCode() > 0 } => 1
+ }
z.isDefinedAt(42)
s.isDefinedAt(42)
// just load the thing, to see if the classes are found
- (None:Option[Boolean] @unchecked) match {
+ (None: Option[Boolean] @unchecked) match {
case x if x.map(x => x).isEmpty =>
}
}
@@ -610,33 +498,33 @@ object Test extends TestConsoleMain {
// bug#457
- object Bug457 extends TestCase("Bug457") {
+ object Bug457 {
def method1() = {
val x = "Hello, world"; val y = 100;
y match {
case _: Int if (x match { case t => t.trim().length() > 0 }) => false;
case _ => true;
- }}
+ }
+ }
def method2(): scala.Boolean = {
val x: String = "Hello, world"; val y: scala.Int = 100; {
var temp1: scala.Int = y
var result: scala.Boolean = false
- if (
- {
- var result1: scala.Boolean = true;
- if (y == 100)
- result1
- else
- throw new MatchError("crazybox.scala, line 11")
- } && (y > 90)
- )
+ if ({
+ var result1: scala.Boolean = true;
+ if (y == 100)
+ result1
+ else
+ throw new MatchError("crazybox.scala, line 11")
+ } && (y > 90))
result
- else
- throw new MatchError("crazybox.scala, line 9")
- }}
+ else
+ throw new MatchError("crazybox.scala, line 9")
+ }
+ }
- override def runTest {
+ def run() {
method1();
method2();
}
@@ -644,7 +532,7 @@ object Test extends TestConsoleMain {
// bug#508
- object Bug508 extends TestCase("aladdin #508") {
+ object Bug508 {
case class Operator(x: Int);
val EQ = new Operator(2);
@@ -653,7 +541,7 @@ object Test extends TestConsoleMain {
case Pair(EQ, 1) => "1"
case Pair(EQ, 2) => "2"
}
- override def runTest {
+ def run() {
val x = Pair(EQ, 0);
assertEquals("0", analyze(x)); // should print "0"
val y = Pair(EQ, 1);
@@ -665,7 +553,7 @@ object Test extends TestConsoleMain {
// bug#789
- object Bug789 extends TestCase("aladdin #789") { // don't do this at home
+ object Bug789 { // don't do this at home
trait Impl
@@ -675,21 +563,21 @@ object Test extends TestConsoleMain {
type Both = SizeImpl with ColorImpl
- def info(x:Impl) = x match {
- case x:Both => "size "+x.size+" color "+x.color // you wish
- case x:SizeImpl => "!size "+x.size
- case x:ColorImpl => "color "+x.color
- case _ => "n.a."
+ def info(x: Impl) = x match {
+ case x: Both => "size " + x.size + " color " + x.color // you wish
+ case x: SizeImpl => "!size " + x.size
+ case x: ColorImpl => "color " + x.color
+ case _ => "n.a."
}
- def info2(x:Impl) = x match {
- case x:SizeImpl with ColorImpl => "size "+x.size+" color "+x.color // you wish
- case x:SizeImpl => "!size "+x.size
- case x:ColorImpl => "color "+x.color
- case _ => "n.a."
+ def info2(x: Impl) = x match {
+ case x: SizeImpl with ColorImpl => "size " + x.size + " color " + x.color // you wish
+ case x: SizeImpl => "!size " + x.size
+ case x: ColorImpl => "color " + x.color
+ case _ => "n.a."
}
- override def runTest {
+ def run() {
// make up some class that has a size
class MyNode extends SizeImpl
assertEquals("!size 42", info(new MyNode))
@@ -699,34 +587,36 @@ object Test extends TestConsoleMain {
// bug#995
- object Bug995 extends TestCase("aladdin #995") {
+ object Bug995 {
def foo(v: Any): String = v match {
case s: Seq[_] => "Seq" // see hack in object Seq.unapplySeq
case a: AnyRef if runtime.ScalaRunTime.isArray(a) => "Array"
case _ => v.toString
}
- override def runTest { assertEquals("Array", foo(Array(0))) }
+ def run() { assertEquals("Array", foo(Array(0))) }
}
// bug#1093 (contribution #460)
- object Bug1093 extends TestCase("aladdin #1093") {
- override def runTest {assertTrue(Some(3) match {
- case Some(1 | 2) => false
- case Some(3) => true
- })}
+ object Bug1093 {
+ def run() {
+ assert(Some(3) match {
+ case Some(1 | 2) => false
+ case Some(3) => true
+ })
+ }
}
// bug#1094 (contribution #461)
- object Bug1094 extends TestCase("aladdin #1094") {
+ object Bug1094 {
def foo(ps: String*) = "Foo"
case class X(p: String, ps: String*)
def bar =
X("a", "b") match {
- case X(p, ps @ _*) => foo(ps : _*)
+ case X(p, ps@_*) => foo(ps: _*)
}
- override def runTest { assertEquals("Foo", bar) }
+ def run() { assertEquals("Foo", bar) }
}
// #2
@@ -740,17 +630,19 @@ object Test extends TestConsoleMain {
}
}
- object Ticket2 extends TestCase("#2") { override def runTest {
- val o1 = new Outer_2; val o2 = new Outer_2; val x: Any = o1.Foo(1, 2); val y: Any = o2.Foo(1, 2)
- assertFalse("equals test returns true (but should not)", x equals y)
- assertTrue("match enters wrong case", x match {
- case o2.Foo(x, y) => false
- case o1.Foo(x, y) => true
- case _ => false
- })
- }}
+ object Ticket2 {
+ def run() {
+ val o1 = new Outer_2; val o2 = new Outer_2; val x: Any = o1.Foo(1, 2); val y: Any = o2.Foo(1, 2)
+ assert(x != y, "equals test returns true (but should not)")
+ assert(x match {
+ case o2.Foo(x, y) => false
+ case o1.Foo(x, y) => true
+ case _ => false
+ }, "match enters wrong case")
+ }
+ }
-// #11
+ // #11
class MyException1 extends Exception
@@ -761,31 +653,31 @@ object Test extends TestConsoleMain {
class MyException2 extends MyException1 with SpecialException
- object Ticket11 extends TestCase("#11") {
- override def runTest {
+ object Ticket11 {
+ def run() {
Array[Throwable](new Exception("abc"),
- new MyException1,
- new MyException2).foreach { e =>
- try {
- throw e
- } catch {
- case e : SpecialException => {
- assume(e.isInstanceOf[SpecialException])
- }
- case e => {
- assume(e.isInstanceOf[Throwable])
- }
- }
- }
+ new MyException1,
+ new MyException2).foreach { e =>
+ try {
+ throw e
+ } catch {
+ case e: SpecialException => {
+ assume(e.isInstanceOf[SpecialException])
+ }
+ case e => {
+ assume(e.isInstanceOf[Throwable])
+ }
+ }
+ }
}
}
// #37
- object Ticket37 extends TestCase("#37") {
+ object Ticket37 {
def foo() {}
- val (a,b) = { foo(); (2,3) }
- override def runTest { assertEquals(this.a, 2) }
+ val (a, b) = { foo(); (2, 3) }
+ def run() { assertEquals(this.a, 2) }
}
// #44
@@ -793,146 +685,78 @@ object Test extends TestConsoleMain {
trait _X {
case class _Foo();
object _Bar {
- def unapply(foo: _Foo):Boolean = true;
+ def unapply(foo: _Foo): Boolean = true;
}
}
object Y extends _X {
val foo = _Foo()
foo match {
case _Bar() =>
- case _ => assert(false)
+ case _ => assert(false)
}
}
- object Ticket44 extends TestCase("#44") {
- override def runTest { assert(Y.toString ne null) /*instantiate Y*/ }
- }
-
- object Ticket211 extends TestCase("#211") {
- override def runTest {
- (Some(123):Option[Int]) match {
- case (x:Option[a]) if false => {};
- case (y:Option[b]) => {};
- }
- }
+ object Ticket44 {
+ def run() { assert(Y.toString ne null) /*instantiate Y*/ }
}
- sealed abstract class Tree
- case class Node(l: Tree, v: Int, r: Tree) extends Tree
- case object EmptyTree extends Tree
-
- object Ticket335 extends TestCase("#335") { // compile-only
- override def runTest {
- (EmptyTree: Tree @unchecked) match {
- case Node(_,v,_) if (v == 0) => 0
- case EmptyTree => 2
+ object Ticket211 {
+ def run() {
+ (Some(123): Option[Int]) match {
+ case (x: Option[a]) if false => {};
+ case (y: Option[b]) => {};
}
}
}
-// this test case checks nothing more than whether
-// case N for object N is translated to a check scrutinee.equals(N)
-// (or the other way round)... for a long time, we got away with
-// scrutinee eq N, but those golden days are, apparently, over.
- object Ticket346 extends TestCase("#346") {
+ // this test case checks nothing more than whether
+ // case N for object N is translated to a check scrutinee.equals(N)
+ // (or the other way round)... for a long time, we got away with
+ // scrutinee eq N, but those golden days are, apparently, over.
+ object Ticket346 {
-class L(val content: List[Int]) {
+ class L(val content: List[Int]) {
- def isEmpty = content.isEmpty
- def head = content.head
- def tail = content.tail
+ def isEmpty = content.isEmpty
+ def head = content.head
+ def tail = content.tail
- override def equals(that: Any): Boolean = {
+ override def equals(that: Any): Boolean = {
val result = that.isInstanceOf[N.type]
- println("L("+content+").equals("+that+") returning "+result)
+ println("L(" + content + ").equals(" + that + ") returning " + result)
result
+ }
}
-}
-object N extends L(Nil) {
-
- override def equals(that: Any): Boolean = {
- val result = (that.isInstanceOf[L] && that.asInstanceOf[L].isEmpty)
- //println("N.equals("+that+") returning "+result)
- result
+ object N extends L(Nil) {
+ override def equals(that: Any): Boolean =
+ (that.isInstanceOf[L] && that.asInstanceOf[L].isEmpty)
}
-}
-object C {
+ object C {
- def unapply(xs: L): Option[(Int, L)] = {
- if (xs.isEmpty)
- { println("xs is empty"); None }
+ def unapply(xs: L): Option[(Int, L)] = {
+ if (xs.isEmpty) { println("xs is empty"); None }
else
- Some((xs.head, new L(xs.tail)))
- }
-
-}
-
+ Some((xs.head, new L(xs.tail)))
+ }
- def empty(xs : L) : Boolean = xs match {
- case N => true
- case _ => false
}
- def singleton(xs : L) : Boolean = xs match {
- case C(_, N) => true
- case _ => false
+ def empty(xs: L): Boolean = xs match {
+ case N => true
+ case _ => false
}
-override def runTest() {
- assertTrue(empty( new L(Nil) ))
- assertTrue(singleton( new L(List(1)) ))
-}
-
-} // end Ticket346
-
- object Ticket495bis { // compile-only
- def signum(x: Int): Int =
- x match {
- case 0 => 0
- case _ if x < 0 => -1
- case _ if x > 0 => 1
- }
- def pair_m(x: Int, y: Int) =
- (x,y) match {
- case (_, 0) => 0
- case (-1, _) => -1
- case (_, _) => 1
- }
- }
-
- object Ticket522 { // compile-only
- class Term[X]
- object App {
- // i'm hidden
- case class InternalApply[Y,Z](fun:Y=>Z, arg:Y) extends Term[Z]
-
- def apply[Y,Z](fun:Y=>Z, arg:Y): Term[Z] =
- new InternalApply[Y,Z](fun,arg)
-
- def unapply[X](arg: Term[X]): Option[(Y=>Z,Y)] forSome {type Y; type Z} =
- arg match {
- case i:InternalApply[y,z] => Some(i.fun, i.arg)
- case _ => None
- }
- }
-
- App({x: Int => x}, 5) match {
- case App(arg, a) =>
- }
- } // end Ticket522
-
+ def singleton(xs: L): Boolean = xs match {
+ case C(_, N) => true
+ case _ => false
+ }
- object Ticket710 { // compile-only
- def method {
- sealed class Parent()
- case object Child extends Parent()
- val x: Parent = Child
- x match {
- case Child => ()
- }
+ def run() {
+ assert(empty(new L(Nil)))
+ assert(singleton(new L(List(1))))
}
- }
-}
+ } // end Ticket346
+}
diff --git a/test/files/run/unapply.scala b/test/files/run/unapply.scala
index 810616850d..85c384ab1f 100644
--- a/test/files/run/unapply.scala
+++ b/test/files/run/unapply.scala
@@ -1,12 +1,11 @@
-import scala.testing.SUnit._
-
-object Test extends TestConsoleMain {
- def suite = new TestSuite(
- Foo,
- Mas,
- LisSeqArr,
- StreamFoo
- )
+object Test {
+ def main(args: Array[String]) {
+ Foo.run()
+ Mas.run()
+ LisSeqArr.run()
+ StreamFoo.run()
+ Test1256.run()
+ }
}
// this class is used for representation
@@ -31,7 +30,8 @@ object FaaPreciseSome {
object VarFoo {
def unapply(a : Int)(implicit b : Int) : Option[Int] = Some(a + b)
}
-object Foo extends TestCase("Foo") with Assert {
+
+object Foo {
def unapply(x: Any): Option[Product2[Int, String]] = x match {
case y: Bar => Some(Tuple(y.size, y.name))
case _ => None
@@ -51,22 +51,22 @@ object Foo extends TestCase("Foo") with Assert {
def doMatch5(b:Bar) = (b:Any) match {
case FaaPreciseSome(n:String) => n
}
- override def runTest {
+ def run() {
val b = new Bar
- assertEquals(doMatch1(b),(50,"medium"))
- assertEquals(doMatch2(b),null)
- assertEquals(doMatch3(b),"medium")
- assertEquals(doMatch4(b),"medium")
- assertEquals(doMatch5(b),"medium")
+ assert(doMatch1(b) == (50,"medium"))
+ assert(doMatch2(b) == null)
+ assert(doMatch3(b) == "medium")
+ assert(doMatch4(b) == "medium")
+ assert(doMatch5(b) == "medium")
implicit val bc: Int = 3
- assertEquals(4 match {
+ assert(7 == (4 match {
case VarFoo(x) => x
- }, 7)
+ }))
}
}
// same, but now object is not top-level
-object Mas extends TestCase("Mas") with Assert {
+object Mas {
object Gaz {
def unapply(x: Any): Option[Product2[Int, String]] = x match {
case y: Baz => Some(Tuple(y.size, y.name))
@@ -77,57 +77,46 @@ object Mas extends TestCase("Mas") with Assert {
var size: Int = 60
var name: String = "too large"
}
- def runTest {
+ def run() {
val b = new Baz
- assertEquals(b match {
+ assert((60,"too large") == (b match {
case Gaz(s:Int, n:String) => (s,n)
- }, (60,"too large"))
+ }))
}
}
-object LisSeqArr extends TestCase("LisSeqArr") with Assert {
-// def foo[A](x:List[A]) {}
- def runTest {
- assertEquals((List(1,2,3): Any) match { case List(x,y,_*) => (x,y)}, (1,2))
- assertEquals((List(1,2,3): Any) match { case Seq(x,y,_*) => (x,y)}, (1,2))
- //assertEquals((Array(1,2,3): Any) match { case Seq(x,y,_*) => (x,y)}, (1,2))
- //assertEquals((Array(1,2,3): Any) match { case Array(x,y,_*) => {x,y}}, {1,2})
-
- // just compile, feature request #1196
-// (List(1,2,3): Any) match {
-// case a @ List(x,y,_*) => foo(a)
-// }
-
+object LisSeqArr {
+ def run() {
+ assert((1,2) == ((List(1,2,3): Any) match { case List(x,y,_*) => (x,y)}))
+ assert((1,2) == ((List(1,2,3): Any) match { case Seq(x,y,_*) => (x,y)}))
}
}
-
-object StreamFoo extends TestCase("unapply for Streams") with Assert {
- //val x:Stream[Int] = Stream.cons(1,x)
-
+object StreamFoo {
def sum(stream: Stream[Int]): Int =
stream match {
case Stream.Empty => 0
case Stream.cons(hd, tl) => hd + sum(tl)
}
- override def runTest {
+ def run() {
val str: Stream[Int] = List(1,2,3).toStream
- assertEquals(sum(str), 6)
+ assert(6 == sum(str))
}
}
-object Test1256 extends TestCase("1256") {
+object Test1256 {
class Sync {
def unapply(scrut: Any): Boolean = false
}
class Buffer {
val Get = new Sync
-
val jp: PartialFunction[Any, Any] = {
case Get() =>
}
}
- override def runTest { assertFalse((new Buffer).jp.isDefinedAt(42)) }
+ def run() {
+ assert(!(new Buffer).jp.isDefinedAt(42))
+ }
}
diff --git a/test/files/run/unittest_collection.scala b/test/files/run/unittest_collection.scala
index d45c23d4b5..822e2b0c98 100644
--- a/test/files/run/unittest_collection.scala
+++ b/test/files/run/unittest_collection.scala
@@ -1,103 +1,58 @@
-
object Test {
- import scala.testing.SUnit._
import scala.collection.mutable.{ArrayBuffer, Buffer, BufferProxy, ListBuffer}
- trait BufferTest extends Assert {
- def doTest(x:Buffer[String]) = {
- // testing method +=
- x += "one"
- assertEquals("retrieving 'one'", x(0), "one")
- assertEquals("length A ", x.length, 1)
- x += "two"
- assertEquals("retrieving 'two'", x(1), "two")
- assertEquals("length B ", x.length, 2)
-
- // testing method -= (removing last element)
- x -= "two"
-
- assertEquals("length C ", x.length, 1)
-
- try { x(1); fail("no exception for removed element") }
- catch { case i:IndexOutOfBoundsException => }
-
- try { x.remove(1); fail("no exception for removed element") }
- catch { case i:IndexOutOfBoundsException => }
-
- x += "two2"
- assertEquals("length D ", x.length, 2)
-
- // removing first element
- x.remove(0)
- assertEquals("length E ", x.length, 1)
-
- // toList
- assertEquals("toList ", x.toList, List("two2"))
-
- // clear
- x.clear
- assertEquals("length F ", x.length, 0)
-
- // copyToBuffer
- x += "a"
- x += "b"
- val dest = new ArrayBuffer[String]
- x copyToBuffer dest
- assertEquals("dest", List("a", "b"), dest.toList)
- assertEquals("source", List("a", "b"), x.toList)
+ def main(args: Array[String]) {
+ test(collection.mutable.ArrayBuffer[String]())
+ test(collection.mutable.ListBuffer[String]())
+ class BBuf(z:ListBuffer[String]) extends BufferProxy[String] {
+ def self = z
}
+ test(new BBuf(collection.mutable.ListBuffer[String]()))
}
- class TArrayBuffer extends TestCase("collection.mutable.ArrayBuffer") with Assert with BufferTest {
-
- var x: ArrayBuffer[String] = _
+ def test(x: Buffer[String]) {
+ // testing method +=
+ x += "one"
+ assert(x(0) == "one", "retrieving 'one'")
+ assert(x.length == 1, "length A")
+ x += "two"
+ assert(x(1) == "two", "retrieving 'two'")
+ assert(x.length == 2, "length B")
- override def runTest = { setUp; doTest(x); tearDown }
+ // testing method -= (removing last element)
+ x -= "two"
- override def setUp = { x = new scala.collection.mutable.ArrayBuffer }
+ assert(x.length == 1, "length C")
- override def tearDown = { x.clear; x = null }
- }
+ try { x(1); sys.error("no exception for removed element") }
+ catch { case i:IndexOutOfBoundsException => }
- class TListBuffer extends TestCase("collection.mutable.ListBuffer") with Assert with BufferTest {
+ try { x.remove(1); sys.error("no exception for removed element") }
+ catch { case i:IndexOutOfBoundsException => }
- var x: ListBuffer[String] = _
+ x += "two2"
+ assert(x.length == 2, "length D")
- override def runTest = { setUp; doTest(x); tearDown }
+ // removing first element
+ x.remove(0)
+ assert(x.length == 1, "length E")
- override def setUp = { x = new scala.collection.mutable.ListBuffer }
+ // toList
+ assert(x.toList == List("two2"), "toList")
- override def tearDown = { x.clear; x = null }
+ // clear
+ x.clear()
+ assert(x.length == 0, "length 0")
+ assert(x.isEmpty, "isEmpty")
+ // copyToBuffer
+ x += "a"
+ x += "b"
+ val dest = new ArrayBuffer[String]
+ x.copyToBuffer(dest)
+ assert(List("a", "b") == dest.toList, "dest")
+ assert(List("a", "b") == x.toList, "source")
}
- class TBufferProxy extends TestCase("collection.mutable.BufferProxy") with Assert with BufferTest {
-
- class BBuf(z:ListBuffer[String]) extends BufferProxy[String] {
- def self = z
- }
-
- var x: BufferProxy[String] = _
-
- override def runTest = { setUp; doTest(x); tearDown }
-
- override def setUp = { x = new BBuf(new scala.collection.mutable.ListBuffer) }
-
- override def tearDown = { x.clear; x = null }
-
- }
-
- def main(args:Array[String]) = {
- val ts = new TestSuite(
- //new TArrayBuffer,
- new TListBuffer//,
- //new TBufferProxy
- )
- val tr = new TestResult()
- ts.run(tr)
- for (failure <- tr.failures) {
- Console.println(failure)
- }
- }
}
diff --git a/test/files/run/unittest_io.scala b/test/files/run/unittest_io.scala
index 974dcff5b3..4d2869ec3b 100644
--- a/test/files/run/unittest_io.scala
+++ b/test/files/run/unittest_io.scala
@@ -1,42 +1,35 @@
-import testing.SUnit._
+object Test {
-object Test extends TestConsoleMain {
- def suite = new TestSuite(new UTF8Tests, new SourceTest)
+ def main(args: Array[String]) {
+ UTF8Tests.run()
+ SourceTest.run()
+ }
- class UTF8Tests extends TestCase("UTF8Codec") {
+ object UTF8Tests {
import io.UTF8Codec.encode
-
- def runTest {
- assertEquals(new String( encode(0x004D), "utf8"), new String(Array(0x004D.asInstanceOf[Char])))
- assertEquals(new String( encode(0x0430), "utf8"), new String(Array(0x0430.asInstanceOf[Char])))
- assertEquals(new String( encode(0x4E8C), "utf8"), new String(Array(0x4E8C.asInstanceOf[Char])))
- assertEquals(new String(encode(0x10302), "utf8"), new String(Array(0xD800.asInstanceOf[Char],
- 0xDF02.asInstanceOf[Char])))
-
+ def run() {
+ assert(new String( encode(0x004D), "utf8") == new String(Array(0x004D.asInstanceOf[Char])))
+ assert(new String( encode(0x0430), "utf8") == new String(Array(0x0430.asInstanceOf[Char])))
+ assert(new String( encode(0x4E8C), "utf8") == new String(Array(0x4E8C.asInstanceOf[Char])))
+ assert(new String(encode(0x10302), "utf8") == new String(Array(0xD800.asInstanceOf[Char],
+ 0xDF02.asInstanceOf[Char])))
// a client
val test = "{\"a\":\"\\u0022\"}"
val Expected = ("a","\"")
- assertTrue(scala.util.parsing.json.JSON.parse(test) match {
+ assert(scala.util.parsing.json.JSON.parse(test) match {
case Some(List(Expected)) => true
case z => Console.println(z); false
})
}
}
- class SourceTest extends TestCase("Source") {
- def runTest {
- val s = "Here is a test string"
+ object SourceTest {
+ def run() {
+ val s = "Here is a test string"
val f = io.Source.fromBytes(s.getBytes("utf-8"))
val b = new collection.mutable.ArrayBuffer[Char]()
f.copyToBuffer(b)
- assertEquals(s, new String(b.toArray))
-
- /* todo: same factories for BufferedSource and Source
- val g = io.BufferedSource.fromBytes(s.getBytes("utf-8"))
- val c = new collection.mutable.ArrayBuffer[Char]()
- g.copyToBuffer(c)
- assertEquals(s, new String(c.toArray))
- */
+ assert(s == new String(b.toArray))
}
}
}