Skip to content

Commit 178b0ff

Browse files
committed
add tests
1 parent d71b3df commit 178b0ff

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

test/Interpreter/synthesized_extension_conformances.swift

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum EGeneric<T> {
3939
}
4040
extension EGeneric: Equatable where T: Equatable {}
4141
extension EGeneric: Hashable where T: Hashable {}
42+
extension EGeneric: Comparable where T: Comparable {}
4243

4344
enum NoValues {
4445
case a, b, c
@@ -89,6 +90,19 @@ func testEquatableHashable<T: Equatable & Hashable>(cases: [Int: (T, T, Bool, Bo
8990
"\(#file):\(testLine) LHS <\(debugDescription(lhs)).hashValue> (\(lhsHash)) == RHS <\(debugDescription(rhs)).hashValue> (\(rhsHash)) doesn't match <\(hashEqual)>")
9091
}
9192
}
93+
func testEquatableHashableComparable<T: Hashable & Comparable>(cases: [Int: (T, T, Bool, Bool, Bool)]) {
94+
for (testLine, (lhs, rhs, equal, hashEqual, less)) in cases {
95+
expectEqual(lhs == rhs, equal,
96+
"\(#file):\(testLine) LHS <\(debugDescription(lhs))> == RHS <\(debugDescription(rhs))> doesn't match <\(equal)>")
97+
expectEqual(lhs < rhs, less,
98+
"\(#file):\(testLine) LHS <\(debugDescription(lhs))> < RHS <\(debugDescription(rhs))> doesn't match <\(less)>")
99+
100+
let lhsHash = lhs.hashValue
101+
let rhsHash = rhs.hashValue
102+
expectEqual(lhsHash == rhsHash, hashEqual,
103+
"\(#file):\(testLine) LHS <\(debugDescription(lhs)).hashValue> (\(lhsHash)) == RHS <\(debugDescription(rhs)).hashValue> (\(rhsHash)) doesn't match <\(hashEqual)>")
104+
}
105+
}
92106

93107
class TestEquatableHashable : TestSuper {
94108
lazy var int: [Int: (SInt, SInt, Bool, Bool)] = [
@@ -147,28 +161,28 @@ class TestEquatableHashable : TestSuper {
147161
testEquatableHashable(cases: generic)
148162
}
149163

150-
lazy var egeneric: [Int: (EGeneric<SInt>, EGeneric<SInt>, Bool, Bool)] = [
151-
#line : (EGaOne, EGaOne, true, true),
152-
#line : (EGaOne, EGaTwo, false, false),
153-
#line : (EGaOne, EGbOne, false, false),
154-
#line : (EGaOne, EGbTwo, false, false),
155-
#line : (EGaOne, EGc___, false, false),
156-
157-
#line : (EGbOne, EGaOne, false, false),
158-
#line : (EGbOne, EGaTwo, false, false),
159-
#line : (EGbOne, EGbOne, true, true),
160-
#line : (EGbOne, EGbTwo, false, false),
161-
#line : (EGbOne, EGc___, false, false),
162-
163-
#line : (EGc___, EGaOne, false, false),
164-
#line : (EGc___, EGaTwo, false, false),
165-
#line : (EGc___, EGbOne, false, false),
166-
#line : (EGc___, EGbTwo, false, false),
167-
#line : (EGc___, EGc___, true, true),
164+
lazy var egeneric: [Int: (EGeneric<SInt>, EGeneric<SInt>, Bool, Bool, Bool)] = [
165+
#line : (EGaOne, EGaOne, true, true, false),
166+
#line : (EGaOne, EGaTwo, false, false, true),
167+
#line : (EGaOne, EGbOne, false, false, true),
168+
#line : (EGaOne, EGbTwo, false, false, true),
169+
#line : (EGaOne, EGc___, false, false, true),
170+
171+
#line : (EGbOne, EGaOne, false, false, false),
172+
#line : (EGbOne, EGaTwo, false, false, false),
173+
#line : (EGbOne, EGbOne, true, true, false),
174+
#line : (EGbOne, EGbTwo, false, false, true),
175+
#line : (EGbOne, EGc___, false, false, true),
176+
177+
#line : (EGc___, EGaOne, false, false, false),
178+
#line : (EGc___, EGaTwo, false, false, false),
179+
#line : (EGc___, EGbOne, false, false, false),
180+
#line : (EGc___, EGbTwo, false, false, false),
181+
#line : (EGc___, EGc___, true, true, false),
168182
]
169183

170184
func test_EGeneric() {
171-
testEquatableHashable(cases: egeneric)
185+
testEquatableHashableComparable(cases: egeneric)
172186
}
173187
}
174188

test/Sema/enum_conformance_synthesis.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,17 @@ func miss(_ a: Publicist, outsold b: Publicist) -> Bool {
357357
return b < a // expected-error{{binary operator '<' cannot be applied to two 'Publicist' operands}}
358358
}
359359

360+
// can synthesize Comparable conformance through extension
361+
enum Birthyear {
362+
case eighties(Int)
363+
case nineties(Int)
364+
case twothousands(Int)
365+
}
366+
extension Birthyear: Comparable {
367+
}
368+
func canEatHotChip(_ birthyear:Birthyear) -> Bool {
369+
return birthyear > .nineties(3)
370+
}
360371
// FIXME: Remove -verify-ignore-unknown.
361372
// <unknown>:0: error: unexpected error produced: invalid redeclaration of 'hashValue'
362373
// <unknown>:0: error: unexpected note produced: candidate has non-matching type '(Foo, Foo) -> Bool'

0 commit comments

Comments
 (0)