// RUN: %target-run-simple-swift // REQUIRES: executable_test // XFAIL: interpret import StdlibUnittest // Also import modules which are used by StdlibUnittest internally. This // workaround is needed to link all required libraries in case we compile // StdlibUnittest with -sil-serialize-all. import SwiftPrivate #if _runtime(_ObjC) import ObjectiveC #endif // Check that the generic parameter is called 'Element'. protocol TestProtocol1 {} extension Range where Element : TestProtocol1 { var _elementIsTestProtocol1: Bool { fatalError("not implemented") } } extension RangeIterator where Element : TestProtocol1 { var _elementIsTestProtocol1: Bool { fatalError("not implemented") } } var RangeTestSuite = TestSuite("Range") RangeTestSuite.test("ReverseRange") { // We no longer have a ReverseRange, but we can still make sure that // lazy reversal works correctly. expectEqualSequence((0..<10).lazy.reversed(), [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) } func isEquatable(e: E) {} RangeTestSuite.test("Range/Equatable") { let r1: Range = 0..<0 let r2: Range = 0..<1 isEquatable(r1) expectTrue(r1 == r1) expectFalse(r1 != r1) expectFalse(r1 == r2) expectTrue(r1 != r2) } // Something to test with that distinguishes debugDescription from description struct X : ForwardIndex, CustomStringConvertible, CustomDebugStringConvertible { init(_ a: T) { self.a = a } func successor() -> X { return X(a.successor()) } var description: String { return String(a) } var debugDescription: String { return "X(\(String(reflecting: a)))" } var a: T } func == (lhs: X, rhs: X) -> Bool { return lhs.a == rhs.a } RangeTestSuite.test("Printing") { expectEqual("0..<10", String(X(0)... Timeouts should make this test fail if this // ends up doing a linear search. expectFalse(1_000_000..<(1_000_000_000_000 as Int64) ~= 1) } RangeTestSuite.test("stride") { var result = [Double]() for i in stride(from: 1.4, through: 3.4, by: 1) { result.append(i) } expectEqual([ 1.4, 2.4, 3.4 ], result) } RangeTestSuite.test("map") { // map method should exist on ranges expectEqual([ 2, 4, 6 ], Array((1...3).map {$0*2})) } runAllTests()