-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathConcatenate.swift
64 lines (54 loc) · 2.15 KB
/
Concatenate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//===--- Concatenate.swift - Tests for lazy/eager concatenate -------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
import StdlibUnittest
import StdlibCollectionUnittest
// 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
var ConcatenateTests = TestSuite("ConcatenateTests")
// Help the type checker (<rdar://problem/17897413> Slow type deduction)
typealias X = ContiguousArray<CountableRange<Int>>
let samples: ContiguousArray<(CountableRange<Int>, X)> = [
(0..<8, [ 1..<1, 0..<5, 7..<7, 5..<7, 7..<8 ] as X),
(0..<8, [ 0..<5, 7..<7, 5..<7, 7..<8 ] as X),
(0..<8, [ 1..<1, 0..<5, 7..<7, 5..<7, 7..<8, 11..<11 ] as X),
(0..<8, [ 0..<5, 7..<7, 5..<7, 7..<8, 11..<11 ] as X),
(0..<0, [ 11..<11 ] as X),
(0..<0, [ 3..<3, 11..<11 ] as X),
(0..<0, [] as X),
]
for (expected, source) in samples {
ConcatenateTests.test("forward-\(source)") {
checkBidirectionalCollection(expected, source.flatten())
}
ConcatenateTests.test("reverse-\(source)")
.xfail(.custom( { true }, reason: "[swift-3-indexing-model] ReversedCollection.advance is not implemented"))
.code {
// FIXME: separate 'expected' and 'reversed' variables are a workaround
// for: <rdar://problem/20789500>
let expected = ContiguousArray(expected.lazy.reversed())
let reversed = source.flatten().reversed()
checkBidirectionalCollection(expected, reversed)
}
ConcatenateTests.test("sequence-\(source)") {
checkSequence(
ContiguousArray(expected),
AnySequence(source).flatten())
}
}
runAllTests()