diff options
Diffstat (limited to 'test/junit')
-rw-r--r-- | test/junit/scala/tools/nsc/symtab/FreshNameExtractorTest.scala | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/symtab/FreshNameExtractorTest.scala b/test/junit/scala/tools/nsc/symtab/FreshNameExtractorTest.scala new file mode 100644 index 0000000000..cf09abdfff --- /dev/null +++ b/test/junit/scala/tools/nsc/symtab/FreshNameExtractorTest.scala @@ -0,0 +1,47 @@ +package scala.tools.nsc +package symtab + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import scala.tools.testing.AssertUtil.assertThrows +import scala.reflect.internal.util.FreshNameCreator + +@RunWith(classOf[JUnit4]) +class FreshNameExtractorTest { + object symbolTable extends SymbolTableForUnitTesting + import symbolTable._ + + val prefixes = List("foo$", "x$", "bar", "bippy$baz$") + + @Test + def extractionPreservesPrefix = + ("" :: prefixes).foreach { creatorPrefix => + prefixes.foreach { newPrefix => + val Creator = new FreshNameCreator(creatorPrefix) + val Extractor = new FreshNameExtractor(creatorPrefix) + val Extractor(extractedPrefix) = TermName(Creator.newName(newPrefix)) + assertEquals(newPrefix, extractedPrefix) + } + } + + @Test + def extractionFailsOnCreatorPrefixMismatch = { + val Creator = new FreshNameCreator(prefixes.head) + val Extractor = new FreshNameExtractor(prefixes.tail.head) + assertThrows[MatchError] { + val Extractor(_) = TermName(Creator.newName("foo")) + } + } + + @Test + def extractionsFailsIfNameDoesntEndWithNumber = { + val Creator = new FreshNameCreator(prefixes.head) + val Extractor = new FreshNameExtractor(prefixes.head) + assertThrows[MatchError] { + val Extractor(_) = TermName(Creator.newName("foo") + "bar") + } + } +}
\ No newline at end of file |