This repository has been archived by the owner on May 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAllOfTest.swift
60 lines (51 loc) · 2.34 KB
/
AllOfTest.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// AllOfTest.swift
// Honour
//
// Created by Jean Pimentel on 8/5/15.
// Copyright (c) 2015 Honour. All rights reserved.
//
import XCTest
import Honour
class AllOfTest: XCTestCase {
func testValidAllOf() {
XCTAssertTrue(AllOf().validate("JEAN"))
XCTAssertTrue(AllOf(StartsWith("J")).validate("JEAN"))
XCTAssertTrue(AllOf(StartsWith("J"), EndsWith("N")).validate("JEAN"))
XCTAssertTrue(AllOf(StartsWith("J"), EndsWith("N"), Length(min: 3, max: 60)).validate("JEAN"))
XCTAssertTrue(AllOf(StartsWith("J"), AllOf(EndsWith("N"), Length(min: 3, max: 60))).validate("JEAN"))
}
func testInvalidAllOf() {
XCTAssertFalse(AllOf(StartsWith("P")).validate("JEAN"))
XCTAssertFalse(AllOf(StartsWith("P"), EndsWith("N")).validate("JEAN"))
XCTAssertFalse(AllOf(StartsWith("P"), EndsWith("N"), Length(min: 3, max: 60)).validate("JEAN"))
XCTAssertFalse(AllOf(StartsWith("P"), AllOf(EndsWith("N"), Length(min: 6, max: 60))).validate("JEAN"))
}
func testAssertWithInvalidRules() {
let validator = AllOf(Lowercase(), StartsWith("j"))
let result = validator.assert("FOOBAR")
XCTAssertFalse(result.isValid)
XCTAssertTrue(result.invalidRules.count == 2)
XCTAssertTrue(result.invalidRules[0] is Lowercase)
XCTAssertTrue(result.invalidRules[1] is StartsWith)
let validator2 = AllOf(StartsWith("P"), AllOf(EndsWith("M"), Length(min: 6, max: 60)))
let result2 = validator2.assert("JEAN")
XCTAssertFalse(result2.isValid)
XCTAssertTrue(result2.invalidRules.count == 3)
XCTAssertTrue(result2.invalidRules[0] is StartsWith)
XCTAssertTrue(result2.invalidRules[1] is EndsWith)
XCTAssertTrue(result2.invalidRules[2] is Length)
}
func testCheckWithInvalidRule() {
let validator = AllOf(Lowercase(), StartsWith("j"))
let result = validator.check("FOOBAR")
XCTAssertFalse(result.isValid)
XCTAssertTrue(result.invalidRule != nil)
XCTAssertTrue(result.invalidRule! is Lowercase)
let validator2 = AllOf(StartsWith("J"), AllOf(EndsWith("M"), Length(min: 6, max: 60)))
let result2 = validator2.check("JEAN")
XCTAssertFalse(result2.isValid)
XCTAssertTrue(result2.invalidRule != nil)
XCTAssertTrue(result2.invalidRule! is EndsWith)
}
}