<commit_before>//
//  UIControlTests.swift
//  Rex
//
//  Created by <NAME> on 21/08/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import ReactiveCocoa
import UIKit
import XCTest

class UIControlTests: XCTestCase {
    
    weak var _control: UIControl?
    
    override func tearDown() {
        XCTAssert(_control == nil, "Retain cycle detected in UIControl properties")
        super.tearDown()
    }
    
    func testEnabledPropertyDoesntCreateRetainCycle() {
        let control = UIControl(frame: CGRectZero)
        _control = control
        
        control.rex_enabled <~ SignalProducer(value: false)
        XCTAssert(_control?.enabled == false)
    }
    
    func testSelectedPropertyDoesntCreateRetainCycle() {
        let control = UIControl(frame: CGRectZero)
        _control = control
        
        control.rex_selected <~ SignalProducer(value: true)
        XCTAssert(_control?.selected == true)
    }
    
    func testHighlightedPropertyDoesntCreateRetainCycle() {
        let control = UIControl(frame: CGRectZero)
        _control = control
        
        control.rex_highlighted <~ SignalProducer(value: true)
        XCTAssert(_control?.highlighted == true)
    }
    
    func testEnabledProperty () {
        let control = UIControl(frame: CGRectZero)
        control.enabled = false
        
        let (pipeSignal, observer) = Signal<Bool, NoError>.pipe()
        control.rex_enabled <~ SignalProducer(signal: pipeSignal)
        
        observer.sendNext(true)
        XCTAssertTrue(control.enabled)
        observer.sendNext(false)
        XCTAssertFalse(control.enabled)
    }
    
    func testSelectedProperty() {
        let control = UIControl(frame: CGRectZero)
        control.selected = false
        
        let (pipeSignal, observer) = Signal<Bool, NoError>.pipe()
        control.rex_selected <~ SignalProducer(signal: pipeSignal)
        
        observer.sendNext(true)
        XCTAssertTrue(control.selected)
        observer.sendNext(false)
        XCTAssertFalse(control.selected)
    }
    
    func testHighlightedProperty() {
        let control = UIControl(frame: CGRectZero)
        control.highlighted = false
        
        let (pipeSignal, observer) = Signal<Bool, NoError>.pipe()
        control.rex_highlighted <~ SignalProducer(signal: pipeSignal)
        
        observer.sendNext(true)
        XCTAssertTrue(control.highlighted)
        observer.sendNext(false)
        XCTAssertFalse(control.highlighted)
    }
}<commit_msg>Add testcase that replicates a bug with binding UIControl.enabled and UIControl.selected<commit_after>//
//  UIControlTests.swift
//  Rex
//
//  Created by <NAME> on 21/08/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import ReactiveCocoa
import UIKit
import XCTest

class UIControlTests: XCTestCase {
    
    weak var _control: UIControl?
    
    override func tearDown() {
        XCTAssert(_control == nil, "Retain cycle detected in UIControl properties")
        super.tearDown()
    }
    
    func testEnabledPropertyDoesntCreateRetainCycle() {
        let control = UIControl(frame: CGRectZero)
        _control = control
        
        control.rex_enabled <~ SignalProducer(value: false)
        XCTAssert(_control?.enabled == false)
    }
    
    func testSelectedPropertyDoesntCreateRetainCycle() {
        let control = UIControl(frame: CGRectZero)
        _control = control
        
        control.rex_selected <~ SignalProducer(value: true)
        XCTAssert(_control?.selected == true)
    }
    
    func testHighlightedPropertyDoesntCreateRetainCycle() {
        let control = UIControl(frame: CGRectZero)
        _control = control
        
        control.rex_highlighted <~ SignalProducer(value: true)
        XCTAssert(_control?.highlighted == true)
    }
    
    func testEnabledProperty () {
        let control = UIControl(frame: CGRectZero)
        control.enabled = false
        
        let (pipeSignal, observer) = Signal<Bool, NoError>.pipe()
        control.rex_enabled <~ SignalProducer(signal: pipeSignal)
        
        observer.sendNext(true)
        XCTAssertTrue(control.enabled)
        observer.sendNext(false)
        XCTAssertFalse(control.enabled)
    }
    
    func testSelectedProperty() {
        let control = UIControl(frame: CGRectZero)
        control.selected = false
        
        let (pipeSignal, observer) = Signal<Bool, NoError>.pipe()
        control.rex_selected <~ SignalProducer(signal: pipeSignal)
        
        observer.sendNext(true)
        XCTAssertTrue(control.selected)
        observer.sendNext(false)
        XCTAssertFalse(control.selected)
    }
    
    func testHighlightedProperty() {
        let control = UIControl(frame: CGRectZero)
        control.highlighted = false
        
        let (pipeSignal, observer) = Signal<Bool, NoError>.pipe()
        control.rex_highlighted <~ SignalProducer(signal: pipeSignal)
        
        observer.sendNext(true)
        XCTAssertTrue(control.highlighted)
        observer.sendNext(false)
        XCTAssertFalse(control.highlighted)
    }
    
    func testEnabledAndSelectedProperty() {
        let control = UIControl(frame: CGRectZero)
        control.selected = false
        control.enabled = false
        
        let (pipeSignalSelected, observerSelected) = Signal<Bool, NoError>.pipe()
        let (pipeSignalEnabled, observerEnabled) = Signal<Bool, NoError>.pipe()
        control.rex_selected <~ SignalProducer(signal: pipeSignalSelected)
        control.rex_enabled <~ SignalProducer(signal: pipeSignalEnabled)
        
        observerSelected.sendNext(true)
        observerEnabled.sendNext(true)
        XCTAssertTrue(control.enabled)
        XCTAssertTrue(control.selected)
        observerSelected.sendNext(false)
        XCTAssertTrue(control.enabled)
        XCTAssertFalse(control.selected)
        observerEnabled.sendNext(false)
        XCTAssertFalse(control.enabled)
        XCTAssertFalse(control.selected)
    }
}
{'fraction_non_alphanumeric': 0.08769589863287762, 'fraction_numerical': 0.003334444814938313, 'mean_word_length': 2.547604967474867, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 15, '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': '6696610', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1682, 'n_words': 324}