1
1
mirror of https://github.com/github/semantic.git synced 2024-11-25 02:58:36 +03:00
semantic/prototype/DoubtTests/RangedTerm.swift

35 lines
690 B
Swift
Raw Normal View History

struct RangedTerm {
2015-10-16 20:23:38 +03:00
typealias Term = Cofree<String, (String, Range<Int>)>
let term: Term
}
2015-10-16 21:24:17 +03:00
struct UnannotatedTerm {
typealias Term = Cofree<String, ()>
let term: Term
}
extension UnannotatedTerm: Arbitrary {
static var arbitrary: Gen<UnannotatedTerm> {
let leaf: Gen<Term> = String.arbitrary.fmap { Term((), .Leaf($0)) }
2015-10-16 21:26:58 +03:00
let indexed: Gen<Term> = Gen.sized { n in
Gen<Int>.choose((0, n)).bind { n in
sequence((0..<n).map(const(UnannotatedTerm.arbitrary))).fmap {
Term((), .Indexed($0.map { $0.term }))
}
}
}
return Gen.oneOf([
leaf,
2015-10-16 21:26:58 +03:00
indexed,
]).fmap {
UnannotatedTerm(term: $0)
2015-10-16 20:23:38 +03:00
}
2015-10-16 19:28:49 +03:00
}
}
@testable import Doubt
import Prelude
2015-10-16 19:28:49 +03:00
import SwiftCheck