aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-05-12 15:44:16 +0200
committerMartin Odersky <odersky@gmail.com>2013-05-12 15:44:16 +0200
commit805d116bd6d504b36db06568d0a160e41cfabfb7 (patch)
tree80c2fb3d55262cc121da40d531a290dfdb99206f
parentc863dd63af8e8e93582841fab4926b5899e0e285 (diff)
downloaddotty-805d116bd6d504b36db06568d0a160e41cfabfb7.tar.gz
dotty-805d116bd6d504b36db06568d0a160e41cfabfb7.tar.bz2
dotty-805d116bd6d504b36db06568d0a160e41cfabfb7.zip
new tests and worksheets
-rw-r--r--src/dotty/tools/dotc/util/kwords.sc18
-rw-r--r--test/test/ParserTest.scala52
-rw-r--r--test/test/parsePackage.scala17
-rw-r--r--test/test/positiontest.sc14
-rw-r--r--test/test/showTree.scala12
5 files changed, 113 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/util/kwords.sc b/src/dotty/tools/dotc/util/kwords.sc
new file mode 100644
index 000000000..94c17eaf4
--- /dev/null
+++ b/src/dotty/tools/dotc/util/kwords.sc
@@ -0,0 +1,18 @@
+package dotty.tools.dotc.util
+
+import dotty.tools.dotc.parsing._
+import Scanners._
+import Tokens._
+
+object kwords {
+ println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
+ keywords.toList.map(tokenString) //> res0: List[String] = List(if, for, else, this, null, new, with, super, case,
+ //| case class, case object, val, abstract, final, private, protected, override
+ //| , implicit, var, def, type, extends, true, false, object, class, import, pac
+ //| kage, yield, do, trait, sealed, throw, try, catch, finally, while, return, m
+ //| atch, lazy, then, forSome, _, :, =, <-, =>, ';', ';', <:, >:, #, @, <%)
+ keywords.toList.filter(kw => tokenString(kw) == null)
+ //> res1: List[Int] = List()
+ canStartStatTokens contains CASE //> res2: Boolean = false
+
+} \ No newline at end of file
diff --git a/test/test/ParserTest.scala b/test/test/ParserTest.scala
new file mode 100644
index 000000000..32bfdfe28
--- /dev/null
+++ b/test/test/ParserTest.scala
@@ -0,0 +1,52 @@
+package test
+
+import scala.reflect.io._
+import dotty.tools.dotc.util._
+import dotty.tools.dotc.core._
+import dotty.tools.dotc.parsing._
+import Tokens._, Parsers._
+import UntypedTrees.untpd._
+import org.junit.Test
+
+class ParserTest extends DottyTest {
+
+ def parse(name: String): Tree = parse(new PlainFile(name))
+
+ var parsed = 0
+
+ def parse(file: PlainFile): Tree = {
+ //println("***** parsing " + file)
+ val source = new SourceFile(file)
+ val parser = new Parser(source)
+ val tree = parser.parse()
+ parsed += 1
+ tree
+ }
+
+ def parseDir(path: String): Unit = parseDir(Directory(path))
+
+ def parseDir(dir: Directory): Unit = {
+ for (f <- dir.files)
+ if (f.name.endsWith(".scala")) parse(new PlainFile(f))
+ for (d <- dir.dirs)
+ parseDir(d.path)
+ }
+/*
+ @Test
+ def parseList() = {
+ println(System.getProperty("user.dir"))
+ parse("src/dotty/tools/dotc/core/Symbols.scala")
+ parse("src/dotty/tools/dotc/core/Types.scala")
+ }
+
+ @Test
+ def parseDotty() = {
+ parseDir("src")
+ }*/
+
+ @Test
+ def parseScala() = {
+ parseDir("/Users/odersky/workspace/scala/src")
+ }
+
+} \ No newline at end of file
diff --git a/test/test/parsePackage.scala b/test/test/parsePackage.scala
new file mode 100644
index 000000000..2bd633609
--- /dev/null
+++ b/test/test/parsePackage.scala
@@ -0,0 +1,17 @@
+package test
+
+object parsePackage extends ParserTest {
+
+ def test() = {
+ val start = System.nanoTime()
+ parseDir("/Users/odersky/workspace/dotty/src")
+ parseDir("/Users/odersky/workspace/scala/src")
+ val ms = (System.nanoTime() - start)/1000000
+ println(s"$parsed files parsed in ${ms}ms")
+ }
+
+ def main(args: Array[String]): Unit = {
+// parse("/Users/odersky/workspace/scala/src/compiler/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala")
+ for (i <- 0 until 10) test()
+ }
+} \ No newline at end of file
diff --git a/test/test/positiontest.sc b/test/test/positiontest.sc
new file mode 100644
index 000000000..11cc54dbe
--- /dev/null
+++ b/test/test/positiontest.sc
@@ -0,0 +1,14 @@
+package test
+
+import dotty.tools.dotc.util._
+import Positions._
+
+object positiontest {
+ println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
+
+ val p = Position(0, 1, 0) //> p : dotty.tools.dotc.util.Positions.Position = [0..1]
+ val p2 = Position(0, 2) //> p2 : dotty.tools.dotc.util.Positions.Position = [0..2]
+ val p3 = Position(1, 0) //> p3 : dotty.tools.dotc.util.Positions.Position = [no position]
+ p3.isSynthetic //> res0: Boolean = false
+ NoPosition.isSynthetic //> res1: Boolean = false
+} \ No newline at end of file
diff --git a/test/test/showTree.scala b/test/test/showTree.scala
new file mode 100644
index 000000000..fa6ef2bf5
--- /dev/null
+++ b/test/test/showTree.scala
@@ -0,0 +1,12 @@
+package test
+import dotty.tools.dotc.core.UntypedTrees.untpd._
+
+object showTree extends ParserTest {
+
+ def main(args: Array[String]): Unit = {
+ for (arg <- args) {
+ val tree: Tree = parse(arg)
+ println("result = "+tree.show)
+ }
+ }
+} \ No newline at end of file