<commit_before>//
//  DeletionTests.swift
//  deferred
//
//  Created by <NAME> on 31/01/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import XCTest
import Foundation
import Dispatch

@testable import deferred

class DeletionTests: XCTestCase
{
  static var allTests = [
    ("testDeallocDeferred1", testDeallocDeferred1),
    ("testDeallocDeferred2", testDeallocDeferred2),
    ("testDeallocTBD1", testDeallocTBD1),
    ("testDeallocTBD2", testDeallocTBD2),
  ]

  class Dealloc: Deferred<Void>
  {
    let e: XCTestExpectation
    init(expectation: XCTestExpectation)
    {
      e = expectation
      super.init(queue: DispatchQueue.global())
    }
    deinit
    {
      e.fulfill()
    }
  }

  func testDeallocDeferred1()
  {
    do {
      let deferred = Dealloc(expectation: expectation(description: "will dealloc deferred 1"))
      do { deferred.notify { _ in XCTFail("Unexpected notification") } }
    }

    waitForExpectations(timeout: 0.1)
  }

  func testDeallocDeferred2()
  {
    do {
      Dealloc(expectation: expectation(description: "will dealloc deferred 2")).cancel()
    }

    waitForExpectations(timeout: 0.1)
  }

  class DeallocTBD: TBD<Void>
  {
    let e: XCTestExpectation
    init(expectation: XCTestExpectation)
    {
      e = expectation
      super.init(queue: DispatchQueue.global())
    }
    deinit
    {
      e.fulfill()
    }
  }

  func testDeallocTBD1()
  {
    do {
      let tbd = DeallocTBD(expectation: expectation(description: "will dealloc tbd 1"))
      do { tbd.notify { _ in XCTFail("Unexpected notification") } }
    }

    waitForExpectations(timeout: 0.1)
  }

  func testDeallocTBD2()
  {
    do {
      DeallocTBD(expectation: expectation(description: "will dealloc tbd 2")).cancel()
    }

    waitForExpectations(timeout: 0.1)
  }
}<commit_msg>additional object lifetime tests<commit_after>//
//  DeletionTests.swift
//  deferred
//
//  Created by <NAME> on 31/01/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import XCTest
import Foundation
import Dispatch

@testable import deferred

class DeletionTests: XCTestCase
{
  static var allTests = [
    ("testDeallocDeferred1", testDeallocDeferred1),
    ("testDeallocDeferred2", testDeallocDeferred2),
    ("testDeallocDeferred3", testDeallocDeferred3),
    ("testDeallocTBD1", testDeallocTBD1),
    ("testDeallocTBD2", testDeallocTBD2),
    ("testDeallocTBD3", testDeallocTBD3),
  ]

  class Dealloc: Deferred<Void>
  {
    let e: XCTestExpectation
    init(expectation: XCTestExpectation)
    {
      e = expectation
      super.init(queue: DispatchQueue.global())
    }
    deinit
    {
      e.fulfill()
    }
  }

  func testDeallocDeferred1()
  {
    do {
      _ = Dealloc(expectation: expectation(description: "will dealloc deferred 1"))
    }

    waitForExpectations(timeout: 0.1)
  }

  func testDeallocDeferred2()
  {
    do {
      let deferred = Dealloc(expectation: expectation(description: "will dealloc deferred 2"))
      do { _ = deferred.map { _ in XCTFail("Unexpected notification") } }
      deferred.cancel()
    }

    waitForExpectations(timeout: 0.1)
  }

  func testDeallocDeferred3()
  {
    do {
      Dealloc(expectation: expectation(description: "will dealloc deferred 3")).cancel()
    }

    waitForExpectations(timeout: 0.1)
  }

  class DeallocTBD: TBD<Void>
  {
    let e: XCTestExpectation
    init(expectation: XCTestExpectation)
    {
      e = expectation
      super.init(queue: DispatchQueue.global())
    }
    deinit
    {
      e.fulfill()
    }
  }

  func testDeallocTBD1()
  {
    do {
      _ = DeallocTBD(expectation: expectation(description: "will dealloc tbd 1"))
    }

    waitForExpectations(timeout: 0.1)
  }

  func testDeallocTBD2()
  {
    do {
      let tbd = DeallocTBD(expectation: expectation(description: "will dealloc tbd 2"))
      do { _ = tbd.map { _ in XCTFail("Unexpected notification") } }
      tbd.cancel()
    }

    waitForExpectations(timeout: 0.1)
  }

  func testDeallocTBD3()
  {
    do {
      DeallocTBD(expectation: expectation(description: "will dealloc tbd 3")).cancel()
    }

    waitForExpectations(timeout: 0.1)
  }
}
{'fraction_non_alphanumeric': 0.11301617966674717, 'fraction_numerical': 0.020284955324800773, 'mean_word_length': 2.9750479846449136, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7472544', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1399, 'n_words': 279}