<commit_before>//
//  HotSignalSpec.swift
//  ReactiveCocoa
//
//  Created by <NAME> on 30/10/2014.
//  Copyright (c) 2014 GitHub. All rights reserved.
//

import Nimble
import Quick
import ReactiveCocoa

class HotSignalSpec: QuickSpec {
	override func spec() {
		describe("lifetime") {
			describe("signals initialized with init") {
				it("generator should keep signal alive while sink is") {
					weak var innerSignal: HotSignal<NSDate>?

					// Use an inner closure to help ARC deallocate things as we
					// expect.
					let test: () -> () = {
						let scheduler = TestScheduler()
						let signal = HotSignal<NSDate> { sink in
							scheduler.schedule {
								sink.put(scheduler.currentDate)
							}

							return
						}

						innerSignal = signal
						expect(innerSignal).notTo(beNil())

						scheduler.run()
					}

					test()
					expect(innerSignal).toEventually(beNil())
				}

				it("derived signals should stay alive until the original terminates") {
					let scheduler = TestScheduler()

					var receivedValue = false
					let test: () -> () = {
						let signal = HotSignal<()> { sink in
							scheduler.schedule {
								sink.put(())
							}
							
							return
						}

						signal.take(1).observe { _ in receivedValue = true }
						return
					}

					test()
					expect(receivedValue).to(beFalsy())

					scheduler.run()
					expect(receivedValue).to(beTruthy())
				}
			}

			describe("weak signals") {<commit_msg>Verify that derived signals don't live too long<commit_after>//
//  HotSignalSpec.swift
//  ReactiveCocoa
//
//  Created by <NAME> on 30/10/2014.
//  Copyright (c) 2014 GitHub. All rights reserved.
//

import Nimble
import Quick
import ReactiveCocoa

class HotSignalSpec: QuickSpec {
	override func spec() {
		describe("lifetime") {
			describe("signals initialized with init") {
				it("generator should keep signal alive while sink is") {
					weak var innerSignal: HotSignal<NSDate>?

					// Use an inner closure to help ARC deallocate things as we
					// expect.
					let test: () -> () = {
						let scheduler = TestScheduler()
						let signal = HotSignal<NSDate> { sink in
							scheduler.schedule {
								sink.put(scheduler.currentDate)
							}

							return
						}

						innerSignal = signal
						expect(innerSignal).notTo(beNil())

						scheduler.run()
					}

					test()
					expect(innerSignal).toEventually(beNil())
				}

				it("derived signals should stay alive until the original terminates") {
					let scheduler = TestScheduler()
					weak var originalSignal: HotSignal<()>?
					weak var derivedSignal: HotSignal<()>?

					var receivedValue = false
					let test: () -> () = {
						let signal = HotSignal<()> { sink in
							scheduler.schedule {
								sink.put(())
							}

							return
						}

						originalSignal = signal
						expect(originalSignal).notTo(beNil())

						derivedSignal = signal.take(1)
						expect(derivedSignal).notTo(beNil())

						derivedSignal?.observe { _ in receivedValue = true }
						return
					}

					test()
					expect(receivedValue).to(beFalsy())
					expect(originalSignal).notTo(beNil())
					expect(derivedSignal).notTo(beNil())

					scheduler.run()
					expect(receivedValue).to(beTruthy())
					expect(originalSignal).toEventually(beNil())
					expect(derivedSignal).toEventually(beNil())
				}
			}

			describe("weak signals") {
{'fraction_non_alphanumeric': 0.11750741839762611, 'fraction_numerical': 0.00771513353115727, 'mean_word_length': 2.47167868177137, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '5516283', 'n_tokens_mistral': 1462, 'n_tokens_neox': 997, 'n_words': 247}