Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 12 additions & 1 deletion Source/CuckooGeneratorFramework/FileHeaderHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct FileHeaderHandler {
// Add new line before code imports
imports = [""] + imports
}
return ["import Cuckoo"] + testableFrameworks.map { "@testable import \($0)" } + imports
return ["import Cuckoo"] + getTestableImports(testableFrameworks) + imports
}

private static func getRelativePath(absolutePath: String) -> String {
Expand Down Expand Up @@ -81,4 +81,15 @@ public struct FileHeaderHandler {
return ""
}
}

private static func getTestableImports(testableFrameworks: [String]) -> [String] {
func replaceIllegalCharacters(char: UnicodeScalar) -> Character {
if NSCharacterSet.letterCharacterSet().longCharacterIsMember(char.value) || NSCharacterSet.decimalDigitCharacterSet().longCharacterIsMember(char.value) {
return Character(char)
} else {
return "_"
}
}
return testableFrameworks.map { String($0.unicodeScalars.map(replaceIllegalCharacters)) }.map { "@testable import \($0)" }
}
}
3 changes: 3 additions & 0 deletions Tests/SourceFiles/Expected/TestableFrameworks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import Cuckoo
@testable import Cuckoo
@testable import A_b
@testable import A_c
@testable import A_d

import Foundation

Expand Down
2 changes: 1 addition & 1 deletion Tests/features/generate_command.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Generate command
When I run `runcuckoo generate --no-timestamp ../SourceFiles/TestedClass.swift ../SourceFiles/TestedProtocol.swift`
Then the file "../SourceFiles/Expected/GeneratedMocks.swift" should be equal to file "GeneratedMocks.swift"
Scenario: with testableFrameworks
When I run `runcuckoo generate --no-timestamp --testable Cuckoo --output Actual.swift ../SourceFiles/TestedEmptyClass.swift`
When I run `runcuckoo generate --no-timestamp --testable "Cuckoo,A b,A-c,A.d" --output Actual.swift ../SourceFiles/TestedEmptyClass.swift`
Then the file "../SourceFiles/Expected/TestableFrameworks.swift" should be equal to file "Actual.swift"
Scenario: non existing input file
When I run `runcuckoo generate non_existing_file.swift`
Expand Down