summaryrefslogtreecommitdiff
path: root/test/files/run/t4339.scala
blob: bb8b847ec34fad2e5b6e69f98464e6df8693e314 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import scala.util.{ Try, Success, Failure }
import xml._
import scala.io.Source.fromString
import java.io.PrintStream

object Test extends App {

  def quietSource(text: String) = new io.Source {
    override protected val iter = io.Source fromString text
    override def report(pos: Int, msg: String, out: PrintStream) = ()
  }
  def reading(text: String)(f: pull.XMLEventReader => Unit): Unit = {
    val r = new pull.XMLEventReader(quietSource(text))
    try f(r)
    finally r.stop()
  }
  def trying(body: => Unit): Unit =
    Try (body) match {
      case Success(_) => Console println "Expected failure"
      case Failure(e) => Console println s"Saw failure: $e"
    }

  val problematic = """<foo bar="baz/>"""

  trying (
    parsing.ConstructingParser.fromSource(quietSource(problematic), false).document.docElem
  )

  trying (
    reading(problematic) { r =>
      while (r.hasNext) println(r.next())
    }
  )
}