<commit_before>//
//  TestSpec.swift
//  AcceptanceMark
//
//  Created by <NAME> on 11/08/2016.
//  Copyright © 2016 musevisions. All rights reserved.
//

import Foundation

struct TestSpec {
    var fileName: String = ""
    var title: String = ""
    var testLines: [String] = []
    
    enum VariableType: String {
        case bool = "Bool"
        case int = "Int"
        case float = "Float"
        case string = "String"
        
        init?(type: String) {
            if type == "Bool" {
                self = .bool
            }
            else if type == "Int" {
                self = .int
            }
            else if type == "Float" {
                self = .float
            }
            else if type == "String" {
                self = .string
            }
            else {
                return nil
            }
        }
    }
    
    struct Variable: CustomDebugStringConvertible {
        let name: String
        let type: VariableType
        var debugDescription: String {
            return "\(name): \(type.rawValue)"
        }
    }
    
    struct TestData: CustomDebugStringConvertible {
        let inputs: [ String ] // Should be Any?
        let outputs: [ String ] // Should be Any?
        var debugDescription: String {
            return "\n          I: \(inputs), O: \(outputs)"
        }
    }
    
    var inputVars: [ Variable ] = []
    var outputVars: [ Variable ] = []
    
    var tests: [ TestData ] = []
}

extension TestSpec: CustomDebugStringConvertible {
    
    var debugDescription: String {
        return "\n  fileName: \(fileName)\n     title: \(title)\n  header I: \(inputVars), O: \(outputVars)\n     tests:\(tests)\n"
    }
}

extension TestSpec {
 
    var namespace: String {
        return (fileName as NSString)
            .replacingOccurrences(of: ".md", with: "")
            .replacingOccurrences(of: ".", with: "_")
            .replacingOccurrences(of: " ", with: "_")
    }
    var testName: String {
        return (title as NSString).replacingOccurrences(of: " ", with: "")
    }
    var sourceFileName: String {
        return "\(namespace)_\(testName).swift"
    }
    
    func inputParametersList(for test:TestData) -> String {
        return parameterList(variables: inputVars, values: test.inputs)
    }
    func outputParametersList(for test:TestData) -> String {
        return parameterList(variables: outputVars, values: test.outputs)<commit_msg>Only use alphanumeric characters in namespace<commit_after>//
//  TestSpec.swift
//  AcceptanceMark
//
//  Created by <NAME> on 11/08/2016.
//  Copyright © 2016 musevisions. All rights reserved.
//

import Foundation

struct TestSpec {
    var fileName: String = ""
    var title: String = ""
    var testLines: [String] = []
    
    enum VariableType: String {
        case bool = "Bool"
        case int = "Int"
        case float = "Float"
        case string = "String"
        
        init?(type: String) {
            if type == "Bool" {
                self = .bool
            }
            else if type == "Int" {
                self = .int
            }
            else if type == "Float" {
                self = .float
            }
            else if type == "String" {
                self = .string
            }
            else {
                return nil
            }
        }
    }
    
    struct Variable: CustomDebugStringConvertible {
        let name: String
        let type: VariableType
        var debugDescription: String {
            return "\(name): \(type.rawValue)"
        }
    }
    
    struct TestData: CustomDebugStringConvertible {
        let inputs: [ String ] // Should be Any?
        let outputs: [ String ] // Should be Any?
        var debugDescription: String {
            return "\n          I: \(inputs), O: \(outputs)"
        }
    }
    
    var inputVars: [ Variable ] = []
    var outputVars: [ Variable ] = []
    
    var tests: [ TestData ] = []
}

extension TestSpec: CustomDebugStringConvertible {
    
    var debugDescription: String {
        return "\n  fileName: \(fileName)\n     title: \(title)\n  header I: \(inputVars), O: \(outputVars)\n     tests:\(tests)\n"
    }
}

extension TestSpec {
 
    var namespace: String {
        return (fileName as NSString)
            .replacingOccurrences(of: ".md", with: "")
            .replacingOccurrences(of: ".", with: "_")
            .replacingOccurrences(of: " ", with: "_").filteredAlphanumericCharacters()
    }
    var testName: String {
        return (title as NSString).replacingOccurrences(of: " ", with: "")
    }
    var sourceFileName: String {
        return "\(namespace)_\(testName).swift"
    }
    
    func inputParametersList(for test:TestData) -> String {
        return parameterList(variables: inputVars, values: test.inputs)
    }
    func outputParametersList(for test:TestData) -> String {
        return parameterList(variables: outputVars, values: test.outputs)
{'fraction_non_alphanumeric': 0.11635410364992942, 'fraction_numerical': 0.004839685420447671, 'mean_word_length': 1.6971179989124525, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2932053', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1377, 'n_words': 373}