Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
eonist committed Jan 22, 2025
1 parent 622559a commit d8d273e
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Sources/MockGen/MockGen+Getter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,9 @@ extension MockGen {
}
return String(first)
}
// fixme: add doc
public static var randomAddress: String {
return AddressGenerator.randomAddress()
}
}
#endif
Empty file.
2 changes: 1 addition & 1 deletion Sources/MockGen/assets/WordsList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public final class WordList {
* - Note: The list of words is based on the BIP-0039 standard and is used for generating word-based passwords.
* - Remark: The text file is located at `Config.Bundle.assets/english.txt`.
* - Fixme: ⚠️️ Consider storing the list of words in a plist instead of a text file.
* - Fixme: ⚠️️ Refactor this class to throw an error if the resource path cannot be obtained or if the data cannot be read or parsed.
* - Fixme: ⚠️⚠️️ Refactor this class to throw an error if the resource path cannot be obtained or if the data cannot be read or parsed.
*/
public final class WordList {
/**
Expand Down
28 changes: 28 additions & 0 deletions Tests/MockGenTests/UnitTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import XCTest
@testable import MockGen

final class MockGenTests: XCTestCase {
// tests for edge cases like zero length passwords.
func testGeneratePasswordWithZeroLength() {
let password = CodeGen.generatePassword(length: 0)
XCTAssertTrue(password.isEmpty, "Password should be empty when length is zero.")
}
/**
* Tests the `randomAddress` property of `MockGen`
* - Description: Verifies that the `randomAddress` returns a non-empty string. Optionally, you can check if it matches a specific address format using a regular expression.
*/
func testRandomAddress() {
// Act
let address = MockGen.randomAddress

// Assert
XCTAssertFalse(address.isEmpty, "The randomAddress should not be empty")

// Optionally, verify the address format using a regular expression
let addressPattern = "^[0-9]+\\s+[A-Za-z]+\\s+[A-Za-z]+,\\s+[A-Za-z\\s]+,\\s+[A-Za-z]{2}\\s+[0-9]{5}$"
let regex = try! NSRegularExpression(pattern: addressPattern)
let range = NSRange(location: 0, length: address.utf16.count)
let match = regex.firstMatch(in: address, options: [], range: range)
XCTAssertNotNil(match, "The randomAddress does not match the expected format")
}
}
46 changes: 46 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,49 @@ Enhance Unit Tests: The current testing suite could be expanded to cover more sc
- Dependency Management: Review and possibly update the dependencies to ensure they are up-to-date and secure. This includes checking the pinned versions in
- User Documentation
Enhance README Documentation: The README.md file could be expanded to include more detailed examples, a clearer explanation of the project's capabilities, and a more comprehensive guide for new users and contributors.
- Add New Mock Data Generators:
Address Generation: Implement functions to generate random street addresses, including street names, numbers, cities, states/provinces, and postal codes.
- Phone Numbers: Generate random phone numbers formatted according to different country standards.
- Payment Information: Add support for generating mock payment data like bank account numbers, IBANs, or Bitcoin wallet addresses.
- User Profiles: Create composite data structures that represent user profiles, combining names, emails, addresses, and other personal information.
- Company Data: Generate random company names, business types, and related data.

- enhance the error handling in your WordList class:


```
public final class WordList {
public static func loadWords() throws -> [String] {
guard let resourcePath = Bundle.module.resourcePath else {
throw WordListError.resourcePathNotFound
}
let filePath = resourcePath + "/" + "words.json"
guard let data = FileParser.data(filePath: filePath) else {
throw WordListError.fileNotFound(filePath)
}
do {
let items: [String] = try data.decode()
return items.sorted()
} catch {
throw WordListError.decodingFailed(error)
}
}
}
public enum WordListError: Error, LocalizedError {
case resourcePathNotFound
case fileNotFound(String)
case decodingFailed(Error)
public var errorDescription: String? {
switch self {
case .resourcePathNotFound:
return "Resource path could not be found."
case .fileNotFound(let path):
return "File not found at path: \(path)"
case .decodingFailed(let error):
return "Failed to decode words.json: \(error.localizedDescription)"
}
}
}
```

0 comments on commit d8d273e

Please sign in to comment.