<commit_before>
@testable import xcodeproj
import XCTest

class PBXOutputSettingsTsts: XCTestCase {
    var proj: PBXProj!
    var buildFileAssets: PBXBuildFile!
    var buildFileMain: PBXBuildFile!

    var objectBuildFileAssets: (PBXObjectReference, PBXBuildFile)!
    var objectBuildFileMain: (PBXObjectReference, PBXBuildFile)!

    var fileReferenceAssets: PBXFileReference!
    var fileReferenceCoreData: PBXFileReference!

    var objectFileReferenceAssets: (PBXObjectReference, PBXFileReference)!
    var objectFileReferenceCoreData: (PBXObjectReference, PBXFileReference)!

    var groupFrameworks: PBXGroup!
    var groupProducts: PBXGroup!

    var objectGroupFrameworks: (PBXObjectReference, PBXGroup)!
    var objectGroupProducts: (PBXObjectReference, PBXGroup)!

    var navigatorFileGroup: PBXGroup!

    override func setUp() {
        let dic = iosProjectDictionary()
        do {
            proj = try PBXProj(jsonDictionary: dic.1)
        } catch let error {
            XCTFail("Failed to load project from file \(error)")
        }

        proj.buildFiles.forEach { print("\(type(of: $0.file!)) \($0.file!.fileName()!)") }
        buildFileAssets = proj.buildFiles.first { $0.file?.fileName() == "Assets.xcassets" }!
        buildFileMain = proj.buildFiles.first { $0.file?.fileName() == "Main.storyboard" }!

        objectBuildFileAssets = (buildFileAssets.reference, buildFileAssets)
        objectBuildFileMain = (buildFileMain.reference, buildFileMain)

        fileReferenceAssets = proj.fileReferences.first { $0.fileName() == "Assets.xcassets" }!
        fileReferenceCoreData = proj.fileReferences.first { $0.fileName() == "CoreData.framework" }!

        objectFileReferenceAssets = (buildFileAssets.reference, fileReferenceAssets)
        objectFileReferenceCoreData = (buildFileMain.reference, fileReferenceCoreData)

        groupFrameworks = proj.groups.first { $0.fileName() == "Frameworks" }!
        groupProducts = proj.groups.first { $0.fileName() == "Products" }!

        objectGroupFrameworks = (groupFrameworks.reference, groupFrameworks)
        objectGroupProducts = (groupProducts.reference, groupProducts)

        navigatorFileGroup = proj.groups.first { $0.fileName() == "iOS" }!
    }

    // MARK: - PBXFileOrder - PBXBuldFile

    func test_PBXFileOrder_PBXBuildFile_by_uuid() {
        XCTAssertFalse(PBXFileOrder.byUUID.sort(lhs: objectBuildFileAssets, rhs: objectBuildFileMain))
        XCTAssertTrue(PBXFileOrder.byUUID.sort(lhs: objectBuildFileMain, rhs: objectBuildFileAssets))
    }

    func test_PBXFileOrder_PBXBuildFile_by_filename() {
        XCTAssertTrue(PBXFileOrder.byFilename.sort(lhs: objectBuildFileAssets, rhs: objectBuildFileMain))
        XCTAssertFalse(PBXFileOrder.byFilename.sort(lhs: objectBuildFileMain, rhs: objectBuildFileAssets))
    }

    func test_PBXFileOrder_PBXBuildFile_by_filename_when_nil_name_and_path() {
        buildFileAssets.file?.name = nil
        buildFileMain.file?.name = nil
        buildFileAssets.file?.path = nil
        buildFileMain.file?.path = nil
        XCTAssertFalse(PBXFileOrder.byFilename.sort(lhs: objectBuildFileAssets, rhs: objectBuildFileMain))
        XCTAssertTrue(PBXFileOrder.byFilename.sort(lhs: objectBuildFileMain, rhs: objectBuildFileAssets))
    }

    func test_PBXFileOrder_PBXBuildFile_by_filename_when_no_file() {
        let ref1 = buildFileAssets.reference
        let ref2 = buildFileMain.reference
        buildFileAssets.file = nil
        buildFileMain.file = nil
        XCTAssertFalse(PBXFileOrder.byFilename.sort(lhs: (ref1, buildFileAssets), rhs: (ref2, buildFileMain)))
        XCTAssertTrue(PBXFileOrder.byFilename.sort(lhs: (ref2, buildFileMain), rhs: (ref1, buildFileAssets)))
    }

