summaryrefslogtreecommitdiff
path: root/test/junit/scala/io
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2014-12-15 14:22:36 -0800
committerSom Snytt <som.snytt@gmail.com>2014-12-15 14:22:36 -0800
commit5343c136e58080d72ec12a6820a0e90ac85b9a08 (patch)
tree312bd647f9036b9c513f54da7044b284160458e2 /test/junit/scala/io
parente320d81f4eecbec139b1bfc4010f54136bd7a308 (diff)
downloadscala-5343c136e58080d72ec12a6820a0e90ac85b9a08.tar.gz
scala-5343c136e58080d72ec12a6820a0e90ac85b9a08.tar.bz2
scala-5343c136e58080d72ec12a6820a0e90ac85b9a08.zip
SI-8538 Document extension
Scaladoc for report extension point.
Diffstat (limited to 'test/junit/scala/io')
-rw-r--r--test/junit/scala/io/SourceTest.scala30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/junit/scala/io/SourceTest.scala b/test/junit/scala/io/SourceTest.scala
index efe081f844..3138a4589c 100644
--- a/test/junit/scala/io/SourceTest.scala
+++ b/test/junit/scala/io/SourceTest.scala
@@ -53,4 +53,34 @@ class SourceTest {
s.reportError(s.pos, "That doesn't sound right.", ps)
assertEquals("0030: THAT DOESN'T SOUND RIGHT.", out.toString(charSet))
}
+ @Test def canAltCustomizeReporting() = {
+ class CapitalReporting(is: InputStream)(implicit codec: Codec) extends Source {
+ override val iter = {
+ val r = new InputStreamReader(is, codec.decoder)
+ Iterator continually (codec wrap r.read()) takeWhile (_ != -1) map (_.toChar)
+ }
+ override def report(pos: Int, msg: String, out: PrintStream): Unit = {
+ out print f"$pos%04x: ${msg.toUpperCase}"
+ }
+ private[this] var _pos: Int = _
+ override def pos = _pos
+ private[this] var _ch: Char = _
+ override def ch = _ch
+ override def next = {
+ _ch = iter.next()
+ _pos += 1
+ _ch
+ }
+ }
+ val s = new CapitalReporting(in)
+ // skip to next line and report an error
+ do {
+ val c = s.next()
+ } while (s.ch != '\n')
+ s.next()
+ val out = new ByteArrayOutputStream
+ val ps = new PrintStream(out, true, charSet)
+ s.reportError(s.pos, "That doesn't sound right.", ps)
+ assertEquals("0030: THAT DOESN'T SOUND RIGHT.", out.toString(charSet))
+ }
}