summaryrefslogtreecommitdiff
path: root/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-09-16 11:12:13 +0200
committerJason Zaugg <jzaugg@gmail.com>2013-09-16 16:44:28 +0200
commitcff8b569c39fb2ce57157fa6adf4ab9289721033 (patch)
tree793273d29da6141bc7b4414a82a5d59c6a2f44fb /test/junit/scala/tools/nsc/symtab/StdNamesTest.scala
parent4aad4eb6c1f10abd64ec5dfd8eeba091491349e2 (diff)
downloadscala-cff8b569c39fb2ce57157fa6adf4ab9289721033.tar.gz
scala-cff8b569c39fb2ce57157fa6adf4ab9289721033.tar.bz2
scala-cff8b569c39fb2ce57157fa6adf4ab9289721033.zip
SI-7841 More robust unspecialization of names
Names like `T1$sp`, which can arise from `AnyRef` specialization, were leading to negative length Names if they ever passed through `unspecializedName` or `splitSpecializedName`. This code path was touched when printing the tree of a certain AnyRef specialized classes after specialization, such as `AbstractPartialFunction` (which had such specialization until a few commits ago.) This commit handles that case correctly, and generally hardens against unexpected names, which could pop up from third party classes. The documentation for `splitSpecializedName` transposed the class and method specializations. The things you discover when you turn examples in documentation in to test cases! In addition, we now require non-negative length and offset in `newTermName`
Diffstat (limited to 'test/junit/scala/tools/nsc/symtab/StdNamesTest.scala')
-rw-r--r--test/junit/scala/tools/nsc/symtab/StdNamesTest.scala46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala b/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala
new file mode 100644
index 0000000000..05e69978c6
--- /dev/null
+++ b/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala
@@ -0,0 +1,46 @@
+package scala.tools.nsc
+package symtab
+
+import org.junit.Assert._
+import scala.tools.testing.AssertUtil._
+import org.junit.{Ignore, Test}
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+@RunWith(classOf[JUnit4])
+class StdNamesTest {
+ object symbolTable extends SymbolTableForUnitTesting
+ import symbolTable._
+ import nme.{SPECIALIZED_SUFFIX, unspecializedName, splitSpecializedName}
+
+ @Test
+ def testNewTermNameInvalid(): Unit = {
+ assertThrows[IllegalArgumentException](newTermName("foo".toCharArray, 0, -1))
+ assertThrows[IllegalArgumentException](newTermName("foo".toCharArray, 0, 0))
+ assertThrows[IllegalArgumentException](newTermName("foo".toCharArray, -1, 1))
+ }
+
+ @Test
+ def testUnspecializedName(): Unit = {
+ def test(expected: Name, nme: Name) {
+ assertEquals(expected, unspecializedName(nme))
+ }
+ test(TermName("Tuple2"), TermName("Tuple2$mcII" + SPECIALIZED_SUFFIX))
+ test(TermName("foo"), TermName("foo$mIcD" + SPECIALIZED_SUFFIX))
+ test(TermName("foo"), TermName("foo$mIc" + SPECIALIZED_SUFFIX))
+ test(TermName("T1"), TermName(s"T1$SPECIALIZED_SUFFIX"))
+ test(TermName(""), SPECIALIZED_SUFFIX)
+ }
+
+ @Test
+ def testSplitSpecializedName(): Unit = {
+ def test(expected: (Name, String, String), nme: Name) {
+ assertEquals(expected, splitSpecializedName(nme))
+ }
+ test((TermName("Tuple2"), "II", ""), TermName("Tuple2$mcII" + SPECIALIZED_SUFFIX))
+ test((TermName("foo"), "D", "I"), TermName("foo$mIcD" + SPECIALIZED_SUFFIX))
+ test((TermName("foo"), "", "I"), TermName("foo$mIc" + SPECIALIZED_SUFFIX))
+ test((TermName("T1"), "", ""), TermName(s"T1$SPECIALIZED_SUFFIX"))
+ test((TermName(""), "", ""), SPECIALIZED_SUFFIX)
+ }
+}