diff --git a/InputValidation.xcodeproj/project.pbxproj b/InputValidation.xcodeproj/project.pbxproj index bd00bb6..1f671ba 100644 --- a/InputValidation.xcodeproj/project.pbxproj +++ b/InputValidation.xcodeproj/project.pbxproj @@ -638,7 +638,7 @@ CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = 6T6JS869VN; + DEVELOPMENT_TEAM = 96M889ZPMH; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -662,7 +662,7 @@ CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = 6T6JS869VN; + DEVELOPMENT_TEAM = 96M889ZPMH; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; diff --git a/InputValidation/InputValue.swift b/InputValidation/InputValue.swift index 810b020..3749cf3 100644 --- a/InputValidation/InputValue.swift +++ b/InputValidation/InputValue.swift @@ -99,7 +99,7 @@ extension InputValue { public var toFloat: Float? { return NumberFormatter().number(from: toString)?.floatValue } public var toDouble: Double? { return NumberFormatter().number(from: toString)?.doubleValue } public var toBool: Bool? { return nil } - public var toString: String { return String(describing: self) } + public var toString: String { return description } public var isEmpty: Bool { return toString.replacingOccurrences(of: " ", with: "").count == 0 } public func isBetween(min: T, max: X) -> Bool { @@ -166,6 +166,7 @@ extension InputValue { extension String: InputValue { public var type: ValueType { return .string } + public var toBool: Bool? { return Bool(description.lowercased()) } } extension NSNumber: InputValue { diff --git a/InputValidationTests/InputValidationTests.swift b/InputValidationTests/InputValidationTests.swift index a862af7..c212b8d 100644 --- a/InputValidationTests/InputValidationTests.swift +++ b/InputValidationTests/InputValidationTests.swift @@ -22,6 +22,8 @@ class InputValidationTests: XCTestCase { XCTAssertFalse((1321321 as InputValue).matches(regex: "^[a-zA-Z]+$"), "Expected 1321321.matches(regex: '^[a-zA-Z]+$') to be false") XCTAssertFalse((1321321 as InputValue).matches(regex: "^[a-zA-Z]+$"), "Expected 1321321.matches(regex: '^[a-zA-Z]+$') to be false") XCTAssertFalse(("askSSdjhDask" as InputValue).matches(regex: "^[0-9]+$"), "Expected askSSdjhDask.matches(regex: '^[0-9]+$') to be false") + XCTAssertFalse((true as InputValue).matches(regex: "^[0-9]+$"), "Expected true.matches(regex: '^[0-9]+$') to be false") + XCTAssertFalse((false as InputValue).matches(regex: "^[0-9]+$"), "Expected false.matches(regex: '^[0-9]+$') to be false") } func testNumber() { @@ -44,10 +46,14 @@ class InputValidationTests: XCTestCase { } func testBool() { - XCTAssertNotNil(true.toBool, "Expected true.toBool to be 'true' not nil") - XCTAssertNotNil(false.toBool, "Expected true.toBool to be 'false' not nil") XCTAssertTrue(true.toBool!, "Expected true.toBool to be true") - XCTAssertFalse(false.toBool!, "Expected true.toBool to be false") + XCTAssertFalse(false.toBool!, "Expected false.toBool to be false") + XCTAssertTrue("true".toBool!, "Expected 'true'.toBool to be 'true'") + XCTAssertFalse("false".toBool!, "Expected 'false'.toBool to be false") + XCTAssertTrue("TRUE".toBool!, "Expected 'TRUE'.toBool to be 'true'") + XCTAssertFalse("FALSE".toBool!, "Expected 'FALSE'.toBool to be false") + XCTAssertTrue("True".toBool!, "Expected 'True'.toBool to be 'true'") + XCTAssertFalse("False".toBool!, "Expected 'False'.toBool to be false") makeValueTypeTest(type: .bool) }