forked from jesseeichar/scala-io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split scala io into 4 projects. core, core-test,file,file-test, core …
…is essentially scala.io, core-test is to allow others to reuse the abstract test classes
- Loading branch information
jeichar
committed
Jan 12, 2011
1 parent
1f3f644
commit 712d684
Showing
189 changed files
with
5,360 additions
and
3,199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
docs | ||
cobertura.ser | ||
.DS_Store | ||
project/boot/ | ||
target/ | ||
lib_managed/ | ||
*.class | ||
.project | ||
.classpath | ||
.scala_dependencies | ||
/ws/ | ||
/.gradle/ | ||
/lib/ | ||
project/plugins/src_managed/ | ||
*.iws | ||
derby.log | ||
.idea | ||
*.iml |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
The goal of this project is to create an Input/Output and filesystem access API for scala. The main inspiration is the Java 7 NIO file API combined with the scala-arm project being worked on by jseureth. | ||
The goal of this project is to create an Input/Output and filesystem access API for scala. The main inspiration is the Java 7 NIO file API combined with the scala-arm project being worked on by jseureth. | ||
|
||
The implementation will work with Java 6+ and will depend on scala-arm but not on the Java 7 NIO file API. | ||
The implementation will work with Java 6+ and will depend on scala-arm but not on the Java 7 NIO file API. | ||
|
||
d |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ A | |
≈ | ||
ゼ | ||
` | ||
|
208 changes: 208 additions & 0 deletions
208
core-test/src/main/scala/scalaio/test/AbstractInputTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
package scalaio.test | ||
|
||
/* __ *\ | ||
** ________ ___ / / ___ Scala API ** | ||
** / __/ __// _ | / / / _ | (c) 2009-2010, Jesse Eichar ** | ||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** | ||
** /____/\___/_/ |_/____/_/ | | ** | ||
** |/ ** | ||
\* */ | ||
|
||
import scalax.io._ | ||
import Codec.UTF8 | ||
import Line.Terminators._ | ||
|
||
import org.junit.Assert._ | ||
import org.junit.{ | ||
Test, Ignore | ||
} | ||
|
||
import Constants.TEXT_VALUE | ||
import java.io.ByteArrayInputStream | ||
|
||
abstract class AbstractInputTests extends scalax.test.sugar.AssertionSugar { | ||
|
||
sealed trait Type | ||
|
||
case object Image extends Type | ||
|
||
abstract class Text(val sep: String) extends Type | ||
|
||
case object TextNewLine extends Text(NewLine.sep) | ||
|
||
case object TextPair extends Text(Pair.sep) | ||
|
||
case object TextCarriageReturn extends Text(CarriageReturn.sep) | ||
|
||
case class TextCustom(s: String) extends Text(s) | ||
|
||
case class TextCustomData(s: String, data: String) extends Text(s) | ||
|
||
protected def input(t: Type): Input | ||
|
||
protected def sizeIsDefined = true | ||
|
||
@Test(timeout = 3000) //@Ignore | ||
def provide_length_for_files(): Unit = { | ||
val size = input(Image).size | ||
if (sizeIsDefined) { | ||
assertTrue(size.isDefined) | ||
assertEquals(Constants.IMAGE_FILE_SIZE, size.get) | ||
} else { | ||
assertTrue(size.isEmpty) | ||
} | ||
} | ||
|
||
@Test(timeout = 3000) //@Ignore | ||
def read_all_bytes(): Unit = { | ||
val bytes = input(TextNewLine).bytes.toArray | ||
|
||
val expected = TEXT_VALUE getBytes UTF8.name | ||
val bytesString = new String(bytes, UTF8.name) | ||
|
||
assertEquals(expected.size, bytes.size) | ||
assertArrayEquals("expected '" + TEXT_VALUE + "' but got '" + bytesString + "'", | ||
expected, bytes) | ||
} | ||
|
||
@Test(timeout = 3000) //@Ignore | ||
def read_a_subset_of_bytes() = { | ||
val bytes = input(TextNewLine).bytes.slice(4, 4).toArray | ||
|
||
val expected = TEXT_VALUE getBytes UTF8.name slice (4, 4) | ||
val bytesString = new String(bytes, UTF8.name) | ||
|
||
assertEquals(expected.size, bytes.size) | ||
assertArrayEquals("expected '" + TEXT_VALUE + "' but got '" + bytesString + "'", | ||
expected, bytes) | ||
} | ||
|
||
|
||
@Test(timeout = 3000) //@Ignore | ||
def read_all_bytes_as_Ints(): Unit = { | ||
val ints = input(TextNewLine).bytesAsInts.toArray | ||
val expected = { | ||
val in = new ByteArrayInputStream(Constants.TEXT_VALUE.getBytes(Codec.UTF8.charSet)) | ||
try { | ||
var i = in.read() | ||
val buffer = new collection.mutable.ArrayBuffer[Int]() | ||
while (i != -1) { | ||
buffer += i | ||
i = in.read() | ||
} | ||
buffer.toArray | ||
} finally { | ||
in.close | ||
} | ||
} | ||
|
||
assertEquals(expected.size, ints.size) | ||
assertArrayEquals(expected, ints) | ||
} | ||
|
||
|
||
@Test(timeout = 3000) //@Ignore | ||
def read_all_bytes_into_array(): Unit = { | ||
val bytes = input(TextNewLine).byteArray | ||
|
||
val expected = TEXT_VALUE getBytes UTF8.name | ||
val bytesString = new String(bytes, UTF8.name) | ||
|
||
assertEquals(expected.size, bytes.size) | ||
assertArrayEquals("expected '" + TEXT_VALUE + "' but got '" + bytesString + "'", | ||
expected, bytes) | ||
} | ||
|
||
// byte ops done now chars | ||
|
||
@Test(timeout = 3000) //@Ignore | ||
def read_all_chars(): Unit = { | ||
val read = input(TextNewLine).chars(UTF8).toArray | ||
|
||
val expected = TEXT_VALUE.toArray | ||
|
||
assertArrayEquals("expected " + expected.mkString + " but got " + read.mkString, expected, read) | ||
} | ||
|
||
@Test(timeout = 3000) //@Ignore | ||
def read_a_subset_of_chars() = { | ||
val read = input(TextNewLine).chars(UTF8).slice(4, 2).toArray | ||
|
||
val expected = { | ||
TEXT_VALUE slice (4, 4) toArray | ||
} | ||
|
||
assertArrayEquals("expected " + expected.mkString + " but got " + read.mkString, expected, read) | ||
} | ||
|
||
@Test(timeout = 3000) //@Ignore | ||
def read_all_chars_into_String(): Unit = { | ||
val read = input(TextNewLine).slurpString(UTF8) | ||
|
||
val expected = TEXT_VALUE | ||
|
||
assertEquals(expected, read) | ||
} | ||
|
||
@Test //(timeout = 3000) //@Ignore | ||
def read_all_lines_auto(): Unit = { | ||
testLines("NewLine", TextCustomData("\n", "\n"), Auto(), false) | ||
testLines("NewLine", TextCustomData("\n", "aa\n"), Auto(), false) | ||
testLines("NewLine", TextCustomData(Pair.sep, "aa" + Pair.sep), Auto(), false) | ||
testLines("NewLine", TextNewLine, Auto(), false) | ||
testLines("Pair", TextPair, Auto(), false) | ||
testLines("CarriageReturn", TextCarriageReturn, Auto(), false) | ||
|
||
testLines("include NewLine", TextNewLine, Auto(), true) | ||
testLines("include Pair", TextPair, Auto(), true) | ||
testLines("include CarriageReturn", TextCarriageReturn, Auto(), true) | ||
} | ||
|
||
@Test //(timeout = 3000) //@Ignore | ||
def read_all_lines(): Unit = { | ||
testLines("NewLine", TextNewLine, NewLine, false) | ||
testLines("Pair", TextPair, Pair, false) | ||
testLines("CarriageReturn", TextCarriageReturn, CarriageReturn, false) | ||
testLines("Custom", TextCustom("x"), Custom("x"), false) | ||
} | ||
|
||
|
||
@Test(timeout = 3000) //@Ignore | ||
def read_all_lines_includeTerminator(): Unit = { | ||
testLines("Auto", TextNewLine, Auto(), true) | ||
testLines("NewLine", TextNewLine, NewLine, true) | ||
testLines("Pair", TextPair, Pair, true) | ||
testLines("CarriageReturn", TextCarriageReturn, CarriageReturn, true) | ||
testLines("Custom", TextCustom("x"), Custom("x"), true) | ||
} | ||
|
||
def testLines(msg: String, t: Text, terminator: Terminator, include: Boolean) { | ||
val read = input(t).lines(terminator, include)(UTF8).toList | ||
val expected = { | ||
val (sep, data) = t match { | ||
case TextCustomData(sep, data) => (sep, data) | ||
case _ => ("\n", TEXT_VALUE) | ||
} | ||
val lines = data.split(sep).toList | ||
|
||
val withLastEl = | ||
if (data.matches("(?ms).*\\s+" + sep) || data.matches("(?ms)\\s*" + sep)) lines :+ "" | ||
else lines | ||
|
||
if (include) withLastEl.map { | ||
_ + t.sep | ||
} | ||
else withLastEl | ||
} | ||
assertEquals(msg, expected, read) | ||
} | ||
|
||
@Test(timeout = 3000) //@Ignore | ||
def read_some_lines(): Unit = { | ||
val read = input(TextNewLine).lines()(UTF8).drop(2).take(2).toList | ||
val expected = TEXT_VALUE.split("\n").toList.drop(2).take(2) | ||
assertEquals(expected, read) | ||
} | ||
|
||
|
||
} |
84 changes: 84 additions & 0 deletions
84
core-test/src/main/scala/scalaio/test/AbstractOutputTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* __ *\ | ||
** ________ ___ / / ___ Scala API ** | ||
** / __/ __// _ | / / / _ | (c) 2009-2010, Jesse Eichar ** | ||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** | ||
** /____/\___/_/ |_/____/_/ | | ** | ||
** |/ ** | ||
\* */ | ||
|
||
package scalaio.test | ||
|
||
import scalax.io._ | ||
import org.junit.Assert._ | ||
import org.junit.{ | ||
Test, Ignore | ||
} | ||
|
||
import Constants.TEXT_VALUE | ||
|
||
abstract class AbstractOutputTests extends scalax.test.sugar.AssertionSugar { | ||
private final val DEFAULT_DATA = "default data" | ||
|
||
def open(): (Input, Output) | ||
|
||
@Test //@Ignore | ||
def write_bytes(): Unit = { | ||
val (input, output) = open() | ||
val bytes = DEFAULT_DATA.getBytes | ||
|
||
output write bytes | ||
|
||
assertArrayEquals(bytes, input.byteArray) | ||
} | ||
|
||
@Test //@Ignore | ||
def write_string(): Unit = { | ||
implicit val codec = Codec.UTF8 | ||
|
||
val (input, output) = open() | ||
|
||
output write DEFAULT_DATA | ||
|
||
assertEquals(DEFAULT_DATA, input.slurpString) | ||
} | ||
|
||
@Test //@Ignore | ||
def write_charseq(): Unit = { | ||
implicit val codec = Codec.UTF8 | ||
|
||
val (input, output) = open() | ||
val charSeq = new StringBuilder(DEFAULT_DATA) | ||
|
||
output writeChars charSeq | ||
|
||
assertEquals(DEFAULT_DATA, input.slurpString) | ||
} | ||
|
||
@Test //@Ignore | ||
def write_traversable_char(): Unit = { | ||
implicit val codec = Codec.UTF8 | ||
|
||
val (input, output) = open() | ||
|
||
output writeChars DEFAULT_DATA.toList | ||
|
||
assertEquals(DEFAULT_DATA, input.slurpString) | ||
} | ||
|
||
|
||
@Test //@Ignore | ||
def write_many_strings(): Unit = { | ||
implicit val codec = Codec.UTF8 | ||
|
||
val (input, output) = open() | ||
|
||
output writeStrings (DEFAULT_DATA :: DEFAULT_DATA :: DEFAULT_DATA :: Nil) | ||
assertEquals(DEFAULT_DATA + DEFAULT_DATA + DEFAULT_DATA, input.slurpString) | ||
|
||
val (input2, output2) = open() | ||
|
||
output2 writeStrings (DEFAULT_DATA :: DEFAULT_DATA :: DEFAULT_DATA :: Nil, "-") | ||
assertEquals(DEFAULT_DATA + "-" + DEFAULT_DATA + "-" + DEFAULT_DATA, input2.slurpString) | ||
} | ||
|
||
} |
Oops, something went wrong.