-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMetadataDebugTests.swift
More file actions
69 lines (57 loc) · 1.64 KB
/
MetadataDebugTests.swift
File metadata and controls
69 lines (57 loc) · 1.64 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
//
// MetadataDebugTests.swift
// OpenAttributeGraphShimsTests
@_spi(Debug) import OpenAttributeGraphShims
import Testing
#if canImport(UIKit)
import UIKit
private typealias PlatformView = UIView
#elseif canImport(AppKit)
import AppKit
private typealias PlatformView = NSView
#endif
@Suite(.disabled(if: attributeGraphVendor == .oag, "forEachField is not implemented for OAG"))
struct MetadataDebugTests {
struct Demo1 {
var a: Int = .zero
var b: Double = .zero
}
class Demo2 {
var a: Int = .zero
var b: Double = .zero
}
@Test
func layout() {
#expect(Metadata(Demo1.self).layoutDescription == #"""
struct Demo1 {
\#tvar a: Int // offset = 0x0
\#tvar b: Double // offset = 0x8
}
"""#)
#expect(Metadata(Demo2.self).layoutDescription == #"""
class Demo2 {
\#tvar a: Int // offset = 0x10
\#tvar b: Double // offset = 0x18
}
"""#)
}
#if canImport(UIKit) || canImport(AppKit)
@Test
func unknownFields() {
class DemoView: PlatformView {
var a: Int = .zero
var b: Double = .zero
}
let layoutDescription = Metadata(DemoView.self).layoutDescription.split(separator: "\n").map(String.init)
#expect(layoutDescription[0] == "class DemoView {")
#expect(layoutDescription[1].contains("var a: Int // offset = "))
#expect(layoutDescription[2].contains("var b: Double // offset = "))
#expect(layoutDescription[3] == "}")
}
#endif
}
extension Int {
private var hex: String {
"0x\(String(format: "%X", self))"
}
}