<commit_before>//
//  FutureDebugTests.swift
//  BrightFutures
//
//  Created by Oleksii on 23/09/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import XCTest
import Result
@testable import BrightFutures

class TestLogger: LoggerType {
    var lastLoggedMessage: String?
    
    func log(message: String) {
        lastLoggedMessage = message
    }
}

class FutureDebugTests: XCTestCase {
    let testIdentifier = "testFutureIdentifier"
    let error = NSError(domain: "test", code: 0, userInfo: nil)
    let file = #file
    let line: UInt = #line
    let function = #function
    
    func testStringLastPathComponent() {
        XCTAssertEqual("/tmp/scratch.tiff".lastPathComponent, "scratch.tiff")
        XCTAssertEqual("/tmp/scratch".lastPathComponent, "scratch")
        XCTAssertEqual("/tmp/".lastPathComponent, "tmp")
        XCTAssertEqual("scratch///".lastPathComponent, "scratch")
        XCTAssertEqual("/".lastPathComponent, "/")
    }
    
    func testDebugFutureSuccess() {
        let logger = TestLogger()
        let f = Future<Void, NoError>(value: ()).debug(logger: logger, file: file, line: line, function: function)
        let expectedMessage = "\(file.lastPathComponent) at line \(line), func: \(function) - future succeeded"
        let debugExpectation = self.expectation(description: "debugLogged")
        
        f.onSuccess {
            XCTAssertEqual(logger.lastLoggedMessage, expectedMessage)
            debugExpectation.fulfill()
        }
        
        self.waitForExpectations(timeout: 2, handler: nil)
    }
    
    func testDebugFutureFailure() {
        let logger = TestLogger()
        let f = Future<Void, NSError>(error: error).debug(logger: logger, file: file, line: line, function: function)
        let debugExpectation = self.expectation(description: "debugLogged")
        let expectedMessage = "\(file.lastPathComponent) at line \(line), func: \(function) - future failed"
        
        f.onFailure { _ in
            XCTAssertEqual(logger.lastLoggedMessage, expectedMessage)
            debugExpectation.fulfill()
        }
        
        self.waitForExpectations(timeout: 2, handler: nil)
    }
    
    func testDebugFutureSuccessWithIdentifier() {
        let logger = TestLogger()
        <commit_msg>Remove tests on String's lastPathComponent<commit_after>//
//  FutureDebugTests.swift
//  BrightFutures
//
//  Created by Oleksii on 23/09/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import XCTest
import Result
import BrightFutures

class TestLogger: LoggerType {
    var lastLoggedMessage: String?
    
    func log(message: String) {
        lastLoggedMessage = message
    }
}

class FutureDebugTests: XCTestCase {
    let testIdentifier = "testFutureIdentifier"
    let error = NSError(domain: "test", code: 0, userInfo: nil)
    let file = #file
    let fileName = (#file as NSString).lastPathComponent
    let line: UInt = #line
    let function = #function
    
    func testDebugFutureSuccess() {
        let logger = TestLogger()
        let f = Future<Void, NoError>(value: ()).debug(logger: logger, file: file, line: line, function: function)
        let expectedMessage = "\(fileName) at line \(line), func: \(function) - future succeeded"
        let debugExpectation = self.expectation(description: "debugLogged")
        
        f.onSuccess {
            XCTAssertEqual(logger.lastLoggedMessage, expectedMessage)
            debugExpectation.fulfill()
        }
        
        self.waitForExpectations(timeout: 2, handler: nil)
    }
    
    func testDebugFutureFailure() {
        let logger = TestLogger()
        let f = Future<Void, NSError>(error: error).debug(logger: logger, file: file, line: line, function: function)
        let debugExpectation = self.expectation(description: "debugLogged")
        let expectedMessage = "\(fileName) at line \(line), func: \(function) - future failed"
        
        f.onFailure { _ in
            XCTAssertEqual(logger.lastLoggedMessage, expectedMessage)
            debugExpectation.fulfill()
        }
        
        self.waitForExpectations(timeout: 2, handler: nil)
    }
    
    func testDebugFutureSuccessWithIdentifier() {
        let logger = TestLogger()
        
{'fraction_non_alphanumeric': 0.10566037735849057, 'fraction_numerical': 0.007075471698113208, 'mean_word_length': 2.726713532513181, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3507285', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1197, 'n_words': 301}