<commit_before>//
//  GenerateMocksCommand.swift
//  CuckooGenerator
//
//  Created by <NAME> on 12/01/16.
//  Copyright © 2016 Brightify. All rights reserved.
//

import Commandant
import Result
import SourceKittenFramework
import FileKit
import CuckooGeneratorFramework

private func curry<P1, P2, P3, P4, P5, P6, P7, P8, P9, R>(_ f: @escaping (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R)
    -> (P1) -> (P2) -> (P3) -> (P4) -> (P5) -> (P6) -> (P7) -> (P8) -> (P9) -> R {
        return { p1 in { p2 in { p3 in { p4 in { p5 in { p6 in { p7 in { p8 in { p9 in f(p1, p2, p3, p4, p5, p6, p7, p8, p9) } } } } } } } } }
}

public struct GenerateMocksCommand: CommandProtocol {
    
    public let verb = "generate"
    public let function = "Generates mock files"
    
    public func run(_ options: Options) -> Result<Void, CuckooGeneratorError> {
        let inputPathValues = Array(Set(options.files.map { Path($0).standardRawValue }))
        let inputFiles = inputPathValues.map { File(path: $0) }
        let tokens = inputFiles.flatMap { $0 }.map { Tokenizer(sourceFile: $0).tokenize() }
        let tokensWithInheritance = options.noInheritance ? tokens : mergeInheritance(tokens)
        let tokensWithoutClasses = options.noClassMocking ? removeClasses(tokensWithInheritance) : tokensWithInheritance
        // filter excluded classes/protocols
        let parsedFiles = removeClassesAndProtocols(from: tokensWithoutClasses, in: options.exclude)

        let headers = parsedFiles.map { options.noHeader ? "" : FileHeaderHandler.getHeader(of: $0, includeTimestamp: !options.noTimestamp) }
        let imports = parsedFiles.map { FileHeaderHandler.getImports(of: $0, testableFrameworks: options.testableFrameworks) }
        let mocks = parsedFiles.map { Generator(file: $0).generate() }
        
        let mergedFiles = zip(zip(headers, imports), mocks).map { $0.0 + $0.1 + $1 }
        let outputPath = Path(options.output)

        do {
            if outputPath.isDirectory {
                let inputPaths = inputPathValues.map { Path($0) }<commit_msg>Fix nondeterministic handling of input files<commit_after>//
//  GenerateMocksCommand.swift
//  CuckooGenerator
//
//  Created by <NAME> on 12/01/16.
//  Copyright © 2016 Brightify. All rights reserved.
//

import Commandant
import Result
import SourceKittenFramework
import FileKit
import CuckooGeneratorFramework

private func curry<P1, P2, P3, P4, P5, P6, P7, P8, P9, R>(_ f: @escaping (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R)
    -> (P1) -> (P2) -> (P3) -> (P4) -> (P5) -> (P6) -> (P7) -> (P8) -> (P9) -> R {
        return { p1 in { p2 in { p3 in { p4 in { p5 in { p6 in { p7 in { p8 in { p9 in f(p1, p2, p3, p4, p5, p6, p7, p8, p9) } } } } } } } } }
}

public struct GenerateMocksCommand: CommandProtocol {
    
    public let verb = "generate"
    public let function = "Generates mock files"
    
    public func run(_ options: Options) -> Result<Void, CuckooGeneratorError> {
        let inputPathValues = Array(Set(options.files.map { Path($0).standardRawValue }))
        let inputFiles = inputPathValues.map { File(path: $0) }.flatMap { $0 }.sorted(by: { $0.path ?? "" > $1.path ?? "" })
        let tokens = inputFiles.map { Tokenizer(sourceFile: $0).tokenize() }
        let tokensWithInheritance = options.noInheritance ? tokens : mergeInheritance(tokens)
        let tokensWithoutClasses = options.noClassMocking ? removeClasses(tokensWithInheritance) : tokensWithInheritance
        // filter excluded classes/protocols
        let parsedFiles = removeClassesAndProtocols(from: tokensWithoutClasses, in: options.exclude)

        let headers = parsedFiles.map { options.noHeader ? "" : FileHeaderHandler.getHeader(of: $0, includeTimestamp: !options.noTimestamp) }
        let imports = parsedFiles.map { FileHeaderHandler.getImports(of: $0, testableFrameworks: options.testableFrameworks) }
        let mocks = parsedFiles.map { Generator(file: $0).generate() }
        
        let mergedFiles = zip(zip(headers, imports), mocks).map { $0.0 + $0.1 + $1 }
        let outputPath = Path(options.output)

        do {
            if outputPath.isDirectory {
                let inputPaths = inputPathValues.map { Path($0) }
{'fraction_non_alphanumeric': 0.13204853675945752, 'fraction_numerical': 0.03283369022127052, 'mean_word_length': 3.0736434108527133, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3137794', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1387, 'n_words': 370}