@@ -59,6 +59,30 @@ public func XCTAssertSameStructure(
59
59
XCTAssertNil ( diff, diff!. debugDescription, file: file, line: line)
60
60
}
61
61
62
+ /// See `SubtreeMatcher.assertSameStructure`.
63
+ public func XCTAssertHasSubstructure(
64
+ _ markedText: String ,
65
+ parse: ( String ) throws -> Syntax ,
66
+ afterMarker: String ? = nil ,
67
+ _ expected: SyntaxProtocol ,
68
+ includeTrivia: Bool = false ,
69
+ file: StaticString = #filePath, line: UInt = #line
70
+ ) throws {
71
+ let subtreeMatcher = try SubtreeMatcher ( markedText, parse: parse)
72
+ try subtreeMatcher. assertSameStructure ( afterMarker: afterMarker, Syntax ( expected) , file: file, line: line)
73
+ }
74
+
75
+ /// See `SubtreeMatcher.assertSameStructure`.
76
+ public func XCTAssertHasSubstructure(
77
+ _ actualTree: SyntaxProtocol ,
78
+ _ expected: SyntaxProtocol ,
79
+ includeTrivia: Bool = false ,
80
+ file: StaticString = #filePath, line: UInt = #line
81
+ ) throws {
82
+ let subtreeMatcher = SubtreeMatcher ( Syntax ( actualTree) )
83
+ try subtreeMatcher. assertSameStructure ( Syntax ( expected) , file: file, line: line)
84
+ }
85
+
62
86
/// Allows matching a subtrees of the given `markedText` against
63
87
/// `baseline`/`expected` trees, where a combination of markers and the type
64
88
/// of the `expected` tree is used to first find the subtree to match. Note
@@ -123,6 +147,11 @@ public struct SubtreeMatcher {
123
147
self . actualTree = try parse ( text)
124
148
}
125
149
150
+ public init ( _ actualTree: Syntax ) {
151
+ self . markers = [ " DEFAULT " : 0 ]
152
+ self . actualTree = actualTree
153
+ }
154
+
126
155
/// Same as `Syntax.findFirstDifference(baseline:includeTrivia:)`, but
127
156
/// matches against the first subtree from parsing `markedText` that is after
128
157
/// `afterMarker` with the root matching the root type of `baseline`.
0 commit comments