Skip to content

Commit a66faf6

Browse files
authored
Add More AnySnapshotStringConvertible Conformances (#115)
* Add More AnySnapshotStringConvertible Conformances * Clean * Fix
1 parent ca1a008 commit a66faf6

10 files changed

+24
-10
lines changed

Sources/SnapshotTesting/Snapshotting/Any.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ extension AnySnapshotStringConvertible {
6969
}
7070
}
7171

72+
extension Character: AnySnapshotStringConvertible {
73+
public var snapshotDescription: String {
74+
return self.debugDescription
75+
}
76+
}
77+
7278
extension Data: AnySnapshotStringConvertible {
7379
public var snapshotDescription: String {
7480
return self.debugDescription
@@ -99,6 +105,12 @@ extension String: AnySnapshotStringConvertible {
99105
}
100106
}
101107

108+
extension Substring: AnySnapshotStringConvertible {
109+
public var snapshotDescription: String {
110+
return self.debugDescription
111+
}
112+
}
113+
102114
extension URL: AnySnapshotStringConvertible {
103115
public var snapshotDescription: String {
104116
return self.debugDescription

Tests/SnapshotTestingTests/SnapshotTestingTests.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ class SnapshotTestingTests: TestCase {
2626
struct User { let id: Int, name: String, bio: String }
2727
let user = User(id: 1, name: "Blobby", bio: "Blobbed around the world.")
2828
assertSnapshot(matching: user, as: .dump)
29-
assertSnapshot(matching: Data("Hello, world!".utf8), as: .dump)
30-
assertSnapshot(matching: URL(string: "https://www.pointfree.co")!, as: .dump)
3129
}
3230

33-
func testDate() {
34-
assertSnapshot(matching: Date(timeIntervalSinceReferenceDate: 0), as: .dump)
31+
func testAnySnapshotStringConvertible() {
32+
assertSnapshot(matching: "a" as Character, as: .dump, named: "character")
33+
assertSnapshot(matching: Data("Hello, world!".utf8), as: .dump, named: "data")
34+
assertSnapshot(matching: Date(timeIntervalSinceReferenceDate: 0), as: .dump, named: "date")
35+
assertSnapshot(matching: NSObject(), as: .dump, named: "nsobject")
36+
assertSnapshot(matching: "Hello, world!", as: .dump, named: "string")
37+
assertSnapshot(matching: "Hello, world!".dropLast(8), as: .dump, named: "substring")
38+
assertSnapshot(matching: URL(string: "https://www.pointfree.co")!, as: .dump, named: "url")
3539
}
3640

3741
func testDeterministicDictionaryAndSetSnapshots() {
@@ -89,10 +93,6 @@ class SnapshotTestingTests: TestCase {
8993
assertSnapshot(matching: user, as: .dump, named: "named")
9094
}
9195

92-
func testNSObject() {
93-
assertSnapshot(matching: NSObject(), as: .dump)
94-
}
95-
9696
func testNSView() {
9797
#if os(macOS)
9898
let button = NSButton()
@@ -472,13 +472,12 @@ extension SnapshotTestingTests {
472472
static var allTests : [(String, (SnapshotTestingTests) -> () throws -> Void)] {
473473
return [
474474
("testAny", testAny),
475-
("testDate", testDate),
475+
("testAnySnapshotStringConvertible", testAnySnapshotStringConvertible),
476476
("testDeterministicDictionaryAndSetSnapshots", testDeterministicDictionaryAndSetSnapshots),
477477
("testEncodable", testEncodable),
478478
("testMixedViews", testMixedViews),
479479
("testMultipleSnapshots", testMultipleSnapshots),
480480
("testNamedAssertion", testNamedAssertion),
481-
("testNSObject", testNSObject),
482481
("testPrecision", testPrecision),
483482
("testSCNView", testSCNView),
484483
("testSKView", testSKView),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- "a"

Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testAny.2.txt renamed to Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testAnySnapshotStringConvertible.data.txt

File renamed without changes.

Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testDate.1.txt renamed to Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testAnySnapshotStringConvertible.date.txt

File renamed without changes.

Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testNSObject.1.txt renamed to Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testAnySnapshotStringConvertible.nsobject.txt

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- "Hello, world!"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- "Hello"

Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testAny.3.txt renamed to Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testAnySnapshotStringConvertible.url.txt

File renamed without changes.
-41 Bytes
Loading

0 commit comments

Comments
 (0)