<commit_before>//
//  RouterTests.swift
//  THGRouter
//
//  Created by <NAME> on 12/1/15.
//  Copyright © 2015 <EMAIL>h<EMAIL>gr<EMAIL>. All rights reserved.
//

import XCTest
import THGRouter

class RouterTests: XCTestCase {
    
    func testBasicOtherRoute() {
        let router = Router.sharedInstance
        let handlerRanExpectation = expectationWithDescription("route handler should run")
        
        let route = Route("foo", type: .Other) { (variable) in
            handlerRanExpectation.fulfill()
            return nil
        }
        
        router.register(route)
        router.evaluate(["foo"])
        waitForExpectationsWithTimeout(2.0, handler: nil)
    }
    
    func testRegister() {
        let router = Router.sharedInstance
        
        let route = Route("registerTest", type: .Other) { (variable) in
            return nil
        }
        
        let originalCount = router.routes.count
        router.register(route)
        XCTAssertTrue(router.routes.count > originalCount)
    }
    
    func testRoutesByName() {
        let router = Router.sharedInstance
        
        router.register(Route("testRouteName", type: .Other) { (variable) in
            return nil
        })
        
        
        router.register(Route("testRouteName", type: .Other) { (variable) in
            return nil
        })
        
        
        let namedRoutes = router.routesByName("testRouteName")
        let fakeRoutes = router.routesByName("definitelyNotARealRouteNameYo")

        XCTAssertEqual(namedRoutes.count, 2)
        XCTAssertEqual(fakeRoutes.count, 0)
    }
    
    func testRoutesByType() {
        let router = Router()
        
        router.register(Route("testRoutesByType", type: .Other) { (variable) in
            return nil
        })
        
        router.register(Route("testRoutesByType", type: .Other) { (variable) in
            return nil
        })
        
        let namedRoutes = router.routesByType(.Other)
        let fakeRoutes = router.routesByType(.Static)
        
        XCTAssertEqual(namedRoutes.count, 2)
        XCTAssertEqual(fakeRoutes.count, 0)
    }
    
    func testEvaluateURLAgainstSingleRouteComponent() {
        let router = Router()
        let handlerExpectation = expectationWithDescription("route handler should run")
        
        router.register(Route("walmart.com", type: .Other) { variable in
            handlerExpectation.fulfill()
            return nil
        })
        router.evaluateURL(NSURL(string: "scheme://walmart.com/foo/bar")!)
        
        waitForExpectationsWithTimeout(2.0, handler: nil)
    }
    
    // TODO: make this test pass
    func testEvaluateURLAgainstSingleVariableComponent() {
        let router = Router()
        let handlerExpectation = expectationWithDescription("route handler should run")
        
        router.register(Route("walmart.com", type: .Other).variable() { variable in
            XCTAssertNotNil(variable)
            XCTAssertEqual(variable!, "12345")
            
            handlerExpectation.fulfill()
            return nil
        })
        
        
        router.evaluateURL(NSURL(string: "scheme://walmart.com/12345")!)
        
        waitForExpectationsWithTimeout(2.0, handler: nil)
    }
    
    // TODO: make this test pass
    func testEvaluateURLAgainstMultipleRouteComponents() {
        let router = Router()
        let handlerExpectation = expectationWithDescription("route handler should run")
        
        router.register(Route("walmart.com", type: .Other).route("item", type: .Other).variable() { variable in
            XCTAssertNotNil(variable)
            XCTAssertEqual(variable!, "12345")
            handlerExpectation.fulfill()
            return nil
        })
        
        router.evaluateURL(NSURL(string: "scheme://walmart.com/item/12345")!)
        
        waitForExpectationsWithTimeout(2.0, handler: nil)
    }
}<commit_msg>test that `evaluate()` returns expected result based on handling or not handling a URL<commit_after>//
//  RouterTests.swift
//  THGRouter
//
//  Created by <NAME> on 12/1/15.
//  Copyright © 2015 theholygrail.io. All rights reserved.
//

import XCTest
import THGRouter

class RouterTests: XCTestCase {
    
