Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPM support #213 #339

Merged
merged 5 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import BlueprintUI
import ListableUI
import UIKit


/// Alias to allow less verbose creation of headers.
Expand Down
1 change: 1 addition & 0 deletions BlueprintUILists/Sources/BlueprintItemContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import BlueprintUI
import ListableUI
import UIKit


///
Expand Down
2 changes: 1 addition & 1 deletion BlueprintUILists/Sources/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

import BlueprintUI

import ListableUI
import UIKit


///
Expand Down
1 change: 1 addition & 0 deletions BlueprintUILists/Sources/ListReorderGesture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import BlueprintUI
import ListableUI
import UIKit


///
Expand Down
14 changes: 11 additions & 3 deletions Internal Pods/EnglishDictionary/Sources/EnglishDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
import UIKit


class BundleFinder : NSObject {}
internal extension Bundle {
static var resources: Bundle {
#if SWIFT_PACKAGE
return .module
#else
let main = Bundle(for: EnglishDictionary.self)
return Bundle(url: main.url(forResource: "EnglishDictionaryResources", withExtension: "bundle")!)!
#endif
}
}

public class EnglishDictionary
{
Expand All @@ -19,8 +28,7 @@ public class EnglishDictionary

public init()
{
let main = Bundle(for: EnglishDictionary.self)
let bundle = Bundle(url: main.url(forResource: "EnglishDictionaryResources", withExtension: "bundle")!)!
let bundle = Bundle.resources

let stream = InputStream(url: bundle.url(forResource: "dictionary", withExtension: "json")!)!
defer { stream.close() }
Expand Down
80 changes: 40 additions & 40 deletions Internal Pods/Snapshot/Sources/Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,53 @@
import XCTest

public struct Snapshot<Iteration:SnapshotIteration>
{
{
public typealias Test = (Iteration) throws -> Iteration.RenderingFormat

public let settings : SnapshotSettings
public let iterations : [Iteration]
public let test : Test

internal typealias OnFail = (_ message : String, _ file : StaticString, _ line : UInt) -> ()
internal var onFail : OnFail = XCTFail
internal var onFail : OnFail = { message, file, line in XCTFail(message, file: file, line: line) }

public init(
for iteration: Iteration ,
settings : SnapshotSettings = .init(),
input : Iteration.RenderingFormat
) {
self.init(for: [iteration], settings : settings) { _ in input }
}

public init(
for iterations: [Iteration] ,
settings : SnapshotSettings = .init(),
input : Iteration.RenderingFormat
) {
self.init(for: iterations, settings : settings) { _ in input }
}

public init(
for iterations : [Iteration],
settings : SnapshotSettings = .init(),
test : @escaping Test
) {
let hasIterations = iterations.isEmpty == false
precondition(hasIterations, "Must provide at least one iteration.")

let allNames = iterations.map { $0.name }

let allNamesUnique = Set(allNames).count == iterations.count
precondition(allNamesUnique, "Must provide iterations with unique names.")

let allNamesNonEmpty = allNames.allSatisfy { $0.isEmpty == false }
precondition(allNamesNonEmpty, "Cannot provide an empty iteration name.")

self.iterations = iterations.sorted { $0.name < $1.name }
self.settings = settings
self.test = test
}

public func test<OutputFormat:SnapshotOutputFormat>(
output: OutputFormat.Type,
testCase : String? = nil,
Expand All @@ -72,16 +72,16 @@ public struct Snapshot<Iteration:SnapshotIteration>
functionName: functionName.description,
iteration: iteration.name
)

var onFailData : Data? = nil

do {
let rendering = iteration.prepare(render: try self.test(iteration))
let data = try OutputFormat.snapshotData(with: rendering)
onFailData = data

let existingData = try self.existingData(at: url)

if let existingData = existingData {
do {
try OutputFormat.validate(render: rendering, existingData: existingData)
Expand All @@ -100,35 +100,35 @@ public struct Snapshot<Iteration:SnapshotIteration>
return "Error generating snapshotData."
}
}()

self.onFail(
"""
Snapshot test '\(iteration.name)' with format '\(OutputFormat.self)' failed.

Error: \(error).

File extension: '.\(output.outputInfo.fileExtension)'.

Base64 Data (pass this to `Data.saveBase64(toPath: "~/Development/etc ...", content: "...")` to inspect locally):

'\(data)'.

""",
testFilePath, line
)
}
}
}
}

func existingData(at url : URL) throws -> Data?
{
guard FileManager.default.fileExists(atPath: url.path) else {
return nil
}

return try Data(contentsOf: url)
}

static func outputUrl<OutputFormat:SnapshotOutputFormat>(
with settings : SnapshotSettings,
output: OutputFormat.Type,
Expand All @@ -141,23 +141,23 @@ public struct Snapshot<Iteration:SnapshotIteration>
let testFileURL = URL(fileURLWithPath: testFilePath)
let testFileName = testFileURL.lastPathComponent
let testDirectory = testFileURL.deletingLastPathComponent()

// For: ~/Development/Project/Tests/Tests.swift
// We Provide: ~/Development/Project/Tests/Snapshot Results/Tests.swift/OSVersion/testFunctionName()/outputFormat/testCase/modifierName.extension

var snapshotsDirectory = testDirectory
.appendingPathComponent("Snapshot Results", isDirectory: true)
.appendingPathComponent(testFileName, isDirectory: true)
.appendingPathComponent(settings.savesBySystemVersion.systemVersionDirectory(), isDirectory: true)
.appendingPathComponent(functionName, isDirectory: true)
.appendingPathComponent(OutputFormat.outputInfo.directoryName, isDirectory: true)

if let testCase = testCase {
snapshotsDirectory = snapshotsDirectory.appendingPathComponent(testCase, isDirectory: true)
}

try! FileManager.default.createDirectory(at: snapshotsDirectory, withIntermediateDirectories: true, attributes: [:])

return snapshotsDirectory
.appendingPathComponent(iteration)
.appendingPathExtension(OutputFormat.outputInfo.fileExtension)
Expand All @@ -170,19 +170,19 @@ public extension Data
static func saveBase64(toPath path : String, content : String) -> Bool
{
let url = URL(fileURLWithPath: (path as NSString).expandingTildeInPath)

guard let data = Data(base64Encoded: content) else {
print("Could not create data from base64 string.")
return false
}

do {
try data.write(to: url)
} catch {
print("Could not write data to disk. Error: \(error)")
return false
}

return true
}
}
Expand All @@ -197,11 +197,11 @@ public enum SnapshotValidationError : Error
public protocol SnapshotOutputFormat
{
associatedtype RenderingFormat

static func snapshotData(with renderingFormat : RenderingFormat) throws -> Data

static var outputInfo : SnapshotOutputInfo { get }

static func validate(render: RenderingFormat, existingData : Data) throws
}

Expand All @@ -210,7 +210,7 @@ public struct SnapshotOutputInfo : Equatable
{
public var directoryName : String
public var fileExtension : String

public init(
directoryName : String,
fileExtension : String
Expand All @@ -224,8 +224,8 @@ public struct SnapshotOutputInfo : Equatable
public protocol SnapshotIteration
{
associatedtype RenderingFormat

var name : String { get }

func prepare(render : RenderingFormat) -> RenderingFormat
}
2 changes: 2 additions & 0 deletions ListableUI/Sources/Appearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Kyle Van Essen on 10/17/19.
//

import UIKit


///
/// Contains all the properties which affect the appearance of all possible kinds of list layouts.
Expand Down
1 change: 1 addition & 0 deletions ListableUI/Sources/Behavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import UIKit


/// Controls various behaviors of the list view, such as keyboard dismissal, selection mode, and behavior
Expand Down
1 change: 1 addition & 0 deletions ListableUI/Sources/Content.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Kyle Van Essen on 6/21/19.
//

import UIKit


public struct Content
Expand Down
1 change: 1 addition & 0 deletions ListableUI/Sources/ContentBounds/ListContentBounds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import UIKit


/// For participating layouts; allows controlling the padding around and width of content when it is laid out.
Expand Down
2 changes: 2 additions & 0 deletions ListableUI/Sources/EmbeddedList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Kyle Van Essen on 11/10/19.
//

import UIKit


public extension Item where Content == EmbeddedList
{
Expand Down
1 change: 1 addition & 0 deletions ListableUI/Sources/HeaderFooter/AnyHeaderFooter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import UIKit


public protocol AnyHeaderFooter : AnyHeaderFooterConvertible, AnyHeaderFooter_Internal
Expand Down
2 changes: 2 additions & 0 deletions ListableUI/Sources/HeaderFooter/HeaderFooter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Kyle Van Essen on 8/10/19.
//

import UIKit


public typealias Header<Content:HeaderFooterContent> = HeaderFooter<Content>
public typealias Footer<Content:HeaderFooterContent> = HeaderFooter<Content>
Expand Down
2 changes: 2 additions & 0 deletions ListableUI/Sources/HeaderFooter/HeaderFooterContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Kyle Van Essen on 8/10/19.
//

import UIKit


public typealias HeaderContent = HeaderFooterContent
public typealias FooterContent = HeaderFooterContent
Expand Down
1 change: 1 addition & 0 deletions ListableUI/Sources/Internal/CGSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import UIKit


internal extension CGSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import UIKit


protocol AnyPresentationHeaderFooterState : AnyObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import UIKit


protocol AnyPresentationItemState : AnyObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import UIKit


extension PresentationState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Kyle Van Essen on 7/22/19.
//

import UIKit


/// A class used to manage the "live" / mutable state of the visible items in the list,
/// which is persistent across diffs of content (instances are only created or destroyed when an item enters or leaves the list).
Expand Down
1 change: 1 addition & 0 deletions ListableUI/Sources/Internal/UIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import UIKit


extension UIView {
Expand Down
Loading