aboutsummaryrefslogtreecommitdiff
path: root/compiler/test/worksheets
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-11-02 11:08:28 +0100
committerGuillaume Martres <smarter@ubuntu.com>2016-11-22 01:35:07 +0100
commit8a61ff432543a29234193cd1f7c14abd3f3d31a0 (patch)
treea8147561d307af862c295cfc8100d271063bb0dd /compiler/test/worksheets
parent6a455fe6da5ff9c741d91279a2dc6fe2fb1b472f (diff)
downloaddotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.tar.gz
dotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.tar.bz2
dotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.zip
Move compiler and compiler tests to compiler dir
Diffstat (limited to 'compiler/test/worksheets')
-rw-r--r--compiler/test/worksheets/baseTypetest.sc26
-rw-r--r--compiler/test/worksheets/denotTest.sc55
-rw-r--r--compiler/test/worksheets/flagtest.sc27
-rw-r--r--compiler/test/worksheets/nesting.sc31
-rw-r--r--compiler/test/worksheets/periodtest.sc18
-rw-r--r--compiler/test/worksheets/positiontest.sc14
-rw-r--r--compiler/test/worksheets/sigtest.sc34
-rw-r--r--compiler/test/worksheets/testnames.sc49
8 files changed, 254 insertions, 0 deletions
diff --git a/compiler/test/worksheets/baseTypetest.sc b/compiler/test/worksheets/baseTypetest.sc
new file mode 100644
index 000000000..001f1e3b3
--- /dev/null
+++ b/compiler/test/worksheets/baseTypetest.sc
@@ -0,0 +1,26 @@
+package test
+
+import dotty.tools.dotc._
+import core._
+import Decorators._
+import Types._, Symbols._
+
+object baseTypetest extends DottyTest {
+ println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
+ val int = defn.IntType //> int : dotty.tools.dotc.core.Types.Type = TypeRef(ThisType(module class scal
+ //| a#35),Int)
+ int.baseClasses //> res0: List[dotty.tools.dotc.core.Symbols.ClassSymbol] = List(class Int#1364,
+ //| class AnyVal#575, class Any#2133)
+ defn.StringClass.typeRef.baseClasses //> res1: List[dotty.tools.dotc.core.Symbols.ClassSymbol] = List(class String#21
+ //| 3, class CharSequence#531, class Comparable#102, class Serializable#3816, cl
+ //| ass Object#129, class Any#2133)
+ defn.StringClass.typeRef.baseType(defn.ObjectClass)
+ //> res2: dotty.tools.dotc.core.Types.Type = TypeRef(ThisType(module class lang#
+ //| 57),Object)
+ defn.StringClass.typeRef.baseType(defn.AnyClass)//> res3: dotty.tools.dotc.core.Types.Type = TypeRef(ThisType(module class scala
+ //| #35),Any)
+ defn.StringClass isSubClass defn.NullClass //> res4: Boolean = false
+ defn.StringClass.typeRef.baseType(defn.NullClass)
+ //> res5: dotty.tools.dotc.core.Types.Type = NoType
+
+} \ No newline at end of file
diff --git a/compiler/test/worksheets/denotTest.sc b/compiler/test/worksheets/denotTest.sc
new file mode 100644
index 000000000..222a347b6
--- /dev/null
+++ b/compiler/test/worksheets/denotTest.sc
@@ -0,0 +1,55 @@
+package test
+
+import dotty.tools.dotc._
+import core._
+import Decorators._
+import Types._, Symbols._
+
+object denotTest extends DottyTest {
+ println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
+
+ val str = defn.StringClass.typeRef //> str : dotty.tools.dotc.core.Types.TypeRef = TypeRef(ThisType(module class l
+ //| ang#57),String)
+ val d= str.member("getBytes".toTermName) //> d : dotty.tools.dotc.core.Denotations.Denotation = val getBytes <and> val g
+ //| etBytes <and> val getBytes <and> val getBytes
+ d.alternatives //> res0: List[dotty.tools.dotc.core.Denotations.SingleDenotation] = List(val ge
+ //| tBytes, val getBytes, val getBytes, val getBytes)
+ d.alternatives.map(_.info) //> res1: List[dotty.tools.dotc.core.Types.Type] = List(JavaMethodType(List(), L
+ //| ist(), RefinedType(TypeRef(ThisType(module class scala#35),Array), scala$Arr
+ //| ay$$T, TypeAlias(TypeRef(ThisType(module class scala#35),Byte)))), JavaMetho
+ //| dType(List(x$0), List(TypeRef(ThisType(module class charset#5432),Charset)),
+ //| RefinedType(TypeRef(ThisType(module class scala#35),Array), scala$Array$$T,
+ //| TypeAlias(TypeRef(ThisType(module class scala#35),Byte)))), JavaMethodType(
+ //| List(x$0), List(TypeRef(ThisType(module class lang#57),String)), RefinedType
+ //| (TypeRef(ThisType(module class scala#35),Array), scala$Array$$T, TypeAlias(T
+ //| ypeRef(ThisType(module class scala#35),Byte)))), JavaMethodType(List(x$0, x$
+ //| 1, x$2, x$3), List(TypeRef(ThisType(module class scala#35),Int), TypeRef(Thi
+ //| sType(module class scala#35),Int), RefinedType(TypeRef(ThisType(module class
+ //| scala#35),Array), scala$Array$$T, TypeAlias(TypeRef(ThisType(module class s
+ //| cala#35),Byte))), TypeRef(ThisType(module class scala#35),Int)), TypeRef(Thi
+ //| sType(module class scala#35),Unit)))
+ val sm = defn.StringClass.companionModule //> sm : dotty.tools.dotc.core.Symbols.Symbol = module String#214
+ val d2 = sm.info.member("valueOf".toTermName) //> d2 : dotty.tools.dotc.core.Denotations.Denotation = val valueOf <and> val v
+ //| alueOf <and> val valueOf <and> val valueOf <and> val valueOf <and> val value
+ //| Of <and> val valueOf <and> val valueOf <and> val valueOf
+ d2.alternatives.map(_.info) //> res2: List[dotty.tools.dotc.core.Types.Type] = List(JavaMethodType(List(x$0)
+ //| , List(TypeRef(ThisType(module class scala#35),Double)), TypeRef(ThisType(mo
+ //| dule class lang#57),String)), JavaMethodType(List(x$0), List(TypeRef(ThisTyp
+ //| e(module class scala#35),Float)), TypeRef(ThisType(module class lang#57),Str
+ //| ing)), JavaMethodType(List(x$0), List(TypeRef(ThisType(module class scala#35
+ //| ),Long)), TypeRef(ThisType(module class lang#57),String)), JavaMethodType(Li
+ //| st(x$0), List(TypeRef(ThisType(module class scala#35),Int)), TypeRef(ThisTyp
+ //| e(module class lang#57),String)), JavaMethodType(List(x$0), List(TypeRef(Thi
+ //| sType(module class scala#35),Char)), TypeRef(ThisType(module class lang#57),
+ //| String)), JavaMethodType(List(x$0), List(TypeRef(ThisType(module class scala
+ //| #35),Boolean)), TypeRef(ThisType(module class lang#57),String)), JavaMethodT
+ //| ype(List(x$0, x$1, x$2), List(RefinedType(TypeRef(ThisType(module class scal
+ //| a#35),Array), scala$Array$$T, TypeAlias(TypeRef(ThisType(module class scala#
+ //| 35),Char))), TypeRef(ThisType(module class scala#35),Int), TypeRef(ThisType(
+ //| module class scala#35),Int)), TypeRef(ThisType(module class lang#57),String)
+ //| ), JavaMethodType(List(x$0), List(RefinedType(TypeRef(ThisType(module class
+ //| scala#35),Array), scala$Array$$T, TypeAlias(TypeRef(ThisType(module class sc
+ //| ala#35),Char)))), TypeRef(ThisType(module class lang#57),String)), JavaMetho
+ //| dType(List(x$0), List(TypeRef(ThisType(module class scala#35),Any)), TypeRef
+ //| (ThisType(module class lang#57),String)))
+} \ No newline at end of file
diff --git a/compiler/test/worksheets/flagtest.sc b/compiler/test/worksheets/flagtest.sc
new file mode 100644
index 000000000..ac3a6ab13
--- /dev/null
+++ b/compiler/test/worksheets/flagtest.sc
@@ -0,0 +1,27 @@
+package dotty.tools.dotc.core
+
+object flagtest {
+ println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
+
+ import Flags._
+
+ val pri = Private //> pri : dotty.tools.dotc.core.Flags.FlagSet = private
+ val pro = Protected //> pro : dotty.tools.dotc.core.Flags.FlagSet = protected
+ val pripro = pri | pro //> pripro : dotty.tools.dotc.core.Flags.FlagSet = private protected
+ pripro is pri //> res0: Boolean = true
+ pripro is pro //> res1: Boolean = true
+ pripro is Local //> res2: Boolean = false
+ val pp = allOf(pri, pro) //> pp : dotty.tools.dotc.core.Flags.FlagConjunction = private protected
+ pripro is pp //> res3: Boolean = true
+ pri is pp //> res4: Boolean = false
+ pri is pripro //> res5: Boolean = true
+ Method //> res6: dotty.tools.dotc.core.Flags.FlagSet = <method>
+ Abstract //> res7: dotty.tools.dotc.core.Flags.FlagSet = abstract
+ Method == Abstract //> res8: Boolean = false
+ Method.toCommonFlags //> res9: dotty.tools.dotc.core.Flags.FlagSet = <method> abstract
+ FromStartFlags //> res10: dotty.tools.dotc.core.Flags.FlagSet = private protected <deferred> <p
+ //| aram> <accessor> sealed <local> module <package> <expandedname> <covariant>
+ //| <contravariant> <static> <touched> <frozen> <existential>
+ AccessFlags <= FromStartFlags //> res11: Boolean = true
+ FromStartFlags <= AccessFlags //> res12: Boolean = false
+} \ No newline at end of file
diff --git a/compiler/test/worksheets/nesting.sc b/compiler/test/worksheets/nesting.sc
new file mode 100644
index 000000000..a6fc92432
--- /dev/null
+++ b/compiler/test/worksheets/nesting.sc
@@ -0,0 +1,31 @@
+package dotty.tools.dotc.core
+
+object nesting {
+ class C {
+
+ class D {
+ private def x = "D"
+ def show = x
+ class E {
+ println(x)
+ }
+ }
+
+ val foo: D = {
+ class D extends C.this.D {
+ private def x = "foo.D"
+ class E {
+ println(x)
+ }
+ }
+ new D
+ }
+ }
+
+ val c = new C //> c : dotty.tools.dotc.core.nesting.C = dotty.tools.dotc.core.nesting$C@1a84d
+ //| a23
+ val d = c.foo //> d : dotty.tools.dotc.core.nesting.c.D = dotty.tools.dotc.core.nesting$C$D$1
+ //| @2705d88a
+ d.show //> res0: String = foo.D
+
+} \ No newline at end of file
diff --git a/compiler/test/worksheets/periodtest.sc b/compiler/test/worksheets/periodtest.sc
new file mode 100644
index 000000000..09c02da19
--- /dev/null
+++ b/compiler/test/worksheets/periodtest.sc
@@ -0,0 +1,18 @@
+package dotty.tools.dotc.core
+
+object periodtest {
+ println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
+
+ import Periods._
+
+ val p1 = Period(1, 2, 7) //> p1 : dotty.tools.dotc.core.Periods.Period = Period(2..7, run = 1)
+ val p2 = Period(1, 3, 7) //> p2 : dotty.tools.dotc.core.Periods.Period = Period(3..7, run = 1)
+ p1 contains p2 //> res0: Boolean = true
+ p1 contains p1 //> res1: Boolean = true
+ p2 contains p1 //> res2: Boolean = false
+ p1 contains Period(0, 3, 3) //> res3: Boolean = false
+ p1 contains Period(2, 3, 3) //> res4: Boolean = false
+ p1 contains Nowhere //> res5: Boolean = false
+ p1 overlaps p1 //> res6: Boolean = true
+ Period(1, 2, 7) overlaps Period(1, 6, 9) //> res7: Boolean = true
+} \ No newline at end of file
diff --git a/compiler/test/worksheets/positiontest.sc b/compiler/test/worksheets/positiontest.sc
new file mode 100644
index 000000000..11cc54dbe
--- /dev/null
+++ b/compiler/test/worksheets/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/compiler/test/worksheets/sigtest.sc b/compiler/test/worksheets/sigtest.sc
new file mode 100644
index 000000000..ed3793f1c
--- /dev/null
+++ b/compiler/test/worksheets/sigtest.sc
@@ -0,0 +1,34 @@
+package test
+
+import dotty.tools.dotc._
+import core._
+import Decorators._
+import Types._, Symbols._
+
+object sigtest extends DottyTest {
+ println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
+ val int = ctx.requiredClass("scala.Int") //> int : dotty.tools.dotc.core.Symbols.ClassSymbol = class Int
+ int.signature //> res0: dotty.tools.dotc.core.Denotations.Signature = List()
+ val intmeth = methType("x")(int.symbolicRef)() //> intmeth : dotty.tools.dotc.core.Types.MethodType = MethodType(List(x), List
+ //| (TypeRef(ThisType(module class scala),Int)), TypeRef(ThisType(module class s
+ //| cala),Unit))
+ intmeth.signature //> res1: dotty.tools.dotc.core.Denotations.Signature = List(Int)
+ val arr = defn.ArrayType.appliedTo(int.symbolicRef)
+ //> arr : dotty.tools.dotc.core.Types.Type = RefinedType(TypeRef(ThisType(modul
+ //| e class scala),Array), scala$Array$$T, TypeAlias(TypeRef(ThisType(module cla
+ //| ss scala),Int)) | hash = 1907214242)
+ val arraymeth = methType("x")(arr)() //> arraymeth : dotty.tools.dotc.core.Types.MethodType = MethodType(List(x), Li
+ //| st(RefinedType(TypeRef(ThisType(module class scala),Array), scala$Array$$T,
+ //| TypeAlias(TypeRef(ThisType(module class scala),Int)) | hash = 1907214242)),
+ //| TypeRef(ThisType(module class scala),Unit))
+ arraymeth.signature //> res2: dotty.tools.dotc.core.Denotations.Signature = List(Int[])
+ val curriedmeth = methType("x", "y")(defn.IntType, defn.BooleanType)(methType("z")(defn.ArrayType.appliedTo(defn.IntType))())
+ //> curriedmeth : dotty.tools.dotc.core.Types.MethodType = MethodType(List(x, y
+ //| ), List(TypeRef(ThisType(module class scala),Int), TypeRef(ThisType(module c
+ //| lass scala),Boolean)), MethodType(List(z), List(RefinedType(TypeRef(ThisType
+ //| (module class scala),Array), scala$Array$$T, TypeAlias(TypeRef(ThisType(modu
+ //| le class scala),Int)) | hash = 1808140099)), TypeRef(ThisType(module class s
+ //| cala),Unit)))
+ curriedmeth.signature //> res3: dotty.tools.dotc.core.Denotations.Signature = List(Int, Boolean, Int[]
+ //| )
+} \ No newline at end of file
diff --git a/compiler/test/worksheets/testnames.sc b/compiler/test/worksheets/testnames.sc
new file mode 100644
index 000000000..282b07d4e
--- /dev/null
+++ b/compiler/test/worksheets/testnames.sc
@@ -0,0 +1,49 @@
+package dotty.tools.dotc.core
+
+object testnames {
+ println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
+
+ import Names._
+ val n = termName("hello") //> n : dotty.tools.dotc.core.Names.TermName = hello
+ val tn = n.toTypeName //> tn : dotty.tools.dotc.core.Names.TypeName = hello
+ val ln = n.toLocalName //> ln : dotty.tools.dotc.core.Names.LocalName = hello
+ assert(tn.toTermName eq n)
+ assert(tn.toLocalName eq ln)
+ assert(n.toLocalName eq ln)
+
+ n == tn //> res0: Boolean = false
+ n == ln //> res1: Boolean = false
+ n eq tn //> res2: Boolean = false
+ n.hashCode //> res3: Int = 0
+ tn.hashCode //> res4: Int = 0
+ val foo = encodedTermName("++") //> foo : dotty.tools.dotc.core.Names.TermName = $plus$plus
+ foo.hashCode //> res5: Int = 5
+ foo.toTypeName.hashCode //> res6: Int = -5
+
+ val nfoo = n ++ foo //> nfoo : dotty.tools.dotc.core.testnames.n.ThisName = hello$plus$plus
+ nfoo contains '$' //> res7: Boolean = true
+ nfoo.replace('$', '.') //> res8: dotty.tools.dotc.core.testnames.nfoo.ThisName = hello.plus.plus
+ n == EmptyTermName //> res9: Boolean = false
+ EmptyTermName.start //> res10: Int = -1
+ nfoo slice (2, 4) //> res11: dotty.tools.dotc.core.testnames.nfoo.ThisName = ll
+ nfoo take 3 //> res12: dotty.tools.dotc.core.Names.Name = hel
+ nfoo drop 3 //> res13: dotty.tools.dotc.core.Names.Name = lo$plus$plus
+ nfoo.head //> res14: Char = h
+ nfoo.tail //> res15: dotty.tools.dotc.core.Names.Name = ello$plus$plus
+ nfoo.isTermName //> res16: Boolean = true
+ val cs = Array('a', 'b', 'c') //> cs : Array[Char] = Array(a, b, c)
+ termName(cs, 0, 2) //> res17: dotty.tools.dotc.core.Names.TermName = ab
+ termName("abc") //> res18: dotty.tools.dotc.core.Names.TermName = abc
+ nfoo.filter(_ >= 'l') //> res19: dotty.tools.dotc.core.Names.Name = lloplusplus
+ nfoo map (_.toUpper) //> res20: dotty.tools.dotc.core.Names.Name = HELLO$PLUS$PLUS
+
+ import Decorators._
+
+ val local = "local".toTermName.toLocalName //> local : dotty.tools.dotc.core.Names.LocalName = local
+ val local1 = local ++ "!" //> local1 : dotty.tools.dotc.core.testnames.local.ThisName = local!
+ local1 //> res21: dotty.tools.dotc.core.testnames.local.ThisName = local!
+ val local2 = "Foo.".toTermName ++: local1 //> local2 : dotty.tools.dotc.core.Names.Name = Foo.local!
+ local2 //> res22: dotty.tools.dotc.core.Names.Name = Foo.local!
+ local1.dropRight(2) //> res23: dotty.tools.dotc.core.Names.Name = loca
+ local1.fromName("Foo.".toTermName ++ local1) //> res24: dotty.tools.dotc.core.testnames.local1.ThisName = Foo.local!
+} \ No newline at end of file