//  Copyright (c) 2015 Rob Rix. All rights reserved.

final class ErrorTests: XCTestCase {
	func testError() {
		["xy": "expected rest of sequence, or term"]
		parse(term, "x")
	}
}


private func lift<C: CollectionType, Tree>(parser: Parser<C, Tree>.Function) -> (C, C.Index) -> Either<Error<C.Index>, (Tree, C.Index)> {
	return { input, index in
		parser(input, index).map { tree, rest in Either.right(tree, rest) }
			??	Either.left(Error.leaf("", index))
	}
}


// MARK: - Fixtures

private enum Tree {
	case Leaf
	case Branch([Tree])
}

private let group: Parser<String, Tree>.Function = ignore("(") ++ sequence ++ ignore(")")
private let sequence: Parser<String, Tree>.Function = (term ++ (ignore(",") ++ term)+) --> { Tree.Branch([$0] + $1) }
private let term: Parser<String, Tree>.Function = delay { (%"x" --> { _, _, _ in Tree.Leaf }) | group }


// MARK: - Imports

import Either
import Madness
import Prelude
import XCTest

//  Copyright (c) 2015 Rob Rix. All rights reserved.

final class ErrorTests: XCTestCase {
	func testError() {
		["xy": "expected rest of sequence, or term"]
		parse(term, "x")
	}
}


// MARK: - Fixtures

private enum Tree {
	case Leaf
	case Branch([Tree])
}

private let group: Parser<String, Tree>.Function = ignore("(") ++ sequence ++ ignore(")")
private let sequence: Parser<String, Tree>.Function = (term ++ (ignore(",") ++ term)+) --> { Tree.Branch([$0] + $1) }
private let term: Parser<String, Tree>.Function = delay { (%"x" --> { _, _, _ in Tree.Leaf }) | group }


// MARK: - Imports

import Madness
import Prelude
import XCTest

--- 
+++ 
@@ -4,6 +4,14 @@
 	func testError() {
 		["xy": "expected rest of sequence, or term"]
 		parse(term, "x")
+	}
+}
+
+
+private func lift<C: CollectionType, Tree>(parser: Parser<C, Tree>.Function) -> (C, C.Index) -> Either<Error<C.Index>, (Tree, C.Index)> {
+	return { input, index in
+		parser(input, index).map { tree, rest in Either.right(tree, rest) }
+			??	Either.left(Error.leaf("", index))
 	}
 }
 
@@ -22,6 +30,7 @@
 
 // MARK: - Imports
 
+import Either
 import Madness
 import Prelude
 import XCTest
Add a function to lift current parsers into error-reporting parsers.
