diff options
author | Philipp Haller <hallerp@gmail.com> | 2009-06-30 10:55:32 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2009-06-30 10:55:32 +0000 |
commit | 978e36705aa429a1e957230cd5f5ccaed8dc5b4c (patch) | |
tree | c170240032017c4c4eb759261899831ce93ab95c /test | |
parent | 96f6c893f1ad84ef81e975820af566a926a246c3 (diff) | |
download | scala-978e36705aa429a1e957230cd5f5ccaed8dc5b4c.tar.gz scala-978e36705aa429a1e957230cd5f5ccaed8dc5b4c.tar.bz2 scala-978e36705aa429a1e957230cd5f5ccaed8dc5b4c.zip |
Applied patch to fix #2104 and added test.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/jvm/t2104.check | 0 | ||||
-rw-r--r-- | test/files/jvm/t2104.scala | 51 |
2 files changed, 51 insertions, 0 deletions
diff --git a/test/files/jvm/t2104.check b/test/files/jvm/t2104.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/jvm/t2104.check diff --git a/test/files/jvm/t2104.scala b/test/files/jvm/t2104.scala new file mode 100644 index 0000000000..e672f02578 --- /dev/null +++ b/test/files/jvm/t2104.scala @@ -0,0 +1,51 @@ +/* https://lampsvn.epfl.ch/trac/scala/ticket/2104 + symptom: Source via Buffered Source always loses the last char of the input file. + cause: BufferedSource? doesn't check return for -1 (EOF), and uses reader.ready() improperly as a substitute. + + test: check over all possible strings of length up to N over alphabet chars: + write file, then read back its chars, and get back the original. + +*/ +object Test +{ + val N=4 + + import java.io.{ File => JFile } + import java.io.FileWriter + import io.Source + def overwrite(file: JFile,w: FileWriter=>Unit) { + val fw=new FileWriter(file) + w(fw) + fw.close + } + def delete_after(f: JFile,g: Source=>Unit) = { + g(Source.fromFile(f)) + f.delete + } + def store_tempfile(f: FileWriter=>Unit)(implicit name:String) : JFile = { + val tp=JFile.createTempFile(name,null) + overwrite(tp,f) + tp + } + + implicit val name="bug2104" + val chars=List('\n','\r','a') + + type Cs = List[Char] + def all_strings(n: Int) : List[Cs] = { + if (n==0) List(Nil) + else { + val sufs=all_strings(n-1) + chars.flatMap((c)=>sufs.map(c :: _)) + } + } + def test(n: Int) { + for(l <- all_strings(n)) { + val tmp=store_tempfile((f)=>l.foreach(f.write(_))) + delete_after(tmp,(s)=>assert(s.toList == l)) + } + } + def main(args: Array[String]) { + (0 until N).foreach(test(_)) + } +} |