-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
289 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "swift-custom-dump", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/swift-custom-dump.git", | ||
"state" : { | ||
"revision" : "c9b6b940d95c0a925c63f6858943415714d8a981", | ||
"version" : "0.5.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-snapshot-testing", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/swift-snapshot-testing.git", | ||
"state" : { | ||
"revision" : "f29e2014f6230cf7d5138fc899da51c7f513d467", | ||
"version" : "1.10.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "xctest-dynamic-overlay", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", | ||
"state" : { | ||
"revision" : "30314f1ece684dd60679d598a9b89107557b67d9", | ||
"version" : "0.4.1" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// swift-tools-version: 5.6 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "swift-snapshot-testing-dump", | ||
platforms: [ | ||
.iOS(.v13), | ||
.macOS(.v10_15), | ||
.tvOS(.v13) | ||
], | ||
products: [ | ||
// Products define the executables and libraries a package produces, and make them visible to other packages. | ||
.library( | ||
name: "SnapshotTestingDump", | ||
targets: ["SnapshotTestingDump"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing.git", from: "1.10.0"), | ||
.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "0.5.2"), | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
.target( | ||
name: "SnapshotTestingDump", | ||
dependencies: [ | ||
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"), | ||
.product(name: "CustomDump", package: "swift-custom-dump"), | ||
]), | ||
.testTarget( | ||
name: "SnapshotTestingDumpTests", | ||
dependencies: ["SnapshotTestingDump"], | ||
exclude: ["__Snapshots__"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# swift-snapshot-testing-dump | ||
A plugin to use swift-custom-dump with swift-snapshot-testing | ||
|
||
A plugin for `swift-snapshot-testing` that combines it with `swift-custom-dump` to be able to produce textual snapshots of model objects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import SnapshotTesting | ||
import CustomDump | ||
|
||
extension Snapshotting where Format == String { | ||
/// A snapshot strategy for comparing any structure based on a sanitized text dump. | ||
public static var customDump: Snapshotting { | ||
.customDump() | ||
} | ||
|
||
public static func customDump(name: String? = nil, | ||
indent: Int = 0, | ||
maxDepth: Int = .max) -> Snapshotting { | ||
SimplySnapshotting.lines.pullback { | ||
var output = "" | ||
CustomDump.customDump($0, to: &output, name: name, indent: indent, maxDepth: maxDepth) | ||
return output | ||
} | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
Tests/SnapshotTestingDumpTests/SnapshotTestingDumpTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import XCTest | ||
import SnapshotTesting | ||
import CustomDump | ||
@testable import SnapshotTestingDump | ||
|
||
final class SnapshotTestingDumpTests: XCTestCase { | ||
func testStruct() throws { | ||
struct User { | ||
let name = "John" | ||
let email = "john@me.com" | ||
let age = 97 | ||
} | ||
|
||
assertSnapshot(matching: User(), as: .customDump) | ||
} | ||
|
||
func testClass() throws { | ||
class User { | ||
let name = "John" | ||
let email = "john@me.com" | ||
let age = 97 | ||
} | ||
|
||
assertSnapshot(matching: User(), as: .customDump) | ||
} | ||
|
||
func testClassWithSuperclass() throws { | ||
class User { | ||
let name = "John" | ||
let email = "john@me.com" | ||
let age = 97 | ||
} | ||
|
||
class Doctor: User { | ||
let field = "Podiatry" | ||
let level = "Expert" | ||
} | ||
|
||
customDump(Doctor()) | ||
assertSnapshot(matching: Doctor(), as: .customDump) | ||
} | ||
|
||
func testNSObjectClass() throws { | ||
class User: NSObject { | ||
let name = "John" | ||
let email = "john@me.com" | ||
let age = 97 | ||
} | ||
|
||
customDump(User()) | ||
assertSnapshot(matching: User(), as: .customDump) | ||
} | ||
|
||
func testComplexStructure() throws { | ||
struct User { | ||
let name = "John" | ||
let email = "john@me.com" | ||
let age = 97 | ||
let friends = [ | ||
"James", | ||
"Lilly", | ||
"Peter", | ||
"Remus", | ||
] | ||
} | ||
|
||
assertSnapshot(matching: User(), as: .customDump) | ||
} | ||
|
||
func testRecursion() throws { | ||
class Human { | ||
let name: String | ||
|
||
init(name: String) { | ||
self.name = name | ||
} | ||
} | ||
|
||
class Child: Human { | ||
weak var parent: Parent? | ||
} | ||
|
||
class Parent: Human { | ||
let children: [Human] | ||
|
||
init(name: String, children: [Child]) { | ||
self.children = children | ||
super.init(name: name) | ||
|
||
children.forEach { | ||
$0.parent = self | ||
} | ||
} | ||
} | ||
|
||
let subject = Parent(name: "Arthur", children: [ | ||
Child(name: "Virginia"), | ||
Child(name: "Ronald"), | ||
Child(name: "Fred"), | ||
Child(name: "George"), | ||
Child(name: "Percy"), | ||
Child(name: "Charles"), | ||
]) | ||
|
||
assertSnapshot(matching: subject, as: .customDump) | ||
} | ||
|
||
func testLevelsOfInheritance() throws { | ||
class Human { | ||
let name: String | ||
|
||
init(name: String) { | ||
self.name = name | ||
} | ||
} | ||
|
||
class Driver: Human { | ||
let wheels: Int | ||
|
||
init(name: String, wheels: Int) { | ||
self.wheels = wheels | ||
super.init(name: name) | ||
} | ||
} | ||
|
||
class TruckDriver: Driver { | ||
let truckType: String | ||
|
||
init(name: String, wheels: Int, truckType: String) { | ||
self.truckType = truckType | ||
super.init(name: name, wheels: wheels) | ||
} | ||
} | ||
|
||
assertSnapshot(matching: TruckDriver(name: "Jimmy", wheels: 6, truckType: "Loader"), as: .customDump) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Tests/SnapshotTestingDumpTests/__Snapshots__/SnapshotTestingDumpTests/testClass.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SnapshotTestingDumpTests.User( | ||
name: "John", | ||
email: "john@me.com", | ||
age: 97 | ||
) |
4 changes: 4 additions & 0 deletions
4
...shotTestingDumpTests/__Snapshots__/SnapshotTestingDumpTests/testClassWithSuperclass.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
SnapshotTestingDumpTests.Doctor( | ||
field: "Podiatry", | ||
level: "Expert" | ||
) |
11 changes: 11 additions & 0 deletions
11
...napshotTestingDumpTests/__Snapshots__/SnapshotTestingDumpTests/testComplexStructure.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
SnapshotTestingDumpTests.User( | ||
name: "John", | ||
email: "john@me.com", | ||
age: 97, | ||
friends: [ | ||
[0]: "James", | ||
[1]: "Lilly", | ||
[2]: "Peter", | ||
[3]: "Remus" | ||
] | ||
) |
1 change: 1 addition & 0 deletions
1
...shotTestingDumpTests/__Snapshots__/SnapshotTestingDumpTests/testLevelsOfInheritance.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SnapshotTestingDumpTests.TruckDriver(truckType: "Loader") |
5 changes: 5 additions & 0 deletions
5
...s/SnapshotTestingDumpTests/__Snapshots__/SnapshotTestingDumpTests/testNSObjectClass.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SnapshotTestingDumpTests.User( | ||
name: "John", | ||
email: "john@me.com", | ||
age: 97 | ||
) |
22 changes: 22 additions & 0 deletions
22
Tests/SnapshotTestingDumpTests/__Snapshots__/SnapshotTestingDumpTests/testRecursion.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
SnapshotTestingDumpTests.Parent( | ||
children: [ | ||
[0]: SnapshotTestingDumpTests.Child( | ||
parent: SnapshotTestingDumpTests.Parent(↩︎) | ||
), | ||
[1]: SnapshotTestingDumpTests.Child( | ||
parent: SnapshotTestingDumpTests.Parent(↩︎) | ||
), | ||
[2]: SnapshotTestingDumpTests.Child( | ||
parent: SnapshotTestingDumpTests.Parent(↩︎) | ||
), | ||
[3]: SnapshotTestingDumpTests.Child( | ||
parent: SnapshotTestingDumpTests.Parent(↩︎) | ||
), | ||
[4]: SnapshotTestingDumpTests.Child( | ||
parent: SnapshotTestingDumpTests.Parent(↩︎) | ||
), | ||
[5]: SnapshotTestingDumpTests.Child( | ||
parent: SnapshotTestingDumpTests.Parent(↩︎) | ||
) | ||
] | ||
) |
5 changes: 5 additions & 0 deletions
5
Tests/SnapshotTestingDumpTests/__Snapshots__/SnapshotTestingDumpTests/testStruct.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SnapshotTestingDumpTests.User( | ||
name: "John", | ||
email: "john@me.com", | ||
age: 97 | ||
) |