Permalink
Browse files

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
jeichar committed Jan 12, 2011
1 parent 1f3f644 commit 712d684b5734566861ac160cc4c9198ca924d1e3
Showing with 5,360 additions and 3,199 deletions.
  1. +2 −7 .gitignore
  2. +9 −0 .idea/copyright/Scala.xml
  3. +4 −2 README
  4. +0 −427 ScalaIO.ipr
  5. BIN core-test/src/main/resources/image.png
  6. +1 −0 {scala-io/src/test/resources → core-test/src/main}/resources/text
  7. +208 −0 core-test/src/main/scala/scalaio/test/AbstractInputTests.scala
  8. +84 −0 core-test/src/main/scala/scalaio/test/AbstractOutputTests.scala
  9. +121 −0 core-test/src/main/scala/scalaio/test/AbstractReadCharsTests.scala
  10. +233 −0 core-test/src/main/scala/scalaio/test/AbstractSeekableTests.scala
  11. +46 −0 core-test/src/main/scala/scalaio/test/AbstractWriteCharsTests.scala
  12. +33 −0 core-test/src/main/scala/scalaio/test/Constants.scala
  13. +44 −0 core-test/src/main/scala/scalaio/test/resource/InputStreamResourceTest.scala
  14. +35 −0 core-test/src/main/scala/scalaio/test/stream/InputTest.scala
  15. +32 −0 core-test/src/main/scala/scalaio/test/stream/OutputTest.scala
  16. +31 −0 core-test/src/main/scala/scalaio/test/stream/ReadCharsTest.scala
  17. +33 −0 core-test/src/main/scala/scalaio/test/stream/WriteCharsTest.scala
  18. +38 −0 core-test/src/main/scala/scalax/io/resource/CharInputStreamTest.scala
  19. +27 −0 core-test/src/main/scala/scalax/io/resource/ReaderResourceTraversableTest.scala
  20. +30 −30 {scala-io/src/test → core-test/src/main}/scala/scalax/io/resource/ResourceTraversableTest.scala
  21. +4 −4 {scala-io/src/test → core-test/src/main}/scala/scalax/io/resource/ResourceTraversableViewTest.scala
  22. +51 −0 core-test/src/main/scala/scalax/io/resource/StreamIteratorTest.scala
  23. +60 −0 core-test/src/main/scala/scalax/io/resource/WriterOutputStreamTest.scala
  24. +6 −32 {scala-io/src/test → core-test/src/main}/scala/scalax/test/sugar/AssertionSugar.scala
  25. +1 −1 {scala-io/src/test → core-test/src/main}/scala/scalax/test/sugar/IOSugar.scala
  26. +1 −1 {scala-io/src/test → core-test/src/main}/scala/scalax/test/sugar/MockitoSugar.scala
  27. +1 −1 {scala-io → core}/integration-tests
  28. +1 −1 {scala-io → core}/peformanceTests
  29. +14 −14 {scala-io → core}/src/main/scala/scalax/io/Codec.scala
  30. +12 −0 core/src/main/scala/scalax/io/Constants.scala
  31. +6 −21 {scala-io → core}/src/main/scala/scalax/io/Input.scala
  32. +1 −1 {scala-io → core}/src/main/scala/scalax/io/JavaConversions.scala
  33. +35 −18 {scala-io → core}/src/main/scala/scalax/io/Line.scala
  34. +34 −0 core/src/main/scala/scalax/io/LineTraverseable.scala
  35. +3 −3 {scala-io → core}/src/main/scala/scalax/io/LongTraversable.scala
  36. +3 −3 {scala-io → core}/src/main/scala/scalax/io/LongTraversableLike.scala
  37. +2 −11 {scala-io → core}/src/main/scala/scalax/io/Output.scala
  38. +1 −1 {scala-io → core}/src/main/scala/scalax/io/OutputConverter.scala
  39. +7 −21 {scala-io → core}/src/main/scala/scalax/io/ReadChars.scala
  40. +36 −34 {scala-io → core}/src/main/scala/scalax/io/Seekable.scala
  41. +5 −5 {scala-io → core}/src/main/scala/scalax/io/SeekableByteChannel.scala
  42. +2 −2 {scala-io → core}/src/main/scala/scalax/io/TraversableOnceOps.scala
  43. +4 −11 {scala-io → core}/src/main/scala/scalax/io/WriteChars.scala
  44. +8 −8 {scala-io → core}/src/main/scala/scalax/io/long-traversable-view.scala
  45. +1 −1 {scala-io → core}/src/main/scala/scalax/io/nio/ByteBuffer.scala
  46. +3 −3 {scala-io → core}/src/main/scala/scalax/io/nio/SeekableFileChannel.scala
  47. +16 −63 scala-io/src/main/scala/scalax/io/OpenOption.scala → core/src/main/scala/scalax/io/open-option.scala
  48. +1 −1 {scala-io → core}/src/main/scala/scalax/io/package.scala
  49. +5 −5 {scala-io → core}/src/main/scala/scalax/io/resource/CharInputStream.scala
  50. +39 −0 core/src/main/scala/scalax/io/resource/Closer.scala
  51. +5 −5 {scala-io → core}/src/main/scala/scalax/io/resource/DeletingFileOutputStream.scala
  52. +39 −45 {scala-io → core}/src/main/scala/scalax/io/resource/Resource.scala
  53. +2 −2 {scala-io → core}/src/main/scala/scalax/io/resource/StreamIterator.scala
  54. +1 −1 {scala-io → core}/src/main/scala/scalax/io/resource/WriterOutputStream.scala
  55. +9 −8 {scala-io → core}/src/main/scala/scalax/io/resource/resource-traversable-view.scala
  56. +19 −19 {scala-io → core}/src/main/scala/scalax/io/resource/resource-traversable.scala
  57. 0 {scala-io → core}/tmp/Glob.scala
  58. +1 −1 {scala-io → core}/tmp/matchers.scala
  59. +1 −1 {scala-io → core}/tmp/path-matcher-dsl.scala
  60. BIN file-test/src/main/resources/resources/image.png
  61. +10 −0 file-test/src/main/resources/resources/text
  62. +216 −0 file-test/src/main/scala/scalaio/test/AbstractFileOpsTests.scala
  63. +111 −0 file-test/src/main/scala/scalaio/test/AbstractPathSetTests.scala
  64. +49 −0 file-test/src/main/scala/scalaio/test/GlobParserTest.scala
  65. +4 −4 {scala-io/src/test → file-test/src/main}/scala/scalaio/test/Node.scala
  66. +63 −0 file-test/src/main/scala/scalaio/test/PathMatcherFactoryTest.scala
  67. +15 −0 file-test/src/main/scala/scalaio/test/ScalaIoMocks.scala
  68. +24 −0 file-test/src/main/scala/scalaio/test/URLStreamHandlerFactoryTest.scala
  69. +139 −0 file-test/src/main/scala/scalaio/test/fs/FileSystemFixture.scala
  70. +37 −0 file-test/src/main/scala/scalaio/test/fs/Fixture.scala
  71. +56 −0 file-test/src/main/scala/scalaio/test/fs/FsAccessSetTests.scala
  72. +779 −0 file-test/src/main/scala/scalaio/test/fs/FsBasicPathTests.scala
  73. +22 −0 file-test/src/main/scala/scalaio/test/fs/FsFileOpsTests.scala
  74. +24 −0 file-test/src/main/scala/scalaio/test/fs/FsFileSystemTests.scala
  75. +26 −0 file-test/src/main/scala/scalaio/test/fs/FsInputTests.scala
  76. +180 −0 file-test/src/main/scala/scalaio/test/fs/FsMatchingTests.scala
  77. +64 −0 file-test/src/main/scala/scalaio/test/fs/FsOutputTests.scala
  78. +153 −0 file-test/src/main/scala/scalaio/test/fs/FsPathFinderTests.scala
  79. +59 −0 file-test/src/main/scala/scalaio/test/fs/FsPathObjectTests.scala
  80. +21 −0 file-test/src/main/scala/scalaio/test/fs/FsPathSetTests.scala
  81. +24 −0 file-test/src/main/scala/scalaio/test/fs/FsSeekableTests.scala
  82. +13 −0 {scala-io/src/test → file-test/src/main}/scala/scalaio/test/fs/default/AllTests.scala
  83. +37 −0 file-test/src/main/scala/scalaio/test/fs/default/DefaultFixture.scala
  84. +22 −0 file-test/src/main/scala/scalaio/test/fs/ram/BackSlashTests.scala
  85. +23 −0 file-test/src/main/scala/scalaio/test/fs/ram/ForwardSlashTests.scala
  86. +33 −0 file-test/src/main/scala/scalaio/test/fs/ram/RamFixture.scala
  87. +47 −0 file-test/src/main/scala/scalax/test/sugar/FSAssertionSugar.scala
  88. +18 −0 file-test/src/main/scala/scalax/test/sugar/IOSugar.scala
  89. +15 −0 file-test/src/main/scala/scalax/test/sugar/MockitoSugar.scala
  90. +1 −1 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/AccessSet.scala
  91. +74 −0 file/src/main/scala/scalax/file/ArrayBufferSeekableChannel.scala
  92. +3 −3 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/Exceptions.scala
  93. +10 −9 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/FileOps.scala
  94. +45 −36 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/FileSystem.scala
  95. +5 −5 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/FileSystemPlugins.scala
  96. +8 −6 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/GlobParser.scala
  97. +119 −88 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/Path.scala
  98. +35 −13 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/PathMatcher.scala
  99. +3 −3 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/PathMatcherFactory.scala
  100. +7 −7 ...-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/PathURLStreamHandlerFactory.scala
  101. +3 −3 ...a-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/attributes/file_attributes.scala
  102. +23 −33 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/defaultfs/DefaultFileOps.scala
  103. +9 −11 ...-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/defaultfs/DefaultFileSystem.scala
  104. +22 −27 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/defaultfs/DefaultPath.scala
  105. +32 −0 file/src/main/scala/scalax/file/option.scala
  106. +16 −16 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/path-set.scala
  107. +6 −4 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/ramfs/Handler.scala
  108. +19 −14 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/ramfs/RamFileOps.scala
  109. +31 −29 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/ramfs/RamFileSystem.scala
  110. +144 −0 file/src/main/scala/scalax/file/ramfs/RamPath.scala
  111. +32 −36 {scala-io/src/main/scala/scalax/io → file/src/main/scala/scalax/file}/ramfs/tree.scala
  112. +2 −2 {scala-io → file}/src/samples/Children.scala
  113. +3 −3 {scala-io → file}/src/samples/Descendants.scala
  114. +4 −4 {scala-io → file}/src/samples/create-paths.scala
  115. +7 −4 {scala-io → file}/src/samples/creating-pathsets.scala
  116. +4 −4 {scala-io → file}/src/samples/execute.scala
  117. +1 −1 {scala-io → file}/src/samples/implicits.scala
  118. +21 −0 file/src/samples/readme
  119. +1 −1 {scala-io → file}/src/samples/roots.scala
  120. +13 −13 {scala-io → file}/src/samples/samples.scala
  121. BIN file/src/test/resources/resources/image.png
  122. +10 −0 file/src/test/resources/resources/text
  123. +15 −17 {scala-io → file}/src/test/scala/scalaio/test/AbstractFileOpsTests.scala
  124. +11 −10 {scala-io → file}/src/test/scala/scalaio/test/AbstractPathSetTests.scala
  125. +7 −7 {scala-io → file}/src/test/scala/scalaio/test/GlobParserTest.scala
  126. +25 −0 file/src/test/scala/scalaio/test/Node.scala
  127. +7 −7 {scala-io → file}/src/test/scala/scalaio/test/PathMatcherFactoryTest.scala
  128. 0 {scala-io → file}/src/test/scala/scalaio/test/ScalaIoMocks.scala
  129. +1 −1 {scala-io → file}/src/test/scala/scalaio/test/URLStreamHandlerFactoryTest.scala
  130. +21 −18 {scala-io → file}/src/test/scala/scalaio/test/fs/FileSystemFixture.scala
  131. +8 −2 {scala-io → file}/src/test/scala/scalaio/test/fs/Fixture.scala
  132. +6 −6 {scala-io → file}/src/test/scala/scalaio/test/fs/FsAccessSetTests.scala
  133. +82 −60 {scala-io → file}/src/test/scala/scalaio/test/fs/FsBasicPathTests.scala
  134. +1 −1 {scala-io → file}/src/test/scala/scalaio/test/fs/FsFileOpsTests.scala
  135. +2 −2 {scala-io → file}/src/test/scala/scalaio/test/fs/FsFileSystemTests.scala
  136. +5 −1 {scala-io → file}/src/test/scala/scalaio/test/fs/FsInputTests.scala
  137. +24 −12 {scala-io → file}/src/test/scala/scalaio/test/fs/FsMatchingTests.scala
  138. +9 −13 {scala-io → file}/src/test/scala/scalaio/test/fs/FsOutputTests.scala
  139. +30 −30 {scala-io → file}/src/test/scala/scalaio/test/fs/FsPathFinderTests.scala
  140. +1 −1 {scala-io → file}/src/test/scala/scalaio/test/fs/FsPathObjectTests.scala
  141. +2 −2 {scala-io → file}/src/test/scala/scalaio/test/fs/FsPathSetTests.scala
  142. +3 −12 {scala-io → file}/src/test/scala/scalaio/test/fs/FsSeekableTests.scala
  143. +23 −12 .../src/test/scala/scalaio/test/fs/ram → file/src/test/scala/scalaio/test/fs/default}/AllTests.scala
  144. +6 −3 {scala-io → file}/src/test/scala/scalaio/test/fs/default/DefaultFixture.scala
  145. +22 −0 file/src/test/scala/scalaio/test/fs/ram/BackSlashTests.scala
  146. +23 −0 file/src/test/scala/scalaio/test/fs/ram/ForwardSlashTests.scala
  147. +2 −2 {scala-io → file}/src/test/scala/scalaio/test/fs/ram/RamFixture.scala
  148. +1 −1 {scala-io → file}/src/test/scala/scalaio/test/resource/InputStreamResourceTest.scala
  149. +5 −0 {scala-io → file}/src/test/scala/scalaio/test/stream/InputTest.scala
  150. +1 −1 {scala-io → file}/src/test/scala/scalaio/test/stream/OutputTest.scala
  151. 0 {scala-io → file}/src/test/scala/scalaio/test/stream/ReadCharsTest.scala
  152. +3 −3 {scala-io → file}/src/test/scala/scalaio/test/stream/WriteCharsTest.scala
  153. +4 −4 ...io/src/test/scala/scalax/io → file/src/test/scala/scalax/file}/resource/CharInputStreamTest.scala
  154. +1 −1 ...t/scala/scalax/io → file/src/test/scala/scalax/file}/resource/ReaderResourceTraversableTest.scala
  155. +230 −0 file/src/test/scala/scalax/file/resource/ResourceTraversableTest.scala
  156. +87 −0 file/src/test/scala/scalax/file/resource/ResourceTraversableViewTest.scala
  157. +8 −8 ...-io/src/test/scala/scalax/io → file/src/test/scala/scalax/file}/resource/StreamIteratorTest.scala
  158. +13 −13 ...src/test/scala/scalax/io → file/src/test/scala/scalax/file}/resource/WriterOutputStreamTest.scala
  159. +47 −0 file/src/test/scala/scalax/test/sugar/AssertionSugar.scala
  160. +18 −0 file/src/test/scala/scalax/test/sugar/IOSugar.scala
  161. +15 −0 file/src/test/scala/scalax/test/sugar/MockitoSugar.scala
  162. +22 −5 {scala-io → file}/todo
  163. +1 −1 gen-docs
  164. +1 −1 project/build.properties
  165. +72 −63 project/build/ScalaIOProject.scala
  166. +0 −11 project/plugins/Plugins.scala
  167. +0 −3 project/plugins/project/build.properties
  168. +0 −248 project/sbt_project_definition.iml
  169. +0 −258 scala-io/Core IO project.iml
  170. +0 −55 scala-io/src/main/scala/scalax/io/LineTraverseable.scala
  171. +0 −31 scala-io/src/main/scala/scalax/io/Process.scala
  172. +0 −13 scala-io/src/main/scala/scalax/io/package.html
  173. +0 −105 scala-io/src/main/scala/scalax/io/ramfs/RamPath.scala
  174. +0 −75 scala-io/src/main/scala/scalax/io/ramfs/SeekableFileNodeChannel.scala
  175. +0 −21 scala-io/src/samples/readme
  176. BIN scala-io/src/test/resources/resources/image.png
  177. +0 −184 scala-io/src/test/scala/scalaio/test/AbstractInputTests.scala
  178. +0 −90 scala-io/src/test/scala/scalaio/test/AbstractOutputTests.scala
  179. +0 −107 scala-io/src/test/scala/scalaio/test/AbstractReadCharsTests.scala
  180. +0 −235 scala-io/src/test/scala/scalaio/test/AbstractSeekableTests.scala
  181. +0 −52 scala-io/src/test/scala/scalaio/test/AbstractWriteCharsTests.scala
  182. +0 −32 scala-io/src/test/scala/scalaio/test/Constants.scala
  183. +0 −118 scala-io/textmate.tmproj
  184. +12 −12 storage/removed/Directory.scala
  185. +17 −17 storage/removed/File.scala
  186. +3 −3 storage/tmp/CopyMovePathSpec.scala
  187. +5 −5 storage/tmp/FileSystemFixture.scala
  188. +7 −7 storage/tmp/PathSpec.scala
  189. +3 −3 storage/tmp/Test.scala
View
@@ -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
@@ -0,0 +1,9 @@
<component name="CopyrightManager">
<copyright>
<option name="notice" value="/* __ *\&#10;** ________ ___ / / ___ Scala API **&#10;** / __/ __// _ | / / / _ | (c) 2009-2011, Jesse Eichar **&#10;** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **&#10;** /____/\___/_/ |_/____/_/ | | **&#10;** |/ **&#10;\* */" />
<option name="keyword" value="Copyright" />
<option name="allowReplaceKeyword" value="" />
<option name="myName" value="Scala" />
<option name="myLocal" value="true" />
</copyright>
</component>
View
6 README
@@ -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
View

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
@@ -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)
}
}
@@ -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.

0 comments on commit 712d684

Please sign in to comment.