<commit_before>//
//  ScanCommandTests.swift
//  GitHub Scanner
//
//  Created by <NAME> on 10/02/2017.
//  Copyright © 2017 ustwo Fampany Ltd. All rights reserved.
//


import Commandant
import Foundation
@testable import GitHubScannerKit
import Result
import XCTest


final class ScanOptionsTests: XCTestCase {


    // MARK: - Tests

    func testDefaultInit() {
        // Given
        let args = ArgumentParser([])

        // Then
        assertOptions(arguments: CommandMode.arguments(args))
    }

    func testOauthToken() {
        // Given
        let expectedOauthToken = "<PASSWORD>"
        let args = ArgumentParser(["--oauth", expectedOauthToken])

        // Then
        assertOptions(arguments: CommandMode.arguments(args),
                      oauthToken: expectedOauthToken)
    }

    func testOrganization() {
        // Given
        let expectedOrganization = "ustwo"
        let args = ArgumentParser(["--organization", expectedOrganization])

        // Then
        assertOptions(arguments: CommandMode.arguments(args),
                      organization: expectedOrganization)
    }

    func testPrimaryLanguage() {
        // Given
        let expectedPrimaryLanguage = "Swift"
        let args = ArgumentParser(["--primary-language", expectedPrimaryLanguage])

        // Then
        assertOptions(arguments: CommandMode.arguments(args),
                      primaryLanguage: expectedPrimaryLanguage)
    }

    func testRepositoryType() {
        // Given
        let expectedRepositoryType = "private"
        let args = ArgumentParser(["--type", expectedRepositoryType])

        // Then
        assertOptions(arguments: CommandMode.arguments(args),
                      repositoryType: expectedRepositoryType)
    }


    // MARK: - Convenience

    private func assertOptions(arguments: CommandMode,
                               oauthToken: String = "",
                               organization: String = "",
                               primaryLanguage: String = "",
                               repositoryType: String = "public",
                               file: String = #file, line: UInt = #line) {

        // When
        let result = ScanOptions.evaluate(arguments)
        let actual = try? result.dematerialize()

        // Then
        guard let actualResult = actual else {
            recordFailure(withDescription: "Unable to dematerialize result.",
                          inFile: file,
                          atLine: line,
                          expected: false)
            return
        }

        guard actualResult.oauthToken == oauthToken else {
            recordFailure(withDescription:  "Expected oauthToken to be: \(oauthToken) " +
                                            "but found: \(actualResult.oauthToken)",
                          inFile: file,
                          atLine: line,
                          expected: true)
            return
        }
        guard actualResult.organization == organization else {
            recordFailure(withDescription:  "Expected organization to be: \(organization) " +
                                            "but found: \(actualResult.organization)",
                          inFile: file,
                          atLine: line,
                          expected: true)
            return
        }
        guard actualResult.primaryLanguage == primaryLanguage else {
            recordFailure(withDescription:  "Expected primary language to be: \(primaryLanguage) " +
                                            "but found: \(actualResult.primaryLanguage)",
                          inFile: file,
                          atLine: line,
                          expected: true)
            return
        }
        guard actualResult.repositoryType == repositoryType else {
            recordFailure(withDescription:  "Expected repositoryType to be: \(repositoryType) " +
                                            "but found: \(actualResult.repositoryType)",
                          inFile: file,
                          atLine: line,
                          expected: true)
            return
        }
    }

}
<commit_msg>Add ScanOptions test for license<commit_after>//
//  ScanCommandTests.swift
//  GitHub Scanner
//
//  Created by <NAME> on 10/02/2017.
//  Copyright © 2017 ustwo Fampany Ltd. All rights reserved.
//


import Commandant
import Foundation
@testable import GitHubScannerKit
import Result
import XCTest


final class ScanOptionsTests: XCTestCase {


    // MARK: - Tests

    func testDefaultInit() {
        // Given
        let args = ArgumentParser([])

        // Then
        assertOptions(arguments: CommandMode.arguments(args))
    }

    func testLicense() {
        // Given
        let expectedLicense = "MIT"
        let args = ArgumentParser(["--license", expectedLicense])

        // Then
        assertOptions(arguments: CommandMode.arguments(args),
                      license: expectedLicense)
    }

    func testOauthToken() {
        // Given
        let expectedOauthToken = "<PASSWORD>"
        let args = ArgumentParser(["--oauth", expectedOauthToken])

        // Then
        assertOptions(arguments: CommandMode.arguments(args),
                      oauthToken: expectedOauthToken)
    }

    func testOrganization() {
        // Given
        let expectedOrganization = "ustwo"
        let args = ArgumentParser(["--organization", expectedOrganization])

        // Then
        assertOptions(arguments: CommandMode.arguments(args),
                      organization: expectedOrganization)
    }

    func testPrimaryLanguage() {
        // Given
        let expectedPrimaryLanguage = "Swift"
        let args = ArgumentParser(["--primary-language", expectedPrimaryLanguage])

        // Then
        assertOptions(arguments: CommandMode.arguments(args),
                      primaryLanguage: expectedPrimaryLanguage)
    }

    func testRepositoryType() {
        // Given
        let expectedRepositoryType = "private"
        let args = ArgumentParser(["--type", expectedRepositoryType])

        // Then
        assertOptions(arguments: CommandMode.arguments(args),
                      repositoryType: expectedRepositoryType)
    }


    // MARK: - Convenience

    private func assertOptions(arguments: CommandMode,
                               license: String = "",
                               oauthToken: String = "",
                               organization: String = "",
                               primaryLanguage: String = "",
                               repositoryType: String = "public",
                               file: String = #file, line: UInt = #line) {

        // When
        let result = ScanOptions.evaluate(arguments)
        let actual = try? result.dematerialize()

        // Then
        guard let actualResult = actual else {
            recordFailure(withDescription: "Unable to dematerialize result.",
                          inFile: file,
                          atLine: line,
                          expected: false)
            return
        }

        guard actualResult.license == license else {
            recordFailure(withDescription:  "Expected license to be: \(license) " +
                                            "but found: \(actualResult.license)",
                          inFile: file,
                          atLine: line,
                          expected: true)
            return
        }
        guard actualResult.oauthToken == oauthToken else {
            recordFailure(withDescription:  "Expected oauthToken to be: \(oauthToken) " +
                                            "but found: \(actualResult.oauthToken)",
                          inFile: file,
                          atLine: line,
                          expected: true)
            return
        }
        guard actualResult.organization == organization else {
            recordFailure(withDescription:  "Expected organization to be: \(organization) " +
                                            "but found: \(actualResult.organization)",
                          inFile: file,
                          atLine: line,
                          expected: true)
            return
        }
        guard actualResult.primaryLanguage == primaryLanguage else {
            recordFailure(withDescription:  "Expected primary language to be: \(primaryLanguage) " +
                                            "but found: \(actualResult.primaryLanguage)",
                          inFile: file,
                          atLine: line,
                          expected: true)
            return
        }
        guard actualResult.repositoryType == repositoryType else {
            recordFailure(withDescription:  "Expected repositoryType to be: \(repositoryType) " +
                                            "but found: \(actualResult.repositoryType)",
                          inFile: file,
                          atLine: line,
                          expected: true)
            return
        }
    }

}

{'fraction_non_alphanumeric': 0.08353484282259838, 'fraction_numerical': 0.002637942404924159, 'mean_word_length': 1.4199468085106384, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2139735', 'n_tokens_mistral': 2058, 'n_tokens_neox': 1950, 'n_words': 505}