<commit_before>"use strict";
/*jshint newcap: false*/
/*global Q: true, describe: false, it: false, expect: false, beforeEach: false,
         afterEach: false, require: false, jasmine: false, waitsFor: false,
         runs: false */

if (typeof Q === "undefined" && typeof require !== "undefined") {
    // For Node compatibility.
    global.Q = require("../q");
    require("./lib/jasmine-promise");
}

var REASON = "this is not an error, but it might show up in the console";

// In browsers that support strict mode, it'll be `undefined`; otherwise, the global.
var calledAsFunctionThis = (function () { return this; }());

afterEach(function () {
    Q.onerror = null;
});

describe("Q function", function () {
    it("should result in a fulfilled promise when given a value", function () {
        expect(Q(5).isFulfilled()).toBe(true);
    });

    it("should be the identity when given promise", function () {
        var f = Q.fulfill(5);
        var r = Q.reject(new Error("aaargh"));
        var p = Q.promise();

        expect(Q(f)).toBe(f);
        expect(Q(r)).toBe(r);
        expect(Q(p)).toBe(p);
    });
});<commit_msg>Failing test in Node.js 0.10 for the nextTick issue.<commit_after>"use strict";
/*jshint newcap: false*/
/*global Q: true, describe: false, it: false, expect: false, beforeEach: false,
         afterEach: false, require: false, jasmine: false, waitsFor: false,
         runs: false */

if (typeof Q === "undefined" && typeof require !== "undefined") {
    // For Node compatibility.
    global.Q = require("../q");
    require("./lib/jasmine-promise");
}

var REASON = "this is not an error, but it might show up in the console";

// In browsers that support strict mode, it'll be `undefined`; otherwise, the global.
var calledAsFunctionThis = (function () { return this; }());

afterEach(function () {
    Q.onerror = null;
});

describe("computing sum of integers using promises", function() {
   it("should compute correct result without blowing stack", function () {
      var array = [];
      var iters = 1000;
      for (var i=1; i<=iters; i++){
       array.push(i)
      }
      var pZero = Q.fulfill(0);
      var result = array.reduce(function(promise, nextVal) {
         return promise.then(function(currentVal) {
            var pNext = Q.fulfill(currentVal + nextVal);
            return pNext;
         });
      }, pZero);
      result.then(function(value){
         expect(value).toEqual(iters*(iters+1)/2);
         done();
      });
   });
});

describe("Q function", function () {
    it("should result in a fulfilled promise when given a value", function () {
        expect(Q(5).isFulfilled()).toBe(true);
    });

    it("should be the identity when given promise", function () {
        var f = Q.fulfill(5);
        var r = Q.reject(new Error("aaargh"));
        var p = Q.promise();

        expect(Q(f)).toBe(f);
        expect(Q(r)).toBe(r);
        expect(Q(p)).toBe(p);
    });
});
{'fraction_non_alphanumeric': 0.16203389830508474, 'fraction_numerical': 0.005084745762711864, 'mean_word_length': 2.837451235370611, 'pattern_counts': {'":': 0, '<': 4, '<?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': '863132', 'n_tokens_mistral': 918, 'n_tokens_neox': 894, 'n_words': 273}