1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 00:12:29 +03:00

Construct arbitrary unannotated leaves.

This commit is contained in:
Rob Rix 2015-10-16 14:26:32 -04:00
parent 412ea9cc04
commit 6a4e1dca39

View File

@ -8,18 +8,14 @@ struct UnannotatedTerm {
let term: Term
}
extension RangedTerm: Arbitrary {
static var arbitrary: Gen<RangedTerm> {
func arbitrary(from: Int) -> Gen<Term> {
let leaf: Gen<Term> = String.arbitrary.fmap {
Cofree(($0, from..<Int($0.characters.count)), .Leaf($0))
}
return Gen.oneOf([
leaf,
])
}
return arbitrary(0).fmap {
RangedTerm(term: $0)
extension UnannotatedTerm: Arbitrary {
static var arbitrary: Gen<UnannotatedTerm> {
let leaf: Gen<Term> = String.arbitrary.fmap { Term((), .Leaf($0)) }
return Gen.oneOf([
leaf,
]).fmap {
UnannotatedTerm(term: $0)
}
}
}