blob: d72d14579ccfa154200bc72412e040983b011e86 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package com.twitter.util
import org.specs.Specification
import java.io.{File, FileOutputStream}
object EvaluatorSpec extends Specification {
def file(path: String) = {
val stream = getClass.getResourceAsStream(path)
val file = File.createTempFile(path, "scala")
val fos = new FileOutputStream(file)
var byte = stream.read()
while (byte != -1) {
fos.write(byte)
byte = stream.read()
}
file
}
"Evaluator" should {
"apply('expression')" in {
Eval[Int]("1 + 1") mustEqual 2
}
"apply(new File(...))" in {
Eval[Int](new File("src/test/resources/OnePlusOne.scala")) mustEqual 2
}
"apply(new File(...), new File(...))" in {
val derived = Eval[() => String](file("/Base.scala"), file("/Derived.scala"))
derived() mustEqual "hello"
}
"apply(InputStream)" in {
Eval[Int](getClass.getResourceAsStream("/OnePlusOne.scala")) mustEqual 2
}
}
}
|