mirror of
https://github.com/github/semantic.git
synced 2024-12-01 09:15:01 +03:00
25 lines
710 B
Swift
25 lines
710 B
Swift
final class DoubtTests: XCTestCase {
|
|
func testEqualSyntaxResultsInRecursivelyCopyingDiff() {
|
|
if let s = sexpr("\t(\n( a) \n)\t")?.value, t = sexpr("((a))")?.value {
|
|
XCTAssertEqual(Diff(s, t), Diff.Copy(.Apply(.Copy(.Apply(.Copy(.Variable("a")), [])), [])))
|
|
}
|
|
}
|
|
}
|
|
|
|
let atom = Syntax<Fix>.Variable <^> ^("abcdefghijklmnopqrstuvwxyz".characters.map { String($0) })
|
|
let ws = ^(" \t\n".characters.map { String($0) })
|
|
|
|
let sexpr: String -> State<Fix>? = fix { sexpr in
|
|
let list = Syntax<Fix>.Apply <^> (ws* *> ^"(" *> ws* *> sexpr <*> sexpr* <* ^")")
|
|
return Fix.init <^> (atom <|> list) <* ws*
|
|
}
|
|
|
|
|
|
func fix<T, U>(f: (T -> U) -> T -> U) -> T -> U {
|
|
return { f(fix(f))($0) }
|
|
}
|
|
|
|
|
|
import Doubt
|
|
import XCTest
|