Skip to content

Commit

Permalink
Merge pull request #15 from kedio/fake-emails
Browse files Browse the repository at this point in the history
Fake.emails
  • Loading branch information
nicorichard authored Nov 17, 2021
2 parents 5684141 + bffb377 commit 570d02e
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 26 deletions.
6 changes: 4 additions & 2 deletions Example/GenythingExample/Pages/BusinessListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ struct BusinessListView: View {
Fake.Addresses.usLastLine
])

let name = Fake.BusinessNames.any.generate(context: ctx)

return BusinessCard(
name: Fake.BusinessNames.any.generate(context: ctx),
email: "business@email.com",
name: name,
email: Fake.Emails.business(name).generate(context: ctx),
symbolName: "circle.fill",
addressLine1: Fake.Addresses.streetLine.generate(context: ctx),
addressLine2: addressLine2Gen.generate(context: ctx)
Expand Down
44 changes: 22 additions & 22 deletions Sources/Genything/gen/combine/Gen+zip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public extension Gen {

// - MARK: zip2

extension Gen {
public extension Gen {
/// Returns: A generator by zipping together the values produced by the supplied generators
///
/// - Parameters:
/// - gen1: First generator
/// - gen2: Second generator
///
/// - Returns: A generator of Tuples
public static func zip<T1, T2>(
static func zip<T1, T2>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>
) -> Gen<(T1, T2)> where T == (T1, T2) {
Expand All @@ -55,7 +55,7 @@ extension Gen {
/// - transform: A function capable of transforming the values produced by the resulting zipped generator
///
/// - Returns: A generator of values
public static func zip<T1, T2>(
static func zip<T1, T2>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
transform: @escaping (T1, T2) -> T
Expand All @@ -66,7 +66,7 @@ extension Gen {

// - MARK: zip3

extension Gen {
public extension Gen {
/// Returns: A generator by zipping together the values produced by the supplied generators
///
/// - Parameters:
Expand All @@ -75,7 +75,7 @@ extension Gen {
/// - gen3: Third generator
///
/// - Returns: A generator of values
public static func zip<T1, T2, T3>(
static func zip<T1, T2, T3>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
_ gen3: Gen<T3>
Expand All @@ -98,7 +98,7 @@ extension Gen {
/// - transform: A function capable of transforming the values produced by the resulting zipped generator
///
/// - Returns: A generator of values
public static func zip<T1, T2, T3>(
static func zip<T1, T2, T3>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
_ gen3: Gen<T3>,
Expand All @@ -110,7 +110,7 @@ extension Gen {

// - MARK: zip4

extension Gen {
public extension Gen {

/// Returns: A generator by zipping together the values produced by the supplied generators
///
Expand Down Expand Up @@ -215,7 +215,7 @@ public extension Gen {

// - MARK: zip6

extension Gen {
public extension Gen {
/// Returns: A generator by zipping together the values produced by the supplied generators
///
/// - Note: This is a very complex zip operation. Perhaps you should consider using `Gen.compose` instead!
Expand All @@ -229,7 +229,7 @@ extension Gen {
/// - gen6: Sixth generator
///
/// - Returns: A generator of values
public static func zip<T1, T2, T3, T4, T5, T6>(
static func zip<T1, T2, T3, T4, T5, T6>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
_ gen3: Gen<T3>,
Expand Down Expand Up @@ -263,7 +263,7 @@ extension Gen {
/// - transform: A function capable of transforming the values produced by the resulting zipped generator
///
/// - Returns: A generator of values
public static func zip<T1, T2, T3, T4, T5, T6>(
static func zip<T1, T2, T3, T4, T5, T6>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
_ gen3: Gen<T3>,
Expand All @@ -280,7 +280,7 @@ extension Gen {

// - MARK: zip7

extension Gen {
public extension Gen {
/// Returns: A generator by zipping together the values produced by the supplied generators
///
/// - Note: This is a very complex zip operation. Perhaps you should consider using `Gen.compose` instead!
Expand All @@ -295,7 +295,7 @@ extension Gen {
/// - gen7: Seventh generator
///
/// - Returns: A generator of values
public static func zip<T1, T2, T3, T4, T5, T6, T7>(
static func zip<T1, T2, T3, T4, T5, T6, T7>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
_ gen3: Gen<T3>,
Expand Down Expand Up @@ -332,7 +332,7 @@ extension Gen {
/// - transform: A function capable of transforming the values produced by the resulting zipped generator
///
/// - Returns: A generator of values
public static func zip<T1, T2, T3, T4, T5, T6, T7>(
static func zip<T1, T2, T3, T4, T5, T6, T7>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
_ gen3: Gen<T3>,
Expand All @@ -350,7 +350,7 @@ extension Gen {

// - MARK: zip8

extension Gen {
public extension Gen {
/// Returns: A generator by zipping together the values produced by the supplied generators
///
/// - Note: This is a very complex zip operation. Perhaps you should consider using `Gen.compose` instead!
Expand All @@ -366,7 +366,7 @@ extension Gen {
/// - gen8: Eighth generator
///
/// - Returns: A generator of values
public static func zip<T1, T2, T3, T4, T5, T6, T7, T8>(
static func zip<T1, T2, T3, T4, T5, T6, T7, T8>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
_ gen3: Gen<T3>,
Expand Down Expand Up @@ -406,7 +406,7 @@ extension Gen {
/// - transform: A function capable of transforming the values produced by the resulting zipped generator
///
/// - Returns: A generator of values
public static func zip<T1, T2, T3, T4, T5, T6, T7, T8>(
static func zip<T1, T2, T3, T4, T5, T6, T7, T8>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
_ gen3: Gen<T3>,
Expand All @@ -425,7 +425,7 @@ extension Gen {

// - MARK: zip9

extension Gen {
public extension Gen {
/// Returns: A generator by zipping together the values produced by the supplied generators
///
/// - Note: This is a very complex zip operation. Perhaps you should consider using `Gen.compose` instead!
Expand All @@ -442,7 +442,7 @@ extension Gen {
/// - gen9: Ninth generator
///
/// - Returns: A generator of values
public static func zip<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
static func zip<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
_ gen3: Gen<T3>,
Expand Down Expand Up @@ -485,7 +485,7 @@ extension Gen {
/// - transform: A function capable of transforming the values produced by the resulting zipped generator
///
/// - Returns: A generator of values
public static func zip<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
static func zip<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
_ gen3: Gen<T3>,
Expand All @@ -505,7 +505,7 @@ extension Gen {

// - MARK: zip10

extension Gen {
public extension Gen {
/// Returns: A generator by zipping together the values produced by the supplied generators
///
/// - Note: This is a very complex zip operation. Perhaps you should consider using `Gen.compose` instead!
Expand All @@ -523,7 +523,7 @@ extension Gen {
/// - gen10: Tenth generator
///
/// - Returns: A generator of values
public static func zip<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
static func zip<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
_ gen3: Gen<T3>,
Expand Down Expand Up @@ -569,7 +569,7 @@ extension Gen {
/// - transform: A function capable of transforming the values produced by the resulting zipped generator
///
/// - Returns: A generator of values
public static func zip<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
static func zip<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
_ gen1: Gen<T1>,
_ gen2: Gen<T2>,
_ gen3: Gen<T3>,
Expand Down
2 changes: 0 additions & 2 deletions Sources/Trickery/Fake+BusinessNames.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ extension Fake {
public static let any: Gen<String> = .one(of: [ restaurant, general ])
}
}


44 changes: 44 additions & 0 deletions Sources/Trickery/Fake+Emails.swift
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)"
}
}
}
}
18 changes: 18 additions & 0 deletions Tests/TrickeryTests/FakeEmailsTests.swift
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)
}
}
}

0 comments on commit 570d02e

Please sign in to comment.