-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathCustomTestReflectableTests.swift
More file actions
44 lines (39 loc) · 1.21 KB
/
CustomTestReflectableTests.swift
File metadata and controls
44 lines (39 loc) · 1.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
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2026 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 import Testing
struct `CustomTestReflectable Tests` {
@Test func `Can get a custom mirror from a value`() throws {
let subject = MyReflectable() as Any
let mirror = Mirror(reflectingForTest: subject)
#expect(mirror.children.count == 4)
let fee = try #require(mirror.children.first)
#expect(fee.label == "fee")
#expect(fee.value is Int)
}
@Test func `Fall back to Mirror(reflecting:)`() throws {
let subject = [1, 2, 3] as Any
let mirror = Mirror(reflectingForTest: subject)
#expect(mirror.children.count > 0)
}
}
// MARK: - Fixtures
struct MyReflectable: CustomTestReflectable {
var customTestMirror: Mirror {
Mirror(
self,
children: [
(label: "fee", value: 1 as Any),
(label: "fi", value: 2.0 as Any),
(label: "fo", value: "3" as Any),
(label: "fum", value: /4/ as Any)
]
)
}
}