Comments (2)
the older EasyPredicate
public enum EasyPredicate: RawRepresentable {
case exists(_ exists: Bool)
case isEnabled(_ isEnabled: Bool)
case isHittable(_ isHittable: Bool)
case isSelected(_ isSelected: Bool)
case label(_ comparison: Comparison, _ value: String)
case identifier(_ identifier: String)
case type(_ type: XCUIElement.ElementType)
case other(_ ragular: String)
public init?(rawValue: PredicateRawValue) {
switch rawValue {
case .bool(let key, _, let value):
switch key {
case .exists: self = .exists(value)
case .isEnabled: self = .isEnabled(value)
case .isSelected: self = .isSelected(value)
case .isHittable: self = .isHittable(value)
}
case .type(let value): self = .type(value)
case .string(let key, let comparison, let value):
switch key {
case .label: self = .label(comparison, value)
case .identifier: self = .identifier(value)
}
case .custom(let regular): self = .other(regular)
}
}
public var rawValue: PredicateRawValue {
switch self {
case .exists(let value):
return .bool(key: .exists, comparison: .equals, value: value)
case .isEnabled(let value):
return .bool(key: .isEnabled, comparison: .equals, value: value)
case .isHittable(let value):
return .bool(key: .isHittable, comparison: .equals, value: value)
case .isSelected(let value):
return .bool(key: .isSelected, comparison: .equals, value: value)
case .label(let comparison, let value):
return .string(key: .label, comparison: comparison, value: value)
case .identifier(let value):
return .string(key: .identifier, comparison: .equals, value: value)
case .type(let value):
return .type(value: value)
case .other(let value):
return .custom(regular: value)
}
}
}
the thinking of new design
struct EasyPredicate {
typealias BoolRawValue = PredicateRawValue<PredicateKey.bool, Bool>
typealias StringRawValue = PredicateRawValue<PredicateKey.string, String>
typealias TypeRawValue = PredicateRawValue<PredicateKey.type, XCUIElement.ElementType>
static func exists(_ exists: Bool) -> BoolRawValue {
return BoolRawValue.keyValue(key: .exists, comparison: .equals, value: exists)
}
static func isEnabled(_ isEnabled: Bool) -> BoolRawValue {
return BoolRawValue.keyValue(key: .isEnabled, comparison: .equals, value: isEnabled)
}
static func isHittable(_ isHittable: Bool) -> BoolRawValue {
return BoolRawValue.keyValue(key: .isHittable, comparison: .equals, value: isHittable)
}
static func isSelected(_ isSelected: Bool) -> BoolRawValue {
return BoolRawValue.keyValue(key: .isSelected, comparison: .equals, value: isSelected)
}
static func type(_ comparison: Comparison, _ value: XCUIElement.ElementType) -> TypeRawValue {
return TypeRawValue.keyValue(key: .elementType, comparison: comparison, value: value)
}
static func label(_ comparison: Comparison, _ value: String) -> StringRawValue {
return StringRawValue.keyValue(key: .label, comparison: comparison, value: value)
}
static func identifier( _ value: String) -> StringRawValue {
return StringRawValue.keyValue(key: PredicateKey.string.label, comparison: .equals, value: value)
}
static func ragular( _ ragular: String) -> StringRawValue {
return StringRawValue.custom(regular: ragular)
}
}
new design requires extensions as below:
extension String: RawRepresentable {
public var rawValue: String { return self }
public init?(rawValue: String) {
self = rawValue
}
}
extension Bool: RawRepresentable {
public var rawValue: Bool { return self }
public init?(rawValue: Bool) {
self = rawValue
}
}
extension XCUIElement.ElementType: RawRepresentable {
public var rawValue: XCUIElement.ElementType { return self }
public init?(rawValue: XCUIElement.ElementType) {
self = rawValue
}
}
from einstein.
About the new design of PredicateRawValue's part is perfect.
But when we going down to the EasyPredicate's design,
Emm... 🤮🤮🤮🤮
from einstein.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from einstein.