Skip to content

Commit

Permalink
Added mocks to primitive types like String, Int..
Browse files Browse the repository at this point in the history
  • Loading branch information
skychiarottoa committed Nov 17, 2020
1 parent 455d21c commit 6ea0036
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Sources/SkyTestFoundation/Mocks.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

// Primitive Mock
enum RealDataDictionary {
public enum RealDataDictionary {
case int
case uint
case url
Expand All @@ -19,7 +19,7 @@ enum RealDataDictionary {
case landlinePhone
}

extension String {
public extension String {
static func mock(_ type: RealDataDictionary = .uuid) -> String {
switch type {
case .city: return ["Torino", "Milano", "Ivrea"].randomElement()!
Expand All @@ -45,25 +45,25 @@ extension String {
}
}

extension Int {
public extension Int {
static func mock() -> Int {
return Int.random(in: 0...100)
}
}

extension Bool {
public extension Bool {
static func mock() -> Bool {
return Bool.random()
}
}

extension URL {
public extension URL {
static func mock(string: String = String.mock(.url)) -> URL {
return URL(string: string)!
}
}

extension Date {
public extension Date {
static func mock(_ date: Date = Date()) -> Date {
let calendar = Calendar(identifier: .gregorian)
return calendar.date(from: calendar.dateComponents([.year, .month, .day, .hour, .minute], from: date))!
Expand Down

0 comments on commit 6ea0036

Please sign in to comment.