    func testBasicOtherRoute() {
        let router = Router.sharedInstance
        let handlerRanExpectation = expectationWithDescription("route handler should run")
        
        let route = Route("foo", type: .Other) { (variable) in
            handlerRanExpectation.fulfill()
            return nil
        }
        
        router.register(route)
        router.evaluate(["foo"])
        waitForExpectationsWithTimeout(2.0, handler: nil)
    }
    
    func testRegister() {
        let router = Router.sharedInstance
        
        let route = Route("registerTest", type: .Other) { (variable) in
            return nil
        }
        
        let originalCount = router.routes.count
        router.register(route)
        XCTAssertTrue(router.routes.count > originalCount)
    }
    
    func testRoutesByName() {
        let router = Router.sharedInstance
        
        router.register(Route("testRouteName", type: .Other) { (variable) in
            return nil
        })
        
        
        router.register(Route("testRouteName", type: .Other) { (variable) in
            return nil
        })
        
        
        let namedRoutes = router.routesByName("testRouteName")
        let fakeRoutes = router.routesByName("definitelyNotARealRouteNameYo")

        XCTAssertEqual(namedRoutes.count, 2)
        XCTAssertEqual(fakeRoutes.count, 0)
    }
    
    func testRoutesByType() {
        let router = Router()
        
        router.register(Route("testRoutesByType", type: .Other) { (variable) in
            return nil
        })
        
        router.register(Route("testRoutesByType", type: .Other) { (variable) in
            return nil
        })
        
        let namedRoutes = router.routesByType(.Other)
        let fakeRoutes = router.routesByType(.Static)
        
        XCTAssertEqual(namedRoutes.count, 2)
        XCTAssertEqual(fakeRoutes.count, 0)
    }
    
    func testEvaluateURLAgainstSingleRouteComponent() {
        let router = Router()
        let handlerExpectation = expectationWithDescription("route handler should run")
        
        router.register(Route("walmart.com", type: .Other) { variable in
            handlerExpectation.fulfill()
            return nil
        })
        router.evaluateURL(NSURL(string: "scheme://walmart.com/foo/bar")!)
        
        waitForExpectationsWithTimeout(2.0, handler: nil)
    }
    
    // TODO: make this test pass
    func testEvaluateURLAgainstSingleVariableComponent() {
        let router = Router()
        let handlerExpectation = expectationWithDescription("route handler should run")
        
        router.register(Route("walmart.com", type: .Other).variable() { variable in
            XCTAssertNotNil(variable)
            XCTAssertEqual(variable!, "12345")
            
            handlerExpectation.fulfill()
            return nil
        })
        
        
        router.evaluateURL(NSURL(string: "scheme://walmart.com/12345")!)
        
        waitForExpectationsWithTimeout(2.0, handler: nil)
    }
    
    // TODO: make this test pass
    func testEvaluateURLAgainstMultipleRouteComponents() {
        let router = Router()
        let handlerExpectation = expectationWithDescription("route handler should run")
        
        router.register(Route("walmart.com", type: .Other).route("item", type: .Other).variable() { variable in
            XCTAssertNotNil(variable)
            XCTAssertEqual(variable!, "12345")
            handlerExpectation.fulfill()
            return nil
        })
        
        router.evaluateURL(NSURL(string: "scheme://walmart.com/item/12345")!)
        
        waitForExpectationsWithTimeout(2.0, handler: nil)
    }
}

// MARK: - Evaluate Tests

extension Router {
    func test_evaluate_returnsTrueForHandledURL() {
        let router = Router()
        
        router.register(Route("walmart.com", type: .Other) { variable in
            return nil
        })
        
        
        let routeWasHandled = router.evaluate(["walmart.com"])
        XCTAssertTrue(routeWasHandled)
    }
    
    func test_evaluate_returnsFalseForUnhandledURL() {
        let router = Router()
        
        let routeWasHandled = router.evaluate(["walmart.com"])
        XCTAssertFalse(routeWasHandled)
    }
}
{'fraction_non_alphanumeric': 0.09811055040488205, 'fraction_numerical': 0.009623283652153503, 'mean_word_length': 2.0809833694866233, 'pattern_counts': {'":': 0, '<': 8, '<?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': '6322173', 'n_tokens_mistral': 2403, 'n_tokens_neox': 2328, 'n_words': 475}