-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathTest.Case.ArgumentTests.swift
More file actions
188 lines (159 loc) · 6.21 KB
/
Test.Case.ArgumentTests.swift
File metadata and controls
188 lines (159 loc) · 6.21 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 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 Swift project authors
//
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
@Suite("Test.Case.Argument Tests")
struct Test_Case_ArgumentTests {
@Test("One parameter")
func oneParameter() async {
var configuration = Configuration()
configuration.setEventHandler { event, context in
guard case .testCaseStarted = event.kind else {
return
}
let arguments = try #require(context.testCase?.arguments)
try #require(arguments.count == 1)
let argument = arguments[0]
#expect(argument.value as? String == "value")
#expect(argument.parameter.index == 0)
#expect(argument.parameter.firstName == "x")
}
await runTestFunction(named: "oneParameter(x:)", in: ParameterizedTests.self, configuration: configuration)
}
@Test("Two parameters")
func twoParameters() async {
var configuration = Configuration()
configuration.setEventHandler { event, context in
guard case .testCaseStarted = event.kind else {
return
}
let arguments = try #require(context.testCase?.arguments)
try #require(arguments.count == 2)
do {
let argument = arguments[0]
#expect(argument.value as? String == "value")
#expect(argument.parameter.index == 0)
#expect(argument.parameter.firstName == "x")
}
do {
let argument = arguments[1]
#expect(argument.value as? Int == 123)
#expect(argument.parameter.index == 1)
#expect(argument.parameter.firstName == "y")
}
}
await runTestFunction(named: "twoParameters(x:y:)", in: ParameterizedTests.self, configuration: configuration)
}
@Test("One 1-tuple parameter")
func one1TupleParameter() async {
var configuration = Configuration()
configuration.setEventHandler { event, context in
guard case .testCaseStarted = event.kind else {
return
}
let arguments = try #require(context.testCase?.arguments)
try #require(arguments.count == 1)
let argument = arguments[0]
#expect(argument.value as? (String) == ("value"))
#expect(argument.parameter.index == 0)
#expect(argument.parameter.firstName == "x")
}
await runTestFunction(named: "one1TupleParameter(x:)", in: ParameterizedTests.self, configuration: configuration)
}
@Test("One 2-tuple parameter")
func one2TupleParameter() async {
var configuration = Configuration()
configuration.setEventHandler { event, context in
guard case .testCaseStarted = event.kind else {
return
}
let arguments = try #require(context.testCase?.arguments)
try #require(arguments.count == 1)
let argument = arguments[0]
let value = try #require(argument.value as? (String, Int))
#expect(value.0 == "value")
#expect(value.1 == 123)
#expect(argument.parameter.index == 0)
#expect(argument.parameter.firstName == "x")
}
await runTestFunction(named: "one2TupleParameter(x:)", in: ParameterizedTests.self, configuration: configuration)
}
@Test("Two Dictionary element (key, value) parameters")
func DictionaryElementParameters() async {
var configuration = Configuration()
configuration.setEventHandler { event, context in
guard case .testCaseStarted = event.kind else {
return
}
let arguments = try #require(context.testCase?.arguments)
try #require(arguments.count == 2)
do {
let argument = arguments[0]
#expect(argument.value as? String == "value")
#expect(argument.parameter.index == 0)
#expect(argument.parameter.firstName == "x")
}
do {
let argument = arguments[1]
#expect(argument.value as? Int == 123)
#expect(argument.parameter.index == 1)
#expect(argument.parameter.firstName == "y")
}
}
await runTestFunction(named: "twoDictionaryElementParameters(x:y:)", in: ParameterizedTests.self, configuration: configuration)
}
@Test("One Dictionary element tuple (key, value) parameter")
func oneDictionaryElementTupleParameter() async {
var configuration = Configuration()
configuration.setEventHandler { event, context in
guard case .testCaseStarted = event.kind else {
return
}
let arguments = try #require(context.testCase?.arguments)
try #require(arguments.count == 1)
let argument = arguments[0]
let value = try #require(argument.value as? (String, Int))
#expect(value.0 == "value")
#expect(value.1 == 123)
#expect(argument.parameter.index == 0)
#expect(argument.parameter.firstName == "x")
#expect(argument.parameter.typeInfo.fullyQualifiedName == "(key: Swift.String, value: Swift.Int)")
#expect(argument.parameter.typeInfo.unqualifiedName == "(key: String, value: Int)")
}
await runTestFunction(named: "oneDictionaryElementTupleParameter(x:)", in: ParameterizedTests.self, configuration: configuration)
}
}
// MARK: - Fixture tests
@Suite(.hidden)
struct ParameterizedTests {
@Test(.hidden, arguments: ["value"])
func oneParameter(x: String) {}
@Test(.hidden, arguments: ["value"], [123])
func twoParameters(x: String, y: Int) {}
@Test(.hidden, arguments: [("value")])
func one1TupleParameter(x: (String)) {}
@Test(.hidden, arguments: [("value", 123)])
func one2TupleParameter(x: (String, Int)) {}
@Test<[(String?, Int?)]>(.hidden, arguments: [
(nil, 123),
("value1", nil),
("value2", nil),
])
func contextualArrayLiteral(x: String?, y: Int?) {}
@Test(.hidden, arguments: ["value": 123])
func twoDictionaryElementParameters(x: String, y: Int) {}
@Test(.hidden, arguments: ["value": 123])
func oneDictionaryElementTupleParameter(x: (key: String, value: Int)) {}
@Test<KeyValuePairs<String, Int?>>(.hidden, arguments: [
"value1": nil,
"value2": 123,
])
func contextualDictionaryLiteral(key: String, value: Int?) {}
@Test(.disabled(), arguments: [1, 2, 3]) func disabled(x: Int) {}
}