Skip to content

Commit

Permalink
Merge pull request #3 from PanPanayotov/develop
Browse files Browse the repository at this point in the history
Now converting strings to boolean
  • Loading branch information
Panayot Panayotov authored Jul 9, 2019
2 parents d4638ef + 49823cb commit 399582a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions InputValidation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion InputValidation/InputValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: InputValue, X: InputValue>(min: T, max: X) -> Bool {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 9 additions & 3 deletions InputValidationTests/InputValidationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
}

Expand Down

0 comments on commit 399582a

Please sign in to comment.