<commit_before>//
//  PublicKeyValidatorTests.swift
//  PAYJPTests
//
//  Created by <NAME> on 2019/11/27.
//  Copyright © 2019 PAY, Inc. All rights reserved.
//

import XCTest
@testable import PAYJP

class PublicKeyValidatorTests: XCTestCase {

    func testPublicKeyValidationSuccess() {
        let assert: (Bool, String, StaticString, UInt) -> Void = { condition, message, _, _ in
            XCTAssertTrue(condition)
        }

        let validator = PublicKeyValidator(assert: assert)
        let cases: [String] = [
            ("pk_test_123456789"),
            ("pk_live_123456789")
        ]
        for (publicKey) in cases {
            validator.validate(publicKey: publicKey)
        }
    }

    func testPublicKeyValidationFailed() {
        let cases: [(String, String)] = [
            ("", "❌You need to set publickey for PAY.JP. You can find in https://pay.jp/d/settings ."),
            (" ", "❌You need to set publickey for PAY.JP. You can find in https://pay.jp/d/settings ."),
            ("sk_test_123456789", "❌You are using secretkey (`sk_xxxx`) instead of PAY.JP publickey." +
                "You can find **public** key like `pk_xxxxxx` in https://pay.jp/d/settings ."),
            ("sk_live_123456789", "❌You are using secretkey (`sk_xxxx`) instead of PAY.JP publickey." +
                "You can find **public** key like `pk_xxxxxx` in https://pay.jp/d/settings .")
        ]

        for (publicKey, expectedMessage) in cases {
            let assert: (Bool, String, StaticString, UInt) -> Void = { condition, message, _, _ in
                if !condition {
                    XCTAssertEqual(message, expectedMessage)
                }
            }
            let validator = PublicKeyValidator(assert: assert)
            validator.validate(publicKey: publicKey)
        }
    }
}<commit_msg>add comment<commit_after>//
//  PublicKeyValidatorTests.swift
//  PAYJPTests
//
//  Created by <NAME> on 2019/11/27.
//  Copyright © 2019 PAY, Inc. All rights reserved.
//

import XCTest
@testable import PAYJP

class PublicKeyValidatorTests: XCTestCase {

    func testPublicKeyValidationSuccess() {
        // assertの成功をチェックするため、condtionがtrueであるかテストする
        let assert: (Bool, String, StaticString, UInt) -> Void = { condition, message, _, _ in
            XCTAssertTrue(condition)
        }

        let validator = PublicKeyValidator(assert: assert)
        let cases: [String] = [
            ("pk_test_123456789"),
            ("pk_live_123456789")
        ]
        for (publicKey) in cases {
            validator.validate(publicKey: publicKey)
        }
    }

    func testPublicKeyValidationFailed() {
        let cases: [(String, String)] = [
            ("", "❌You need to set publickey for PAY.JP. You can find in https://pay.jp/d/settings ."),
            (" ", "❌You need to set publickey for PAY.JP. You can find in https://pay.jp/d/settings ."),
            ("sk_test_123456789", "❌You are using secretkey (`sk_xxxx`) instead of PAY.JP publickey." +
                "You can find **public** key like `pk_xxxxxx` in https://pay.jp/d/settings ."),
            ("sk_live_123456789", "❌You are using secretkey (`sk_xxxx`) instead of PAY.JP publickey." +
                "You can find **public** key like `pk_xxxxxx` in https://pay.jp/d/settings .")
        ]

        for (publicKey, expectedMessage) in cases {
            // assertの失敗をチェックするため、conditionがfalseの場合にmessageの内容が正しいかテストする
            let assert: (Bool, String, StaticString, UInt) -> Void = { condition, message, _, _ in
                if !condition {
                    XCTAssertEqual(message, expectedMessage)
                }
            }
            let validator = PublicKeyValidator(assert: assert)
            validator.validate(publicKey: publicKey)
        }
    }
}
{'fraction_non_alphanumeric': 0.11817462410973358, 'fraction_numerical': 0.02532313373780005, 'mean_word_length': 2.1390728476821192, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 8, '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': '1682307', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1121, 'n_words': 293}