-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resize command: support absolute values
- Loading branch information
1 parent
e8e0f2c
commit d9bac2d
Showing
7 changed files
with
107 additions
and
31 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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
extension Result { | ||
func getOrNil(appendErrorTo errors: inout [Failure]) -> Success? { | ||
switch self { | ||
case .success(let success): | ||
return success | ||
case .failure(let error): | ||
errors += [error] | ||
return nil | ||
} | ||
} | ||
|
||
func getOrNils() -> (Success?, Failure?) { | ||
switch self { | ||
case .success(let success): | ||
return (success, nil) | ||
case .failure(let failure): | ||
return (nil, failure) | ||
} | ||
} | ||
} |
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,38 @@ | ||
import XCTest | ||
@testable import AeroSpace_Debug | ||
|
||
final class ResizeCommandTest: XCTestCase { | ||
override func setUpWithError() throws { setUpWorkspacesForTests() } | ||
|
||
func testParseCommand() { | ||
testParseCommandSucc("resize smart +10", .resizeCommand(dimension: .smart, mode: .add, unit: 10)) | ||
testParseCommandSucc("resize smart -10", .resizeCommand(dimension: .smart, mode: .subtract, unit: 10)) | ||
testParseCommandSucc("resize smart 10", .resizeCommand(dimension: .smart, mode: .set, unit: 10)) | ||
|
||
testParseCommandSucc("resize height 10", .resizeCommand(dimension: .height, mode: .set, unit: 10)) | ||
testParseCommandSucc("resize width 10", .resizeCommand(dimension: .width, mode: .set, unit: 10)) | ||
|
||
testParseCommandFail("resize s 10", msg: "Can't parse 'resize' first arg") | ||
testParseCommandFail("resize smart foo", msg: "'resize' command: Second arg must be a number") | ||
} | ||
} | ||
|
||
private func testParseCommandSucc(_ command: String, _ expected: CommandDescription) { | ||
let parsed = parseSingleCommand(command) | ||
switch parsed { | ||
case .success(let command): | ||
XCTAssertEqual(command.describe, expected) | ||
case .failure(let msg): | ||
XCTFail(msg) | ||
} | ||
} | ||
|
||
private func testParseCommandFail(_ command: String, msg expected: String) { | ||
let parsed = parseSingleCommand(command) | ||
switch parsed { | ||
case .success(let command): | ||
XCTFail("\(command) isn't supposed to be parcelable") | ||
case .failure(let msg): | ||
XCTAssertEqual(msg, expected) | ||
} | ||
} |
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