@@ -3,50 +3,50 @@ import SwiftSyntax
3
3
4
4
5
5
public class CustomReflectableTests : XCTestCase {
6
- public static let allTests = [
7
- ( " testConformanceToCustomReflectable " , testConformanceToCustomReflectable) ,
8
- ]
9
-
10
-
11
- public func testConformanceToCustomReflectable( ) {
12
- XCTAssertNoThrow ( try {
13
- let parsed = try SyntaxParser . parse ( getInput ( " near-empty.swift " ) )
14
- XCTAssertEqual ( collectSyntaxNotConformedCustomReflectable ( from: parsed) , [ ] )
15
- } ( ) )
16
- XCTAssertNoThrow ( try {
17
- let parsed = try SyntaxParser . parse ( getInput ( " closure.swift " ) )
18
- XCTAssertEqual ( collectSyntaxNotConformedCustomReflectable ( from: parsed) , [ ] )
19
- } ( ) )
20
- XCTAssertNoThrow ( try {
21
- let parsed = try SyntaxParser . parse ( getInput ( " nested-blocks.swift " ) )
22
- XCTAssertEqual ( collectSyntaxNotConformedCustomReflectable ( from: parsed) , [ ] )
23
- } ( ) )
24
- XCTAssertNoThrow ( try {
25
- let parsed = try SyntaxParser . parse ( getInput ( " visitor.swift " ) )
26
- XCTAssertEqual ( collectSyntaxNotConformedCustomReflectable ( from: parsed) , [ ] )
27
- } ( ) )
28
- }
29
-
30
-
31
- public func collectSyntaxNotConformedCustomReflectable< S: Any > ( from object: S ) -> [ String ] {
32
- var paths = [ String] ( )
33
- collectSyntaxNotConformedCustomReflectable ( from: object, ancestors: [ " root " ] , foundPaths: & paths)
34
- return paths
35
- }
36
-
37
-
38
- public func collectSyntaxNotConformedCustomReflectable< S: Any > ( from object: S , ancestors: [ String ] , foundPaths: inout [ String ] ) {
39
- Mirror ( reflecting: object) . children. forEach { child in
40
- let ( label: label, value: value) = child
41
-
42
- var currentPathComponents = ancestors
43
- currentPathComponents. append ( label ?? " (nil) " )
44
-
45
- if let syntax = value as? Syntax , !( syntax is CustomReflectable ) {
46
- foundPaths. append ( " \( currentPathComponents. joined ( separator: " . " ) ) : \( type ( of: value as Any ) ) " )
47
- }
48
-
49
- collectSyntaxNotConformedCustomReflectable ( from: value, ancestors: currentPathComponents, foundPaths: & foundPaths)
50
- }
6
+ public static let allTests = [
7
+ ( " testConformanceToCustomReflectable " , testConformanceToCustomReflectable) ,
8
+ ]
9
+
10
+
11
+ public func testConformanceToCustomReflectable( ) {
12
+ XCTAssertNoThrow ( try {
13
+ let parsed = try SyntaxParser . parse ( getInput ( " near-empty.swift " ) )
14
+ XCTAssertEqual ( collectSyntaxNotConformedCustomReflectable ( from: parsed) , [ ] )
15
+ } ( ) )
16
+ XCTAssertNoThrow ( try {
17
+ let parsed = try SyntaxParser . parse ( getInput ( " closure.swift " ) )
18
+ XCTAssertEqual ( collectSyntaxNotConformedCustomReflectable ( from: parsed) , [ ] )
19
+ } ( ) )
20
+ XCTAssertNoThrow ( try {
21
+ let parsed = try SyntaxParser . parse ( getInput ( " nested-blocks.swift " ) )
22
+ XCTAssertEqual ( collectSyntaxNotConformedCustomReflectable ( from: parsed) , [ ] )
23
+ } ( ) )
24
+ XCTAssertNoThrow ( try {
25
+ let parsed = try SyntaxParser . parse ( getInput ( " visitor.swift " ) )
26
+ XCTAssertEqual ( collectSyntaxNotConformedCustomReflectable ( from: parsed) , [ ] )
27
+ } ( ) )
28
+ }
29
+
30
+
31
+ public func collectSyntaxNotConformedCustomReflectable< S: Any > ( from object: S ) -> [ String ] {
32
+ var paths = [ String] ( )
33
+ collectSyntaxNotConformedCustomReflectable ( from: object, ancestors: [ " root " ] , foundPaths: & paths)
34
+ return paths
35
+ }
36
+
37
+
38
+ public func collectSyntaxNotConformedCustomReflectable< S: Any > ( from object: S , ancestors: [ String ] , foundPaths: inout [ String ] ) {
39
+ Mirror ( reflecting: object) . children. forEach { child in
40
+ let ( label: label, value: value) = child
41
+
42
+ var currentPathComponents = ancestors
43
+ currentPathComponents. append ( label ?? " (nil) " )
44
+
45
+ if let syntax = value as? Syntax , !( syntax is CustomReflectable ) {
46
+ foundPaths. append ( " \( currentPathComponents. joined ( separator: " . " ) ) : \( type ( of: value as Any ) ) " )
47
+ }
48
+
49
+ collectSyntaxNotConformedCustomReflectable ( from: value, ancestors: currentPathComponents, foundPaths: & foundPaths)
51
50
}
51
+ }
52
52
}
0 commit comments