<commit_before>//
//  craftTests.swift
//  craftTests
//
//  Created by <NAME> on 6/28/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import XCTest
import craft

//Promises/A+ spec: http://promises-aplus.github.io/promises-spec/
class craftTests: 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 testCreatePromise()
    {
        let p : Promise = Craft.promise()
        
        XCTAssertNotNil(p, "promise was not created")
    }
    
    //spec 2.2.4
    func testResolveAsync()
    {
        let expectation = expectationWithDescription("resolveAsync");
        
        let p : Promise = createImmediateResolvePromise()
        p.then({
            (value: AnyObject?) -> AnyObject? in
            
            expectation.fulfill()
            
            return nil;
        })
        
        waitForExpectationsWithTimeout(5.0, handler: {
            (error: NSError!) -> () in
            
        });
    }
    
    //spec 2.2.4
    func testRejectAsync()
    {
        let expectation = expectationWithDescription("rejectAsync");
        
        let p : Promise = createImmediateRejectPromise()
        p.then(nil, reject: {
            (value: AnyObject?) -> AnyObject? in
            
            expectation.fulfill()
            
            return nil;
        })
        
        waitForExpectationsWithTimeout(5.0, handler: {
            (error: NSError!) -> () in
            
        });
    }
    
    func testThenable()
    {
        let expectation = expectationWithDescription("thenable");
        
        let p : Promise = createImmediateResolvePromise()
        p.then({
            (value: AnyObject?) -> AnyObject? in
            expectation.fulfill()
            return nil;
        },
        reject: {
            (value: AnyObject?) -> AnyObject? in
            return nil;
        })
        
        waitForExpectationsWithTimeout(5.0, handler: {
            (error: NSError!) -> () in
            
        });
    }
    
    func testThenableNoReject()
    {
        let expectation = expectationWithDescription("thenableNoReject");
        
        let p : Promise = createImmediateResolvePromise()
        p.then({
            (value: AnyObject?) -> AnyObject? in
            expectation.fulfill()
            return nil;
        })
        
        waitForExpectationsWithTimeout(5.0, handler: {
            (error: NSError!) -> () in
            
        });
    }
    
    func testMultiThen()
    {
        let expectation1 = expectationWithDescription("multiThen1");
        let expectation2 = expectationWithDescription("multiThen2");
        
        let p : Promise = createImmediateResolvePromise()
        
        p.then({
            (value: AnyObject?) -> AnyObject? in
            expectation1.fulfill()
            return nil
        })
        
        p.then({
            (value: AnyObject?) -> AnyObject? in
            expectation2.fulfill()
            return nil
        })
        
        waitForExpectationsWithTimeout(5.0, handler: {
            (error: NSError!) -> () in
            
        });
    }
    
    func testChainable()
    {
        let expectation = expectationWithDescription("chainable");
        
        let p : Promise = createWillResolvePromise()
        p.then({
            (value: AnyObject?) -> AnyObject? in<commit_msg>added test for multi reject on thens from a single promise<commit_after>//
//  craftTests.swift
//  craftTests
//
//  Created by <NAME> on 6/28/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import XCTest
import craft

//Promises/A+ spec: http://promises-aplus.github.io/promises-spec/
class craftTests: 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 testCreatePromise()
    {
        let p : Promise = Craft.promise()
        
        XCTAssertNotNil(p, "promise was not created")
    }
    
    //spec 2.2.4
    func testResolveAsync()
    {
        let expectation = expectationWithDescription("resolveAsync");
        
        let p : Promise = createImmediateResolvePromise()
        p.then({
            (value: AnyObject?) -> AnyObject? in
            
            expectation.fulfill()
            
            return nil;
        })
        
        waitForExpectationsWithTimeout(5.0, handler: {
            (error: NSError!) -> () in
            
        });
    }
    
    //spec 2.2.4
    func testRejectAsync()
    {
        let expectation = expectationWithDescription("rejectAsync");
        
        let p : Promise = createImmediateRejectPromise()
        p.then(nil, reject: {
            (value: AnyObject?) -> AnyObject? in
            
            expectation.fulfill()
            
            return nil;
        })
        
        waitForExpectationsWithTimeout(5.0, handler: {
            (error: NSError!) -> () in
            
        });
    }
    
    func testThenable()
    {
        let expectation = expectationWithDescription("thenable");
        
        let p : Promise = createImmediateResolvePromise()
        p.then({
            (value: AnyObject?) -> AnyObject? in
            expectation.fulfill()
            return nil;
        },
        reject: {
            (value: AnyObject?) -> AnyObject? in
            return nil;
        })
        
        waitForExpectationsWithTimeout(5.0, handler: {
            (error: NSError!) -> () in
            
        });
    }
    
    func testThenableNoReject()
    {
        let expectation = expectationWithDescription("thenableNoReject");
        
        let p : Promise = createImmediateResolvePromise()
        p.then({
            (value: AnyObject?) -> AnyObject? in
            expectation.fulfill()
            return nil;
        })
        
        waitForExpectationsWithTimeout(5.0, handler: {
            (error: NSError!) -> () in
            
        });
    }
    
    func testMultiThenResolve()
    {
        let expectation1 = expectationWithDescription("multiThenResolve1");
        let expectation2 = expectationWithDescription("multiThenResolve2");
        
        let p : Promise = createImmediateResolvePromise()
        
        p.then({
            (value: AnyObject?) -> AnyObject? in
            expectation1.fulfill()
            return nil
        })
        
        p.then({
            (value: AnyObject?) -> AnyObject? in
            expectation2.fulfill()
            return nil
        })
        
        waitForExpectationsWithTimeout(5.0, handler: {
            (error: NSError!) -> () in
            
        });
    }
    
    func testMultiThenReject()
    {
        let expectation1 = expectationWithDescription("multiThenReject1");
        let expectation2 = expectationWithDescription("multiThenReject2");
        
        let p : Promise = createImmediateRejectPromise()
        
        p.catch({
            (value: AnyObject?) -> AnyObject? in
            expectation1.fulfill()
            return nil
        })
        
        p.catch({
            (value: AnyObject?) -> AnyObject? in
            expectation2.fulfill()
            return nil
        })
        
        waitForExpectationsWithTimeout(5.0, handler: {
            (error: NSError!) -> () in
            
        });
    }
    
    func testChainable()
    {
        let expectation = expectationWithDescription("chainable");
        
        let p : Promise = createWillResolvePromise()
        p.then({
            (value: AnyObject?) -> AnyObject? in
{'fraction_non_alphanumeric': 0.10126268878435256, 'fraction_numerical': 0.008665511265164644, 'mean_word_length': 1.516822429906542, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 36, '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': '5871047', 'n_tokens_mistral': 2168, 'n_tokens_neox': 2159, 'n_words': 496}