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

Generate arbitrary keyed terms.

This commit is contained in:
Rob Rix 2015-10-16 14:30:53 -04:00
parent cc1f0a07a3
commit 4a24c3f872

View File

@ -19,9 +19,17 @@ extension UnannotatedTerm: Arbitrary {
}
}
}
let keyed: Gen<Term> = Gen.sized { n in
Gen<Int>.choose((0, n)).bind { n in
sequence((0..<n).map { _ in String.arbitrary.bind { key in UnannotatedTerm.arbitrary.fmap { (key, $0.term) } } }).fmap {
Term((), .Keyed(Dictionary(elements: $0)))
}
}
}
return Gen.oneOf([
leaf,
indexed,
keyed,
]).fmap {
UnannotatedTerm(term: $0)
}