Skip to content

Commit a6f5f16

Browse files
committed
[test] Fix #keyPath2/\ validation tests.
1 parent 07c5ab8 commit a6f5f16

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

test/stdlib/KeyPath.swift

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,24 @@ struct ComputedB {
7878

7979
keyPath.test("key path in-place instantiation") {
8080
for _ in 1...2 {
81-
let s_x = (#keyPath2(S<Int>, .x) as AnyKeyPath) as! WritableKeyPath<S<Int>, Int>
82-
let s_y = (#keyPath2(S<Int>, .y) as AnyKeyPath) as! WritableKeyPath<S<Int>, LifetimeTracked?>
83-
let s_z = (#keyPath2(S<Int>, .z) as AnyKeyPath) as! WritableKeyPath<S<Int>, Int>
84-
let s_p = (#keyPath2(S<Int>, .p) as AnyKeyPath) as! WritableKeyPath<S<Int>, Point>
85-
let s_p_x = (#keyPath2(S<Int>, .p.x) as AnyKeyPath) as! WritableKeyPath<S<Int>, Double>
86-
let s_p_y = (#keyPath2(S<Int>, .p.y) as AnyKeyPath) as! WritableKeyPath<S<Int>, Double>
87-
let s_c = (#keyPath2(S<Int>, .c) as AnyKeyPath) as! WritableKeyPath<S<Int>, C<Int>>
88-
let s_c_x = (#keyPath2(S<Int>, .c.x) as AnyKeyPath) as! ReferenceWritableKeyPath<S<Int>, Int>
89-
90-
let c_x = (#keyPath2(C<Int>, .x) as AnyKeyPath) as! ReferenceWritableKeyPath<C<Int>, Int>
81+
let s_x = (\S<Int>.x as AnyKeyPath) as! WritableKeyPath<S<Int>, Int>
82+
let s_y = (\S<Int>.y as AnyKeyPath) as! WritableKeyPath<S<Int>, LifetimeTracked?>
83+
let s_z = (\S<Int>.z as AnyKeyPath) as! WritableKeyPath<S<Int>, Int>
84+
let s_p = (\S<Int>.p as AnyKeyPath) as! WritableKeyPath<S<Int>, Point>
85+
let s_p_x = (\S<Int>.p.x as AnyKeyPath) as! WritableKeyPath<S<Int>, Double>
86+
let s_p_y = (\S<Int>.p.y as AnyKeyPath) as! WritableKeyPath<S<Int>, Double>
87+
let s_c = (\S<Int>.c as AnyKeyPath) as! WritableKeyPath<S<Int>, C<Int>>
88+
let s_c_x = (\S<Int>.c.x as AnyKeyPath) as! ReferenceWritableKeyPath<S<Int>, Int>
89+
90+
let c_x = (\C<Int>.x as AnyKeyPath) as! ReferenceWritableKeyPath<C<Int>, Int>
9191
let s_c_x_2 = s_c.appending(path: c_x)
9292

9393
expectEqual(s_c_x, s_c_x_2)
9494
expectEqual(s_c_x_2, s_c_x)
9595
expectEqual(s_c_x.hashValue, s_c_x_2.hashValue)
9696

97-
let point_x = (#keyPath2(Point, .x) as AnyKeyPath) as! WritableKeyPath<Point, Double>
98-
let point_y = (#keyPath2(Point, .y) as AnyKeyPath) as! WritableKeyPath<Point, Double>
97+
let point_x = (\Point.x as AnyKeyPath) as! WritableKeyPath<Point, Double>
98+
let point_y = (\Point.y as AnyKeyPath) as! WritableKeyPath<Point, Double>
9999

100100
let s_p_x_2 = s_p.appending(path: point_x)
101101
let s_p_y_2 = s_p.appending(path: point_y)
@@ -107,19 +107,19 @@ keyPath.test("key path in-place instantiation") {
107107
expectEqual(s_p_y_2, s_p_y)
108108
expectEqual(s_p_y_2.hashValue, s_p_y.hashValue)
109109

110-
let ca_readOnly = (#keyPath2(ComputedA, .readOnly) as AnyKeyPath) as! KeyPath<ComputedA, ComputedB>
111-
let ca_nonmutating = (#keyPath2(ComputedA, .nonmutating) as AnyKeyPath) as! ReferenceWritableKeyPath<ComputedA, ComputedB>
112-
let ca_reabstracted = (#keyPath2(ComputedA, .reabstracted) as AnyKeyPath) as! ReferenceWritableKeyPath<ComputedA, () -> ()>
110+
let ca_readOnly = (\ComputedA.readOnly as AnyKeyPath) as! KeyPath<ComputedA, ComputedB>
111+
let ca_nonmutating = (\ComputedA.nonmutating as AnyKeyPath) as! ReferenceWritableKeyPath<ComputedA, ComputedB>
112+
let ca_reabstracted = (\ComputedA.reabstracted as AnyKeyPath) as! ReferenceWritableKeyPath<ComputedA, () -> ()>
113113

114-
let cb_readOnly = (#keyPath2(ComputedB, .readOnly) as AnyKeyPath) as! KeyPath<ComputedB, ComputedA>
115-
let cb_mutating = (#keyPath2(ComputedB, .mutating) as AnyKeyPath) as! WritableKeyPath<ComputedB, ComputedA>
116-
let cb_nonmutating = (#keyPath2(ComputedB, .nonmutating) as AnyKeyPath) as! ReferenceWritableKeyPath<ComputedB, ComputedA>
117-
let cb_reabstracted = (#keyPath2(ComputedB, .reabstracted) as AnyKeyPath) as! WritableKeyPath<ComputedB, () -> ()>
114+
let cb_readOnly = (\ComputedB.readOnly as AnyKeyPath) as! KeyPath<ComputedB, ComputedA>
115+
let cb_mutating = (\ComputedB.mutating as AnyKeyPath) as! WritableKeyPath<ComputedB, ComputedA>
116+
let cb_nonmutating = (\ComputedB.nonmutating as AnyKeyPath) as! ReferenceWritableKeyPath<ComputedB, ComputedA>
117+
let cb_reabstracted = (\ComputedB.reabstracted as AnyKeyPath) as! WritableKeyPath<ComputedB, () -> ()>
118118

119-
let ca_readOnly_mutating = (#keyPath2(ComputedA, .readOnly.mutating) as AnyKeyPath) as! KeyPath<ComputedA, ComputedA>
120-
let cb_mutating_readOnly = (#keyPath2(ComputedB, .mutating.readOnly) as AnyKeyPath) as! KeyPath<ComputedB, ComputedB>
121-
let ca_readOnly_nonmutating = (#keyPath2(ComputedA, .readOnly.nonmutating) as AnyKeyPath) as! ReferenceWritableKeyPath<ComputedA, ComputedA>
122-
let cb_readOnly_reabstracted = (#keyPath2(ComputedB, .readOnly.reabstracted) as AnyKeyPath) as! ReferenceWritableKeyPath<ComputedB, () -> ()>
119+
let ca_readOnly_mutating = (\ComputedA.readOnly.mutating as AnyKeyPath) as! KeyPath<ComputedA, ComputedA>
120+
let cb_mutating_readOnly = (\ComputedB.mutating.readOnly as AnyKeyPath) as! KeyPath<ComputedB, ComputedB>
121+
let ca_readOnly_nonmutating = (\ComputedA.readOnly.nonmutating as AnyKeyPath) as! ReferenceWritableKeyPath<ComputedA, ComputedA>
122+
let cb_readOnly_reabstracted = (\ComputedB.readOnly.reabstracted as AnyKeyPath) as! ReferenceWritableKeyPath<ComputedB, () -> ()>
123123

124124
let ca_readOnly_mutating2 = ca_readOnly.appending(path: cb_mutating)
125125
expectEqual(ca_readOnly_mutating, ca_readOnly_mutating2)
@@ -150,24 +150,24 @@ keyPath.test("key path in-place instantiation") {
150150
keyPath.test("key path generic instantiation") {
151151
func testWithGenericParam<T: Equatable>(_: T.Type) -> ReferenceWritableKeyPath<S<T>, Int> {
152152
for i in 1...2 {
153-
let s_x = (#keyPath2(S<T>, .x) as AnyKeyPath) as! WritableKeyPath<S<T>, Int>
154-
let s_y = (#keyPath2(S<T>, .y) as AnyKeyPath) as! WritableKeyPath<S<T>, LifetimeTracked?>
155-
let s_z = (#keyPath2(S<T>, .z) as AnyKeyPath) as! WritableKeyPath<S<T>, T>
156-
let s_p = (#keyPath2(S<T>, .p) as AnyKeyPath) as! WritableKeyPath<S<T>, Point>
157-
let s_p_x = (#keyPath2(S<T>, .p.x) as AnyKeyPath) as! WritableKeyPath<S<T>, Double>
158-
let s_p_y = (#keyPath2(S<T>, .p.y) as AnyKeyPath) as! WritableKeyPath<S<T>, Double>
159-
let s_c = (#keyPath2(S<T>, .c) as AnyKeyPath) as! WritableKeyPath<S<T>, C<T>>
160-
let s_c_x = (#keyPath2(S<T>, .c.x) as AnyKeyPath) as! ReferenceWritableKeyPath<S<T>, Int>
161-
162-
let c_x = (#keyPath2(C<T>, .x) as AnyKeyPath) as! ReferenceWritableKeyPath<C<T>, Int>
153+
let s_x = (\S<T>.x as AnyKeyPath) as! WritableKeyPath<S<T>, Int>
154+
let s_y = (\S<T>.y as AnyKeyPath) as! WritableKeyPath<S<T>, LifetimeTracked?>
155+
let s_z = (\S<T>.z as AnyKeyPath) as! WritableKeyPath<S<T>, T>
156+
let s_p = (\S<T>.p as AnyKeyPath) as! WritableKeyPath<S<T>, Point>
157+
let s_p_x = (\S<T>.p.x as AnyKeyPath) as! WritableKeyPath<S<T>, Double>
158+
let s_p_y = (\S<T>.p.y as AnyKeyPath) as! WritableKeyPath<S<T>, Double>
159+
let s_c = (\S<T>.c as AnyKeyPath) as! WritableKeyPath<S<T>, C<T>>
160+
let s_c_x = (\S<T>.c.x as AnyKeyPath) as! ReferenceWritableKeyPath<S<T>, Int>
161+
162+
let c_x = (\C<T>.x as AnyKeyPath) as! ReferenceWritableKeyPath<C<T>, Int>
163163
let s_c_x_2 = s_c.appending(path: c_x)
164164

165165
expectEqual(s_c_x, s_c_x_2)
166166
expectEqual(s_c_x_2, s_c_x)
167167
expectEqual(s_c_x.hashValue, s_c_x_2.hashValue)
168168

169-
let point_x = (#keyPath2(Point, .x) as AnyKeyPath) as! WritableKeyPath<Point, Double>
170-
let point_y = (#keyPath2(Point, .y) as AnyKeyPath) as! WritableKeyPath<Point, Double>
169+
let point_x = (\Point.x as AnyKeyPath) as! WritableKeyPath<Point, Double>
170+
let point_y = (\Point.y as AnyKeyPath) as! WritableKeyPath<Point, Double>
171171

172172
let s_p_x_2 = s_p.appending(path: point_x)
173173
let s_p_y_2 = s_p.appending(path: point_y)
@@ -184,15 +184,15 @@ keyPath.test("key path generic instantiation") {
184184
fatalError()
185185
}
186186
let s_c_x_int = testWithGenericParam(Int.self)
187-
let s_c_x_int2 = #keyPath2(S<Int>, .c.x)
187+
let s_c_x_int2 = \S<Int>.c.x
188188
expectEqual(s_c_x_int, s_c_x_int2)
189189

190190
let s_c_x_string = testWithGenericParam(String.self)
191-
let s_c_x_string2 = #keyPath2(S<String>, .c.x)
191+
let s_c_x_string2 = \S<String>.c.x
192192
expectEqual(s_c_x_string, s_c_x_string2)
193193

194194
let s_c_x_lt = testWithGenericParam(LifetimeTracked.self)
195-
let s_c_x_lt2 = #keyPath2(S<LifetimeTracked>, .c.x)
195+
let s_c_x_lt2 = \S<LifetimeTracked>.c.x
196196
expectEqual(s_c_x_lt, s_c_x_lt2)
197197
}
198198

test/stdlib/KeyPathObjC.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ class Bar: NSObject {
3333
var testKVCStrings = TestSuite("KVC strings")
3434

3535
testKVCStrings.test("KVC strings") {
36-
expectEqual((#keyPath2(NonObjC, .x))._kvcKeyPathString, nil)
37-
expectEqual((#keyPath2(NonObjC, .y))._kvcKeyPathString, nil)
38-
expectEqual((#keyPath2(Foo, .int))._kvcKeyPathString, "int")
39-
expectEqual((#keyPath2(Foo, .bar))._kvcKeyPathString, "bar")
40-
expectEqual((#keyPath2(Foo, .bar.foo))._kvcKeyPathString, "bar.foo")
41-
expectEqual((#keyPath2(Foo, .bar.foo.bar))._kvcKeyPathString, "bar.foo.bar")
42-
expectEqual((#keyPath2(Foo, .nonobjc))._kvcKeyPathString, nil)
43-
expectEqual((#keyPath2(Foo, .bar.foo.nonobjc.y))._kvcKeyPathString, nil)
44-
expectEqual((#keyPath2(Foo, .differentName))._kvcKeyPathString, "thisIsADifferentName")
45-
expectEqual((#keyPath2(Bar, .foo))._kvcKeyPathString, "foo")
36+
expectEqual((\NonObjC.x)._kvcKeyPathString, nil)
37+
expectEqual((\NonObjC.y)._kvcKeyPathString, nil)
38+
expectEqual((\Foo.int)._kvcKeyPathString, "int")
39+
expectEqual((\Foo.bar)._kvcKeyPathString, "bar")
40+
expectEqual((\Foo.bar.foo)._kvcKeyPathString, "bar.foo")
41+
expectEqual((\Foo.bar.foo.bar)._kvcKeyPathString, "bar.foo.bar")
42+
expectEqual((\Foo.nonobjc)._kvcKeyPathString, nil)
43+
expectEqual((\Foo.bar.foo.nonobjc.y)._kvcKeyPathString, nil)
44+
expectEqual((\Foo.differentName)._kvcKeyPathString, "thisIsADifferentName")
45+
expectEqual((\Bar.foo)._kvcKeyPathString, "foo")
4646

47-
let foo_bar = #keyPath2(Foo, .bar)
48-
let foo_nonobjc = #keyPath2(Foo, .nonobjc)
49-
let bar_foo = #keyPath2(Bar, .foo)
47+
let foo_bar = \Foo.bar
48+
let foo_nonobjc = \Foo.nonobjc
49+
let bar_foo = \Bar.foo
5050

51-
let nonobjc_y = #keyPath2(NonObjC, .y)
51+
let nonobjc_y = \NonObjC.y
5252

5353
do {
5454
let foo_bar_foo = foo_bar.appending(path: bar_foo)

0 commit comments

Comments
 (0)