Fix ArgumentList with multiple values.

This commit is contained in:
Yaroslav Zhurakovskiy 2016-07-24 17:59:25 +03:00
parent 01012dbd88
commit e4e2fab557
3 changed files with 17 additions and 2 deletions

View File

@ -19,7 +19,7 @@ public struct ArgumentList {
FatalErrorNotifier.currentNotifier.notify("Expected \(T.self) parameter at index \(index) but got nothing: file \(file), line \(line)")
return nil
}
if let value = _args[0] as? T {
if let value = _args[index] as? T {
return value
}
FatalErrorNotifier.currentNotifier.notify("Expected \(T.self) parameter at index \(index) but got \(_args[0].dynamicType): file \(file), line \(line)")

View File

@ -43,6 +43,17 @@ class ArgumentListTests: XCTestCase {
let line = #line - 2
notifier.assertLastMessage("Expected NSDictionary parameter at index 0 but got nothing: file \(file), line \(line)")
}
func testShouldUseMultipleParams() {
let list = ArgumentList(args: ["Hello", 12])
let text: String = list.at(0)
let number: Int = list.at(1)
XCTAssertEqual(text, "Hello")
XCTAssertEqual(number, 12)
notifier.assertNotErrors()
}

View File

@ -44,6 +44,10 @@ class TestFatalErrorNotifier: FatalErrorNotifierProtocol {
lastMessage = message
}
func assertNotErrors(file: StaticString = #file, line: UInt = #line) {
XCTAssertNil(lastMessage, "Should not raise any errors")
}
func assertLastMessage(message: String, file: StaticString = #file, line: UInt = #line) {
XCTAssertEqual(lastMessage!, message, file: file, line: line)
}