diff options
author | mmcbride <mccv@twitter.com> | 2011-10-26 14:26:58 -0700 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-11-07 02:08:38 -0500 |
commit | deadedb9bcb21d49b49a84987deda66868c110b8 (patch) | |
tree | dcbb579adc900fa96d4366435d18ab9b2e3272a1 /libraries/eval/test | |
parent | de4f870d5ad294408b6fa97a3a6ff1d02a4273b8 (diff) | |
download | cbt-deadedb9bcb21d49b49a84987deda66868c110b8.tar.gz cbt-deadedb9bcb21d49b49a84987deda66868c110b8.tar.bz2 cbt-deadedb9bcb21d49b49a84987deda66868c110b8.zip |
[split] Fixing eval precompile issues with invalid characters in classnames. Also, git-review bump
Diffstat (limited to 'libraries/eval/test')
-rw-r--r-- | libraries/eval/test/EvalTest.scala | 37 | ||||
-rw-r--r-- | libraries/eval/test/resources/file-with-dash.scala | 1 |
2 files changed, 37 insertions, 1 deletions
diff --git a/libraries/eval/test/EvalTest.scala b/libraries/eval/test/EvalTest.scala index 40d15a7..32855de 100644 --- a/libraries/eval/test/EvalTest.scala +++ b/libraries/eval/test/EvalTest.scala @@ -7,6 +7,7 @@ import com.twitter.io.TempFile object EvalSpec extends Specification { "Evaluator" should { + "apply('expression')" in { (new Eval).apply[Int]("1 + 1") mustEqual 2 } @@ -22,6 +23,23 @@ object EvalSpec extends Specification { derived() mustEqual "hello" } + "apply(new File(...) with a dash in the name with target" in { + val f = File.createTempFile("eval", "target") + f.delete() + f.mkdir() + val e = new Eval(Some(f)) + val sourceFile = TempFile.fromResourcePath("/file-with-dash.scala") + val res: String = e(sourceFile) + res mustEqual "hello" + val className = e.fileToClassName(sourceFile) + val fullClassName = "Evaluator__%s_%s.class".format( + className, e.uniqueId(sourceFile.getCanonicalPath, None)) + val targetFileName = f.getAbsolutePath() + File.separator + fullClassName + val targetFile = new File(targetFileName) + targetFile.exists must be_==(true) + val targetMod = targetFile.lastModified + } + "apply(new File(...) with target" in { val f = File.createTempFile("eval", "target") f.delete() @@ -32,7 +50,10 @@ object EvalSpec extends Specification { res mustEqual 2 // make sure it created a class file with the expected name - val targetFileName = f.getAbsolutePath() + File.separator + "Evaluator__" + sourceFile.getName + ".class" + val className = e.fileToClassName(sourceFile) + val fullClassName = "Evaluator__%s_%s.class".format( + className, e.uniqueId(sourceFile.getCanonicalPath, None)) + val targetFileName = f.getAbsolutePath() + File.separator + fullClassName val targetFile = new File(targetFileName) targetFile.exists must be_==(true) val targetMod = targetFile.lastModified @@ -103,5 +124,19 @@ object EvalSpec extends Specification { Eval[() => String]( TempFile.fromResourcePath("RubyInclude.scala")) must throwA[Throwable] } + + "clean class names" in { + val e = new Eval() + // regular old scala file + e.fileToClassName(new File("foo.scala")) mustEqual "foo" + // without an extension + e.fileToClassName(new File("foo")) mustEqual "foo" + // with lots o dots + e.fileToClassName(new File("foo.bar.baz")) mustEqual "foo$2ebar" + // with dashes + e.fileToClassName(new File("foo-bar-baz.scala")) mustEqual "foo$2dbar$2dbaz" + // with crazy things + e.fileToClassName(new File("foo$! -@@@")) mustEqual "foo$24$21$20$2d$40$40$40" + } } } diff --git a/libraries/eval/test/resources/file-with-dash.scala b/libraries/eval/test/resources/file-with-dash.scala new file mode 100644 index 0000000..3580093 --- /dev/null +++ b/libraries/eval/test/resources/file-with-dash.scala @@ -0,0 +1 @@ +"hello" |