<commit_before>//
//  Rule.swift
//  Reactant
//
//  Created by <NAME> on 26/10/2017.
//  Copyright © 2017 Brightify. All rights reserved.
//

import Quick
import Nimble
import Reactant
import Result

class RuleTest: QuickSpec {
    override func spec() {
        describe("Rule Validation Tests") {
            let permissiveRule = Rule<String?, ValidationError> { _ in nil }
            let restrictiveRule = Rule<String?, ValidationError> { _ in .invalid }
            describe("anything should pass permissive rule") {
                expect(permissiveRule.test("value")).to(beTruthy())
                expect(permissiveRule.test("")).to(beTruthy())
                expect(permissiveRule.test(nil)).to(beTruthy())

                if case .success = permissiveRule.run("value") {
                } else {
                    fail()
                }
                if case .success = permissiveRule.run(nil) {
                } else {
                    fail()
                }
            }
            describe("nothing should pass restrictive rule") {
                expect(restrictiveRule.test("value")).to(beFalsy())
                expect(restrictiveRule.test("")).to(beFalsy())
                expect(restrictiveRule.test(nil)).to(beFalsy())

                if case .success = restrictiveRule.run("value") {
                } else {
                    fail()
                }
                if case .success = restrictiveRule.run(nil) {
                } else {
                    fail()
                }
            }
        }
    }
}<commit_msg>Add more tests for Rule validation. Fix previous tests.<commit_after>//
//  Rule.swift
//  Reactant
//
//  Created by <NAME> on 26/10/2017.
//  Copyright © 2017 Brightify. All rights reserved.
//

import Quick
import Nimble
import Reactant
import Result

class RuleTest: QuickSpec {
    override func spec() {
        describe("Rule Validation Tests") {
            let permissiveRule = Rule<String?, ValidationError> { _ in nil }
            let restrictiveRule = Rule<String?, ValidationError> { _ in .invalid }
            let divBy2StringLengthRule = Rule<String, ValidationError> { string in
                return string.count % 2 == 0 ? nil : .invalid
            }
            describe("anything should pass permissive rule") {
                expect(permissiveRule.test("value")).to(beTruthy())
                expect(permissiveRule.test("")).to(beTruthy())
                expect(permissiveRule.test(nil)).to(beTruthy())

                if case .failure = permissiveRule.run("value") {
                    fail()
                }
                if case .failure = permissiveRule.run(nil) {
                    fail()
                }
            }
            describe("nothing should pass restrictive rule") {
                expect(restrictiveRule.test("value")).to(beFalsy())
                expect(restrictiveRule.test("")).to(beFalsy())
                expect(restrictiveRule.test(nil)).to(beFalsy())

                if case .success = restrictiveRule.run("value") {
                    fail()
                }
                if case .success = restrictiveRule.run(nil) {
                    fail()
                }
            }
            describe("strings appropriate should pass \"div by 2 string length rule\" and others should not") {
                expect(divBy2StringLengthRule.test("")).to(beTruthy())
                expect(divBy2StringLengthRule.test("nilu")).to(beTruthy())
                expect(divBy2StringLengthRule.test("value")).to(beFalsy())
                expect(divBy2StringLengthRule.test("valueueueueueueue")).to(beFalsy())

                if case .failure = divBy2StringLengthRule.run("") {
                    fail()
                }
                if case .failure = divBy2StringLengthRule.run("valu") {
                    fail()
                }
                if case .success = divBy2StringLengthRule.run("value") {
                    fail()
                }
                if case .success = divBy2StringLengthRule.run("valueueueueueueue") {
                    fail()
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.11392100192678227, 'fraction_numerical': 0.008670520231213872, 'mean_word_length': 1.5276932440657334, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6171299', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1053, 'n_words': 222}