Skip to content

Commit

Permalink
Merge branch 'release/0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoconti83 committed Dec 18, 2015
2 parents 4deabfd + 48c4179 commit fbf7dd6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Sources/ParsingResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,22 @@ public struct ParsingResult {
public func value<Type>(argument: PositionalArgument<Type>) -> Type? {
return self.valueForArgument(argument) as? Type
}

/// Returns the Bool value for the given label.
/// It will assert if the value is not a boolean or not present
public func boolValue(label: String) -> Bool {
return self.labelsToValues[label] as! Bool
}

/// Returns the String value for the given label.
/// It will assert if the value is not a boolean or not present
public func value(label: String) -> String {
return self.labelsToValues[label] as! String
}

/// Returns the Int value for the given label.
/// It will assert if the value is not a boolean or not present
public func intValue(label: String) -> Int {
return self.labelsToValues[label] as! Int
}
}
12 changes: 12 additions & 0 deletions Tests/ParsingResultTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,16 @@ class ParsingResultTests: XCTestCase {
XCTAssertNil(parsed.value(argument1))
XCTAssertNil(parsed.value(argument2))
}

func testThatItReturnsBoolValues() {

// when
let parsed = ParsingResult(labelsToValues: ["yes" : true, "no" : false, "number" : 24, "string" : "FOO"])

// then
XCTAssertTrue(parsed.boolValue("yes"))
XCTAssertFalse(parsed.boolValue("no"))
XCTAssertEqual(parsed.intValue("number"), 24)
XCTAssertEqual(parsed.value("string"), "FOO")
}
}

0 comments on commit fbf7dd6

Please sign in to comment.