-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from kedio/fake-emails
Fake.emails
- Loading branch information
Showing
5 changed files
with
88 additions
and
26 deletions.
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
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
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 |
---|---|---|
|
@@ -12,5 +12,3 @@ extension Fake { | |
public static let any: Gen<String> = .one(of: [ restaurant, general ]) | ||
} | ||
} | ||
|
||
|
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,44 @@ | ||
import Foundation | ||
import Genything | ||
|
||
extension Fake { | ||
public enum Emails { | ||
public static let topLevelDomains: Gen<String> = .of([ | ||
"com", | ||
"ca", | ||
"gov", | ||
"tv", | ||
"org" | ||
]) | ||
public static let personalDomains: Gen<String> = .of([ | ||
"gmail", | ||
"yahoo", | ||
"hotmail", | ||
"aol", | ||
"msn" | ||
]) | ||
public static let contacts: Gen<String> = .of([ | ||
"contact", | ||
"info", | ||
"help", | ||
"about", | ||
"general", | ||
"sales", | ||
"emailus" | ||
]) | ||
public static let separator: Gen<String> = .of([".", "_", "-", ""]) | ||
|
||
public static let personal = Gen<String>.zip(Fake.PersonNames.full, separator, personalDomains, topLevelDomains) { name, separator, personalDomain, topLevelDomain in | ||
let transformedName = name.replacingOccurrences(of: " ", with: separator).lowercased() | ||
return "\(transformedName)@\(personalDomain).\(topLevelDomain)" | ||
} | ||
|
||
public static func business(_ name: String? = nil) -> Gen<String> { | ||
let nameGen = name == nil ? Fake.BusinessNames.any : Gen<String>.constant(name!) | ||
return Gen<String>.zip(nameGen, contacts, topLevelDomains) { name, contacts, topLevelDomains in | ||
let transformedName = String(name.filter { $0.isLetter }).lowercased() | ||
return "\(contacts)@\(transformedName).\(topLevelDomains)" | ||
} | ||
} | ||
} | ||
} |
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,18 @@ | ||
import XCTest | ||
@testable import Trickery | ||
|
||
class FakeEmailsTests: XCTestCase { | ||
func test_personalEmails() { | ||
Fake.Emails.personal.forEach { email in | ||
let parts = email.split(separator: "@") | ||
XCTAssertEqual(parts.count, 2) | ||
} | ||
} | ||
|
||
func test_businessEmails() { | ||
Fake.Emails.business().forEach { email in | ||
let parts = email.split(separator: "@") | ||
XCTAssertEqual(parts.count, 2) | ||
} | ||
} | ||
} |