-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathSequenceWrapperTest.swift
94 lines (81 loc) · 2.99 KB
/
SequenceWrapperTest.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//===--- SequenceWrapperTest.swift ----------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
import StdlibUnittest
import StdlibCollectionUnittest
struct BasicSequenceWrapper<
Base_: Sequence
> : _SequenceWrapper, Sequence {
var _base: Base_
}
var sequenceWrapperTests = TestSuite("SequenceWrapper")
let base = LoggingSequence(wrapping: [OpaqueValue(1)])
let direct = BasicSequenceWrapper(_base: base)
let indirect = LoggingSequence(wrapping: direct)
let dispatchLog = base.log
func expectWrapperDispatch<R1, R2>(
_ directOperation: @autoclosure () -> R1,
_ indirectOperation: @autoclosure () -> R2,
_ counters: TypeIndexed<Int>,
//===--- TRACE boilerplate ----------------------------------------------===//
_ message: @autoclosure () -> String = "",
showFrame: Bool = true,
stackTrace: SourceLocStack = SourceLocStack(),
file: String = #file, line: UInt = #line
) {
let newTrace = stackTrace.pushIf(showFrame, file: file, line: line)
counters.reset()
_ = directOperation()
expectEqual([base.selfType: 1], counters, message(), stackTrace: newTrace)
counters.reset()
_ = indirectOperation()
expectEqual(
[base.selfType: 1, indirect.selfType: 1], counters,
message(), stackTrace: newTrace)
}
sequenceWrapperTests.test("Dispatch/makeIterator()") {
expectWrapperDispatch(
direct.makeIterator(), indirect.makeIterator(), dispatchLog.makeIterator)
}
sequenceWrapperTests.test("Dispatch/underestimatedCount") {
expectWrapperDispatch(
direct.underestimatedCount, indirect.underestimatedCount,
dispatchLog.underestimatedCount)
}
sequenceWrapperTests.test("Dispatch/map") {
expectWrapperDispatch(
direct.map { $0 }, indirect.map { $0 }, dispatchLog.map)
}
sequenceWrapperTests.test("Dispatch/filter") {
expectWrapperDispatch(
direct.filter { _ in true },
indirect.filter { _ in true }, dispatchLog.filter)
}
sequenceWrapperTests.test("Dispatch/_customContainsEquatableElement") {
expectWrapperDispatch(
direct._customContainsEquatableElement(OpaqueValue(1)),
indirect._customContainsEquatableElement(OpaqueValue(1)),
dispatchLog._customContainsEquatableElement)
}
sequenceWrapperTests.test("Dispatch/_preprocessingPass") {
expectWrapperDispatch(
direct._preprocessingPass { 1 },
indirect._preprocessingPass { 1 },
dispatchLog._preprocessingPass)
}
sequenceWrapperTests.test("Dispatch/_copyToContiguousArray") {
expectWrapperDispatch(
direct._copyToContiguousArray(), indirect._copyToContiguousArray(),
dispatchLog._copyToContiguousArray)
}
runAllTests()