Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hishma committed Mar 6, 2021
1 parent d1d1bd0 commit a067deb
Show file tree
Hide file tree
Showing 13 changed files with 446 additions and 387 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Change Log

## 0.1.2

### Improvements

* Add Makfile for easier installation of command line tool.
* Switched to using a swift package based executable.
* Add more tests.

## 0.1.1

Initial release




1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PackageDescription
let package = Package(
name: "lorem",
platforms: [.macOS(.v11)],
products: [.executable(name: "lorem", targets: ["lorem"])],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "0.3.0"),
.package(url: "https://github.com/lukaskubanek/LoremSwiftum.git", from: "2.2.1"),
Expand Down
26 changes: 26 additions & 0 deletions Tests/loremTests/Subcommands/EmailAddressTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import XCTest

class EmailAddressTests: XCTestCase {

func testEmailAddress() throws {
let result = runProcess(args: "email-address")

switch result {
case .success(let output):
XCTAssertFalse(output.isEmpty)

// should have one email address
let emails = output.components(separatedBy: .whitespaces)
XCTAssertEqual(1, emails.count)

emails.forEach { XCTAssertTrue($0.isEmailAddress) }

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

static var allTests = [
("testEmailAddress", testEmailAddress),
]
}
90 changes: 90 additions & 0 deletions Tests/loremTests/Subcommands/NameTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import XCTest

class NameTests: XCTestCase {

func testName() throws {
let result = runProcess(args: "name")

switch result {
case .success(let output):
XCTAssertFalse(output.isEmpty)

let words = output.words()
XCTAssertEqual(1, words.count)

words.forEach {
XCTAssertFalse($0.isEmpty)
XCTAssertTrue($0.isCapitalized)
}

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

func testFirstName() throws {
let result = runProcess(args: "name", "--portion", "first")

switch result {
case .success(let output):
XCTAssertFalse(output.isEmpty)

let words = output.words()
XCTAssertEqual(1, words.count)

words.forEach {
XCTAssertFalse($0.isEmpty)
XCTAssertTrue($0.isCapitalized)
}

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

func testLastName() throws {
let result = runProcess(args: "name", "--portion", "last")

switch result {
case .success(let output):
XCTAssertFalse(output.isEmpty)

let words = output.words()
XCTAssertEqual(1, words.count)

words.forEach {
XCTAssertFalse($0.isEmpty)
XCTAssertTrue($0.isCapitalized)
}

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

func testFullName() throws {
let result = runProcess(args: "name", "--portion", "full")

switch result {
case .success(let output):
XCTAssertFalse(output.isEmpty)

let words = output.words()
XCTAssertEqual(2, words.count)

words.forEach {
XCTAssertFalse($0.isEmpty)
XCTAssertTrue($0.isCapitalized)
}

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

static var allTests = [
("testFirstName", testFirstName),
("testLastName", testLastName),
("testFullName", testFullName),
]
}
45 changes: 45 additions & 0 deletions Tests/loremTests/Subcommands/ParagraphTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import XCTest

class ParagraphTests: XCTestCase {

func testParagraph() throws {
let result = runProcess(args: "paragraph")

switch result {
case .success(let output):
let paragraphs = output.paragraphs()
XCTAssertEqual(1, paragraphs.count)

paragraphs.forEach {
XCTAssertFalse($0.isEmpty)
XCTAssertTrue($0.sentences().count > 1)
}

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

func testParagraphCount() throws {
let result = runProcess(args: "paragraph", "--count", "3")

switch result {
case .success(let output):
let paragraphs = output.paragraphs()
XCTAssertEqual(3, paragraphs.count)

paragraphs.forEach {
XCTAssertFalse($0.isEmpty)
XCTAssertTrue($0.sentences().count > 1)
}

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

static var allTests = [
("testParagraph", testParagraph),
("testParagraphCount", testParagraphCount),
]
}
45 changes: 45 additions & 0 deletions Tests/loremTests/Subcommands/SentenceTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import XCTest

class SentenceTests: XCTestCase {

func testSentence() throws {
let result = runProcess(args: "sentence")

switch result {
case .success(let output):
let sentences = output.sentences()
XCTAssertEqual(1, sentences.count)

sentences.forEach {
XCTAssertFalse($0.isEmpty)
XCTAssertTrue($0.words().count > 1)
}

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

func testSentenceCount() throws {
let result = runProcess(args: "sentence", "--count", "3")

switch result {
case .success(let output):
let sentences = output.sentences()
XCTAssertEqual(3, sentences.count)

sentences.forEach {
XCTAssertFalse($0.isEmpty)
XCTAssertTrue($0.words().count > 1)
}

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

static var allTests = [
("testSentence", testSentence),
("testSentenceCount", testSentenceCount),
]
}
28 changes: 28 additions & 0 deletions Tests/loremTests/Subcommands/TitleTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import XCTest

class TitleTests: XCTestCase {

func testTitle() throws {
let result = runProcess(args: "title")

switch result {
case .success(let output):
XCTAssertFalse(output.isEmpty)

let words = output.words()
XCTAssertTrue(words.count > 1)

words.forEach {
XCTAssertFalse($0.isEmpty)
XCTAssertTrue($0.isCapitalized)
}

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

static var allTests = [
("testTitle", testTitle),
]
}
58 changes: 58 additions & 0 deletions Tests/loremTests/Subcommands/TweetTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import XCTest

class TweetTests: XCTestCase {

func testTweet() throws {
let result = runProcess(args: "tweet")

switch result {
case .success(let output):
XCTAssertFalse(output.isEmpty)
XCTAssertLessThan(output.count, 140)

let words = output.words()
XCTAssertTrue(words.count >= 1)

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

func testShortTweet() throws {
let result = runProcess(args: "tweet", "--length", "short")

switch result {
case .success(let output):
XCTAssertFalse(output.isEmpty)
XCTAssertLessThan(output.count, 140)

let words = output.words()
XCTAssertTrue(words.count >= 1)

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

func testLongTweet() throws {
let result = runProcess(args: "tweet", "--length", "long")

switch result {
case .success(let output):
XCTAssertFalse(output.isEmpty)
XCTAssertLessThan(output.count, 280)

let words = output.words()
XCTAssertTrue(words.count >= 1)

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

static var allTests = [
("testTweet", testTweet),
("testShortTweet", testShortTweet),
("testLongTweet", testLongTweet),
]
}
25 changes: 25 additions & 0 deletions Tests/loremTests/Subcommands/UrlTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import XCTest

class UrlTests: XCTestCase {

func testUrl() throws {
let result = runProcess(args: "url")

switch result {
case .success(let output):
XCTAssertFalse(output.isEmpty)

let urls = output.components(separatedBy: .whitespaces)
XCTAssertEqual(1, urls.count)

urls.forEach { XCTAssertTrue($0.isWebUrl) }

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

static var allTests = [
("testUrl", testUrl),
]
}
41 changes: 41 additions & 0 deletions Tests/loremTests/Subcommands/WordTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import XCTest

class WordTests: XCTestCase {

func testWord() throws {
let result = runProcess(args: "word")

switch result {
case .success(let output):
XCTAssertFalse(output.isEmpty)

let words = output.words()
XCTAssertEqual(1, words.count)

words.forEach { XCTAssertFalse($0.isEmpty) }

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

func testWordCount() throws {
let result = runProcess(args: "word", "--count", "3")

switch result {
case .success(let output):
let words = output.words()
XCTAssertEqual(3, words.count)

words.forEach { XCTAssertFalse($0.isEmpty) }

case .failure(let error):
XCTFail(error.localizedDescription)
}
}

static var allTests = [
("testWord", testWord),
("testWordCount", testWordCount),
]
}
Loading

0 comments on commit a067deb

Please sign in to comment.