summaryrefslogtreecommitdiff
path: root/test/junit
diff options
context:
space:
mode:
authorGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2013-08-02 11:22:04 -0700
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2013-08-02 11:22:04 -0700
commitd5e0f728c322a3beec5c62a9f4e28b3a3f86e84d (patch)
treec9c9a2703f58052705f8eb6f3be6fe45db03ae67 /test/junit
parent3cb3c8e35c3df31a7f661903eca48cca557d5a49 (diff)
downloadscala-d5e0f728c322a3beec5c62a9f4e28b3a3f86e84d.tar.gz
scala-d5e0f728c322a3beec5c62a9f4e28b3a3f86e84d.tar.bz2
scala-d5e0f728c322a3beec5c62a9f4e28b3a3f86e84d.zip
Add sample to SymbolTableTest using custom symbols and type.
Add a test which demonstrates how one can create symbols and types from scratch and perform sub type check using them.
Diffstat (limited to 'test/junit')
-rw-r--r--test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala b/test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala
index 166e0382f7..537cb93ef3 100644
--- a/test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala
+++ b/test/junit/scala/tools/nsc/symtab/SymbolTableTest.scala
@@ -26,4 +26,25 @@ class SymbolTableTest {
assertTrue("List should be subclass of Seq", listClassTpe <:< seqClassTpe)
}
+ /**
+ * Demonstrates how one can create symbols and type completely
+ * from scratch and perform sub type check.
+ */
+ @Test
+ def customClassesSubTypeCheck: Unit = {
+ val symbolTable = createSymbolTable
+ import symbolTable._
+ symbolTable.definitions.init()
+ val rootClass = symbolTable.rootMirror.RootClass
+ val fooSymbol = rootClass.newClassSymbol("Foo": TypeName, NoPosition, 0)
+ val fooType = new ClassInfoType(Nil, EmptyScope, fooSymbol)
+ fooSymbol.info = fooType
+ val barSymbol = rootClass.newClassSymbol("Bar": TypeName, NoPosition, 0)
+ val fooTypeRef = TypeRef(fooSymbol.owner.tpe, fooSymbol, Nil)
+ val barType = new ClassInfoType(List(fooTypeRef), EmptyScope, barSymbol)
+ barSymbol.info = barType
+ assertTrue("Bar should be subclass of Foo", barSymbol.tpe <:< fooSymbol.tpe)
+ assertFalse("Foo should be a superclass of Foo", fooSymbol.tpe <:< barSymbol.tpe)
+ }
+
}