<commit_before>//
//  BxTextFieldFormattingTests.swift
//  BxTextField
//
//  Created by Sergan on 22/01/2018.
//  Copyright © 2018 Byterix. All rights reserved.
//

import XCTest
@testable import BxTextField

class BxTextFieldFormattingTests: XCTestCase {
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
        
    func testChangedDirection() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        textField.formattingTemplate = "+#(###)###-##-##"
        textField.formattingDirection = .rightToLeft
        textField.enteredText = "78901234567"
        XCTAssertEqual(textField.text!, "+7(890)123-45-67")
    }
    
    func testFormatChange1() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        textField.formattingTemplate = "+#(###)###-##-##"
        textField.formattingReplacementChar = "*"
        textField.enteredText = "78901234567"
        XCTAssertNotEqual(textField.text!, "+7(890)123-45-67")
        XCTAssertEqual(textField.text!, textField.formattingTemplate)
        
        textField.formattingTemplate = "+*(***)***-**-**"
        textField.enteredText = "78901234567"
        XCTAssertEqual(textField.text!, "+7(890)123-45-67")
    }
    
    func testFormatChange2() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        
        textField.formattingTemplate = "+%(%%%)%%%-%%-%%"
        textField.formattingReplacementChar = "%"
        textField.enteredText = "78901234567"
        XCTAssertEqual(textField.text!, "+7(890)123-45-67")
    }
    
    func testRightToLeftDirection() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        textField.formattingTemplate = "#.##"
        textField.formattingDirection = .rightToLeft
        textField.enteredText = "1"
        XCTAssertEqual(textField.text!, "1")
        textField.enteredText = "12"
        XCTAssertEqual(textField.text!, ".12")
        textField.enteredText = "123"
        XCTAssertEqual(textField.text!, "1.23")
    }
    
    func testLeftToRightDirection() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        textField.formattingTemplate = "#.##"
        textField.formattingDirection = .leftToRight
        textField.enteredText = "1"
        XCTAssertEqual(textField.text!, "1")
        textField.enteredText = "12"
        XCTAssertEqual(textField.text!, "1.2")
        textField.enteredText = "123"
        XCTAssertEqual(textField.text!, "1.23")
    }
    
    func testLeftPattern() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        textField.leftPatternText = "$ "
        textField.formattingTemplate = "###"
        textField.formattingDirection = .rightToLeft
        textField.enteredText = "123"
        XCTAssertEqual(textField.text!, "$ 123")
        textField.enteredText = ""
        XCTAssertEqual(textField.text!, "$ ")
    }
    <commit_msg>added unit tests for rewriting<commit_after>//
//  BxTextFieldFormattingTests.swift
//  BxTextField
//
//  Created by Sergan on 22/01/2018.
//  Copyright © 2018 Byterix. All rights reserved.
//

import XCTest
@testable import BxTextField

class BxTextFieldFormattingTests: XCTestCase {
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
        
    func testChangedDirection() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        textField.formattingTemplate = "+#(###)###-##-##"
        textField.formattingDirection = .rightToLeft
        textField.enteredText = "78901234567"
        XCTAssertEqual(textField.text!, "+7(890)123-45-67")
    }
    
    func testFormatChange1() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        textField.formattingTemplate = "+#(###)###-##-##"
        textField.formattingReplacementChar = "*"
        textField.enteredText = "78901234567"
        XCTAssertNotEqual(textField.text!, "+7(890)123-45-67")
        XCTAssertEqual(textField.text!, textField.formattingTemplate)
        
        textField.formattingTemplate = "+*(***)***-**-**"
        textField.enteredText = "78901234567"
        XCTAssertEqual(textField.text!, "+7(890)123-45-67")
    }
    
    func testFormatChange2() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        
        textField.formattingTemplate = "+%(%%%)%%%-%%-%%"
        textField.formattingReplacementChar = "%"
        textField.enteredText = "78901234567"
        XCTAssertEqual(textField.text!, "+7(890)123-45-67")
    }
    
    func testRightToLeftDirection() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        textField.formattingTemplate = "#.##"
        textField.formattingDirection = .rightToLeft
        textField.enteredText = "1"
        XCTAssertEqual(textField.text!, "1")
        textField.enteredText = "12"
        XCTAssertEqual(textField.text!, ".12")
        textField.enteredText = "123"
        XCTAssertEqual(textField.text!, "1.23")
    }
    
    func testLeftToRightDirection() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        textField.formattingTemplate = "#.##"
        textField.formattingDirection = .leftToRight
        textField.enteredText = "1"
        XCTAssertEqual(textField.text!, "1")
        textField.enteredText = "12"
        XCTAssertEqual(textField.text!, "1.2")
        textField.enteredText = "123"
        XCTAssertEqual(textField.text!, "1.23")
    }
    
    func testLeftPattern() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        textField.leftPatternText = "$ "
        textField.formattingTemplate = "###"
        textField.formattingDirection = .rightToLeft
        textField.enteredText = "123"
        XCTAssertEqual(textField.text!, "$ 123")
        textField.enteredText = ""
        XCTAssertEqual(textField.text!, "$ ")
    }
    
    func testNotRewriting() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        textField.leftPatternText = "$ "
        textField.formattingTemplate = "###"
        textField.isFormattingRewriting = false
        textField.formattingDirection = .rightToLeft
        textField.enteredText = "12345"
        XCTAssertEqual(textField.text!, "$ 345")
        textField.enteredText = "09"
        XCTAssertEqual(textField.text!, "$ 09")
        
        textField.enteredText = "xxxxxx"
        XCTAssertEqual(textField.text!, "$ xxx")
        
        textField.formattingDirection = .leftToRight
        textField.enteredText = "12345"
        XCTAssertEqual(textField.text!, "$ 123")
    }
    
    func testRewriting() {
        let textField = BxTextField(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
        textField.leftPatternText = "$ "
        textField.formattingTemplate = "###"
        textField.isFormattingRewriting = true
        textField.formattingDirection = .rightToLeft
        textField.enteredText = "12345"
        XCTAssertEqual(textField.text!, "$ 345")
        textField.enteredText = "09"
        XCTAssertEqual(textField.text!, "$ 09")
        
        textField.enteredText = "xxxxxx"
        XCTAssertEqual(textField.text!, "$ xxx")
        
        textField.formattingDirection = .leftToRight
        textField.enteredText = "12345"
        XCTAssertEqual(textField.text!, "$ 123")
    }
    
{'fraction_non_alphanumeric': 0.13010924266601204, 'fraction_numerical': 0.0493433165582423, 'mean_word_length': 2.6101019051838725, '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': '247716', 'n_tokens_mistral': 2897, 'n_tokens_neox': 2528, 'n_words': 500}