Removed old scala tests from new Scala core module.
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@5368 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
f604778a2a
commit
bd31aa5c99
|
@ -1,9 +0,0 @@
|
|||
# the compiler executable
|
||||
scala.compiler=scalac
|
||||
|
||||
# the vm to run scala programs with
|
||||
scala.vm=scala
|
||||
|
||||
# the location where your scala distribution is
|
||||
# it should point to the parent of the 'test/' directory
|
||||
scala.home=${user.home}/scala
|
|
@ -1,23 +0,0 @@
|
|||
<project name="benchmark" default="run.benchmark">
|
||||
|
||||
<import file="predef.xml"/>
|
||||
|
||||
<target name="init" depends="clean.benchmark">
|
||||
<mkdir dir="${benchmark.classes.dir}"/>
|
||||
<mkdir dir="times"/>
|
||||
</target>
|
||||
|
||||
<target name="clean.benchmark"
|
||||
description="Clean the files generated for the benchmark classes">
|
||||
<delete dir="${benchmark.classes.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="run.benchmark" depends="init"
|
||||
description="Run the benchmark suite">
|
||||
|
||||
<subant inheritAll="false">
|
||||
<fileset dir="${benchmark.sources.dir}" includes="*/build.xml"/>
|
||||
</subant>
|
||||
</target>
|
||||
|
||||
</project>
|
|
@ -1,73 +0,0 @@
|
|||
<project name="predef">
|
||||
|
||||
<!-- Include the file defining private properties -->
|
||||
<dirname property="predef.basedir" file="${ant.file.predef}"/>
|
||||
<property file="${predef.basedir}/ant.private"/>
|
||||
|
||||
<!-- Define some basic paths -->
|
||||
<property name="benchmark.home" value="${scala.home}/test/benchmark"/>
|
||||
<property name="benchmark.sources.dir"
|
||||
value="${benchmark.home}/sources"/>
|
||||
<property name="benchmark.classes.dir"
|
||||
value="${benchmark.home}/classes"/>
|
||||
<property name="log.file"
|
||||
value="${benchmark.home}/times/times.log"/>
|
||||
|
||||
<!-- Define a <run-benchmark> element that can be used to run -->
|
||||
<!-- benchmarks -->
|
||||
<!-- It accepts these attributes: -->
|
||||
<!-- count - how many times to run each benchmark (default:5) -->
|
||||
<!-- classname - the name of the class to be ran (default: -->
|
||||
<!-- the name of the ant project -->
|
||||
<!-- logfile - the location of the file where running times -->
|
||||
<!-- are logged (default: ${log.file} property) -->
|
||||
<!-- location - the location of the classfiles: it will end -->
|
||||
<!-- up as head of the current classpath (default: -->
|
||||
<!-- benchmark classes dir/project name -->
|
||||
<macrodef name="run-benchmark">
|
||||
<attribute name="count" default="5"/>
|
||||
<attribute name="classname" default="benchmarks.${ant.project.name}"/>
|
||||
<attribute name="logfile" default="${log.file}"/>
|
||||
<attribute name="location" default="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
|
||||
<sequential>
|
||||
<echo>** Running benchmark @{classname} in @{location}..</echo>
|
||||
<exec executable="${scala.vm}" failonerror="true">
|
||||
<arg line="-cp @{location}:${java.class.path}"/>
|
||||
<arg line="@{classname} @{count} @{logfile}"/>
|
||||
</exec>
|
||||
<echo>Done</echo>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<!-- Define a <compile-benchmark> element that can be used to -->
|
||||
<!-- compile benchmarks -->
|
||||
<!-- It accepts these attributes: -->
|
||||
<!-- compiler - the name of the scalac compiler to use. It is -->
|
||||
<!-- useful in case you have multiple compilers -->
|
||||
<!-- installed (default: scalac) -->
|
||||
<!-- additionalArgs - additional arguments to pass to scalac -->
|
||||
<!-- (default: none) -->
|
||||
<!-- destination - the location where class files should be -->
|
||||
<!-- created (default: benchmark classes dir/project -->
|
||||
<!-- name) -->
|
||||
<!-- files - the source files to be compiled -->
|
||||
<macrodef name="compile-benchmark">
|
||||
<attribute name="compiler" default="${scala.compiler}"/>
|
||||
<attribute name="additionalArgs" default=""/>
|
||||
<attribute name="destination" default="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
<attribute name="files"/>
|
||||
|
||||
<sequential>
|
||||
<echo>
|
||||
** Building project ${ant.project.name} to @{destination}</echo>
|
||||
|
||||
<exec executable="@{compiler}" failonerror="true">
|
||||
<arg line="-d @{destination}"/>
|
||||
<arg line="@{additionalArgs}"/>
|
||||
<arg line="@{files}"/>
|
||||
</exec>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
</project>
|
|
@ -1,36 +0,0 @@
|
|||
<project name="impfor" default="run">
|
||||
|
||||
<import file="../../predef.xml"/>
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile the impfor benchmark without optimizations -->
|
||||
<target name="compile-noopt"
|
||||
description="Compile the ${ant.project.name} benchmark with no optimizations">
|
||||
<compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/impfor.scala"
|
||||
destination="${benchmark.classes.dir}/${ant.project.name}/noopt"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile the impfor benchmark with optimizations -->
|
||||
<target name="compile-opt"
|
||||
description="Compile the ${ant.project.name} benchmark with opt">
|
||||
<compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/impfor.scala"
|
||||
destination="${benchmark.classes.dir}/${ant.project.name}/opt"
|
||||
additionalArgs="-separate:no -Xinline"/>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="run" depends="init,compile-noopt,compile-opt"
|
||||
description="Run this benchmark">
|
||||
<run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/noopt"/>
|
||||
<run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/opt"/>
|
||||
</target>
|
||||
|
||||
<target name="clean.benchmark"
|
||||
description="Clean the object files for ${ant.project.name} benchmark">
|
||||
<delete dir="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
</target>
|
||||
|
||||
</project>
|
|
@ -1,46 +0,0 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala benchmark suite **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
** $Id$
|
||||
\* */
|
||||
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/** Imperative for construct. Translated from MLton benchmarking suite */
|
||||
|
||||
class For {
|
||||
def impFor[A](start: Int, stop: Int, f: Int => A) = {
|
||||
var i = start;
|
||||
def loop: Unit = if (i >= stop) ()
|
||||
else { f(i); i = i + 1; loop }
|
||||
|
||||
loop;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
object impfor extends For with scala.testing.Benchmark {
|
||||
|
||||
def doit: Unit = {
|
||||
var x = 0;
|
||||
|
||||
impFor(0, 10, t =>
|
||||
impFor(0, 10, t =>
|
||||
impFor(0, 10, t =>
|
||||
impFor(0, 10, t =>
|
||||
impFor(0, 10, t =>
|
||||
impFor(0, 10, t =>
|
||||
impFor(0, 10, t => x = x + 1))))))); // 7 inner loops
|
||||
|
||||
if (x != 10000000) {
|
||||
Console.println("Error");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
def run: Unit = doit;
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
<project name="parsers" default="run">
|
||||
|
||||
<import file="../../predef.xml"/>
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
</target>
|
||||
|
||||
|
||||
<!-- Compile the parsers benchmark without optimizations -->
|
||||
<target name="compile-noopt"
|
||||
description="Compile the ${ant.project.name} benchmark with no optimizations">
|
||||
<compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/parsers.scala"
|
||||
destination="${benchmark.classes.dir}/${ant.project.name}/noopt"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile the parsers benchmark with optimizations -->
|
||||
<target name="compile-opt"
|
||||
description="Compile the ${ant.project.name} benchmark with opt">
|
||||
<compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/parsers.scala"
|
||||
destination="${benchmark.classes.dir}/${ant.project.name}/opt"
|
||||
additionalArgs="-separate:no -Xinline"/>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="run" depends="init,compile-noopt,compile-opt"
|
||||
description="Run this benchmark">
|
||||
<run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/noopt"/>
|
||||
<run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/opt"/>
|
||||
</target>
|
||||
|
||||
<target name="clean.benchmark"
|
||||
description="Clean the object files for ${ant.project.name} benchmark">
|
||||
<delete dir="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
</target>
|
||||
|
||||
</project>
|
|
@ -1,124 +0,0 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala benchmark suite **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
** $Id$
|
||||
\* */
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/** The parsers example from the scala distribution. */
|
||||
abstract class Parsers {
|
||||
|
||||
type intype;
|
||||
|
||||
abstract class Parser {
|
||||
|
||||
type Result = Option[intype];
|
||||
|
||||
def apply(in: intype): Result;
|
||||
|
||||
/*** p &&& q applies first p, and if that succeeds, then q
|
||||
*/
|
||||
def &&& (q: => Parser) = new Parser {
|
||||
def apply(in: intype): Result = Parser.this.apply(in) match {
|
||||
case None => None
|
||||
case Some(in1) => q(in1)
|
||||
}
|
||||
}
|
||||
|
||||
/*** p ||| q applies first p, and, if that fails, then q.
|
||||
*/
|
||||
def ||| (q: => Parser) = new Parser {
|
||||
def apply(in: intype): Result = Parser.this.apply(in) match {
|
||||
case None => q(in)
|
||||
case s => s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val empty = new Parser {
|
||||
def apply(in: intype): Result = Some(in)
|
||||
}
|
||||
|
||||
val fail = new Parser {
|
||||
def apply(in: intype): Result = None
|
||||
}
|
||||
|
||||
def opt(p: Parser): Parser = p ||| empty; // p? = (p | <empty>)
|
||||
def rep(p: Parser): Parser = opt(rep1(p)); // p* = [p+]
|
||||
def rep1(p: Parser): Parser = p &&& rep(p); // p+ = p p*
|
||||
}
|
||||
|
||||
abstract class ListParsers extends Parsers {
|
||||
|
||||
def chr(p: char => boolean): Parser;
|
||||
|
||||
def chr(c: char): Parser = chr(d: char => d == c);
|
||||
|
||||
def letter : Parser = chr(Character.isLetter);
|
||||
def digit : Parser = chr(Character.isDigit);
|
||||
|
||||
def ident : Parser = letter &&& rep(letter ||| digit);
|
||||
def number : Parser = digit &&& rep(digit);
|
||||
def list : Parser = chr('(') &&& listElems &&& chr(')');
|
||||
def listElems : Parser = expr &&& (chr(',') &&& listElems ||| empty);
|
||||
def expr : Parser = ident ||| number ||| list;
|
||||
}
|
||||
|
||||
abstract class ExprParsers extends Parsers {
|
||||
def chr(p: char => boolean): Parser;
|
||||
def chr(c: char): Parser = chr(d: char => d == c);
|
||||
|
||||
def digit : Parser = chr(Character.isDigit);
|
||||
def number : Parser = digit &&& rep(digit);
|
||||
def summand : Parser = number ||| chr('(') &&& expr &&& chr(')');
|
||||
def expr : Parser = summand &&& rep(chr('+') &&& summand)
|
||||
}
|
||||
|
||||
class ParseString(s: String) extends Parsers {
|
||||
type intype = int;
|
||||
val input = 0;
|
||||
def chr(p: char => boolean) = new Parser {
|
||||
def apply(in: int): Parser#Result =
|
||||
if (in < s.length() && p(s charAt in)) Some(in + 1);
|
||||
else None;
|
||||
}
|
||||
}
|
||||
|
||||
object TestList {
|
||||
|
||||
def main(args: Array[String]): unit =
|
||||
if (args.length == 1) {
|
||||
val ps = new ListParsers with ParseString(args(0));
|
||||
ps.expr(ps.input) match {
|
||||
case Some(n) =>
|
||||
System.out.println("parsed: " + args(0).substring(0, n));
|
||||
case None =>
|
||||
System.out.println("nothing parsed");
|
||||
}
|
||||
} else System.out.println("usage: java examples.TestList <expr-string>");
|
||||
}
|
||||
|
||||
object TestExpr {
|
||||
|
||||
def main(args: Array[String]): unit =
|
||||
if (args.length == 1) {
|
||||
val ps = new ExprParsers with ParseString(args(0));
|
||||
ps.expr(ps.input) match {
|
||||
case Some(n) =>
|
||||
System.out.println("parsed: " + args(0).substring(0, n));
|
||||
case None =>
|
||||
System.out.println("nothing parsed");
|
||||
}
|
||||
} else System.out.println("usage: java examples.TestExpr <expr-string>");
|
||||
}
|
||||
|
||||
object parsers with scala.testing.Benchmark {
|
||||
def run: Unit = {
|
||||
TestList.main(Array("(a,b,(1,2))"));
|
||||
TestExpr.main(Array("2+3+(4+1)"))
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<project name="sort1" default="run">
|
||||
|
||||
<import file="../../predef.xml"/>
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile the sort1 benchmark without optimizations -->
|
||||
<target name="compile-noopt"
|
||||
description="Compile the ${ant.project.name} benchmark with no optimizations">
|
||||
<compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/sort1.scala"
|
||||
destination="${benchmark.classes.dir}/${ant.project.name}/noopt"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile the sort1 benchmark with optimizations -->
|
||||
<target name="compile-opt"
|
||||
description="Compile the ${ant.project.name} benchmark with opt">
|
||||
<compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/sort1.scala"
|
||||
destination="${benchmark.classes.dir}/${ant.project.name}/opt"
|
||||
additionalArgs="-separate:no -Xinline"/>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="run" depends="init,compile-noopt,compile-opt"
|
||||
description="Run this benchmark">
|
||||
<run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/noopt"/>
|
||||
<run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/opt"/>
|
||||
</target>
|
||||
|
||||
<target name="clean.benchmark"
|
||||
description="Clean the object files for ${ant.project.name} benchmark">
|
||||
<delete dir="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
</target>
|
||||
|
||||
</project>
|
|
@ -1,28 +0,0 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala benchmark suite **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
** $Id$
|
||||
\* */
|
||||
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/** Quick sort with a functional taste. */
|
||||
object sort1 with scala.testing.Benchmark {
|
||||
|
||||
def sort(a: List[Int]): List[Int] = {
|
||||
if (a.length < 2)
|
||||
a
|
||||
else {
|
||||
val pivot = a(a.length / 2);
|
||||
sort(a.filter(x => x < pivot))
|
||||
::: a.filter(x => x == pivot)
|
||||
::: sort(a.filter(x => x > pivot))
|
||||
}
|
||||
}
|
||||
|
||||
def run: Unit = sort(List.range(1, 10000));
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<project name="sort2" default="run">
|
||||
<import file="../../predef.xml"/>
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
</target>
|
||||
|
||||
|
||||
<!-- Compile the sort2 benchmark without optimizations -->
|
||||
<target name="compile-noopt"
|
||||
description="Compile the ${ant.project.name} benchmark with no optimizations">
|
||||
<compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/sort2.scala"
|
||||
destination="${benchmark.classes.dir}/${ant.project.name}/noopt"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile the sort2 benchmark with optimizations -->
|
||||
<target name="compile-opt"
|
||||
description="Compile the ${ant.project.name} benchmark with opt">
|
||||
<compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/sort2.scala"
|
||||
destination="${benchmark.classes.dir}/${ant.project.name}/opt"
|
||||
additionalArgs="-separate:no -Xinline"/>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="run" depends="init,compile-noopt,compile-opt"
|
||||
description="Run this benchmark">
|
||||
<run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/noopt"/>
|
||||
<run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/opt"/>
|
||||
</target>
|
||||
|
||||
<target name="clean.benchmark"
|
||||
description="Clean the object files for ${ant.project.name} benchmark">
|
||||
<delete dir="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
</target>
|
||||
|
||||
</project>
|
|
@ -1,35 +0,0 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala benchmark suite **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
** $Id$
|
||||
\* */
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/** Quick-sort a list of integers, version 2. Taken from the
|
||||
Scala distribution examples. */
|
||||
class Sorter {
|
||||
|
||||
def sort(a: List[Int]): List[Int] = {
|
||||
if (a.length < 2)
|
||||
a
|
||||
else {
|
||||
val pivot = a(a.length / 2);
|
||||
def lePivot(x: Int) = x < pivot;
|
||||
def gtPivot(x: Int) = x > pivot;
|
||||
def eqPivot(x: Int) = x == pivot;
|
||||
sort(a filter lePivot)
|
||||
::: sort(a filter eqPivot)
|
||||
::: sort(a filter gtPivot)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object sort2 extends Sorter with scala.testing.Benchmark {
|
||||
def run: Unit = sort(List.range(1,10000));
|
||||
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<project name="tak" default="run">
|
||||
|
||||
<import file="../../predef.xml"/>
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile the tak benchmark without optimizations -->
|
||||
<target name="compile-noopt"
|
||||
description="Compile the ${ant.project.name} benchmark with no optimizations">
|
||||
<compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/tak.scala"
|
||||
destination="${benchmark.classes.dir}/${ant.project.name}/noopt"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile the tak benchmark with optimizations -->
|
||||
<target name="compile-opt"
|
||||
description="Compile the ${ant.project.name} benchmark with opt">
|
||||
<compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/tak.scala"
|
||||
destination="${benchmark.classes.dir}/${ant.project.name}/opt"
|
||||
additionalArgs="-separate:no -Xinline"/>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="run" depends="init,compile-noopt,compile-opt"
|
||||
description="Run this benchmark">
|
||||
<run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/noopt"/>
|
||||
<run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/opt"/>
|
||||
</target>
|
||||
|
||||
<target name="clean.benchmark"
|
||||
description="Clean the object files for ${ant.project.name} benchmark">
|
||||
<delete dir="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
</target>
|
||||
|
||||
</project>
|
|
@ -1,29 +0,0 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala benchmark suite **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
** $Id$
|
||||
\* */
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/** The Tak recursive function. Translated from the MLton benchmarking
|
||||
suite. */
|
||||
class Tak {
|
||||
def tak(x: Int, y: Int, z: Int): Int =
|
||||
if (! (y < x))
|
||||
z
|
||||
else
|
||||
tak (tak(x - 1, y, z), tak(y - 1, z, x), tak(z - 1, z, y));
|
||||
|
||||
def f(x: Int): Unit = x match {
|
||||
case 0 => ();
|
||||
case n => {tak (36, 42, 12); f (n - 1) }
|
||||
}
|
||||
}
|
||||
|
||||
object tak extends Tak with scala.testing.Benchmark {
|
||||
def run = f(10000);
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<project name="viewtest" default="run">
|
||||
|
||||
<import file="../../predef.xml"/>
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile the viewtest benchmark without optimizations -->
|
||||
<target name="compile-noopt"
|
||||
description="Compile the ${ant.project.name} benchmark with no optimizations">
|
||||
<compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/viewtest.scala"
|
||||
destination="${benchmark.classes.dir}/${ant.project.name}/noopt"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile the viewtest benchmark with optimizations -->
|
||||
<target name="compile-opt"
|
||||
description="Compile the ${ant.project.name} benchmark with opt">
|
||||
<compile-benchmark files="${benchmark.sources.dir}/${ant.project.name}/viewtest.scala"
|
||||
destination="${benchmark.classes.dir}/${ant.project.name}/opt"
|
||||
additionalArgs="-separate:no -Xinline"/>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="run" depends="init,compile-noopt,compile-opt"
|
||||
description="Run this benchmark">
|
||||
<run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/noopt"/>
|
||||
<run-benchmark location="${benchmark.classes.dir}/${ant.project.name}/opt"/>
|
||||
</target>
|
||||
|
||||
<target name="clean.benchmark"
|
||||
description="Clean the object files for ${ant.project.name} benchmark">
|
||||
<delete dir="${benchmark.classes.dir}/${ant.project.name}"/>
|
||||
</target>
|
||||
|
||||
</project>
|
|
@ -1,52 +0,0 @@
|
|||
/* __ *\
|
||||
** ________ ___ / / ___ Scala benchmark suite **
|
||||
** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL **
|
||||
** __\ \/ /__/ __ |/ /__/ __ | **
|
||||
** /____/\___/_/ |_/____/_/ | | **
|
||||
** |/ **
|
||||
** $Id$
|
||||
\* */
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/* View test class from the scala test suite */
|
||||
|
||||
trait Ordered[a] {
|
||||
def < (x: a): boolean;
|
||||
}
|
||||
|
||||
object O {
|
||||
def view (x: String): Ordered[String] = new Ordered[String] {
|
||||
def < (y: String) = x.compareTo(y) < 0;
|
||||
}
|
||||
}
|
||||
|
||||
object Empty extends Tree[All];
|
||||
case class Node[+c <% Ordered[c]](elem: c, l: Tree[c], r: Tree[c]) extends Tree[c];
|
||||
|
||||
trait Tree[+a <% Ordered[a]] {
|
||||
def insert[b >: a <% Ordered[b]](x: b): Tree[b] = this match {
|
||||
case Empty => new Node(x, Empty, Empty)
|
||||
case Node(elem, l, r) =>
|
||||
if (x == elem) this
|
||||
else if (x < elem) Node(elem, l insert x, r)
|
||||
else Node(elem, l, r insert x);
|
||||
}
|
||||
def elements: List[a] = this match {
|
||||
case Empty => List()
|
||||
case Node(elem, l, r) =>
|
||||
l.elements ::: List(elem) ::: r.elements
|
||||
}
|
||||
}
|
||||
|
||||
object viewtest with scala.testing.Benchmark {
|
||||
import O.view;
|
||||
|
||||
def run: Unit = {
|
||||
var t: Tree[String] = Empty;
|
||||
val args = List("1", "2", "3", "4", "5", "7", "8", "9", "10");
|
||||
for (val s <- args) {
|
||||
t = t insert s
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
scala.List
|
|
@ -1,74 +0,0 @@
|
|||
abstract sealed class List[+a]() extends scala.Seq[a] with scala.ScalaObject {
|
||||
def isEmpty: scala.Boolean;
|
||||
def head: a;
|
||||
def tail: scala.List[a];
|
||||
def ::[b >: a](b): scala.List[b];
|
||||
def :::[b >: a](scala.List[b]): scala.List[b];
|
||||
def reverse_:::[b >: a](scala.List[b]): scala.List[b];
|
||||
def length: scala.Int;
|
||||
def indices: scala.List[scala.Int];
|
||||
def elements: scala.Iterator[a];
|
||||
override def toList: scala.List[a];
|
||||
def init: scala.List[a];
|
||||
def last: a;
|
||||
override def take(scala.Int): scala.List[a];
|
||||
override def drop(scala.Int): scala.List[a];
|
||||
def takeRight(scala.Int): scala.List[a];
|
||||
def dropRight(scala.Int): scala.List[a];
|
||||
def splitAt(scala.Int): scala.Tuple2[scala.List[a], scala.List[a]];
|
||||
def takeWhile(a => scala.Boolean): scala.List[a];
|
||||
def dropWhile(a => scala.Boolean): scala.List[a];
|
||||
def span(a => scala.Boolean): scala.Tuple2[scala.List[a], scala.List[a]];
|
||||
def break(a => scala.Boolean): scala.Tuple2[scala.List[a], scala.List[a]];
|
||||
def apply(scala.Int): a;
|
||||
def map[b](a => b): scala.List[b];
|
||||
def reverseMap[b](a => b): scala.List[b];
|
||||
override def foreach(a => scala.Unit): scala.Unit;
|
||||
def filter(a => scala.Boolean): scala.List[a];
|
||||
def remove(a => scala.Boolean): scala.List[a];
|
||||
def partition(a => scala.Boolean): scala.Tuple2[scala.List[a], scala.List[a]];
|
||||
def sort((a, a) => scala.Boolean): scala.List[a];
|
||||
def count(a => scala.Boolean): scala.Int;
|
||||
override def forall(a => scala.Boolean): scala.Boolean;
|
||||
override def exists(a => scala.Boolean): scala.Boolean;
|
||||
def contains(scala.Any): scala.Boolean;
|
||||
override def find(a => scala.Boolean): scala.Option[a];
|
||||
override def foldLeft[b](b)((b, a) => b): b;
|
||||
override def foldRight[b](b)((a, b) => b): b;
|
||||
def reduceLeft[b >: a]((b, b) => b): b;
|
||||
def reduceRight[b >: a]((b, b) => b): b;
|
||||
def flatMap[b](a => scala.List[b]): scala.List[b];
|
||||
def reverse: scala.List[a];
|
||||
def mkString(java.lang.String, java.lang.String, java.lang.String): java.lang.String;
|
||||
override def toString(): java.lang.String;
|
||||
def zip[b](scala.List[b]): scala.List[scala.Tuple2[a, b]];
|
||||
def zipAll[c >: a, b](scala.List[b], c, b): scala.List[scala.Tuple2[c, b]];
|
||||
def union[b >: a](scala.List[b]): scala.List[b];
|
||||
def diff[b >: a](scala.List[b]): scala.List[b];
|
||||
def intersect[b >: a](scala.List[b]): scala.List[b];
|
||||
def removeDuplicates: scala.List[a]
|
||||
}
|
||||
object List extends scala.AnyRef with scala.ScalaObject {
|
||||
final def apply[A](A*): scala.List[A];
|
||||
final def range(scala.Int, scala.Int): scala.List[scala.Int];
|
||||
final def range(scala.Int, scala.Int, scala.Int): scala.List[scala.Int];
|
||||
final def range(scala.Int, scala.Int, scala.Int => scala.Int): scala.List[scala.Int];
|
||||
final def make[a](scala.Int, a): scala.List[a];
|
||||
final def tabulate[a](scala.Int, scala.Int => a): scala.List[a];
|
||||
final def flatten[a](scala.List[scala.List[a]]): scala.List[a];
|
||||
final def unzip[a, b](scala.List[scala.Tuple2[a, b]]): scala.Tuple2[scala.List[a], scala.List[b]];
|
||||
final def fromIterator[a](scala.Iterator[a]): scala.List[a];
|
||||
final def fromArray[a](scala.Array[a]): scala.List[a];
|
||||
final def fromArray[a](scala.Array[a], scala.Int, scala.Int): scala.List[a];
|
||||
final def fromString(java.lang.String, scala.Char): scala.List[java.lang.String];
|
||||
final def fromString(java.lang.String): scala.List[scala.Char];
|
||||
final def toString(scala.List[scala.Char]): java.lang.String;
|
||||
final def map2[a, b, c](scala.List[a], scala.List[b])((a, b) => c): scala.List[c];
|
||||
final def mapConserve[a <: scala.AnyRef](scala.List[a])(a => a): scala.List[a];
|
||||
final def map3[a, b, c, d](scala.List[a], scala.List[b], scala.List[c])((a, b, c) => d): scala.List[d];
|
||||
final def forall2[a, b](scala.List[a], scala.List[b])((a, b) => scala.Boolean): scala.Boolean;
|
||||
final def exists2[a, b](scala.List[a], scala.List[b])((a, b) => scala.Boolean): scala.Boolean;
|
||||
final def transpose[a](scala.List[scala.List[a]]): scala.List[scala.List[a]];
|
||||
final def list2ordered[a <% scala.Ordered[a]](a => scala.Ordered[a])(scala.List[a]): scala.Ordered[scala.List[a]];
|
||||
final def view[a <% scala.Ordered[a]](a => scala.Ordered[a])(scala.List[a]): scala.Ordered[scala.List[a]]
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
p.x = 5
|
||||
p.c = java.awt.Color[r=255,g=0,b=0]
|
||||
p.getX() = 5.0
|
||||
p.getC() = java.awt.Color[r=255,g=0,b=0]
|
|
@ -1,24 +0,0 @@
|
|||
//############################################################################
|
||||
// Test Java interaction
|
||||
//############################################################################
|
||||
// $Id$
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Point;
|
||||
|
||||
class ColoredPoint(x: Int, y: Int, c_ : Color) extends Point(x, y) {
|
||||
val c: Color = c_;
|
||||
def getC(): Color = c;
|
||||
}
|
||||
|
||||
object Test {
|
||||
def main(args: Array[String]): Unit = {
|
||||
val p = new ColoredPoint(5,7,Color.RED);
|
||||
System.out.println("p.x = " + p.x);
|
||||
System.out.println("p.c = " + p.c);
|
||||
System.out.println("p.getX() = " + p.getX());
|
||||
System.out.println("p.getC() = " + p.getC());
|
||||
}
|
||||
}
|
||||
|
||||
//############################################################################
|
|
@ -1,72 +0,0 @@
|
|||
===== polymorphic classes
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
===== nested classes
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
===== classes nested inside functions
|
||||
true
|
||||
true
|
||||
true
|
||||
===== type paramater variance
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
===== singleton types
|
||||
true
|
||||
true
|
||||
===== compound types
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
===== null
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
===== default value
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
===== arrays
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
|
@ -1,200 +0,0 @@
|
|||
class C[T](x: T) { override def toString(): String = x.toString(); }
|
||||
|
||||
object TestPolymorphicClasses {
|
||||
def main(args: Array[String]): Unit = {
|
||||
Console.println("===== polymorphic classes");
|
||||
Console.println(new C("true"));
|
||||
Console.println(new C(true));
|
||||
Console.println((new C("a")).isInstanceOf[C[String]]);
|
||||
Console.println(!(new C(42)).isInstanceOf[C[String]]);
|
||||
}
|
||||
}
|
||||
|
||||
class Outer {
|
||||
class Inner;
|
||||
}
|
||||
|
||||
class SubOuter extends Outer {
|
||||
class SubInner extends Inner;
|
||||
}
|
||||
|
||||
object TestNestedClasses {
|
||||
def main(args: Array[String]): Unit = {
|
||||
Console.println("===== nested classes");
|
||||
val o1 = new Outer;
|
||||
val i1 = new o1.Inner;
|
||||
val o2 = new Outer;
|
||||
val i2 = new o2.Inner;
|
||||
Console.println( i1.isInstanceOf[o1.Inner]);
|
||||
Console.println( i2.isInstanceOf[o2.Inner]);
|
||||
Console.println(!i1.isInstanceOf[o2.Inner]);
|
||||
Console.println(!i2.isInstanceOf[o1.Inner]);
|
||||
val so1 = new SubOuter;
|
||||
val si1 = new so1.SubInner;
|
||||
val i3 = new so1.Inner;
|
||||
Console.println( si1.isInstanceOf[so1.Inner]);
|
||||
Console.println(!si1.isInstanceOf[o1.Inner]);
|
||||
Console.println(! i3.isInstanceOf[so1.SubInner]);
|
||||
// Console.println( i3.isInstanceOf[Outer#SubInner]);
|
||||
// Console.println( i3.isInstanceOf[Outer#Inner]);
|
||||
}
|
||||
}
|
||||
|
||||
object TestClassesInsideFunctions {
|
||||
def f(x: String): ScalaObject = {
|
||||
class C { override def toString() = x; };
|
||||
new C
|
||||
}
|
||||
def main(args: Array[String]): Unit = {
|
||||
Console.println("===== classes nested inside functions");
|
||||
val c1 = f("true");
|
||||
val c2 = f("true");
|
||||
Console.println(c1);
|
||||
Console.println(c2);
|
||||
Console.println(!c1.getScalaType().isSameType(c2.getScalaType()));
|
||||
}
|
||||
}
|
||||
|
||||
class Invariant[T];
|
||||
class Covariant[+T];
|
||||
class Contravariant[-T];
|
||||
|
||||
class MultiVariant[T1, -T2, +T3, T4, -T5, +T6];
|
||||
|
||||
object TestVariance {
|
||||
def main(args: Array[String]): Unit = {
|
||||
Console.println("===== type paramater variance");
|
||||
val invO = new Invariant[Object];
|
||||
val invS = new Invariant[String];
|
||||
Console.println( invO.isInstanceOf[Invariant[Object]]);
|
||||
Console.println(!invO.isInstanceOf[Invariant[String]]);
|
||||
Console.println(!invS.isInstanceOf[Invariant[Object]]);
|
||||
Console.println( invS.isInstanceOf[Invariant[String]]);
|
||||
val covO = new Covariant[Object];
|
||||
val covS = new Covariant[String];
|
||||
Console.println( covO.isInstanceOf[Covariant[Object]]);
|
||||
Console.println(!covO.isInstanceOf[Covariant[String]]);
|
||||
Console.println( covS.isInstanceOf[Covariant[Object]]);
|
||||
Console.println( covS.isInstanceOf[Covariant[String]]);
|
||||
val conO = new Contravariant[Object];
|
||||
val conS = new Contravariant[String];
|
||||
Console.println( conO.isInstanceOf[Contravariant[Object]]);
|
||||
Console.println( conO.isInstanceOf[Contravariant[String]]);
|
||||
Console.println(!conS.isInstanceOf[Contravariant[Object]]);
|
||||
Console.println( conS.isInstanceOf[Contravariant[String]]);
|
||||
val mulO = new MultiVariant[Object,Object,Object,Object,Object,Object];
|
||||
val mulS = new MultiVariant[String,String,String,String,String,String];
|
||||
Console.println( mulO.isInstanceOf[MultiVariant[Object,Object,Object,Object,Object,Object]]);
|
||||
Console.println( mulO.isInstanceOf[MultiVariant[Object,String,Object,Object,String,Object]]);
|
||||
Console.println( mulS.isInstanceOf[MultiVariant[String,String,String,String,String,String]]);
|
||||
Console.println(!mulS.isInstanceOf[MultiVariant[Object,Object,Object,Object,Object,Object]]);
|
||||
Console.println( mulS.isInstanceOf[MultiVariant[String,String,Object,String,String,Object]]);
|
||||
}
|
||||
}
|
||||
|
||||
object TestSingletonTypes {
|
||||
def main(args: Array[String]): Unit = {
|
||||
Console.println("===== singleton types");
|
||||
val x: String = "x";
|
||||
val y: String = "y";
|
||||
Console.println( x.isInstanceOf[x.type]);
|
||||
Console.println(!x.isInstanceOf[y.type]);
|
||||
}
|
||||
}
|
||||
|
||||
object TestCompoundTypes {
|
||||
class C, D;
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
Console.println("===== compound types");
|
||||
val c = new C;
|
||||
val d = new D;
|
||||
Console.println(!c.isInstanceOf[C with D]);
|
||||
Console.println(!c.isInstanceOf[D with C]);
|
||||
Console.println(!d.isInstanceOf[C with D]);
|
||||
Console.println(!d.isInstanceOf[D with C]);
|
||||
|
||||
val cd = new C with D;
|
||||
val dc = new D with C;
|
||||
Console.println(cd.isInstanceOf[C]);
|
||||
Console.println(cd.isInstanceOf[D]);
|
||||
Console.println(cd.isInstanceOf[C with D]);
|
||||
Console.println(cd.isInstanceOf[D with C]);
|
||||
Console.println(dc.isInstanceOf[C]);
|
||||
Console.println(dc.isInstanceOf[D]);
|
||||
Console.println(dc.isInstanceOf[C with D]);
|
||||
Console.println(dc.isInstanceOf[D with C]);
|
||||
}
|
||||
}
|
||||
|
||||
object TestNull {
|
||||
class C;
|
||||
def main(args: Array[String]): Unit = {
|
||||
Console.println("===== null");
|
||||
Console.println(!null.isInstanceOf[Any]);
|
||||
Console.println(!null.isInstanceOf[AnyRef]);
|
||||
Console.println(!null.isInstanceOf[AllRef]);
|
||||
Console.println(!null.isInstanceOf[C]);
|
||||
Console.println((null.asInstanceOf[AnyRef]) == null);
|
||||
try {
|
||||
Console.println(null.asInstanceOf[Any]);
|
||||
Console.println("false (THIS SHOULD NOT BE PRINTED!!!)");
|
||||
} catch {
|
||||
case _: ClassCastException => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object TestDefaultValue {
|
||||
def defaultValue[T]: T = {
|
||||
class Cell[T] { var x: T = _; }
|
||||
return (new Cell[T]).x;
|
||||
}
|
||||
|
||||
class C;
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
Console.println("===== default value");
|
||||
Console.println(defaultValue[Boolean] == false);
|
||||
Console.println(defaultValue[Byte] == 0.asInstanceOf[Byte]);
|
||||
Console.println(defaultValue[Short] == 0.asInstanceOf[Short]);
|
||||
Console.println(defaultValue[Int] == 0);
|
||||
Console.println(defaultValue[Long] == 0.asInstanceOf[Long]);
|
||||
Console.println(defaultValue[Float] == 0.asInstanceOf[Float]);
|
||||
Console.println(defaultValue[Double] == 0.asInstanceOf[Double]);
|
||||
Console.println(defaultValue[String] == null);
|
||||
Console.println(defaultValue[C] == null);
|
||||
}
|
||||
}
|
||||
|
||||
object TestArrays {
|
||||
def isInst[T](x: Any): Boolean = x.isInstanceOf[T];
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
Console.println("===== arrays");
|
||||
|
||||
import java.lang.reflect.{Array => JArray};
|
||||
|
||||
val iArray = JArray.newInstance(Integer.TYPE, 5);
|
||||
Console.println(iArray.isInstanceOf[Array[Int]]);
|
||||
Console.println(isInst[Array[Int]](iArray));
|
||||
|
||||
val oArray = JArray.newInstance(Class.forName("java.lang.Object"), 5);
|
||||
Console.println(oArray.isInstanceOf[Array[Object]]);
|
||||
Console.println(isInst[Array[Object]](oArray));
|
||||
}
|
||||
}
|
||||
|
||||
object Test {
|
||||
def main(args: Array[String]): Unit = {
|
||||
TestPolymorphicClasses.main(args);
|
||||
TestNestedClasses.main(args);
|
||||
TestClassesInsideFunctions.main(args);
|
||||
TestVariance.main(args);
|
||||
TestSingletonTypes.main(args);
|
||||
TestCompoundTypes.main(args);
|
||||
TestNull.main(args);
|
||||
TestDefaultValue.main(args);
|
||||
TestArrays.main(args);
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
//############################################################################
|
||||
// Bug 281
|
||||
|
||||
class Bug281A extends java.util.Hashtable {
|
||||
class B { def f = rehash() };
|
||||
}
|
||||
|
||||
object Test {
|
||||
def main(args: Array[String]): Unit = {
|
||||
val a = new Bug281A;
|
||||
val b = new a.B;
|
||||
b.f
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
x1 = List()
|
||||
y1 = List()
|
||||
x1 eq y1: true - y1 eq x1: true
|
||||
|
||||
x2 = None
|
||||
y2 = None
|
||||
x2 eq y2: true - y2 eq x2: true
|
||||
|
||||
x3 = Array[1,2,3]
|
||||
y3 = Array[1,2,3]
|
||||
arrayEquals(x3, y3): true
|
||||
|
||||
x4 = <na>
|
||||
y4 = <na>
|
||||
x4(2): 4 - y4(2): 4
|
||||
|
||||
x = List((buffers,20),(layers,2),(title,3))
|
||||
y = List((buffers,20),(layers,2),(title,3))
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = {buffers -> 20, layers -> 2, title -> 3}
|
||||
y = {buffers -> 20, layers -> 2, title -> 3}
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = {1}
|
||||
y = {1}
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = {5, 3}
|
||||
y = {5, 3}
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = Queue(a,b,c)
|
||||
y = Queue(a,b,c)
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = Stack(c, b, a)
|
||||
y = Stack(c, b, a)
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = {42 -> FortyTwo}
|
||||
y = {42 -> FortyTwo}
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = {0, 2}
|
||||
y = {0, 2}
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = {title -> 3, buffers -> 20, layers -> 2}
|
||||
y = {title -> 3, buffers -> 20, layers -> 2}
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = {0, 8, 9}
|
||||
y = {0, 8, 9}
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = {title, buffers, layers}
|
||||
y = {title, buffers, layers}
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = LinkedList(2, 3)
|
||||
y = LinkedList(2, 3)
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = Queue(20, 2, 3)
|
||||
y = Queue(20, 2, 3)
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = Stack(20, 2, 3)
|
||||
y = Stack(20, 2, 3)
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = <html><title>title</title><body></body></html>
|
||||
y = <html><title>title</title><body></body></html>
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = <html><body><table cellspacing="0" cellpadding="2"><tr><th>Last Name</th><th>First Name</th></tr><tr><td>Tom</td><td>20</td></tr> <tr><td>Bob</td><td>22</td></tr> <tr><td>James</td><td>19</td></tr></table></body></html>
|
||||
y = <html><body><table cellspacing="0" cellpadding="2"><tr><th>Last Name</th><th>First Name</th></tr><tr><td>Tom</td><td>20</td></tr> <tr><td>Bob</td><td>22</td></tr> <tr><td>James</td><td>19</td></tr></table></body></html>
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = Tim
|
||||
y = Tim
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = Bob
|
||||
y = Bob
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = John
|
||||
y = John
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = Bill
|
||||
y = Bill
|
||||
x equals y: true - y equals x: true
|
||||
|
||||
x = Paul
|
||||
y = Paul
|
||||
x equals y: true - y equals x: true
|
||||
|
|
@ -1,316 +0,0 @@
|
|||
//############################################################################
|
||||
// Serialization
|
||||
//############################################################################
|
||||
// $Id$
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
object EqualityTest {
|
||||
def check[A, B](x: A, y: B): Unit = {
|
||||
System.out.println("x = " + x);
|
||||
System.out.println("y = " + y);
|
||||
System.out.println(
|
||||
"x equals y: " + (x equals y) + " - y equals x: " + (y equals x));
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
object Serialize {
|
||||
def write[A](o: A): Array[Byte] = { // throws Exception
|
||||
val ba = new java.io.ByteArrayOutputStream(512);
|
||||
val out = new java.io.ObjectOutputStream(ba);
|
||||
out.writeObject(o);
|
||||
out.close();
|
||||
ba.toByteArray()
|
||||
}
|
||||
def read[A](buffer: Array[Byte]): A = { // throws Exception
|
||||
val in =
|
||||
new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer));
|
||||
in.readObject().asInstanceOf[A]
|
||||
}
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
// Test classes in package "scala"
|
||||
|
||||
[serializable]
|
||||
object Test1_scala {
|
||||
private def arrayToString[A](arr: Array[A]): String =
|
||||
List.fromArray(arr).mkString("Array[",",","]");
|
||||
private def arrayEquals[A, B](a1: Array[A], a2: Array[B]) =
|
||||
(a1.length == a2.length) &&
|
||||
(Iterator.range(0, a1.length) forall { i => a1(i) == a2(i) });
|
||||
val x1 = Nil;
|
||||
val x2 = None;
|
||||
val x3 = Array(1, 2, 3);
|
||||
val x4 = x: Int => 2 * x;
|
||||
|
||||
try {
|
||||
val y1: List[All] = Serialize.read(Serialize.write(x1));
|
||||
val y2: Option[All] = Serialize.read(Serialize.write(x2));
|
||||
val y3: Array[Int] = Serialize.read(Serialize.write(x3));
|
||||
val y4: Function[Int, Int] = Serialize.read(Serialize.write(x4));
|
||||
|
||||
System.out.println("x1 = " + x1);
|
||||
System.out.println("y1 = " + y1);
|
||||
System.out.println("x1 eq y1: " + (x1 eq y1) + " - y1 eq x1: " + (y1 eq x1));
|
||||
System.out.println();
|
||||
System.out.println("x2 = " + x2);
|
||||
System.out.println("y2 = " + y2);
|
||||
System.out.println("x2 eq y2: " + (x2 eq y2) + " - y2 eq x2: " + (y2 eq x2));
|
||||
System.out.println();
|
||||
System.out.println("x3 = " + arrayToString(x3));
|
||||
System.out.println("y3 = " + arrayToString(y3));
|
||||
System.out.println("arrayEquals(x3, y3): " + arrayEquals(x3, y3));
|
||||
System.out.println();
|
||||
System.out.println("x4 = <na>");
|
||||
System.out.println("y4 = <na>");
|
||||
System.out.println("x4(2): " + x4(2) + " - y4(2): " + y4(2));
|
||||
System.out.println();
|
||||
}
|
||||
catch {
|
||||
case e: Exception =>
|
||||
e.printStackTrace();
|
||||
System.out.println("Error in Test1_scala: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
// Test classes in package "scala.collection.immutable"
|
||||
[serializable]
|
||||
object Test2_immutable {
|
||||
import scala.collection.immutable.{BitSet,ListMap,ListSet,Queue,Stack,
|
||||
TreeSet,TreeMap};
|
||||
|
||||
val x1 = List(
|
||||
Pair("buffers", 20),
|
||||
Pair("layers", 2),
|
||||
Pair("title", 3)
|
||||
);
|
||||
|
||||
val x2 = new ListMap[String, Int]
|
||||
.incl(Pair("buffers", 20))
|
||||
.incl(Pair("layers", 2))
|
||||
.incl(Pair("title", 3));
|
||||
|
||||
val x3 = new BitSet(4, Array(2), true);
|
||||
|
||||
val x4 = new ListSet[Int]().incl(3).incl(5);
|
||||
|
||||
val x5 = new Queue("a", "b", "c");
|
||||
|
||||
val x6 = new Stack().push("a", "b", "c");
|
||||
|
||||
val x7 = new TreeMap[Int, String] + 42 -> "FortyTwo";
|
||||
|
||||
val x8 = new TreeSet[Int]().incl(2).incl(0);
|
||||
|
||||
try {
|
||||
val y1: List[Pair[String, Int]] = Serialize.read(Serialize.write(x1));
|
||||
val y2: ListMap[String, Int] = Serialize.read(Serialize.write(x2));
|
||||
val y3: BitSet = Serialize.read(Serialize.write(x3));
|
||||
val y4: ListSet[Int] = Serialize.read(Serialize.write(x4));
|
||||
val y5: Queue[String] = Serialize.read(Serialize.write(x5));
|
||||
val y6: Stack[String] = Serialize.read(Serialize.write(x6));
|
||||
val y7: TreeMap[Int, String] = Serialize.read(Serialize.write(x7));
|
||||
val y8: TreeSet[Int] = Serialize.read(Serialize.write(x8));
|
||||
|
||||
EqualityTest.check(x1, y1);
|
||||
EqualityTest.check(x2, y2);
|
||||
EqualityTest.check(x3, y3);
|
||||
EqualityTest.check(x4, y4);
|
||||
EqualityTest.check(x5, y5);
|
||||
EqualityTest.check(x6, y6);
|
||||
EqualityTest.check(x7, y7);
|
||||
EqualityTest.check(x8, y8);
|
||||
}
|
||||
catch {
|
||||
case e: Exception =>
|
||||
System.out.println("Error in Test2_immutable: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
// Test classes in package "scala.collection.mutable"
|
||||
|
||||
object Test3_mutable {
|
||||
import scala.collection.mutable.{BitSet,HashMap,HashSet,LinkedList,
|
||||
Queue,Stack};
|
||||
|
||||
val x1 = new HashMap[String, Int];
|
||||
x1 ++= Test2_immutable.x1;
|
||||
|
||||
val x2 = new BitSet();
|
||||
x2.set(0);
|
||||
x2.set(8);
|
||||
x2.set(9);
|
||||
|
||||
val x3 = new HashSet[String];
|
||||
x3 ++= Test2_immutable.x1.map(p => p._1);
|
||||
|
||||
val x4 = new LinkedList[Int](2, null);
|
||||
x4.append(new LinkedList(3, null));
|
||||
|
||||
val x5 = new Queue[Int];
|
||||
x5 ++= Test2_immutable.x1.map(p => p._2);
|
||||
|
||||
val x6 = new Stack[Int];
|
||||
x6 ++= x5;
|
||||
|
||||
try {
|
||||
val y1: HashMap[String, Int] = Serialize.read(Serialize.write(x1));
|
||||
val y2: BitSet = Serialize.read(Serialize.write(x2));
|
||||
val y3: HashSet[String] = Serialize.read(Serialize.write(x3));
|
||||
val y4: LinkedList[Int] = Serialize.read(Serialize.write(x4));
|
||||
val y5: Queue[Int] = Serialize.read(Serialize.write(x5));
|
||||
val y6: Stack[Int] = Serialize.read(Serialize.write(x6));
|
||||
|
||||
EqualityTest.check(x1, y1);
|
||||
EqualityTest.check(x2, y2);
|
||||
EqualityTest.check(x3, y3);
|
||||
EqualityTest.check(x4, y4);
|
||||
EqualityTest.check(x5, y5);
|
||||
EqualityTest.check(x6, y6);
|
||||
}
|
||||
catch {
|
||||
case e: Exception =>
|
||||
System.out.println("Error in Test3_mutable: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
// Test classes in package "scala.xml"
|
||||
|
||||
object Test4_xml {
|
||||
import scala.xml.{Elem};
|
||||
|
||||
val x1 = <html><title>title</title><body></body></html>;
|
||||
|
||||
case class Person(name: String, age: Int);
|
||||
|
||||
class AddressBook(a: Person*) {
|
||||
private val people: List[Person] = a.toList;
|
||||
def toXHTML =
|
||||
<table cellpadding="2" cellspacing="0">
|
||||
<tr>
|
||||
<th>Last Name</th>
|
||||
<th>First Name</th>
|
||||
</tr>
|
||||
{ for (val p <- people) yield
|
||||
<tr>
|
||||
<td> { p.name } </td>
|
||||
<td> { p.age.toString() } </td>
|
||||
</tr> }
|
||||
</table>;
|
||||
}
|
||||
|
||||
val people = new AddressBook(
|
||||
Person("Tom", 20),
|
||||
Person("Bob", 22),
|
||||
Person("James", 19));
|
||||
|
||||
val x2 =
|
||||
<html>
|
||||
<body>
|
||||
{ people.toXHTML }
|
||||
</body>
|
||||
</html>;
|
||||
|
||||
try {
|
||||
val y1: scala.xml.Elem = Serialize.read(Serialize.write(x1));
|
||||
val y2: scala.xml.Elem = Serialize.read(Serialize.write(x2));
|
||||
|
||||
EqualityTest.check(x1, y1);
|
||||
EqualityTest.check(x2, y2);
|
||||
}
|
||||
catch {
|
||||
case e: Exception =>
|
||||
System.out.println("Error in Test4_xml: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
// Test user-defined classes WITHOUT nesting
|
||||
|
||||
[serializable]
|
||||
class Person(_name: String) {
|
||||
private var name = _name;
|
||||
override def toString() = name;
|
||||
override def equals(that: Any): Boolean =
|
||||
that.isInstanceOf[Person] &&
|
||||
(name == that.asInstanceOf[Person].name);
|
||||
}
|
||||
|
||||
[serializable]
|
||||
class Employee(_name: String) {
|
||||
private var name = _name;
|
||||
override def toString() = name;
|
||||
}
|
||||
[serializable]
|
||||
object bob extends Employee("Bob");
|
||||
|
||||
object Test5 {
|
||||
val x1 = new Person("Tim");
|
||||
val x2 = bob;
|
||||
|
||||
try {
|
||||
val y1: Person = Serialize.read(Serialize.write(x1));
|
||||
val y2: Employee = Serialize.read(Serialize.write(x2));
|
||||
|
||||
EqualityTest.check(x1, y1);
|
||||
EqualityTest.check(x2, y2);
|
||||
}
|
||||
catch {
|
||||
case e: Exception =>
|
||||
System.out.println("Error in Test5: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
// Test user-defined classes WITH nesting
|
||||
|
||||
[serializable]
|
||||
object Test6 {
|
||||
[serializable]
|
||||
object bill extends Employee("Bill") {
|
||||
val x = paul;
|
||||
}
|
||||
[serializable]
|
||||
object paul extends Person("Paul") {
|
||||
val x = 4; // bill; => StackOverflowException !!!
|
||||
}
|
||||
val x1 = new Person("John");
|
||||
val x2 = bill;
|
||||
val x3 = paul;
|
||||
|
||||
try {
|
||||
val y1: Person = Serialize.read(Serialize.write(x1));
|
||||
val y2: Employee = Serialize.read(Serialize.write(x2));
|
||||
val y3: Person = Serialize.read(Serialize.write(x3));
|
||||
|
||||
EqualityTest.check(x1, y1);
|
||||
EqualityTest.check(x2, y2);
|
||||
EqualityTest.check(x3, y3);
|
||||
}
|
||||
catch {
|
||||
case e: Exception =>
|
||||
System.out.println("Error in Test6: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
// Test code
|
||||
|
||||
object Test {
|
||||
def main(args: Array[String]): Unit = {
|
||||
Test1_scala;
|
||||
Test2_immutable;
|
||||
Test3_mutable;
|
||||
Test4_xml;
|
||||
Test5;
|
||||
Test6
|
||||
}
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
passed ok
|
||||
equality
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
xpath \
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
xpath \\ DESCENDANTS
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
<book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book>
|
||||
attribute value normalization
|
||||
passed ok
|
||||
passed ok
|
|
@ -1,205 +0,0 @@
|
|||
import java.io.StringReader;
|
||||
import org.xml.sax.InputSource;
|
||||
import scala.xml._;
|
||||
import scala.util.logging._;
|
||||
|
||||
import scala.testing.UnitTest._ ;
|
||||
|
||||
object Test {
|
||||
def main(args:Array[String]) = {
|
||||
val e: scala.xml.MetaData = Null; //Node.NoAttributes;
|
||||
val sc: scala.xml.NamespaceBinding = TopScope;
|
||||
|
||||
val xmlFile1 = "<hello><world/></hello>";
|
||||
val isrc1 = new InputSource( new StringReader(xmlFile1) );
|
||||
val parsedxml1 = XML.load(isrc1);
|
||||
val isrc11 = new InputSource( new StringReader( xmlFile1 ) );
|
||||
val parsedxml11 = XML.load(isrc11);
|
||||
|
||||
val c = new Node {
|
||||
def label = "hello";
|
||||
override def hashCode() =
|
||||
Utility.hashCode(prefix, label, attributes.hashCode(), scope.hashCode(), child);
|
||||
def child = Elem(null, "world", e, sc);
|
||||
//def attributes = e;
|
||||
override def text = "";
|
||||
};
|
||||
|
||||
assertSameElements( List( 3 ), List( 3 ));
|
||||
|
||||
Console.println("equality");
|
||||
assertEquals(c, parsedxml11);
|
||||
assertEquals(parsedxml1, parsedxml11);
|
||||
assertSameElements( List(parsedxml1), List(parsedxml11));
|
||||
assertSameElements( Iterator.fromArray(Predef.Array(parsedxml1)).toList, 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 );
|
||||
|
||||
assertEquals(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
|
||||
Console.println("xpath \\");
|
||||
|
||||
|
||||
assertSameElements( parsedxml1 \ "_" , List( Elem(null,"world",e,sc) ) );
|
||||
|
||||
assertSameElements( parsedxml1 \ "world", List( Elem(null,"world",e,sc) ) );
|
||||
|
||||
/*
|
||||
Console.println( parsedxml2 \ "_" );
|
||||
Console.println( (parsedxml2 \ "_" ).elements);
|
||||
for( val i <- (parsedxml2 \ "_" ).elements) {
|
||||
Console.println( i );
|
||||
};
|
||||
*/
|
||||
|
||||
assertSameElements(
|
||||
parsedxml2 \ "_" ,
|
||||
|
||||
List(
|
||||
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"))),
|
||||
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 );
|
||||
|
||||
assertSameElements(
|
||||
parsedxml2 \ "book",
|
||||
|
||||
List(
|
||||
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"))),
|
||||
Elem(null,"book",e,sc,
|
||||
Elem(null,"author", e, sc, Text("John Mitchell")),
|
||||
Elem(null,"title" , e, sc, Text("Foundations of Programming Languages")))
|
||||
)
|
||||
);
|
||||
|
||||
assertSameElements(
|
||||
|
||||
parsedxml2 \ "_" \ "_",
|
||||
|
||||
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"))
|
||||
)
|
||||
);
|
||||
|
||||
assertSameElements(
|
||||
|
||||
parsedxml2 \ "_" \ "author",
|
||||
|
||||
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"))
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
assertSameElements( (parsedxml2 \ "_" \ "_" \ "author"), List() );
|
||||
|
||||
Console.println("xpath \\\\ DESCENDANTS");
|
||||
|
||||
assertSameElements(
|
||||
|
||||
parsedxml2 \\ "author",
|
||||
|
||||
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"))
|
||||
)
|
||||
|
||||
);
|
||||
assertEquals(
|
||||
|
||||
(new NodeSeq { val theSeq = List( parsedxml2 ) }) \\ "_",
|
||||
|
||||
List(
|
||||
Elem(null,"bib",e,sc,
|
||||
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"))),
|
||||
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,"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"))),
|
||||
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")
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
assertSameElements(
|
||||
|
||||
parsedxml2 \\ "title",
|
||||
|
||||
List(
|
||||
Elem(null,"title", e, sc, Text("Data on ze web")),
|
||||
Elem(null,"title", e, sc, Text("Foundations of Programming Languages")))
|
||||
);
|
||||
|
||||
|
||||
Console.println(
|
||||
(parsedxml2 \\ "book" ){ n:Node => n \ "title" == "Data on ze web" }
|
||||
);
|
||||
|
||||
// test unicode escapes backslash u
|
||||
|
||||
Console println ("attribute value normalization");
|
||||
val xmlAttrValueNorm = "<personne id='p0003' nom='Şahingöz' />";
|
||||
{
|
||||
val isrcA = new InputSource( new StringReader(xmlAttrValueNorm) );
|
||||
val parsedxmlA = XML.load(isrcA);
|
||||
val c = (parsedxmlA \ "@nom").text.charAt(0);
|
||||
//Console.println("char '"+c+"' \u015e");
|
||||
assertTrue(c == '\u015e');
|
||||
}
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
Test01Literals
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
ws trimming in patterns
|
||||
passed ok
|
||||
passed ok
|
||||
<testTag ab="bkla" value="This is a test."></testTag>
|
||||
<testTag bla="foo" value="42"></testTag>
|
||||
Test02Embed
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
Test03Servlet
|
||||
<html><head><title>ModularFormatting</title></head><body><h2>Welcome</h2><p>What follows is an example of modular formatting.</p><p><table align="center"><tr><td bgcolor="#AAAAFF" color="#222255"><h1>message</h1></td></tr></table></p><p>1a23.23</p><p><table align="center"><tr><td bgcolor="#AAAAFF" color="#222255"><h1>message</h1></td></tr></table> <table align="center"><tr><td bgcolor="#AAAAFF" color="#222255"><h1>message</h1></td></tr></table></p><hr></hr><p>Complicated layout tasks can be encapsulated and outsourced.</p><h2>Bye!</h2></body></html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ModularFormatting</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Welcome</h2>
|
||||
<p>What follows is an example of modular formatting.</p>
|
||||
<p>
|
||||
<table align="center">
|
||||
<tr>
|
||||
<td bgcolor="#AAAAFF" color="#222255">
|
||||
<h1>message</h1>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</p>
|
||||
<p>1a23.23</p>
|
||||
<p>
|
||||
<table align="center">
|
||||
<tr>
|
||||
<td bgcolor="#AAAAFF" color="#222255">
|
||||
<h1>message</h1>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table align="center">
|
||||
<tr>
|
||||
<td bgcolor="#AAAAFF" color="#222255">
|
||||
<h1>message</h1>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</p>
|
||||
<hr></hr>
|
||||
<p>Complicated layout tasks can be encapsulated and outsourced.</p>
|
||||
<h2>Bye!</h2>
|
||||
</body>
|
||||
</html>
|
||||
Test04
|
||||
List(<foo></foo>,<bar>Text</bar>,<foo></foo>)
|
||||
<foo></foo>
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
Test05Ref
|
||||
<foo>{</foo>
|
||||
<foo> {<bar><baz></baz></bar><bar></bar></foo>
|
||||
namespace
|
||||
<bar:foo xmlns:bar="www.bar.com" xmlns="www.baz.com"><baz></baz></bar:foo>
|
|
@ -1,306 +0,0 @@
|
|||
//############################################################################
|
||||
// XML Literals
|
||||
//############################################################################
|
||||
// $Id$
|
||||
|
||||
import scala.testing.UnitTest._ ;
|
||||
|
||||
import scala.xml._ ;
|
||||
import scala.collection.immutable ;
|
||||
|
||||
|
||||
object Test {
|
||||
|
||||
val e = Node.NoAttributes;
|
||||
|
||||
/* a helper function to compare up to whitespace */
|
||||
|
||||
def noWS(x:String):String = {
|
||||
val res = new StringBuffer();
|
||||
var i = 0; while( i < x.length() ) {
|
||||
val c = x.charAt( i );
|
||||
c match {
|
||||
case ' ' | '\n' | '\t' =>
|
||||
case _ => res.append( c )
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
res.toString();
|
||||
}
|
||||
|
||||
|
||||
object Test01Literals {
|
||||
|
||||
|
||||
|
||||
/* === tags, elements === */
|
||||
|
||||
assertEquals( <hello></hello>.toString(),
|
||||
<hello ></hello>.toString()); /* ws in tags */
|
||||
|
||||
assertEquals( <hello></hello>.toString(),
|
||||
noWS(<hello > </hello>.toString()));
|
||||
|
||||
val xx3 = <hello>
|
||||
<world></world>
|
||||
<test/>
|
||||
<mars></mars></hello>;
|
||||
|
||||
val x3 = xx3.toString(); /* ws in element content */
|
||||
|
||||
//Console.println("tmp1:"+x3);
|
||||
//Console.println("tmp2:"+Elem(null,"mars",e,TopScope).toString() );
|
||||
assertEquals( noWS( x3 ),
|
||||
Elem(null,"hello",e,TopScope,
|
||||
Elem(null,"world",e,TopScope),
|
||||
Elem(null,"test",e,TopScope),
|
||||
Elem(null,"mars",e,TopScope)).toString() );
|
||||
|
||||
|
||||
Console.println("ws trimming in patterns");
|
||||
|
||||
assertEquals( true, <hello> <world/> </hello> match {
|
||||
case <hello> <world/> </hello> => true;
|
||||
case _ => false;} );
|
||||
|
||||
|
||||
/* === attributes === */
|
||||
|
||||
val z = <html>
|
||||
<body background="#FFFFFF">
|
||||
<h1>Hello World</h1>
|
||||
<p>Check the <a href="scala.epfl.ch">scala</a> page!</p>
|
||||
</body>
|
||||
</html>.toString();
|
||||
|
||||
assertEquals( noWS( z ), noWS(
|
||||
Elem(null,"html",e,TopScope,
|
||||
Elem(null,"body",e,TopScope,
|
||||
Elem(null,"h1",e,TopScope,Text("Hello World")),
|
||||
Elem(null,"p",e,TopScope,Text("Check the "),
|
||||
Elem(null,"a", e,TopScope,Text("scala"))
|
||||
% (new UnprefixedAttribute("href","scala.epfl.ch",Null)),
|
||||
Text("page!"))
|
||||
) % new UnprefixedAttribute("background","#FFFFFF",Null)
|
||||
).toString()
|
||||
));
|
||||
|
||||
/* === attributes are Scala expr === */
|
||||
|
||||
val testValue = "This is a test.";
|
||||
val testValue2 = 42;
|
||||
val page = <testTag value={ testValue } ab="bkla" />;
|
||||
val page2 = <testTag value={testValue2.toString()} bla="foo"></testTag>;
|
||||
|
||||
Console.println( page.toString() );
|
||||
Console.println( page2.toString() );
|
||||
|
||||
}
|
||||
|
||||
object Test02Embed {
|
||||
|
||||
/* === embedded Scala blocks === */
|
||||
|
||||
def computeDate() = {
|
||||
Elem(null,"date", e, TopScope, Text("now!"));
|
||||
}
|
||||
/* embedding Scala strings as text and elements */
|
||||
val sc = <hello>{ "World" }{ Text("42") }{ computeDate() }</hello>;
|
||||
|
||||
assertEquals( sc.child.elements.toList,
|
||||
List( Text("World"), Text("42"), Elem(null, "date", e,TopScope, Text("now!") ) ) );
|
||||
|
||||
assertEquals( sc.toString(),
|
||||
Elem(null,"hello",e,TopScope,Text("World42"),Elem(null,"date",e,TopScope, Text("now!"))).toString() );
|
||||
|
||||
def foo( m:Node ):String = m match {
|
||||
case <hello/> => "hello node"
|
||||
case <hallo ></hallo > => "hallo node"
|
||||
case <test>{ z }</test> => "test node:"+z
|
||||
case <list>{ e1:Node }{ e2:Node }{ _* }</list> => e1.toString() + e2.toString();
|
||||
}
|
||||
|
||||
assertEquals( foo(<hello/>), "hello node" );
|
||||
assertEquals( foo(<hallo/>), "hallo node" );
|
||||
assertEquals( foo(<test>42</test>), "test node:42" );
|
||||
assertEquals( foo(<list><a/><b><c/></b><d/><d/></list>),
|
||||
<a/>.toString() + <b><c/></b>.toString() );
|
||||
|
||||
val rows = <tr>
|
||||
<td>1.1</td><td>1.2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2.1</td><td>2.2</td>
|
||||
</tr>;
|
||||
|
||||
assertEquals( noWS( rows.toList.toString() ),
|
||||
noWS( List(Elem(null,"tr",e,TopScope,
|
||||
Elem(null,"td",e,TopScope,Text("1.1")),Elem(null,"td",e,TopScope, Text("1.2"))
|
||||
),
|
||||
Elem(null,"tr",e,TopScope,
|
||||
Elem(null,"td",e,TopScope,Text("2.1")),Elem(null,"td",e,TopScope,Text("2.2"))
|
||||
)
|
||||
).toString() )
|
||||
);
|
||||
val rows2 = <tr><!-- an XML comment --><?pinotext?><?pi text?></tr>;
|
||||
val rows3 = <tr> a <!-- an XML comment --> b <?pinotext?> c <?pi text?> d </tr>;
|
||||
|
||||
// these are not equal as comments are valid XML Info items.
|
||||
assertEquals( rows2, Elem(null,"tr",e,TopScope,Comment(" an XML comment "),ProcInstr("pinotext",""),ProcInstr("pi","text")));
|
||||
|
||||
assertEquals( rows3, Elem(null,"tr",e,TopScope,Text("a"),Comment(" an XML comment "),Text("b"),ProcInstr("pinotext",""),Text("c"),ProcInstr("pi","text"),Text("d")));
|
||||
|
||||
}
|
||||
|
||||
object Test03Servlet {
|
||||
|
||||
val headerMsg = Text("What follows is an example of modular formatting.");
|
||||
val footerMsg = Text("Complicated layout tasks can be encapsulated and outsourced.");
|
||||
|
||||
/** helper function for the main page, provides header and a footer
|
||||
*/
|
||||
def page( ns:Seq[Node] ) = {
|
||||
<html>
|
||||
<head>
|
||||
<title>ModularFormatting</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Welcome</h2>
|
||||
<p>
|
||||
{headerMsg }
|
||||
</p>
|
||||
<p>
|
||||
{ ns }
|
||||
</p>
|
||||
<p>
|
||||
{ 1 } {'a'} { 23.23 }
|
||||
</p>
|
||||
<p>
|
||||
{ for(val n <- ns.toList) yield { n::n::Nil } }
|
||||
</p>
|
||||
<hr/>
|
||||
<p>
|
||||
{footerMsg}
|
||||
</p>
|
||||
<h2>Bye!</h2>
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
|
||||
/** applies beautify to every element in a sequence
|
||||
*/
|
||||
def beautify( xs:Seq[Node] ):Seq[Node] = xs.toList.map { beautify }
|
||||
|
||||
/** this is a recursive procedure that adds some attributes to the tree
|
||||
*/
|
||||
def beautify( n:Node ):Node = n match {
|
||||
case <td>{xs @ _* }</td> =>
|
||||
<td bgcolor="#AAAAFF" color="#222255">{ xs }</td>
|
||||
|
||||
case <table>{ xs @ _* }</table> =>
|
||||
<table align="center">{ beautify( xs )}</table>
|
||||
|
||||
case Elem(null, label, _, _, xs @ _* ) =>
|
||||
new Elem(null, label, e, TopScope, beautify( xs ):_*)
|
||||
|
||||
case _ => n
|
||||
}
|
||||
|
||||
/** this function will take a node and put it in a table
|
||||
*/
|
||||
def format( msg:Node ):Node = {
|
||||
<table>
|
||||
<tr>
|
||||
<td>{ msg }</td>
|
||||
</tr>
|
||||
</table>
|
||||
}
|
||||
|
||||
/** returns a highlighted text node with the string given as arguemnt. if it
|
||||
* is null, supplies a default string.
|
||||
*/
|
||||
def getMessage( x:String ) = {
|
||||
if( x == null )
|
||||
<h1> This could be YOUR message ! </h1>
|
||||
else
|
||||
<h1> { Text( x ) } </h1>
|
||||
}
|
||||
|
||||
/** the entry method
|
||||
*/
|
||||
def doGetXML() = {
|
||||
beautify( page( List( format( getMessage( "message" ) )) ));
|
||||
//page( List( format( theMessage )));
|
||||
}
|
||||
|
||||
def main( args:Array[String] ) = {
|
||||
val x = doGetXML();
|
||||
Console.println( x );
|
||||
Console.println( new PrettyPrinter( 80, 2 ).format( x ));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
object Test04 {
|
||||
val sequence = <foo/>
|
||||
<bar>Text</bar>
|
||||
<foo/>;
|
||||
|
||||
Console.println( sequence );
|
||||
|
||||
val onlyOne = <foo/>;
|
||||
|
||||
Console.println( onlyOne );
|
||||
|
||||
val tryBrace = <try>Now escaped {{ braces } </try>;
|
||||
assertEquals( tryBrace, Elem(null,"try",e,TopScope,Text("Now escaped { braces }")));
|
||||
|
||||
val tryBrace2 = <try myAttrib={(3+4).toString() }> cool ?</try>;
|
||||
assertEquals( tryBrace2.attribute("myAttrib"), "7" );
|
||||
|
||||
/* Scala comments are not allowed in XML literals. see neg(2) */
|
||||
val zzz = <hello>/* no comment */</hello>;
|
||||
assertEquals( zzz, Elem(null,"hello", e,TopScope, Text("/* no comment */")));
|
||||
|
||||
}
|
||||
|
||||
|
||||
def test05main = {
|
||||
val x1s = <foo>{</foo>.toString();
|
||||
Console.println( x1s );
|
||||
val x2 = <foo> {<bar><baz/></bar><bar/></foo>.toString();
|
||||
Console.println( x2 );
|
||||
}
|
||||
|
||||
def test06 = {
|
||||
|
||||
val foo =
|
||||
<bar:foo xmlns:bar="www.bar.com" xmlns="www.baz.com">
|
||||
<baz/>
|
||||
</bar:foo>;
|
||||
|
||||
Console.println( foo );
|
||||
|
||||
}
|
||||
|
||||
|
||||
def main( args:Array[String] ):Unit = {
|
||||
Console.println("Test01Literals");
|
||||
Test01Literals;
|
||||
Console.println("Test02Embed");
|
||||
Test02Embed;
|
||||
Console.println("Test03Servlet");
|
||||
Test03Servlet.main( args );
|
||||
Console.println("Test04");
|
||||
Test04;
|
||||
Console.println("Test05Ref");
|
||||
test05main;
|
||||
Console.println("namespace");
|
||||
test06;{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
NodeSeq
|
||||
passed ok
|
||||
passed ok
|
||||
<result>
|
||||
<title>Blabla</title>
|
||||
<remarks>Hallo Welt.</remarks>
|
||||
</result><result>
|
||||
<title>Blubabla</title>
|
||||
<remarks>Hello Blu</remarks>
|
||||
</result><result>
|
||||
<title>Blubabla</title>
|
||||
<remarks>rem 2</remarks>
|
||||
</result>
|
||||
List(<book><title>Blabla</title></book>)
|
||||
<result>
|
||||
<name>John</name>
|
||||
|
||||
<street>Elm Street</street>
|
||||
|
||||
<city>Dolphin City</city>
|
||||
<phone where="work">+41 21 693 68 67</phone>
|
||||
|
||||
<phone where="mobile">+41 79 602 23 23</phone>
|
||||
</result>
|
||||
patterns
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
namespaces
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
validation - elements
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
validation - attributes
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
||||
passed ok
|
|
@ -1,278 +0,0 @@
|
|||
import java.io.StringReader;
|
||||
import org.xml.sax.InputSource;
|
||||
import scala.testing.UnitTest._ ;
|
||||
import scala.xml.{Node, NodeSeq, Elem, Text, XML};
|
||||
|
||||
object Test {
|
||||
|
||||
/** returns true if exception was thrown */
|
||||
def catcher(att:Function1[Unit,scala.xml.MetaData]): Boolean = {
|
||||
var ex = false;
|
||||
try {
|
||||
val x = att.apply({});
|
||||
} catch {
|
||||
case scala.xml.MalformedAttributeException(msg) =>
|
||||
Console.println(msg);
|
||||
ex = true;
|
||||
}
|
||||
return ex;
|
||||
}
|
||||
|
||||
def main(args:Array[String]) = {
|
||||
|
||||
//val e: scala.xml.MetaData = null; //Node.NoAttributes;
|
||||
//val sc: scala.xml.NamespaceBinding = null;
|
||||
|
||||
// ------------------------------------------ tests for class NodeSeq
|
||||
|
||||
/**
|
||||
Console.println("checking wellformed attributes");
|
||||
{
|
||||
import scala.xml.{ UnprefixedAttribute, Null }
|
||||
assertTrue(catcher {x:Unit => new UnprefixedAttribute("key", "<", Null)}); // < illegal
|
||||
assertTrue(catcher(x:Unit => new UnprefixedAttribute("key", "&", Null))); // & illegal
|
||||
assertTrue(catcher(x:Unit => new UnprefixedAttribute("key", "a&a", Null))); // & illegal
|
||||
assertTrue(catcher(x:Unit => new UnprefixedAttribute("key", "a&a;&", Null))); // 2nd &
|
||||
|
||||
assertFalse(catcher(x:Unit => new UnprefixedAttribute("key", "a&a; <<", Null)));
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
checking wellformed attributes
|
||||
< not allowed in attribute value
|
||||
passed ok
|
||||
malformed entity reference in attribute value [&]
|
||||
passed ok
|
||||
malformed entity reference in attribute value [a&a]
|
||||
passed ok
|
||||
malformed entity reference in attribute value [a&a;&]
|
||||
passed ok
|
||||
passed ok
|
||||
*/
|
||||
|
||||
Console.println("NodeSeq");
|
||||
import scala.xml.Utility.view ;
|
||||
|
||||
val p = <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.attribute("value").toString() + y.attribute("bazValue").toString()+ "!")
|
||||
};
|
||||
val pelems_2 = new NodeSeq { val theSeq = List(Text("38!"),Text("58!")) };
|
||||
assertSameElements(pelems_1, pelems_2);
|
||||
assertSameElements(
|
||||
p \\ "@value", new NodeSeq { val theSeq = List(Text("3"), Text("5")) }
|
||||
);
|
||||
|
||||
|
||||
/* // more test cases !!!
|
||||
val test = <a name="bar"/>;
|
||||
|
||||
Console.println(test \ "@name");
|
||||
|
||||
val x = test.attributes.nodes;
|
||||
Console.println("trying to print");
|
||||
val it = x.elements;
|
||||
while(it.hasNext) {
|
||||
val c = it.next;
|
||||
Console.println(c);
|
||||
Console.println("c.label == @name? "+(c.label == "@name"));
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
for(val c <- x) {
|
||||
Console.println(x);
|
||||
}
|
||||
*/
|
||||
|
||||
val books =
|
||||
<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>
|
||||
</entry>
|
||||
<entry><title>Blubabla</title>
|
||||
<remarks>
|
||||
Hello Blu
|
||||
</remarks>
|
||||
</entry>
|
||||
<entry><title>Blubabla</title>
|
||||
<remarks>
|
||||
rem 2
|
||||
</remarks>
|
||||
</entry>
|
||||
</reviews>;
|
||||
|
||||
Console.println( new scala.xml.PrettyPrinter(80, 5).formatNodes (
|
||||
for( val t <- books \\ "title";
|
||||
val r <- reviews \\ "entry";
|
||||
r \ "title" == t) yield
|
||||
<result>
|
||||
{ t }
|
||||
{ r \ "remarks" }
|
||||
</result>
|
||||
));
|
||||
|
||||
// example
|
||||
Console.println(
|
||||
for( val t @ <book><title>Blabla</title></book> <- new NodeSeq { val theSeq = books.child }.asList)
|
||||
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>
|
||||
</addrbook>;
|
||||
|
||||
Console.println( new scala.xml.PrettyPrinter(80, 5).formatNodes (
|
||||
for( val t <- addrBook \\ "entry";
|
||||
val r <- phoneBook \\ "entry";
|
||||
t \ "name" == r \ "name") yield
|
||||
<result>
|
||||
{ t.child }
|
||||
{ r \ "phone" }
|
||||
</result>
|
||||
));
|
||||
|
||||
/* patterns */
|
||||
Console.println("patterns");
|
||||
assertEquals(<hello/> match { case <hello/> => true; case _ => false; },
|
||||
true);
|
||||
|
||||
assertEquals(
|
||||
<hello foo="bar">
|
||||
<world/>
|
||||
</hello> match { case x @ <hello>
|
||||
<world/>
|
||||
</hello> if x.attribute("foo") == "bar" => true;
|
||||
case _ => false; },
|
||||
true);
|
||||
|
||||
assertEquals(
|
||||
<hello foo="bar">
|
||||
crazy text world
|
||||
</hello> match { case <hello>
|
||||
crazy text world
|
||||
</hello> => true;
|
||||
case _ => false; },
|
||||
true);
|
||||
|
||||
|
||||
/* namespaces */
|
||||
// begin tmp
|
||||
Console.println("namespaces");
|
||||
val cuckoo = <cuckoo xmlns="http://cuckoo.com">
|
||||
<foo/>
|
||||
<bar/>
|
||||
</cuckoo>;
|
||||
assertEquals( cuckoo.namespace, "http://cuckoo.com");
|
||||
for( val n <- cuckoo.child ) {
|
||||
assertEquals( n.namespace, "http://cuckoo.com");
|
||||
}
|
||||
// end tmp
|
||||
/*
|
||||
|
||||
DEPRECATED, don't support namespaces in pattern match anymore
|
||||
*/
|
||||
/*
|
||||
assertEquals( true, cuckoo match {
|
||||
case <cuckoo xmlns="http://cuckoo.com">
|
||||
<foo/>
|
||||
<bar/>
|
||||
</cuckoo> => true;
|
||||
case _ => false; });
|
||||
*/
|
||||
/*
|
||||
// begin tmp
|
||||
assertEquals( false, cuckoo match {
|
||||
case <cuckoo>
|
||||
<foo/>
|
||||
<bar/>
|
||||
</cuckoo> => true;
|
||||
case _ => false; });
|
||||
// end tmp
|
||||
*/
|
||||
Console.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")))));
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
Console.println("validation - attributes");
|
||||
vtor.setContentModel(null);
|
||||
vtor.setMetaData(List());
|
||||
assertEquals( vtor( <foo bar="hello"/> ), false );
|
||||
|
||||
{
|
||||
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 );
|
||||
|
||||
{
|
||||
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 );
|
||||
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
bug182.scala:2: error overriding class Foo.I in class Foo;
|
||||
class Bar.I in class Bar cannot override a class
|
||||
class Bar extends Foo { class I; }
|
||||
^
|
||||
one error found
|
|
@ -1,7 +0,0 @@
|
|||
S2.scala:14: type z.type escapes its defining scope as part of z.Inner
|
||||
def x = { val z = new S2(); new z.Inner(); }
|
||||
^
|
||||
S2.scala:15: type z.type escapes its defining scope as part of z.Inner
|
||||
def y = { val z = new S2(); new z.Inner(); }
|
||||
^
|
||||
two errors found
|
|
@ -1,19 +0,0 @@
|
|||
/* I was wondering for a long time what types x and y have;
|
||||
** the compiler claims: z.Inner (see commented out line)
|
||||
** This is strange because z is not in scope.
|
||||
** Furthermore, compilation of this class yields the message: (why?)
|
||||
**
|
||||
** S2.scala:16: illegal cyclic reference involving value t
|
||||
** def t = foo(x, y);
|
||||
** ^
|
||||
*/
|
||||
object M {
|
||||
def foo[T](x: T, y: T): T = x;
|
||||
class S2() {
|
||||
class Inner() extends S2() {}
|
||||
def x = { val z = new S2(); new z.Inner(); }
|
||||
def y = { val z = new S2(); new z.Inner(); }
|
||||
def t = foo(x, y);
|
||||
//def testType: Inner = x;
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
S4.scala:4: type a.type escapes its defining scope as part of a.Inner with scala.ScalaObject { def foo(a.Inner): a.Inner, val b$: Other, def b: Other }
|
||||
class S4(a: Other) extends a.Inner() {
|
||||
^
|
||||
one error found
|
|
@ -1,11 +0,0 @@
|
|||
/* This one compiles, but even if we would have dependent
|
||||
** constructor types, it would be not sound.
|
||||
*/
|
||||
class S4(a: Other) extends a.Inner() {
|
||||
def foo(x: a.Inner) = x;
|
||||
val b = new Other();
|
||||
foo(new S4(b))
|
||||
}
|
||||
class Other() {
|
||||
class Inner() {}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
S6.scala:11: illegal cyclic reference involving type S
|
||||
type S <: T;
|
||||
^
|
||||
one error found
|
|
@ -1,12 +0,0 @@
|
|||
/* This program puts the compiler into an endless loop
|
||||
*/
|
||||
trait T1 {
|
||||
type T;
|
||||
}
|
||||
trait T2 {
|
||||
type S;
|
||||
type T <: S;
|
||||
}
|
||||
abstract class S6() extends T1 with T2 {
|
||||
type S <: T;
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
S7.scala:6: illegal cyclic reference involving class A
|
||||
class C() extends a.A() {}
|
||||
^
|
||||
one error found
|
|
@ -1,7 +0,0 @@
|
|||
/* Another example for a non-terminating compiler run.
|
||||
*/
|
||||
class S7[T]() {
|
||||
val a: S7[T] = this;
|
||||
class A() extends a.C() {}
|
||||
class C() extends a.A() {}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
Y.scala:3: `match' needs to be applied fully
|
||||
def f(x: Object): java.lang.Object /* !!! Object */ = x.match;
|
||||
^
|
||||
one error found
|
|
@ -1,7 +0,0 @@
|
|||
object test {
|
||||
|
||||
def f(x: Object): java.lang.Object /* !!! Object */ = x.match;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
abstract.scala:5: malformed type: A.this.T#T
|
||||
def foo1 = bar().bar();
|
||||
^
|
||||
abstract.scala:7: malformed type: A#T
|
||||
def foo3 = baz().bar();
|
||||
^
|
||||
two errors found
|
|
@ -1,9 +0,0 @@
|
|||
trait A {
|
||||
type T <: A;
|
||||
def baz(): A;
|
||||
def bar(): T;
|
||||
def foo1 = bar().bar();
|
||||
def foo2 = bar().baz();
|
||||
def foo3 = baz().bar();
|
||||
def foo4 = baz().baz();
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
altherr2.scala:5: ';' expected but '[' found.
|
||||
foo()[Int];
|
||||
^
|
||||
one error found
|
|
@ -1,7 +0,0 @@
|
|||
trait Foo[a];
|
||||
|
||||
object Bug {
|
||||
def foo[a](): Foo[a] = foo[a]();
|
||||
foo()[Int];
|
||||
}
|
||||
|
|
@ -1,171 +0,0 @@
|
|||
altherr3.scala:26: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Int](foo0()); // error 1
|
||||
^
|
||||
altherr3.scala:27: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[scala.All])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Int](foo0(foo0())); // error 2
|
||||
^
|
||||
altherr3.scala:28: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[bug.Foo[scala.All]])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Int](foo0(foo0(foo0()))); // error 3
|
||||
^
|
||||
altherr3.scala:29: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[bug.Foo[bug.Foo[scala.All]]])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Int](foo0(foo0(foo0(foo0())))); // error 4
|
||||
^
|
||||
altherr3.scala:32: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Foo[Int]](foo0(foo0())); // error 5
|
||||
^
|
||||
altherr3.scala:33: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[scala.All])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Foo[Int]](foo0(foo0(foo0()))); // error 6
|
||||
^
|
||||
altherr3.scala:34: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[bug.Foo[scala.All]])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Foo[Int]](foo0(foo0(foo0(foo0())))); // error 7
|
||||
^
|
||||
altherr3.scala:38: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Foo[Foo[Int]]](foo0(foo0(foo0()))); // error 8
|
||||
^
|
||||
altherr3.scala:39: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[scala.All])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Foo[Foo[Int]]](foo0(foo0(foo0(foo0())))); // error 9
|
||||
^
|
||||
altherr3.scala:49: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar1[Int](foo0(foo0())); // error 10
|
||||
^
|
||||
altherr3.scala:50: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[scala.All])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar1[Int](foo0(foo0(foo0()))); // error 11
|
||||
^
|
||||
altherr3.scala:51: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[bug.Foo[scala.All]])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar1[Int](foo0(foo0(foo0(foo0())))); // error 12
|
||||
^
|
||||
altherr3.scala:55: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar1[Foo[Int]](foo0(foo0(foo0()))); // error 13
|
||||
^
|
||||
altherr3.scala:56: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[scala.All])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar1[Foo[Int]](foo0(foo0(foo0(foo0())))); // error 14
|
||||
^
|
||||
altherr3.scala:61: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar1[Foo[Foo[Int]]](foo0(foo0(foo0(foo0())))); // error 15
|
||||
^
|
||||
altherr3.scala:72: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar2[Int](foo0(foo0(foo0()))); // error 16
|
||||
^
|
||||
altherr3.scala:73: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[scala.All])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar2[Int](foo0(foo0(foo0(foo0())))); // error 17
|
||||
^
|
||||
altherr3.scala:78: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar2[Foo[Int]](foo0(foo0(foo0(foo0())))); // error 18
|
||||
^
|
||||
altherr3.scala:95: no type parameters for method foo0 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar3[Int](foo0(foo0(foo0(foo0())))); // error 20
|
||||
^
|
||||
altherr3.scala:116: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Int](foo1()); // error 21
|
||||
^
|
||||
altherr3.scala:117: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[scala.All])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Int](foo1(foo1())); // error 22
|
||||
^
|
||||
altherr3.scala:118: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[bug.Foo[scala.All]])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Int](foo1(foo1(foo1()))); // error 23
|
||||
^
|
||||
altherr3.scala:119: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[bug.Foo[bug.Foo[scala.All]]])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Int](foo1(foo1(foo1(foo1())))); // error 24
|
||||
^
|
||||
altherr3.scala:122: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Foo[Int]](foo1(foo1())); // error 25
|
||||
^
|
||||
altherr3.scala:123: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[scala.All])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Foo[Int]](foo1(foo1(foo1()))); // error 26
|
||||
^
|
||||
altherr3.scala:124: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[bug.Foo[scala.All]])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Foo[Int]](foo0(foo1(foo1(foo1())))); // error 27
|
||||
^
|
||||
altherr3.scala:128: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Foo[Foo[Int]]](foo1(foo1(foo1()))); // error 28
|
||||
^
|
||||
altherr3.scala:129: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[scala.All])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar0[Foo[Foo[Int]]](foo1(foo0(foo1(foo1())))); // error 29
|
||||
^
|
||||
altherr3.scala:139: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar1[Int](foo1(foo1())); // error 30
|
||||
^
|
||||
altherr3.scala:140: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[scala.All])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar1[Int](foo1(foo1(foo1()))); // error 31
|
||||
^
|
||||
altherr3.scala:141: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[bug.Foo[scala.All]])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar1[Int](foo1(foo1(foo1(foo1())))); // error 32
|
||||
^
|
||||
altherr3.scala:145: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar1[Foo[Int]](foo1(foo1(foo1()))); // error 33
|
||||
^
|
||||
altherr3.scala:146: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments (bug.Foo[scala.All])
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar1[Foo[Int]](foo1(foo1(foo1(foo1())))); // error 34
|
||||
^
|
||||
altherr3.scala:151: no type parameters for method foo1 of type [a](a*)bug.Foo[a] exist so that it can be applied to arguments ()
|
||||
--- because ---
|
||||
result type bug.Foo[a] is incompatible with expected type scala.Int
|
||||
bar1[Foo[Foo[Int]]](foo1(foo1(foo1(foo1())))); // error 35
|
||||
^
|
||||
34 errors found
|
|
@ -1,154 +0,0 @@
|
|||
// $Id$
|
||||
|
||||
object bug {
|
||||
|
||||
//##########################################################################
|
||||
|
||||
trait Foo[+a];
|
||||
|
||||
def foo0[a](x: a*): Foo[a] = foo0();
|
||||
|
||||
val foo1: Int = 0;
|
||||
def foo1[a](x: a*): Foo[a] = foo1();
|
||||
|
||||
def bar0[a](x: a): Int = 0;
|
||||
def bar1[a](x: Foo[a]): Int = 0;
|
||||
def bar2[a](x: Foo[Foo[a]]): Int = 0;
|
||||
def bar3[a](x: Foo[Foo[Foo[a]]]): Int = 0;
|
||||
|
||||
//##########################################################################
|
||||
|
||||
bar0(foo0());
|
||||
bar0(foo0(foo0()));
|
||||
bar0(foo0(foo0(foo0())));
|
||||
bar0(foo0(foo0(foo0(foo0()))));
|
||||
|
||||
bar0[Int](foo0()); // error 1
|
||||
bar0[Int](foo0(foo0())); // error 2
|
||||
bar0[Int](foo0(foo0(foo0()))); // error 3
|
||||
bar0[Int](foo0(foo0(foo0(foo0())))); // error 4
|
||||
|
||||
bar0[Foo[Int]](foo0());
|
||||
bar0[Foo[Int]](foo0(foo0())); // error 5
|
||||
bar0[Foo[Int]](foo0(foo0(foo0()))); // error 6
|
||||
bar0[Foo[Int]](foo0(foo0(foo0(foo0())))); // error 7
|
||||
|
||||
bar0[Foo[Foo[Int]]](foo0());
|
||||
bar0[Foo[Foo[Int]]](foo0(foo0()));
|
||||
bar0[Foo[Foo[Int]]](foo0(foo0(foo0()))); // error 8
|
||||
bar0[Foo[Foo[Int]]](foo0(foo0(foo0(foo0())))); // error 9
|
||||
|
||||
//##########################################################################
|
||||
|
||||
bar1(foo0());
|
||||
bar1(foo0(foo0()));
|
||||
bar1(foo0(foo0(foo0())));
|
||||
bar1(foo0(foo0(foo0(foo0()))));
|
||||
|
||||
bar1[Int](foo0());
|
||||
bar1[Int](foo0(foo0())); // error 10
|
||||
bar1[Int](foo0(foo0(foo0()))); // error 11
|
||||
bar1[Int](foo0(foo0(foo0(foo0())))); // error 12
|
||||
|
||||
bar1[Foo[Int]](foo0());
|
||||
bar1[Foo[Int]](foo0(foo0()));
|
||||
bar1[Foo[Int]](foo0(foo0(foo0()))); // error 13
|
||||
bar1[Foo[Int]](foo0(foo0(foo0(foo0())))); // error 14
|
||||
|
||||
bar1[Foo[Foo[Int]]](foo0());
|
||||
bar1[Foo[Foo[Int]]](foo0(foo0()));
|
||||
bar1[Foo[Foo[Int]]](foo0(foo0(foo0())));
|
||||
bar1[Foo[Foo[Int]]](foo0(foo0(foo0(foo0())))); // error 15
|
||||
|
||||
//##########################################################################
|
||||
|
||||
bar2(foo0());
|
||||
bar2(foo0(foo0()));
|
||||
bar2(foo0(foo0(foo0())));
|
||||
bar2(foo0(foo0(foo0(foo0()))));
|
||||
|
||||
bar2[Int](foo0());
|
||||
bar2[Int](foo0(foo0()));
|
||||
bar2[Int](foo0(foo0(foo0()))); // error 16
|
||||
bar2[Int](foo0(foo0(foo0(foo0())))); // error 17
|
||||
|
||||
bar2[Foo[Int]](foo0());
|
||||
bar2[Foo[Int]](foo0(foo0()));
|
||||
bar2[Foo[Int]](foo0(foo0(foo0())));
|
||||
bar2[Foo[Int]](foo0(foo0(foo0(foo0())))); // error 18
|
||||
|
||||
bar2[Foo[Foo[Int]]](foo0());
|
||||
bar2[Foo[Foo[Int]]](foo0(foo0()));
|
||||
bar2[Foo[Foo[Int]]](foo0(foo0(foo0())));
|
||||
bar2[Foo[Foo[Int]]](foo0(foo0(foo0(foo0()))));
|
||||
|
||||
//##########################################################################
|
||||
|
||||
bar3(foo0());
|
||||
bar3(foo0(foo0()));
|
||||
bar3(foo0(foo0(foo0())));
|
||||
bar3(foo0(foo0(foo0(foo0()))));
|
||||
|
||||
bar3[Int](foo0());
|
||||
bar3[Int](foo0(foo0()));
|
||||
bar3[Int](foo0(foo0(foo0())));
|
||||
bar3[Int](foo0(foo0(foo0(foo0())))); // error 20
|
||||
|
||||
bar3[Foo[Int]](foo0());
|
||||
bar3[Foo[Int]](foo0(foo0()));
|
||||
bar3[Foo[Int]](foo0(foo0(foo0())));
|
||||
bar3[Foo[Int]](foo0(foo0(foo0(foo0()))));
|
||||
|
||||
bar3[Foo[Foo[Int]]](foo0());
|
||||
bar3[Foo[Foo[Int]]](foo0(foo0()));
|
||||
bar3[Foo[Foo[Int]]](foo0(foo0(foo0())));
|
||||
bar3[Foo[Foo[Int]]](foo0(foo0(foo0(foo0()))));
|
||||
|
||||
//##########################################################################
|
||||
//##########################################################################
|
||||
//##########################################################################
|
||||
|
||||
bar0(foo1());
|
||||
bar0(foo1(foo1()));
|
||||
bar0(foo1(foo1(foo1())));
|
||||
bar0(foo1(foo1(foo1(foo1()))));
|
||||
|
||||
bar0[Int](foo1()); // error 21
|
||||
bar0[Int](foo1(foo1())); // error 22
|
||||
bar0[Int](foo1(foo1(foo1()))); // error 23
|
||||
bar0[Int](foo1(foo1(foo1(foo1())))); // error 24
|
||||
|
||||
bar0[Foo[Int]](foo1());
|
||||
bar0[Foo[Int]](foo1(foo1())); // error 25
|
||||
bar0[Foo[Int]](foo1(foo1(foo1()))); // error 26
|
||||
bar0[Foo[Int]](foo0(foo1(foo1(foo1())))); // error 27
|
||||
|
||||
bar0[Foo[Foo[Int]]](foo1());
|
||||
bar0[Foo[Foo[Int]]](foo1(foo1()));
|
||||
bar0[Foo[Foo[Int]]](foo1(foo1(foo1()))); // error 28
|
||||
bar0[Foo[Foo[Int]]](foo1(foo0(foo1(foo1())))); // error 29
|
||||
|
||||
//##########################################################################
|
||||
|
||||
bar1(foo1());
|
||||
bar1(foo1(foo1()));
|
||||
bar1(foo1(foo1(foo1())));
|
||||
bar1(foo1(foo1(foo1(foo1()))));
|
||||
|
||||
bar1[Int](foo1());
|
||||
bar1[Int](foo1(foo1())); // error 30
|
||||
bar1[Int](foo1(foo1(foo1()))); // error 31
|
||||
bar1[Int](foo1(foo1(foo1(foo1())))); // error 32
|
||||
|
||||
bar1[Foo[Int]](foo1());
|
||||
bar1[Foo[Int]](foo1(foo1()));
|
||||
bar1[Foo[Int]](foo1(foo1(foo1()))); // error 33
|
||||
bar1[Foo[Int]](foo1(foo1(foo1(foo1())))); // error 34
|
||||
|
||||
bar1[Foo[Foo[Int]]](foo1());
|
||||
bar1[Foo[Foo[Int]]](foo1(foo1()));
|
||||
bar1[Foo[Foo[Int]]](foo1(foo1(foo1())));
|
||||
bar1[Foo[Foo[Int]]](foo1(foo1(foo1(foo1())))); // error 35
|
||||
|
||||
//##########################################################################
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
bounds.scala:11: type arguments [T] do not conform to constructor A's type parameter bounds [T >: I]
|
||||
class B[T >: J](init: T) extends A[T](init) {
|
||||
^
|
||||
one error found
|
|
@ -1,12 +0,0 @@
|
|||
class I {
|
||||
def i(): Unit = {}
|
||||
}
|
||||
class J extends I {
|
||||
def j(): Unit = {}
|
||||
}
|
||||
class A[T >: I](init: T) {
|
||||
var y: T = new B();
|
||||
class B() extends I {}
|
||||
}
|
||||
class B[T >: J](init: T) extends A[T](init) {
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
bug105.scala:1: illegal inheritance from sealed class
|
||||
object T extends Array[Int](1);
|
||||
^
|
||||
one error found
|
|
@ -1 +0,0 @@
|
|||
object T extends Array[Int](1);
|
|
@ -1,4 +0,0 @@
|
|||
bug106.scala:2: Java class may not be used as mixin
|
||||
class S extends T with Object;
|
||||
^
|
||||
one error found
|
|
@ -1,2 +0,0 @@
|
|||
class T extends AnyRef;
|
||||
class S extends T with Object;
|
|
@ -1,4 +0,0 @@
|
|||
bug107.scala:4: object creation impossible, since method foo in trait C is not defined
|
||||
object O extends C {
|
||||
^
|
||||
one error found
|
|
@ -1,8 +0,0 @@
|
|||
trait C {
|
||||
def foo: Int;
|
||||
}
|
||||
object O extends C {
|
||||
def main(args: Array[String]) = {
|
||||
System.out.println(foo);
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
bug108.scala:3: x is already defined as value x
|
||||
case x :: x => "first"
|
||||
^
|
||||
one error found
|
|
@ -1,4 +0,0 @@
|
|||
bug112.scala:6: T.A is not a legal prefix for a constructor
|
||||
class D extends C;
|
||||
^
|
||||
one error found
|
|
@ -1,7 +0,0 @@
|
|||
object T {
|
||||
class A {
|
||||
class B;
|
||||
}
|
||||
type C = A#B;
|
||||
class D extends C;
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
bug113.scala:3: illegal cyclic reference involving type A
|
||||
type B <: A;
|
||||
^
|
||||
bug113.scala:2: only classes can have declared but undefined members
|
||||
type A <: B;
|
||||
^
|
||||
two errors found
|
|
@ -1,4 +0,0 @@
|
|||
object T {
|
||||
type A <: B;
|
||||
type B <: A;
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
bug117.scala:2: '(' expected but '[' found.
|
||||
def this[A](x: A, y: A) = {
|
||||
^
|
||||
bug117.scala:4: identifier expected but '}' found.
|
||||
}
|
||||
^
|
||||
bug117.scala:5: illegal start of expression
|
||||
}
|
||||
^
|
||||
three errors found
|
|
@ -1,5 +0,0 @@
|
|||
class C[A](x: A) {
|
||||
def this[A](x: A, y: A) = {
|
||||
this(x);
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
bug118.scala:4: return outside method definition
|
||||
return null;
|
||||
^
|
||||
one error found
|
|
@ -1,6 +0,0 @@
|
|||
class C(y: Int) {
|
||||
def this() = {
|
||||
this(1);
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
bug122.scala:2: recursive value v$ needs type
|
||||
val List(v:int,2) = List(2,v:int);
|
||||
^
|
||||
bug122.scala:3: recursive value ds$0$ needs type
|
||||
val Pair(a:int,b:int) = Pair(1,a);
|
||||
^
|
||||
two errors found
|
|
@ -1,4 +0,0 @@
|
|||
class L{
|
||||
val List(v:int,2) = List(2,v:int);
|
||||
val Pair(a:int,b:int) = Pair(1,a);
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
bug128_129.scala:3: '=' expected but identifier found.
|
||||
val x | 1 = 2; // not allowed
|
||||
^
|
||||
bug128_129.scala:3: illegal start of expression
|
||||
val x | 1 = 2; // not allowed
|
||||
^
|
||||
bug128_129.scala:10: recursive patterns not allowed
|
||||
case PT(a@PT(a)) => // not allowed
|
||||
^
|
||||
three errors found
|
|
@ -1,15 +0,0 @@
|
|||
object Test {
|
||||
def foo:int = {
|
||||
val x | 1 = 2; // not allowed
|
||||
x
|
||||
}
|
||||
|
||||
class Bar {
|
||||
case class PT(x: PT) {
|
||||
def foo(x: Any) = x match {
|
||||
case PT(a@PT(a)) => // not allowed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
bug136.scala:5: type mismatch;
|
||||
found : Bar
|
||||
required: Foo
|
||||
val foo2: Foo = bar;
|
||||
^
|
||||
bug136.scala:7: object bar does not implement Foo
|
||||
object bar: Foo {
|
||||
^
|
||||
two errors found
|
|
@ -1,4 +0,0 @@
|
|||
bug144.scala:2: trait I is inherited twice
|
||||
class C with I with I;
|
||||
^
|
||||
one error found
|
|
@ -1,2 +0,0 @@
|
|||
trait I;
|
||||
class C with I with I;
|
|
@ -1,4 +0,0 @@
|
|||
bug145.scala:8: symbol accessed from super may not be abstract
|
||||
abstract override def foo(x: T): Int = super[J].foo(x) + 1;
|
||||
^
|
||||
one error found
|
|
@ -1,17 +0,0 @@
|
|||
class B[T] {
|
||||
def foo(x: T): Int = 1;
|
||||
}
|
||||
trait J[T] {
|
||||
def foo(x: T): Int;
|
||||
}
|
||||
trait I[T] extends B[T] with J[T] {
|
||||
abstract override def foo(x: T): Int = super[J].foo(x) + 1;
|
||||
}
|
||||
class C extends B[Int] {
|
||||
override def foo(x: Int): Int = x;
|
||||
}
|
||||
class D extends C with I[Int];
|
||||
object T with Application {
|
||||
System.out.println((new D).foo(3));
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
bug152.scala:5: type foo.type escapes its defining scope as part of java.lang.Object with scala.ScalaObject { def a: foo.T }
|
||||
class Bar(foo: Foo) {
|
||||
^
|
||||
one error found
|
|
@ -1,7 +0,0 @@
|
|||
abstract class Foo {
|
||||
type T;
|
||||
}
|
||||
|
||||
class Bar(foo: Foo) {
|
||||
def a: foo.T = a;
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
bug169.scala:8: not found: type TIMEOUT
|
||||
case TIMEOUT() => {
|
||||
^
|
||||
bug169.scala:9: value ! is not a member of java.lang.Process
|
||||
Child ! 'foo;
|
||||
^
|
||||
two errors found
|
|
@ -1,14 +0,0 @@
|
|||
import scala.concurrent.Process._;
|
||||
|
||||
class D() {
|
||||
def start_listener(Child:Process) = {
|
||||
var running = true;
|
||||
while (running) {
|
||||
receiveWithin(0) {
|
||||
case TIMEOUT() => {
|
||||
Child ! 'foo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
bug170.scala:9: class D needs to be abstract, since method foo in class D is marked `abstract' and `override' and overrides an incomplete superclass member in J
|
||||
class D extends J with I {
|
||||
^
|
||||
one error found
|
|
@ -1,15 +0,0 @@
|
|||
trait J {
|
||||
def foo(): Unit;
|
||||
}
|
||||
|
||||
trait I with J {
|
||||
override def foo(): Unit = ();
|
||||
}
|
||||
|
||||
class D extends J with I {
|
||||
abstract override def foo(): Unit = super.foo();
|
||||
}
|
||||
|
||||
object Test with Application {
|
||||
(new D).foo();
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
bug191.scala:11: type mismatch;
|
||||
found : B.this.C
|
||||
required: B.this.C
|
||||
foo(new C);
|
||||
^
|
||||
one error found
|
|
@ -1,15 +0,0 @@
|
|||
class A {
|
||||
private class C {
|
||||
def print = Console.println("A.C");
|
||||
}
|
||||
def foo(c: C) = c.print;
|
||||
}
|
||||
class B extends A {
|
||||
class C {
|
||||
def show = Console.println("B.C");
|
||||
}
|
||||
foo(new C);
|
||||
}
|
||||
object Main with Application {
|
||||
val b = new B;
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
bug228.scala:11: constructor AccessibleObject cannot be accessed in Foo
|
||||
val o = new AccessibleObject;
|
||||
^
|
||||
one error found
|
|
@ -1,13 +0,0 @@
|
|||
import java.lang.reflect.AccessibleObject;
|
||||
|
||||
class Test extends AccessibleObject {
|
||||
|
||||
val o = new AccessibleObject;
|
||||
|
||||
}
|
||||
|
||||
class Foo {
|
||||
|
||||
val o = new AccessibleObject;
|
||||
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
bug236.scala:4: wrong number of arguments for constructor A()
|
||||
class B extends A(1) {
|
||||
^
|
||||
one error found
|
|
@ -1,6 +0,0 @@
|
|||
class A {
|
||||
private def this(i: Int) = this();
|
||||
}
|
||||
class B extends A(1) {
|
||||
val a = new A(1);
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
bug25.scala:5: constructor javax.rmi.PortableRemoteObject cannot be accessed in javax.rmi
|
||||
class A extends javax.rmi.PortableRemoteObject();
|
||||
^
|
||||
one error found
|
|
@ -1,4 +0,0 @@
|
|||
bug283.scala:7: illegal cyclic reference involving constructor A
|
||||
type A[t1] = P[A[t1],t1];
|
||||
^
|
||||
one error found
|
|
@ -1,8 +0,0 @@
|
|||
// bug contribution #12
|
||||
|
||||
trait P[a<:P[a,t1],t1]:a;
|
||||
|
||||
object X
|
||||
{
|
||||
type A[t1] = P[A[t1],t1];
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
bug38.scala:3: * is not a member of scala.xml
|
||||
import scala.xml.* ; // does not work
|
||||
^
|
||||
bug38.scala:7: not found: type Element
|
||||
val foo = new Element { def getName = "hallo"; def getChildren = Nil; def getAttribs = new HashMap[String,String] };
|
||||
^
|
||||
two errors found
|
|
@ -1,11 +0,0 @@
|
|||
object testElem {
|
||||
|
||||
import scala.xml.* ; // does not work
|
||||
//import scala.xml.Element ; //works
|
||||
|
||||
def main( args:Array[String] ) = {
|
||||
val foo = new Element { def getName = "hallo"; def getChildren = Nil; def getAttribs = new HashMap[String,String] };
|
||||
()
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
bug40.scala:2: 'val' expected but integer literal found.
|
||||
val v = for (1 == 0) yield 1;
|
||||
^
|
||||
bug40.scala:3: illegal start of pattern
|
||||
}
|
||||
^
|
||||
bug40.scala:2: '<-' expected but '}' found.
|
||||
val v = for (1 == 0) yield 1;
|
||||
^
|
||||
three errors found
|
|
@ -1,3 +0,0 @@
|
|||
object M {
|
||||
val v = for (1 == 0) yield 1;
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
bug43.scala:1: class C takes type parameters.
|
||||
case class C[A >: C](x: A) {}
|
||||
^
|
||||
one error found
|
|
@ -1 +0,0 @@
|
|||
case class C[A >: C](x: A) {}
|
|
@ -1,6 +0,0 @@
|
|||
bug44.scala:2: type mismatch;
|
||||
found : java.lang.Object
|
||||
required: java.lang.Object { def t: scala.Int }
|
||||
var x: Object { def t: Int; } = new Object() {
|
||||
^
|
||||
one error found
|
|
@ -1,5 +0,0 @@
|
|||
abstract class C {
|
||||
var x: Object { def t: Int; } = new Object() {
|
||||
def t: Int = 1;
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
bug45.scala:4: type mismatch;
|
||||
found : scala.AllRef(null)
|
||||
required: Int
|
||||
def foo[Int](x: Int): Int = null;
|
||||
^
|
||||
one error found
|
|
@ -1,10 +0,0 @@
|
|||
object Main {
|
||||
|
||||
def main(args: Array[String]) = {
|
||||
def foo[Int](x: Int): Int = null;
|
||||
val y1 = null;
|
||||
val y2 = foo(2);
|
||||
()
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue