<commit_before>//
//  CodeManagerTests.swift
//  Dials-Desktop
//
//  Created by <NAME> on 3/22/15.
//
//

import Cocoa
import XCTest
import Dials

extension Optional {
    func toResult(failureString : String) -> Result<Wrapped> {
        if let v = self {
            return Success(v)
        }
        else {
            return Failure(failureString)
        }
    }
}

class CodeManagerTests: XCTestCase {
    
    func sampleFileURLWithName(name : String) -> Result<NSURL> {
        let url = NSURL(fileURLWithPath: name)
        let path = NSBundle(forClass: CodeManagerTests.classForCoder()).URLForResource(url.URLByDeletingPathExtension?.lastPathComponent, withExtension: url.pathExtension, subdirectory: "Sample Files")
        XCTAssertNotNil(path)
        return path.toResult("Could not find file: \(name)")
    }

    func testFindSymbolBasic() {
        let path = sampleFileURLWithName("find-name.m")
        path.bind {
            return CodeManager().findSymbolWithName("Description", inFileAtURL: $0)
        }.ifSuccess {(s : String) in
            XCTAssertEqual(s, "SomeBoolean")
        }.ifFailure {
            XCTFail($0)
        }
    }
    
    func testFindSymbolArgumentsObjC() {
        let path = sampleFileURLWithName("find-name.m")
        path.bind {
            CodeManager().findSymbolWithName("Other Content", inFileAtURL: $0)
            }.ifSuccess {
                XCTAssertEqual($0, "SomeFloat")
            }.ifFailure {
                XCTFail($0)
        }
    }
    
    func testFindSymbolArgumentsSwiftBase() {
        let symbol = CodeManager().findSymbolWithName("Test", inString: "DLSControl(\"Test\").colorOf(&foo)", ofLanguage: .Swift)
        XCTAssertEqual(symbol.value ?? "", "foo", symbol.error ?? "Unknown Error")
    }
    
    func testFindSymbolArgumentsSwiftSpaceDots() {
        let symbol = CodeManager().findSymbolWithName("Test", inString: "DLSControl(\"Test\") . colorOf(&foo)", ofLanguage: .Swift)
        XCTAssertEqual(symbol.value ?? "", "foo", symbol.error ?? "Unknown Error")
    }
    
    
    func testReplace() {
        let path = sampleFileURLWithName("find-name.m")
        path.bind {
            CodeManager().findSymbolWithName("Other Content", inFileAtURL: $0)
            }.ifSuccess {
                XCTAssertEqual($0, "SomeFloat")
            }.ifFailure {
                XCTFail($0)
        }
    }
}<commit_msg>Fix tests for Swift2 style error passing<commit_after>//
//  CodeManagerTests.swift
//  Dials-Desktop
//
//  Created by <NAME> on 3/22/15.
//
//

import Cocoa
import XCTest
import Dials

extension Optional {
    func toResult(failureString : String) -> Result<Wrapped> {
        if let v = self {
            return Success(v)
        }
        else {
            return Failure(failureString)
        }
    }
}

class CodeManagerTests: XCTestCase {
    
    func sampleFileURLWithName(name : String) -> NSURL! {
        let url = NSURL(fileURLWithPath: name)
        let path = NSBundle(forClass: CodeManagerTests.classForCoder()).URLForResource(url.URLByDeletingPathExtension?.lastPathComponent, withExtension: url.pathExtension, subdirectory: "Sample Files")
        XCTAssertNotNil(path)
        return path
    }

    func testFindSymbolBasic() {
        let url = sampleFileURLWithName("find-name.m")
        do {
            let symbol = try CodeManager().findSymbolWithName("Description", inFileAtURL: url)
            XCTAssertEqual(symbol, "SomeBoolean")
        }
        catch let e as NSError {
            XCTFail(e.localizedDescription)
        }
    }
    
    func testFindSymbolArgumentsObjC() {
        let url = sampleFileURLWithName("find-name.m")
        do {
            let symbol = try CodeManager().findSymbolWithName("Other Content", inFileAtURL: url)
            XCTAssertEqual(symbol, "SomeFloat")
        }
        catch let e as NSError {
            XCTFail(e.localizedDescription)
        }
    }
    
    func testFindSymbolArgumentsSwiftBase() {
        do {
            let symbol = try CodeManager().findSymbolWithName("Test", inString: "DLSControl(\"Test\").colorOf(&foo)", ofLanguage: .Swift)
            XCTAssertEqual(symbol, "foo")
        }
        catch let e as NSError {
            XCTFail(e.localizedDescription)
        }
    }
    
    func testFindSymbolArgumentsSwiftSpaceDots() {
        do {
            let symbol = try CodeManager().findSymbolWithName("Test", inString: "DLSControl(\"Test\") . colorOf(&foo)", ofLanguage: .Swift)
            XCTAssertEqual(symbol, "foo")
        }
        catch let e as NSError {
            XCTFail(e.localizedDescription)
        }
    }
    
    
    func testReplace() {
        let url = sampleFileURLWithName("find-name.m")
        do {
            let symbol = try CodeManager().findSymbolWithName("Other Content", inFileAtURL: url)
            XCTAssertEqual(symbol, "SomeFloat")
        }
        catch let e as NSError {
            XCTFail(e.localizedDescription)
        }
    }
}
{'fraction_non_alphanumeric': 0.1126930018046922, 'fraction_numerical': 0.0038099057549629035, 'mean_word_length': 2.2347600518806745, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, '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': '5882606', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1443, 'n_words': 292}