<commit_before>import Foundation
import XCTest
import PathKit
import xcodeproj

final class XCWorkspaceDataSpec: XCTestCase {

    var subject: XCWorkspace.Data!
    var fileRef: XCWorkspace.Data.FileRef!
    
    override func setUp() {
        super.setUp()
        fileRef = "path"
        subject = XCWorkspace.Data(path: Path("test"), references: [])
    }
    
    
    func test_equal_returnsTheCorrectValue() {
        let another = XCWorkspace.Data(path: Path("test"), references: [])
        XCTAssertEqual(subject, another)
    }
    
    func test_addingReference_returnsANewWorkspaceDatawithTheReferenceAdded() {
        let got = subject.adding(reference: "path2")
        XCTAssertTrue(got.references.contains("path2"))
    }
    
    func test_removingReference_returnsANewWorkspaceDataWithTheReferenceRemoved() {
        let got = subject.removing(reference: "path")
        XCTAssertFalse(got.references.contains("path"))
    }
    
    // MARK: - Integration
    
    func test_integration_init_returnsTheModelWithTheRightProperties() {
        let path = fixturePath()
        let got = try? XCWorkspace.Data(path: path)
        XCTAssertEqual(got?.path, path)
        XCTAssertNotNil(got?.references.first?.project)
    }
    
    func test_integration_init_throwsIfThePathIsWrong() {
        do {
            _ = try XCWorkspace.Data(path: Path("test"))
            XCTAssertTrue(false, "Expected to throw an error but it didn't")
        } catch {}
    }
    
    func test_integration_write() {
        testWrite(from: fixturePath(),
                  initModel: { try? XCWorkspace.Data(path: $0) },
                  modify: { return $0.adding(reference: .file(path: "shakira")) }) { (data) in
                    XCTAssertTrue(data.references.filter{ $0.description.contains("shakira")}.count == 1)
        }
    }
    
    // MARK: - Private
    
    private func fixturePath() -> Path {
        let fixtures = Path(#file).parent().parent().parent() + Path("Fixtures")
        let path = fixtures + Path("iOS/Project.xcodeproj/project.xcworkspace/contents.xcworkspacedata")
        return path
    }
}<commit_msg>Extract integration tests from XCWorkspaceDataSpec<commit_after>import Foundation
import XCTest
import PathKit
import xcodeproj

final class XCWorkspaceDataSpec: XCTestCase {

    var subject: XCWorkspace.Data!
    var fileRef: XCWorkspace.Data.FileRef!
    
    override func setUp() {
        super.setUp()
        fileRef = "path"
        subject = XCWorkspace.Data(path: Path("test"), references: [])
    }
    
    
    func test_equal_returnsTheCorrectValue() {
        let another = XCWorkspace.Data(path: Path("test"), references: [])
        XCTAssertEqual(subject, another)
    }
    
    func test_addingReference_returnsANewWorkspaceDatawithTheReferenceAdded() {
        let got = subject.adding(reference: "path2")
        XCTAssertTrue(got.references.contains("path2"))
    }
    
    func test_removingReference_returnsANewWorkspaceDataWithTheReferenceRemoved() {
        let got = subject.removing(reference: "path")
        XCTAssertFalse(got.references.contains("path"))
    }
    
}

final class XCWorkspaceDataIntegrationSpec: XCTestCase {
    
    func test_init_returnsTheModelWithTheRightProperties() {
        let path = fixturePath()
        let got = try? XCWorkspace.Data(path: path)
        XCTAssertEqual(got?.path, path)
        XCTAssertNotNil(got?.references.first?.project)
    }
    
    func test_init_throwsIfThePathIsWrong() {
        do {
            _ = try XCWorkspace.Data(path: Path("test"))
            XCTAssertTrue(false, "Expected to throw an error but it didn't")
        } catch {}
    }
    
    func test_write() {
        testWrite(from: fixturePath(),
                  initModel: { try? XCWorkspace.Data(path: $0) },
                  modify: { return $0.adding(reference: .file(path: "shakira")) }) { (data) in
                    XCTAssertTrue(data.references.filter{ $0.description.contains("shakira")}.count == 1)
        }
    }
    
    // MARK: - Private
    
    private func fixturePath() -> Path {
        let fixtures = Path(#file).parent().parent().parent() + Path("Fixtures")
        let path = fixtures + Path("iOS/Project.xcodeproj/project.xcworkspace/contents.xcworkspacedata")
        return path
    }
    
}
{'fraction_non_alphanumeric': 0.11090530215327622, 'fraction_numerical': 0.0027784209307710117, 'mean_word_length': 2.6923076923076925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4930622', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1292, 'n_words': 238}