-
-
Notifications
You must be signed in to change notification settings - Fork 605
/
Diffable.stencil
16 lines (15 loc) · 1.01 KB
/
Diffable.stencil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import Foundation
{% for type in types.implementing.AutoDiffable|!protocol|!annotated:"skipDiffing" %}
extension {{ type.name }}{% if not type.supertype.implements.AutoDiffable %}: Diffable{% endif %} {
{% if type.based.Type %}override {% else %}@objc {% endif %}public func diffAgainst(_ object: Any?) -> DiffableResult {
let results = DiffableResult()
guard let castObject = object as? {{ type.name }} else {
results.append("Incorrect type <expected: {{ type.name }}, received: \(Swift.type(of: object))>")
return results
}
{% for variable in type.storedVariables|!annotated:"skipEquality" %}results.append(contentsOf: DiffableResult(identifier: "{{ variable.name }}").trackDifference(actual: self.{{ variable.name }}, expected: castObject.{{ variable.name }}))
{% endfor %}
{% if type.supertype.implements.AutoDiffable %}results.append(contentsOf: super.diffAgainst(castObject))
return results{% else %}return results{% endif %}
}
}{% endfor %}