|
| 1 | + |
| 2 | +%{ |
| 3 | +from keypaths_gyb import testCases |
| 4 | +}% |
| 5 | + |
| 6 | +public var globalSink: Int = 0 |
| 7 | + |
| 8 | +public enum AnEnum { |
| 9 | + |
| 10 | + case unset, set(Int) |
| 11 | + |
| 12 | + init() { self = .unset } |
| 13 | + |
| 14 | + public var sink: Int { |
| 15 | + get { |
| 16 | + switch self { |
| 17 | + case .unset: |
| 18 | + return 0 |
| 19 | + case .set(let x): |
| 20 | + return x |
| 21 | + } |
| 22 | + } |
| 23 | + set { |
| 24 | + self = .set(newValue) |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | +% for (name, kind, before, after) in testCases: |
| 29 | + |
| 30 | +% if kind == "mutating" or kind == "nonmutating": |
| 31 | + |
| 32 | + #if BEFORE |
| 33 | + ${before.format(name=name, nonmutating="nonmutating")} |
| 34 | + #else |
| 35 | + ${after.format(name=name, nonmutating="nonmutating")} |
| 36 | + #endif |
| 37 | + |
| 38 | + public static var keyPath_${name}: PartialKeyPath<AnEnum> { return \AnEnum.${name} } |
| 39 | + |
| 40 | +% elif kind == "stored": |
| 41 | + |
| 42 | +% else: |
| 43 | + %{ raise ValueError("improper test case kind") }% |
| 44 | +% end |
| 45 | + |
| 46 | +% end |
| 47 | + |
| 48 | +} |
| 49 | + |
| 50 | +public struct AStruct { |
| 51 | + |
| 52 | + public var sink: Int = 0 |
| 53 | + |
| 54 | +% for (name, kind, before, after) in testCases: |
| 55 | + |
| 56 | +% if kind == "mutating" or kind == "nonmutating" or kind == "stored": |
| 57 | + |
| 58 | + #if BEFORE |
| 59 | + ${before.format(name=name, nonmutating="nonmutating")} |
| 60 | + #else |
| 61 | + ${after.format(name=name, nonmutating="nonmutating")} |
| 62 | + #endif |
| 63 | + |
| 64 | + public static var keyPath_${name}: PartialKeyPath<AStruct> { return \AStruct.${name} } |
| 65 | + |
| 66 | +% else: |
| 67 | + %{ raise ValueError("improper test case kind") }% |
| 68 | +% end |
| 69 | + |
| 70 | +% end |
| 71 | + |
| 72 | +} |
| 73 | + |
| 74 | +public class AClass { |
| 75 | + |
| 76 | + public var sink: Int = 0 |
| 77 | + |
| 78 | +% for (name, kind, before, after) in testCases: |
| 79 | + |
| 80 | +% if kind == "nonmutating" or kind == "stored": |
| 81 | + |
| 82 | + #if BEFORE |
| 83 | + ${before.format(name=name, nonmutating="")} |
| 84 | + #else |
| 85 | + ${after.format(name=name, nonmutating="")} |
| 86 | + #endif |
| 87 | + |
| 88 | + public static var keyPath_${name}: PartialKeyPath<AClass> { return \AClass.${name} } |
| 89 | + |
| 90 | +% elif kind == "mutating": |
| 91 | + |
| 92 | +% else: |
| 93 | + %{ raise ValueError("improper test case kind") }% |
| 94 | +% end |
| 95 | + |
| 96 | +% end |
| 97 | + |
| 98 | +} |
| 99 | + |
0 commit comments