    // MARK: - PBXFileOrder - PBXFileReference

    func test_PBXFileOrder_PBXFileReference_by_uuid() {
        XCTAssertFalse(PBXFileOrder.byUUID.sort(lhs: objectFileReferenceAssets, rhs: objectFileReferenceCoreData))
        XCTAssertTrue(PBXFileOrder.byUUID.sort(lhs: objectFileReferenceCoreData, rhs: objectFileReferenceAssets))
    }

    func test_PBXFileOrder_PBXFileReference_by_filename() {
        XCTAssertTrue(PBXFileOrder.byFilename.sort(lhs: objectFileReferenceAssets, rhs: objectFileReferenceCoreData))
        XCTAssertFalse(PBXFileOrder.byFilename.sort(lhs: objectFileReferenceCoreData, rhs: objectFileReferenceAssets))
    }

    func test_PBXFileOrder_PBXFileReference_by_filename_when_nil_name_and_path() {
        fileReferenceAssets.name = nil
        fileReferenceCoreData.name = nil
        fileReferenceAssets.path = nil
        fileReferenceCoreData.path = nil
        XCTAssertFalse(PBXFileOrder.byFilename.sort(lhs: objectFileReferenceAssets, rhs: objectFileReferenceCoreData))<commit_msg>Add test on correct PBXBuildPhaseFile sorting order<commit_after>
@testable import xcodeproj
import XCTest

class PBXOutputSettingsTsts: XCTestCase {
    var proj: PBXProj!
    var buildFileAssets: PBXBuildFile!
    var buildFileMain: PBXBuildFile!

    var objectBuildFileAssets: (PBXObjectReference, PBXBuildFile)!
    var objectBuildFileMain: (PBXObjectReference, PBXBuildFile)!
    
    var objectBuildPhaseFileAssets: (PBXObjectReference, PBXBuildPhaseFile)!
    var objectBuildPhaseFileMain: (PBXObjectReference, PBXBuildPhaseFile)!

    var fileReferenceAssets: PBXFileReference!
    var fileReferenceCoreData: PBXFileReference!

    var objectFileReferenceAssets: (PBXObjectReference, PBXFileReference)!
    var objectFileReferenceCoreData: (PBXObjectReference, PBXFileReference)!

    var groupFrameworks: PBXGroup!
    var groupProducts: PBXGroup!

    var objectGroupFrameworks: (PBXObjectReference, PBXGroup)!
    var objectGroupProducts: (PBXObjectReference, PBXGroup)!

    var navigatorFileGroup: PBXGroup!

    override func setUp() {
        let dic = iosProjectDictionary()
        do {
            proj = try PBXProj(jsonDictionary: dic.1)
        } catch let error {
            XCTFail("Failed to load project from file \(error)")
        }

        proj.buildFiles.forEach { print("\(type(of: $0.file!)) \($0.file!.fileName()!)") }
        buildFileAssets = proj.buildFiles.first { $0.file?.fileName() == "Assets.xcassets" }!
        buildFileMain = proj.buildFiles.first { $0.file?.fileName() == "Main.storyboard" }!

        objectBuildFileAssets = (buildFileAssets.reference, buildFileAssets)
        objectBuildFileMain = (buildFileMain.reference, buildFileMain)
        
        objectBuildPhaseFileAssets = proj.objects.buildPhaseFile.first { $0.value.buildFile.file?.fileName() == "Assets.xcassets" }!
        objectBuildPhaseFileMain = proj.objects.buildPhaseFile.first { $0.value.buildFile.file?.fileName() == "Main.storyboard" }!

        fileReferenceAssets = proj.fileReferences.first { $0.fileName() == "Assets.xcassets" }!
        fileReferenceCoreData = proj.fileReferences.first { $0.fileName() == "CoreData.framework" }!

        objectFileReferenceAssets = (buildFileAssets.reference, fileReferenceAssets)
        objectFileReferenceCoreData = (buildFileMain.reference, fileReferenceCoreData)

        groupFrameworks = proj.groups.first { $0.fileName() == "Frameworks" }!
        groupProducts = proj.groups.first { $0.fileName() == "Products" }!

        objectGroupFrameworks = (groupFrameworks.reference, groupFrameworks)
        objectGroupProducts = (groupProducts.reference, groupProducts)

        navigatorFileGroup = proj.groups.first { $0.fileName() == "iOS" }!
    }

    // MARK: - PBXFileOrder - PBXBuldFile

    func test_PBXFileOrder_PBXBuildFile_by_uuid() {
        XCTAssertFalse(PBXFileOrder.byUUID.sort(lhs: objectBuildFileAssets, rhs: objectBuildFileMain))
        XCTAssertTrue(PBXFileOrder.byUUID.sort(lhs: objectBuildFileMain, rhs: objectBuildFileAssets))
    }

    func test_PBXFileOrder_PBXBuildFile_by_filename() {
        XCTAssertTrue(PBXFileOrder.byFilename.sort(lhs: objectBuildFileAssets, rhs: objectBuildFileMain))
        XCTAssertFalse(PBXFileOrder.byFilename.sort(lhs: objectBuildFileMain, rhs: objectBuildFileAssets))
    }

    func test_PBXFileOrder_PBXBuildFile_by_filename_when_nil_name_and_path() {
        buildFileAssets.file?.name = nil
        buildFileMain.file?.name = nil
        buildFileAssets.file?.path = nil
        buildFileMain.file?.path = nil
        XCTAssertFalse(PBXFileOrder.byFilename.sort(lhs: objectBuildFileAssets, rhs: objectBuildFileMain))
        XCTAssertTrue(PBXFileOrder.byFilename.sort(lhs: objectBuildFileMain, rhs: objectBuildFileAssets))
    }

    func test_PBXFileOrder_PBXBuildFile_by_filename_when_no_file() {
        let ref1 = buildFileAssets.reference
        let ref2 = buildFileMain.reference
        buildFileAssets.file = nil
        buildFileMain.file = nil
        XCTAssertFalse(PBXFileOrder.byFilename.sort(lhs: (ref1, buildFileAssets), rhs: (ref2, buildFileMain)))
        XCTAssertTrue(PBXFileOrder.byFilename.sort(lhs: (ref2, buildFileMain), rhs: (ref1, buildFileAssets)))
    }
    
    // MARK: - PBXFileOrder - PBXBuildPhaseFile
    
    func test_PBXFileOrder_PBXBuildPhaseFile_by_uuid() {
        XCTAssertFalse(PBXFileOrder.byUUID.sort(lhs: objectBuildPhaseFileAssets, rhs: objectBuildPhaseFileMain))
        XCTAssertTrue(PBXFileOrder.byUUID.sort(lhs: objectBuildPhaseFileMain, rhs: objectBuildPhaseFileAssets))
    }
    
    func test_PBXFileOrder_PBXBuildPhaseFile_by_filename() {
        XCTAssertTrue(PBXFileOrder.byFilename.sort(lhs: objectBuildPhaseFileAssets, rhs: objectBuildPhaseFileMain))
        XCTAssertFalse(PBXFileOrder.byFilename.sort(lhs: objectBuildPhaseFileMain, rhs: objectBuildPhaseFileAssets))
    }

    // MARK: - PBXFileOrder - PBXFileReference

    func test_PBXFileOrder_PBXFileReference_by_uuid() {
        XCTAssertFalse(PBXFileOrder.byUUID.sort(lhs: objectFileReferenceAssets, rhs: objectFileReferenceCoreData))
        XCTAssertTrue(PBXFileOrder.byUUID.sort(lhs: objectFileReferenceCoreData, rhs: objectFileReferenceAssets))
    }

    func test_PBXFileOrder_PBXFileReference_by_filename() {
        XCTAssertTrue(PBXFileOrder.byFilename.sort(lhs: objectFileReferenceAssets, rhs: objectFileReferenceCoreData))
        XCTAssertFalse(PBXFileOrder.byFilename.sort(lhs: objectFileReferenceCoreData, rhs: objectFileReferenceAssets))
    }

    func test_PBXFileOrder_PBXFileReference_by_filename_when_nil_name_and_path() {
        fileReferenceAssets.name = nil
        fileReferenceCoreData.name = nil
        fileReferenceAssets.path = nil
        fileReferenceCoreData.path = nil
        XCTAssertFalse(PBXFileOrder.byFilename.sort(lhs: objectFileReferenceAssets, rhs: objectFileReferenceCoreData))
{'fraction_non_alphanumeric': 0.09140544102419279, 'fraction_numerical': 0.0032006024663466066, 'mean_word_length': 4.25940594059406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6743413', 'n_tokens_mistral': 3373, 'n_tokens_neox': 3220, 'n_words': 504}