Skip to content

Commit

Permalink
Merge pull request #12 from dtop/feature/RC9
Browse files Browse the repository at this point in the history
Feature/rc9
  • Loading branch information
Danilo Topalovic committed Mar 15, 2016
2 parents 7109b27 + 674b4ad commit c5b1bc0
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 6 deletions.
42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Version History

### Version 0.0.9

- fixed bugs within the generic iterators (thanks @jpaas)
- added related tests

### Version 0.0.7 / 0.0.8

- fixed bugs in ValidatorEmail (thanks @jpaas)
- added more tests to ValidatorEmail

### Version 0.0.6

- unified some validators
- added some tests for previously fixed bugs

### Version 0.0.5

- renamed the project
- fixed travis-ci
- enhanced code coverage to 98%

### Version 0.0.4

- bugfixes in ValidationIterator
- bugfixes in other validators

### Version 0.0.3

- added the ValidationIterator for mass validation
- added travis-ci

### Version 0.0.2

- added ValidatorRequired
- changed the behavior of nil value validation

### Version 0.0.1

- initial prerelease

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ class MyValidator: BaseValidator, ValidatorProtocol {
Generic:

```swift
class MyGenericValidator<TYPE where TYPE: Equatable>: ValidatorProtocol {
class MyGenericValidator<TYPE where TYPE: Equatable>: ValidatorProtocol, ValidationAwareProtocol {

required public init(@noescape _ initializer: MyGenericValidator -> () = { _ in }) {
initializer(self)
Expand Down
2 changes: 1 addition & 1 deletion SwiftValidate.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SwiftValidate"
s.version = "0.0.8"
s.version = "0.0.9"
s.summary = "A highly customizable validation library for swift"
s.homepage = "http://github.com/dtop/SwiftValidate"
s.license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion validate/Validators/ValidatorBetween.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public class ValidatorBetween<TYPE: SignedNumberType>: ValidatorProtocol {
public class ValidatorBetween<TYPE: SignedNumberType>: ValidatorProtocol, ValidationAwareProtocol {

/// allows the value to be nil
public var allowNil: Bool = true
Expand Down
2 changes: 1 addition & 1 deletion validate/Validators/ValidatorGreaterThan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public class ValidatorGreaterThan<TYPE: SignedNumberType>: ValidatorProtocol {
public class ValidatorGreaterThan<TYPE: SignedNumberType>: ValidatorProtocol, ValidationAwareProtocol {

/// nil is allowed
public var allowNil: Bool = true
Expand Down
2 changes: 1 addition & 1 deletion validate/Validators/ValidatorInArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public class ValidatorInArray<TYPE where TYPE: Equatable>: ValidatorProtocol {
public class ValidatorInArray<TYPE where TYPE: Equatable>: ValidatorProtocol, ValidationAwareProtocol {

/// nil value is allowed and true
public var allowNil: Bool = true
Expand Down
2 changes: 1 addition & 1 deletion validate/Validators/ValidatorSmallerThan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public class ValidatorSmallerThan<TYPE: SignedNumberType>: ValidatorProtocol {
public class ValidatorSmallerThan<TYPE: SignedNumberType>: ValidatorProtocol, ValidationAwareProtocol {

/// nil is allowed
public var allowNil: Bool = true
Expand Down
21 changes: 21 additions & 0 deletions validateTests/ValidatorChainTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,25 @@ class ValidatorChainTests: XCTestCase {
XCTAssertTrue(chain.errors.contains("Exception Thrown"))
}

func testEverythingCanBeAppliedToChain() {

let chain = ValidatorChain()

chain <~~ ValidatorInArray<Int>()
chain <~~ ValidatorRequired()
chain <~~ ValidatorDateTime()
chain <~~ ValidatorDateBetween()
chain <~~ ValidatorCallback()
chain <~~ ValidatorNumeric()
chain <~~ ValidatorNumeric()
chain <~~ ValidatorBetween<Int>()
chain <~~ ValidatorGreaterThan<Int>()
chain <~~ ValidatorSmallerThan<Int>()
chain <~~ ValidatorEmpty()
chain <~~ ValidatorStrLen()
chain <~~ ValidatorAlnum()
chain <~~ ValidatorEmail()
chain <~~ ValidatorRegex()
chain <~~ ValidatorCharset()
}
}
20 changes: 20 additions & 0 deletions validateTests/ValidatorSmallerThanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ class ValidatorSmallerThanTests: XCTestCase {
}
}

func testValidatorCanHandleNegatives() {

let validator = ValidatorSmallerThan<Double>() {
$0.max = -10.0
}

var result = false

do {

result = try validator.validate(-9.9, context: nil)
XCTAssertFalse(result)

result = try validator.validate(-11.1, context: nil)
XCTAssertTrue(result)
} catch _ {
XCTAssert(false)
}
}

func testValidatorRespectsInclusive() {

let validator = ValidatorSmallerThan<Int>() {
Expand Down

0 comments on commit c5b1bc0

Please sign in to comment.