diff options
author | Haoyi Li <haoyi@haoyi-mbp.corp.dropbox.com> | 2014-11-26 00:45:31 -0800 |
---|---|---|
committer | Haoyi Li <haoyi@haoyi-mbp.corp.dropbox.com> | 2014-11-26 00:45:31 -0800 |
commit | 24f31e120f9537faede7a174bb09ee35f64e1ce4 (patch) | |
tree | 06ffc3ecc7847789008352b7e2b7c040dad48907 /examples/scala-js/tools/jvm/src/test/scala/scala/scalajs/tools/classpath/builder/test/JarBuilderTest.scala | |
parent | b89ce9cbf79363f8cab09186a5d7ba94bc0af02a (diff) | |
parent | 2c4b142503bd2d871e6818b5cab8c38627d9e4a0 (diff) | |
download | hands-on-scala-js-24f31e120f9537faede7a174bb09ee35f64e1ce4.tar.gz hands-on-scala-js-24f31e120f9537faede7a174bb09ee35f64e1ce4.tar.bz2 hands-on-scala-js-24f31e120f9537faede7a174bb09ee35f64e1ce4.zip |
Merge commit '2c4b142503bd2d871e6818b5cab8c38627d9e4a0' as 'examples/scala-js'
Diffstat (limited to 'examples/scala-js/tools/jvm/src/test/scala/scala/scalajs/tools/classpath/builder/test/JarBuilderTest.scala')
-rw-r--r-- | examples/scala-js/tools/jvm/src/test/scala/scala/scalajs/tools/classpath/builder/test/JarBuilderTest.scala | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/examples/scala-js/tools/jvm/src/test/scala/scala/scalajs/tools/classpath/builder/test/JarBuilderTest.scala b/examples/scala-js/tools/jvm/src/test/scala/scala/scalajs/tools/classpath/builder/test/JarBuilderTest.scala new file mode 100644 index 0000000..6ed68fc --- /dev/null +++ b/examples/scala-js/tools/jvm/src/test/scala/scala/scalajs/tools/classpath/builder/test/JarBuilderTest.scala @@ -0,0 +1,74 @@ +package scala.scalajs.tools.classpath.builder.test + +import scala.scalajs.tools.classpath.builder._ + +import org.junit.Test +import org.junit.Assert._ + +class JarBuilderTest { + + val jsFileContent = "window.alert('Hello World');" + val jsFileName = "lib.js" + + private def getJARInputStream = { + // Keep imports local so we don't accidentally use something we shouldn't + import java.util.zip._ + import java.io._ + + // Write a ZIP to a byte array + val outBuf = new ByteArrayOutputStream + val out = new ZipOutputStream(outBuf) + + out.putNextEntry(new ZipEntry(jsFileName)) + val w = new OutputStreamWriter(out, "UTF-8") + w.write(jsFileContent) + w.flush() + + out.close() + + new ByteArrayInputStream(outBuf.toByteArray) + } + + /** Trivial FS that has only one jar */ + trait TrivialFS extends FileSystem { + // Keep imports local so we don't accidentally use something we shouldn't + import java.io.{InputStream, Reader} + import scala.scalajs.tools.io._ + import scala.collection.immutable.Traversable + + type File = Unit + + val DummyVersion: String = "DUMMY" + + def isDirectory(f: File): Boolean = false + def isFile(f: File): Boolean = true + def isJSFile(f: File): Boolean = false + def isIRFile(f: File): Boolean = false + def isJARFile(f: File): Boolean = true + def exists(f: File): Boolean = true + + def getName(f: File): String = "jar" + def getAbsolutePath(f: File): String = "jar" + def getVersion(f: File): String = "" + + def listFiles(d: File): Traversable[File] = ??? + + def toJSFile(f: File): VirtualJSFile = ??? + def toIRFile(f: File): VirtualScalaJSIRFile = ??? + def toReader(f: File): Reader = ??? + def toInputStream(f: File): InputStream = getJARInputStream + } + + class TestJARBuilder extends AbstractJarLibClasspathBuilder with TrivialFS + + @Test + def readInMemoryJarClasspath { + val builder = new TestJARBuilder + val cp = builder.build(Seq(())) + + assertArrayEquals( + Array[Object](jsFileName -> jsFileContent), + cp.availableLibs.mapValues(_.content).toArray[Object]) + } + +} |