Skip to content

Commit e7a0189

Browse files
committed
Adds test for tabs
1 parent 38b3aec commit e7a0189

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

MockGeneratorTests/MemberTransformingVisitorTests.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MemberTransformingVisitorTests: XCTestCase {
2424
}
2525

2626
// MARK: - visit
27-
27+
2828
func test_shouldTransformTypeIdentifier() {
2929
assertTypeIs("Type", UseCasesTypeIdentifier.self, "Type")
3030
}
@@ -168,6 +168,13 @@ class MemberTransformingVisitorTests: XCTestCase {
168168
XCTAssertEqual(method.declarationText, "func a(a: A, b c: D, _ e: @escaping F)")
169169
}
170170

171+
func test_visit_shouldRemoveBackticksFromLetAndVar() {
172+
let method = transformMethod("func a(`let`: A, `var`: B)")
173+
assertParameter(method.parametersList[0], internalName: "let", type: "A")
174+
assertParameter(method.parametersList[1], internalName: "var", type: "B")
175+
XCTAssertEqual(method.declarationText, "func a(`let`: A, `var`: B)")
176+
}
177+
171178
func test_visit_shouldTransformThrowingProtocolMethod() {
172179
let method = transformMethod("func a() throws")
173180
XCTAssert(method.throws)

MockGeneratorTests/MockGeneratorTests.swift

+13-9
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@ import AST
88
class MockGeneratorTests: XCTestCase {
99

1010
var trackedLines: Int?
11-
11+
1212
// The test project is copied to the resources directory build phases
1313
let testProject = Bundle(for: MockGeneratorTests.self).resourcePath! + "/TestProject"
1414

15+
override func setUp() {
16+
super.setUp()
17+
formatterFactory = FormatterFactory { DefaultFormatter(useTabs: false, indentationWidth: 4) }
18+
}
19+
1520
func test_generatesSimpleMock() {
1621
assertMockGeneratesExpected("SimpleProtocolMock")
1722
}
1823

24+
func test_generatesSimpleMockWithTabs() {
25+
formatterFactory = FormatterFactory { DefaultFormatter(useTabs: true, indentationWidth: 4) }
26+
assertMockGeneratesExpected("TabSimpleProtocolMock")
27+
}
28+
1929
func test_deletesMockBody() {
2030
assertMockGeneratesExpected("DeleteBodyMock")
2131
}
@@ -179,7 +189,7 @@ class MockGeneratorTests: XCTestCase {
179189
func test_subscriptInClass() {
180190
assertMockGeneratesExpected("ClassSubscriptMock")
181191
}
182-
192+
183193
func test_overriddenSubscripts() {
184194
assertMockGeneratesExpected("AugmentedClassSubscriptMock")
185195
}
@@ -215,8 +225,6 @@ class MockGeneratorTests: XCTestCase {
215225
_ = try Generator(
216226
projectURL: URL(fileURLWithPath: testProject),
217227
templateName: "spy",
218-
useTabsForIndentation: false,
219-
indentationWidth: 4,
220228
trackLines: { self.trackedLines = $0 }
221229
).execute(buffer: buffer)
222230
}
@@ -238,8 +246,6 @@ class MockGeneratorTests: XCTestCase {
238246
_ = try Generator(
239247
projectURL: URL(fileURLWithPath: testProject),
240248
templateName: "spy",
241-
useTabsForIndentation: false,
242-
indentationWidth: 4,
243249
trackLines: { self.trackedLines = $0 }
244250
).execute(buffer: buffer)
245251
} catch {
@@ -276,7 +282,7 @@ class MockGeneratorTests: XCTestCase {
276282
let nsError = error as NSError?
277283
XCTAssertEqual(nsError?.localizedDescription, expectedError, line: line)
278284
}
279-
285+
280286
private func readMock(named fileName: String) -> (String, String) {
281287
let mock = readFile(named: fileName + ".swift")
282288
let expected = readFile(named: fileName + "_expected.swift")
@@ -301,8 +307,6 @@ class MockGeneratorTests: XCTestCase {
301307
let generator = Generator(
302308
projectURL: URL(fileURLWithPath: testProject),
303309
templateName: templateName,
304-
useTabsForIndentation: false,
305-
indentationWidth: 4,
306310
trackLines: { self.trackedLines = $0 }
307311
)
308312
let result = try CommandTestHelper().execute(buffer: buffer, command: generator)
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@testable import TestProject
2+
3+
class TabSimpleProtocolMock: SimpleProtocol {
4+
<selection></selection>
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@testable import TestProject
2+
3+
class TabSimpleProtocolMock: SimpleProtocol {
4+
5+
var invokedSimpleMethod = false
6+
var invokedSimpleMethodCount = 0
7+
8+
func simpleMethod() {
9+
invokedSimpleMethod = true
10+
invokedSimpleMethodCount += 1
11+
}
12+
}

TestProject/TestProject.xcodeproj/project.pbxproj

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
1453D098244241FA00340789 /* TabSimpleProtocolMock_expected.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1453D096244241EE00340789 /* TabSimpleProtocolMock_expected.swift */; };
1011
146F2877217741E800689278 /* FolderSpacesMock_expected.swift in Sources */ = {isa = PBXBuildFile; fileRef = 146F2871217741E000689278 /* FolderSpacesMock_expected.swift */; };
1112
146F2878217741EE00689278 /* UTFMock_expected.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14F6107321524187006EE58B /* UTFMock_expected.swift */; };
1213
1486D8E32250C1800001E250 /* ReadOnlySubscriptProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1486D8E22250C1800001E250 /* ReadOnlySubscriptProtocol.swift */; };
@@ -118,6 +119,8 @@
118119
/* End PBXContainerItemProxy section */
119120

120121
/* Begin PBXFileReference section */
122+
1453D094244241B800340789 /* TabSimpleProtocolMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabSimpleProtocolMock.swift; sourceTree = "<group>"; };
123+
1453D096244241EE00340789 /* TabSimpleProtocolMock_expected.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabSimpleProtocolMock_expected.swift; sourceTree = "<group>"; usesTabs = 1; };
121124
146F2871217741E000689278 /* FolderSpacesMock_expected.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FolderSpacesMock_expected.swift; sourceTree = "<group>"; };
122125
146F2872217741E000689278 /* FolderSpacesMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FolderSpacesMock.swift; sourceTree = "<group>"; };
123126
146F2873217741E100689278 /* FolderSpaces.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FolderSpaces.swift; sourceTree = "<group>"; };
@@ -494,6 +497,8 @@
494497
1A93A103B52E0B9663053DCA /* SimpleProtocol.swift */,
495498
1A93ADEB4F4BA8D8F10D08C6 /* SimpleProtocolMock_expected.swift */,
496499
1A93A3223B77F2C61C26669F /* SimpleProtocolMock.swift */,
500+
1453D094244241B800340789 /* TabSimpleProtocolMock.swift */,
501+
1453D096244241EE00340789 /* TabSimpleProtocolMock_expected.swift */,
497502
1A93AD19E201C6EBC0F0F83F /* ThrowingProtocol.swift */,
498503
1A93A72F5912F59161FD8BA1 /* ThrowingProtocolMock_expected.swift */,
499504
1A93AD1C8E8078F5253DAD98 /* ThrowingProtocolMock.swift */,
@@ -708,6 +713,7 @@
708713
1486D8EC22511F750001E250 /* SubscriptProtocolMock_expected.swift in Sources */,
709714
1A93A7274B374D6566730D84 /* InitialiserProtocolMock_expected.swift in Sources */,
710715
1486D8FD225120D10001E250 /* ClassSubscriptMock_expected.swift in Sources */,
716+
1453D098244241FA00340789 /* TabSimpleProtocolMock_expected.swift in Sources */,
711717
146F2878217741EE00689278 /* UTFMock_expected.swift in Sources */,
712718
1A93A8EF01B9BCBABFA8A1C6 /* KeywordsMock_expected.swift in Sources */,
713719
1486D8F222511FFE0001E250 /* ArgumentsSubscriptProtocolMock_expected.swift in Sources */,

0 commit comments

Comments
 (0)