title: Pattern matching ParseResult in unit test
body: <p>I'm stepping through my first Scala project, and looking at parser combinators in particular. I'm having trouble getting a simple unit test scenario to work, and trying to understand what I'm missing.</p>
  
  <p>I'm stuck on pattern matching a ParseResult into the case classes of Success, Failure and Error. I can't get Scala to resolve the case classes. There's a few examples around of this, but they all seem to be using them inside something that extends of of the parser classes. For example the <a href="https://github.com/scala/scala-parser-combinators/blob/master/src/test/scala/scala/util/parsing/combinator/JavaTokenParsersTest.scala" rel="nofollow noreferrer">tests on github</a> are inside the same package. The example <a href="https://stackoverflow.com/questions/1348121/scala-parser-issues">here</a> is inside a class extending a parser.</p>
  
  <p>The test i'm trying to write looks like:</p>
  
  <pre><code>package test.parsertests
  
  import parser.InputParser // my sut   
  import scala.util.parsing.combinator._
  
  import org.scalatest.FunSuite   
  class SetSuite extends FunSuite {
  
    val sut = new InputParser()
  
    test("Parsing a valid command") {
      val result = sut.applyParser(sut.commandParser, "SOME VALID INPUT")
      result match {
         case Success(x, _) =&gt; println("Result: " + x.toString) // &lt;-- not found: value Success
         case Failure(msg, _) =&gt; println("Failure: " + msg) // similar
         case Error(msg, _) =&gt; println("Error: " + msg) // similar
      }
    }
  }
  </code></pre>
  
  <p>and the method I'm calling is designed to let me exersize each of my parsers on my SUT:</p>
  
  <pre><code>package parser
  
  import scala.util.parsing.combinator._
  import scala.util.parsing.combinator.syntactical._
  
  class InputParser extends StandardTokenParsers  {
  
    def commandParser: Parser[Command] =
  ("Command " ~&gt; coord ~ coord ~ direction) ^^ { case x ~ y ~ d =&gt; new Command(x, y, d) }
  
    def applyParser[T](p: Parser[T], c: String): ParseResult[T] = {
      val tokens = new lexical.Scanner(c)
      phrase(p)(tokens)
  
  }
  </code></pre>
  
  <p>The fundamental issue is getting the case classes resolved in my test scope. Based on the <a href="https://github.com/scala/scala-parser-combinators/blob/a082ed0d0699b9d0036a971db549d72cdb252d31/src/main/scala/scala/util/parsing/combinator/Parsers.scala" rel="nofollow noreferrer">source</a> for the Parsers class, how can I get them defined? Can I resolve this with some additional import statements, or are they only accessible via inheritance? I've tried all the combinations that should resolve this issue, but I'm obviously missing something here.</p>