Skip to content

Commit

Permalink
spustio target
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar Otasevic committed Sep 7, 2024
1 parent c8a0b92 commit 03ee170
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PackageDescription

let package = Package(
name: "ViewInspection",
platforms: [.iOS(.v15), .macOS(.v12), .tvOS(.v15), .watchOS(.v8)] + [.visionOS(.v1)],
platforms: [.iOS(.v13), .macOS(.v10_15), .tvOS(.v13), .watchOS(.v6)] + [.visionOS(.v1)],
products: [
.library(
name: "ViewInspection",
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PackageDescription

let package = Package(
name: "ViewInspection",
platforms: [.iOS(.v15), .macOS(.v12), .tvOS(.v15), .watchOS(.v8)] + [.visionOS(.v1)],
platforms: [.iOS(.v13), .macOS(.v10_15), .tvOS(.v13), .watchOS(.v6)] + [.visionOS(.v1)],
products: [
.library(
name: "ViewInspection",
Expand Down
6 changes: 6 additions & 0 deletions Sources/ViewInspection/Elements/TestElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,13 @@ enum TestElement {
}

enum Modifier {
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
struct _Refreshable: ModifierDerivedElement {
let node: ReflectionNode
static func makeModifiedContent() -> Any { EmptyView().refreshable {} }
}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
struct _Task: ModifierDerivedElement {
let node: ReflectionNode
static func makeModifiedContent() -> Any { EmptyView().task {} }
Expand All @@ -478,6 +480,7 @@ enum TestElement {
static func makeModifiedContent() -> Any { EmptyView().onDisappear {} }
}

@available(iOS 13.0, macOS 10.15, tvOS 16.0, watchOS 6.0, *)
struct _OnTap: ModifierDerivedElement {
let node: ReflectionNode
static func makeModifiedContent() -> Any { EmptyView().onTapGesture {} }
Expand All @@ -501,12 +504,14 @@ enum TestElement {
}
}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
extension TestElement.Modifier._Refreshable {
func doRefresh() async {
await node.oneElement(TestElement.Value._asyncClosure.self).castValue()
}
}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
extension TestElement.Modifier._Task {
func doTask() async {
await node.oneElement(TestElement.Value._asyncClosure.self).castValue()
Expand All @@ -519,6 +524,7 @@ extension TestElement.Modifier._OnAppear {
}
}

@available(iOS 13.0, macOS 10.15, tvOS 16.0, watchOS 6.0, *)
extension TestElement.Modifier._OnTap {
func doTap() {
node.oneElement(TestElement.Value._voidParamClosure.self).castValue(())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

extension View {
var reflectionSnapshot: ReflectionNode {
var snapshot: ReflectionNode {
ReflectionNode(object: self)
}
}
8 changes: 4 additions & 4 deletions Tests/ViewInspectionTests/InteractiveViewElementsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import XCTest
final class InteractiveViewElementsTests: XCTestCase {}

@MainActor extension InteractiveViewElementsTests {
func testToggle() {
func test_Toggle() {
let b = Binding<Bool>.variable(false)
Toggle("", isOn: b).reflectionSnapshot.oneElement(TestElement.View._Toggle.self).toggle()
Toggle("", isOn: b).snapshot.oneElement(TestElement.View._Toggle.self).toggle()
XCTAssertEqual(b.wrappedValue, true)
}

func testButton() {
func test_Button() {
var b = false
Button("") { b = true }.reflectionSnapshot.oneElement(TestElement.View._Button.self).tap()
Button("") { b = true }.snapshot.oneElement(TestElement.View._Button.self).tap()
XCTAssertEqual(b, true)
}
}
19 changes: 11 additions & 8 deletions Tests/ViewInspectionTests/ModifierElementsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@ import XCTest
final class ModifierElementsTests: XCTestCase {}

@MainActor extension ModifierElementsTests {
func testRefreshable() async {
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
func test_Refreshable() async {
var x = 0
await EmptyView().refreshable { x = 1 }.reflectionSnapshot.oneElement(TestElement.Modifier._Refreshable.self).doRefresh()
await EmptyView().refreshable { x = 1 }.snapshot.oneElement(TestElement.Modifier._Refreshable.self).doRefresh()
XCTAssert(x == 1)
}

func testTask() async {
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
func test_Task() async {
var x = 0
await EmptyView().task { x = 1 }.reflectionSnapshot.oneElement(TestElement.Modifier._Task.self).doTask()
await EmptyView().task { x = 1 }.snapshot.oneElement(TestElement.Modifier._Task.self).doTask()
XCTAssert(x == 1)
}

func testOnAppear() {
func test_OnAppear() {
var x = 0
EmptyView().onAppear { x = 1 }.reflectionSnapshot.oneElement(TestElement.Modifier._OnAppear.self).doOnAppear()
EmptyView().onAppear { x = 1 }.snapshot.oneElement(TestElement.Modifier._OnAppear.self).doOnAppear()
XCTAssert(x == 1)
}

func testOnTap() {
@available(iOS 13.0, macOS 10.15, tvOS 16.0, watchOS 6.0, *)
func test_OnTap() {
var x = 0
EmptyView().onTapGesture { x = 1 }.reflectionSnapshot.oneElement(TestElement.Modifier._OnTap.self).doTap()
EmptyView().onTapGesture { x = 1 }.snapshot.oneElement(TestElement.Modifier._OnTap.self).doTap()
XCTAssert(x == 1)
}
}
8 changes: 4 additions & 4 deletions Tests/ViewInspectionTests/PropertyWrappersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ final class PropertyWrappersTests: XCTestCase {}
@MainActor extension PropertyWrappersTests {
func testEnvironment() {
struct Dummy: View {
@Environment(\.dismiss) private var dismiss
@Environment(\.colorScheme) private var colorScheme
let body = EmptyView()
}
let t = Dummy().reflectionSnapshot.allElements(TestElement.PropertyWrapper._Environment.self)
let t = Dummy().snapshot.allElements(TestElement.PropertyWrapper._Environment.self)
XCTAssertEqual(t.count, 2)
XCTAssert(t[1].node.parent === t[0].node)
}
Expand All @@ -20,14 +20,14 @@ final class PropertyWrappersTests: XCTestCase {}
@State private var x = 0
let body = EmptyView()
}
XCTAssertEqual(Dummy().reflectionSnapshot.allElements(TestElement.PropertyWrapper._State.self).count, 1)
XCTAssertEqual(Dummy().snapshot.allElements(TestElement.PropertyWrapper._State.self).count, 1)
}

func testBinding() {
struct Dummy: View {
@Binding var x: Int
let body = EmptyView()
}
XCTAssertEqual(Dummy(x: .constant(1)).reflectionSnapshot.allElements(TestElement.PropertyWrapper._Binding.self).count, 1)
XCTAssertEqual(Dummy(x: .constant(1)).snapshot.allElements(TestElement.PropertyWrapper._Binding.self).count, 1)
}
}
24 changes: 12 additions & 12 deletions Tests/ViewInspectionTests/StaticViewElementsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import XCTest
final class StaticViewElementsTests: XCTestCase {}

@MainActor extension StaticViewElementsTests {
func testText() {
func test_Text() {
XCTAssertEqual(
Text("a").reflectionSnapshot.oneElement(TestElement.View._Text.self).string,
Text("a").snapshot.oneElement(TestElement.View._Text.self).string,
"a"
)
}

func testImage() {
let ref = Image(systemName: "circle").reflectionSnapshot.oneElement(TestElement.View._Image.self)
func test_Image() {
let ref = Image(systemName: "circle").snapshot.oneElement(TestElement.View._Image.self)
XCTAssertEqual(ref.name, "circle")
}

@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
func testNavigationStack() {
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *)
func test_NavigationStack() {
XCTAssertEqual(
NavigationStack { Text("a") }
.reflectionSnapshot
.snapshot
.oneElement(TestElement.View._NavigationStack.self)
.node
.oneElement(TestElement.View._Text.self)
Expand All @@ -30,22 +30,22 @@ final class StaticViewElementsTests: XCTestCase {}
)
}

func testGeomReader() {
func test_GeometryReader() {
XCTAssertEqual(
GeometryReader { _ in }
.reflectionSnapshot
.snapshot
.allElements(TestElement.View._GeometryReader.self)
.count,
1
)
}

func testForEach() {
func test_ForEach() {
XCTAssertEqual(
ForEach(Array(0 ... 1), id: \.self) {
Text($0.description)
}
.reflectionSnapshot
.snapshot
.allElements(TestElement.View._ForEach.self)
.count,
2
Expand All @@ -54,7 +54,7 @@ final class StaticViewElementsTests: XCTestCase {}
ForEach(Array(0 ... 1), id: \.self) {
Text($0.description)
}
.reflectionSnapshot
.snapshot
.allElements(TestElement.View._Text.self)
.count,
0
Expand Down
6 changes: 3 additions & 3 deletions Tests/ViewInspectionTests/TypeInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import XCTest
@testable import ViewInspection

final class TypeInfoTests: XCTestCase {
func testTypeInfoBinding() {
func test_TypeInfo_Binding() {
let t1 = TypeInfo(type: Binding<Int>.self)
let b: Binding<Int> = .constant(1)
let t2 = TypeInfo(object: b)
Expand All @@ -13,7 +13,7 @@ final class TypeInfoTests: XCTestCase {
XCTAssertEqual(t1.generics, ["Swift.Int"])
}

func testTypeInfoInt() {
func test_TypeInfo_Int() {
let t1 = TypeInfo(type: Int.self)
let int = 0
let t2 = TypeInfo(object: int)
Expand All @@ -23,7 +23,7 @@ final class TypeInfoTests: XCTestCase {
XCTAssert(t1.generics.isEmpty)
}

func testGenerics() {
func test_TypeInfo_Generics() {
XCTAssert(TypeInfo(typename: "Gen").generics.isEmpty)
XCTAssert(TypeInfo(typename: "Gen<>").generics.isEmpty)
XCTAssert(TypeInfo(typename: "Gen<,>").generics.isEmpty)
Expand Down

0 comments on commit 03ee170

Please sign in to comment.