diff --git a/Sources/ViewInspection/Utils/BindingHelpers.swift b/Sources/ViewInspection/BindingHelpers.swift similarity index 100% rename from Sources/ViewInspection/Utils/BindingHelpers.swift rename to Sources/ViewInspection/BindingHelpers.swift diff --git a/Sources/ViewInspection/Utils/CastingUtils.swift b/Sources/ViewInspection/CastingUtils.swift similarity index 100% rename from Sources/ViewInspection/Utils/CastingUtils.swift rename to Sources/ViewInspection/CastingUtils.swift diff --git a/Sources/ViewInspection/Elements/DummyObjects.swift b/Sources/ViewInspection/DummyObjects.swift similarity index 100% rename from Sources/ViewInspection/Elements/DummyObjects.swift rename to Sources/ViewInspection/DummyObjects.swift diff --git a/Sources/ViewInspection/Elements/AnyInspectable.swift b/Sources/ViewInspection/Elements/AnyInspectable.swift deleted file mode 100644 index b08b5df..0000000 --- a/Sources/ViewInspection/Elements/AnyInspectable.swift +++ /dev/null @@ -1,27 +0,0 @@ -enum AnyInspectable { - typealias Element = T - case some -} - -// MARK: - modifiers - -extension AnyInspectable { - @available(tvOS 16.0, *) - static var onTap: AnyInspectable { .some } - - static var refreshable: AnyInspectable { .some } -} - -// MARK: - closures - -extension AnyInspectable { - static var closure: AnyInspectable Void>> { .some } - static var closureWithVoidParam: AnyInspectable Void>> { .some } - static var asyncClosure: AnyInspectable Void>> { .some } -} - -// MARK: - native - -extension AnyInspectable { - static var string: AnyInspectable> { .some } -} diff --git a/Sources/ViewInspection/Elements/Extensions/_Button.swift b/Sources/ViewInspection/Elements/_Button.swift similarity index 100% rename from Sources/ViewInspection/Elements/Extensions/_Button.swift rename to Sources/ViewInspection/Elements/_Button.swift diff --git a/Sources/ViewInspection/Elements/Extensions/_Image.swift b/Sources/ViewInspection/Elements/_Image.swift similarity index 100% rename from Sources/ViewInspection/Elements/Extensions/_Image.swift rename to Sources/ViewInspection/Elements/_Image.swift diff --git a/Sources/ViewInspection/Elements/Extensions/_SecureField.swift b/Sources/ViewInspection/Elements/_SecureField.swift similarity index 100% rename from Sources/ViewInspection/Elements/Extensions/_SecureField.swift rename to Sources/ViewInspection/Elements/_SecureField.swift diff --git a/Sources/ViewInspection/Elements/Extensions/_Slider.swift b/Sources/ViewInspection/Elements/_Slider.swift similarity index 100% rename from Sources/ViewInspection/Elements/Extensions/_Slider.swift rename to Sources/ViewInspection/Elements/_Slider.swift diff --git a/Sources/ViewInspection/Elements/Extensions/_Text.swift b/Sources/ViewInspection/Elements/_Text.swift similarity index 100% rename from Sources/ViewInspection/Elements/Extensions/_Text.swift rename to Sources/ViewInspection/Elements/_Text.swift diff --git a/Sources/ViewInspection/Elements/Extensions/_TextField.swift b/Sources/ViewInspection/Elements/_TextField.swift similarity index 100% rename from Sources/ViewInspection/Elements/Extensions/_TextField.swift rename to Sources/ViewInspection/Elements/_TextField.swift diff --git a/Sources/ViewInspection/Elements/Extensions/_Toggle.swift b/Sources/ViewInspection/Elements/_Toggle.swift similarity index 100% rename from Sources/ViewInspection/Elements/Extensions/_Toggle.swift rename to Sources/ViewInspection/Elements/_Toggle.swift diff --git a/Sources/ViewInspection/Elements/Extensions/_OnTap.swift b/Sources/ViewInspection/Elements/_onTapGesture.swift similarity index 74% rename from Sources/ViewInspection/Elements/Extensions/_OnTap.swift rename to Sources/ViewInspection/Elements/_onTapGesture.swift index 5080f16..3c73b3c 100644 --- a/Sources/ViewInspection/Elements/Extensions/_OnTap.swift +++ b/Sources/ViewInspection/Elements/_onTapGesture.swift @@ -1,8 +1,8 @@ import SwiftUI @available(tvOS 16.0, *) -extension InspectableType._OnTap { +extension InspectableType._onTapGesture { func tap() throws { try node.one(.closureWithVoidParam).castValue(()) } -} \ No newline at end of file +} diff --git a/Sources/ViewInspection/Elements/Extensions/_Refreshable.swift b/Sources/ViewInspection/Elements/_refreshable.swift similarity index 71% rename from Sources/ViewInspection/Elements/Extensions/_Refreshable.swift rename to Sources/ViewInspection/Elements/_refreshable.swift index 229a7b4..f5f1020 100644 --- a/Sources/ViewInspection/Elements/Extensions/_Refreshable.swift +++ b/Sources/ViewInspection/Elements/_refreshable.swift @@ -1,7 +1,7 @@ import SwiftUI -extension InspectableType._Refreshable { +extension InspectableType._refreshable { func refresh() async throws { try await node.one(.asyncClosure).castValue() } -} \ No newline at end of file +} diff --git a/Sources/ViewInspection/Inspection/AnyInspectable+Modifiers.swift b/Sources/ViewInspection/Inspection/AnyInspectable+Modifiers.swift new file mode 100644 index 0000000..38cbf27 --- /dev/null +++ b/Sources/ViewInspection/Inspection/AnyInspectable+Modifiers.swift @@ -0,0 +1,6 @@ +extension AnyInspectable { + @available(tvOS 16.0, *) + static var onTapGesture: AnyInspectable { .some } + + static var refreshable: AnyInspectable { .some } +} diff --git a/Sources/ViewInspection/Inspection/AnyInspectable+Values.swift b/Sources/ViewInspection/Inspection/AnyInspectable+Values.swift new file mode 100644 index 0000000..9645349 --- /dev/null +++ b/Sources/ViewInspection/Inspection/AnyInspectable+Values.swift @@ -0,0 +1,6 @@ +extension AnyInspectable { + static var closure: AnyInspectable Void>> { .some } + static var closureWithVoidParam: AnyInspectable Void>> { .some } + static var asyncClosure: AnyInspectable Void>> { .some } + static var string: AnyInspectable> { .some } +} diff --git a/Sources/ViewInspection/Inspection/AnyInspectable.swift b/Sources/ViewInspection/Inspection/AnyInspectable.swift new file mode 100644 index 0000000..c0a7d47 --- /dev/null +++ b/Sources/ViewInspection/Inspection/AnyInspectable.swift @@ -0,0 +1,3 @@ +enum AnyInspectable { + case some +} diff --git a/Sources/ViewInspection/Elements/InspectableType+Modifiers.swift b/Sources/ViewInspection/Inspection/InspectableType+Modifiers.swift similarity index 75% rename from Sources/ViewInspection/Elements/InspectableType+Modifiers.swift rename to Sources/ViewInspection/Inspection/InspectableType+Modifiers.swift index 94351bd..842753f 100644 --- a/Sources/ViewInspection/Elements/InspectableType+Modifiers.swift +++ b/Sources/ViewInspection/Inspection/InspectableType+Modifiers.swift @@ -1,14 +1,14 @@ import SwiftUI extension InspectableType { - struct _Refreshable: ModifierDerivedElement { + struct _refreshable: ModifierDerivedElement { let node: ReflectionNode static func makeModifiedContent() -> Any { EmptyView().refreshable {} } } @available(tvOS 16.0, *) - struct _OnTap: ModifierDerivedElement { + struct _onTapGesture: ModifierDerivedElement { let node: ReflectionNode static func makeModifiedContent() -> Any { EmptyView().onTapGesture {} } } -} \ No newline at end of file +} diff --git a/Sources/ViewInspection/Elements/InspectableType.swift b/Sources/ViewInspection/Inspection/InspectableType.swift similarity index 60% rename from Sources/ViewInspection/Elements/InspectableType.swift rename to Sources/ViewInspection/Inspection/InspectableType.swift index 7d9834c..2fe7f4f 100644 --- a/Sources/ViewInspection/Elements/InspectableType.swift +++ b/Sources/ViewInspection/Inspection/InspectableType.swift @@ -1,3 +1 @@ -import SwiftUI - enum InspectableType {} diff --git a/Sources/ViewInspection/Elements/ReflectionElement.swift b/Sources/ViewInspection/Inspection/InspectionElement.swift similarity index 86% rename from Sources/ViewInspection/Elements/ReflectionElement.swift rename to Sources/ViewInspection/Inspection/InspectionElement.swift index 95f9fd0..5547087 100644 --- a/Sources/ViewInspection/Elements/ReflectionElement.swift +++ b/Sources/ViewInspection/Inspection/InspectionElement.swift @@ -1,19 +1,19 @@ -protocol ReflectionElement { +protocol InspectionElement { var node: ReflectionNode { get } init(node: ReflectionNode) static func isValid(_ node: ReflectionNode) -> Bool } -extension ReflectionElement { +extension InspectionElement { func tryCast(_ t: T.Type = T.self) throws -> T { guard let obj = node.object as? T else { - throw ViewInspectionError.wrongType + throw InspectionError.wrongType } return obj } } -protocol TypeDerivedElement: ReflectionElement { +protocol TypeDerivedElement: InspectionElement { associatedtype RelatedType } @@ -35,7 +35,7 @@ struct SameBaseElement: TypeDerivedElement { static func isValid(_ node: ReflectionNode) -> Bool { node.typeInfo.baseTypename == typeInfo.baseTypename } } -protocol ModifierDerivedElement: ReflectionElement { +protocol ModifierDerivedElement: InspectionElement { static func makeModifiedContent() -> Any } @@ -58,7 +58,7 @@ struct ClosureElement: CastableTypeDerivedElement { static func isValid(_ node: ReflectionNode) -> Bool { node.typeInfo.typename.hasSuffix(typeInfo.typename) } } -struct SomeClosureElement: ReflectionElement { +struct SomeClosureElement: InspectionElement { let node: ReflectionNode static func isValid(_ node: ReflectionNode) -> Bool { node.typeInfo.typename.contains("->") diff --git a/Sources/ViewInspection/ViewInspectionError.swift b/Sources/ViewInspection/Inspection/InspectionError.swift similarity index 59% rename from Sources/ViewInspection/ViewInspectionError.swift rename to Sources/ViewInspection/Inspection/InspectionError.swift index f28d54e..518f2d6 100644 --- a/Sources/ViewInspection/ViewInspectionError.swift +++ b/Sources/ViewInspection/Inspection/InspectionError.swift @@ -1,4 +1,4 @@ -enum ViewInspectionError: Error { +enum InspectionError: Error { case wrongNumberOfItems case wrongType } diff --git a/Sources/ViewInspection/Reflection/ReflectionNode.swift b/Sources/ViewInspection/Inspection/ReflectionNode.swift similarity index 74% rename from Sources/ViewInspection/Reflection/ReflectionNode.swift rename to Sources/ViewInspection/Inspection/ReflectionNode.swift index 89bb8cb..4c4141d 100644 --- a/Sources/ViewInspection/Reflection/ReflectionNode.swift +++ b/Sources/ViewInspection/Inspection/ReflectionNode.swift @@ -23,18 +23,18 @@ final class ReflectionNode: @unchecked Sendable { // MARK: - Utilities extension ReflectionNode { - var tree: [ReflectionNode] { - children.reduce([self]) { $0 + $1.tree } + var nodes: [ReflectionNode] { + children.reduce([self]) { $0 + $1.nodes } } - func all(_ t: AnyInspectable = .some, _ filter: (CP) -> Bool = { _ in true }) -> [CP] { - tree.filter(CP.isValid).map(CP.init).filter(filter) + func all(_ t: AnyInspectable = .some, _ filter: (CP) -> Bool = { _ in true }) -> [CP] { + nodes.filter(CP.isValid).map(CP.init).filter(filter) } - @discardableResult func one(_ t: AnyInspectable = .some, _ filter: (CP) -> Bool = { _ in true }) throws -> CP { + @discardableResult func one(_ t: AnyInspectable = .some, _ filter: (CP) -> Bool = { _ in true }) throws -> CP { let items = all(t, filter) if items.count != 1 { - throw ViewInspectionError.wrongNumberOfItems + throw InspectionError.wrongNumberOfItems } return items[0] } diff --git a/Sources/ViewInspection/Reflection/TypeInfo.swift b/Sources/ViewInspection/Inspection/TypeInfo.swift similarity index 100% rename from Sources/ViewInspection/Reflection/TypeInfo.swift rename to Sources/ViewInspection/Inspection/TypeInfo.swift diff --git a/Tests/ViewInspectionTests/Elements/_OnTap.swift b/Tests/ViewInspectionTests/Elements/_onTapGesture.swift similarity index 50% rename from Tests/ViewInspectionTests/Elements/_OnTap.swift rename to Tests/ViewInspectionTests/Elements/_onTapGesture.swift index 63cde93..1b103ae 100644 --- a/Tests/ViewInspectionTests/Elements/_OnTap.swift +++ b/Tests/ViewInspectionTests/Elements/_onTapGesture.swift @@ -2,11 +2,11 @@ import SwiftUI @testable import ViewInspection import XCTest -@MainActor final class Test_OnTap: XCTestCase { +@MainActor final class Test_onTapGesture: XCTestCase { @available(iOS 13.0, macOS 10.15, tvOS 16.0, watchOS 6.0, *) - func test_OnTap() throws { + func test_onTapGesture() throws { var x = 0 - try EmptyView().onTapGesture { x = 1 }.snap.one(.onTap).tap() + try EmptyView().onTapGesture { x = 1 }.snap.one(.onTapGesture).tap() XCTAssert(x == 1) } -} \ No newline at end of file +} diff --git a/Tests/ViewInspectionTests/Elements/_Refreshable.swift b/Tests/ViewInspectionTests/Elements/_refreshable.swift similarity index 72% rename from Tests/ViewInspectionTests/Elements/_Refreshable.swift rename to Tests/ViewInspectionTests/Elements/_refreshable.swift index 150782f..d48458e 100644 --- a/Tests/ViewInspectionTests/Elements/_Refreshable.swift +++ b/Tests/ViewInspectionTests/Elements/_refreshable.swift @@ -2,11 +2,11 @@ import SwiftUI @testable import ViewInspection import XCTest -@MainActor final class Test_Refreshable: XCTestCase { +@MainActor final class Test_refreshable: XCTestCase { @available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) - func test_Refreshable() async throws { + func test_refreshable() async throws { var x = 0 try await EmptyView().refreshable { x = 1 }.snap.one(.refreshable).refresh() XCTAssert(x == 1) } -} \ No newline at end of file +}