<commit_before>//
//  EventTests.swift
//  Vapor
//
//  Created by <NAME> on 4/6/16.
//
//

import XCTest
@testable import Vapor

class Name: ValidationSuite {
    static func validate(input value: String) throws {
        let evaluation = OnlyAlphanumeric.self
            + Count.min(5)
            + Count.max(20)

        try evaluation.validate(input: value)
    }
}


class ValidationTests: XCTestCase {
    static var allTests: [(String, ValidationTests -> () throws -> Void)] {
        return [
            ("testName", testName),
            ("testPassword", testPassword),
            ("testNot", testNot),
            ("testComposition", testComposition),
            ("testAlternateSyntax", testAlternateSyntax)
        ]
    }

    func testName() throws {
        let validName = try "fancyUser".validated(by: Name.self)
        XCTAssert(validName.value == "fancyUser")

        let failed: Valid<Name>? = try? "a*cd".validated()
        XCTAssert(failed == nil)
    }

    func testPassword() throws {
        let no = try? "no".validated(by: !OnlyAlphanumeric.self + Count.min(5))
        XCTAssert(no == nil)

        let yes = try? "yes*/pass".validated(by: !OnlyAlphanumeric.self + Count.min(5))
        XCTAssert(yes != nil)
    }

    func testNot() throws {
        let a = try? "a".validated(by: !OnlyAlphanumeric.self)
        XCTAssertNil(a)
    }

    func testComposition() throws {
        let contrived = Count.max(9)
            || Count.min(11)
            + Name.self
            + OnlyAlphanumeric.self

        let pass = try "contrive".validated(by: contrived)
        XCTAssert(pass.value == "contrive")
    }

    func testAlternateSyntax() throws {
        let _ = try Valid<Name>("Vapor")
    }
}<commit_msg>add detailed failure test<commit_after>//
//  EventTests.swift
//  Vapor
//
//  Created by <NAME> on 4/6/16.
//
//

import XCTest
@testable import Vapor

class Name: ValidationSuite {
    static func validate(input value: String) throws {
        let evaluation = OnlyAlphanumeric.self
            + Count.min(5)
            + Count.max(20)

        try evaluation.validate(input: value)
    }
}


class ValidationTests: XCTestCase {
    static var allTests: [(String, ValidationTests -> () throws -> Void)] {
        return [
            ("testName", testName),
            ("testPassword", testPassword),
            ("testNot", testNot),
            ("testComposition", testComposition),
            ("testAlternateSyntax", testAlternateSyntax)
        ]
    }

    func testName() throws {
        let validName = try "fancyUser".validated(by: Name.self)
        XCTAssert(validName.value == "fancyUser")

        let failed: Valid<Name>? = try? "a*cd".validated()
        XCTAssert(failed == nil)
    }

    func testPassword() throws {
        let no = try? "no".validated(by: !OnlyAlphanumeric.self + Count.min(5))
        XCTAssert(no == nil)

        let yes = try? "yes*/pass".validated(by: !OnlyAlphanumeric.self + Count.min(5))
        XCTAssert(yes != nil)
    }

    func testNot() throws {
        let a = try? "a".validated(by: !OnlyAlphanumeric.self)
        XCTAssertNil(a)
    }

    func testComposition() throws {
        let contrived = Count.max(9)
            || Count.min(11)
            + Name.self
            + OnlyAlphanumeric.self

        let pass = try "contrive".validated(by: contrived)
        XCTAssert(pass.value == "contrive")
    }

    func testAlternateSyntax() throws {
        let _ = try Valid<Name>("Vapor")
    }

    func testDetailedFailure() throws {
        let fail = Count<Int>.min(10)
        let pass = Count<Int>.max(30)
        let combo = pass + fail
        do {
            let _ = try 2.tested(by: combo)
            XCTFail("should throw error")
        } catch let e as ValidationError<Count<Int>> {
            XCTAssertNotNil(e.validator)
            XCTAssertNotNil(e.input == 2)
        }
    }
}
{'fraction_non_alphanumeric': 0.12813299232736572, 'fraction_numerical': 0.0076726342710997444, 'mean_word_length': 2.1288, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '1343456', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1200, 'n_words': 268}