mirror of
https://github.com/github/semantic.git
synced 2024-12-26 08:25:19 +03:00
Construct arbitrary unannotated leaves.
This commit is contained in:
parent
412ea9cc04
commit
6a4e1dca39
@ -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))
|
||||
}
|
||||
|
||||
extension UnannotatedTerm: Arbitrary {
|
||||
static var arbitrary: Gen<UnannotatedTerm> {
|
||||
let leaf: Gen<Term> = String.arbitrary.fmap { Term((), .Leaf($0)) }
|
||||
return Gen.oneOf([
|
||||
leaf,
|
||||
])
|
||||
}
|
||||
return arbitrary(0).fmap {
|
||||
RangedTerm(term: $0)
|
||||
]).fmap {
|
||||
UnannotatedTerm(term: $0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user