<commit_before>/* globals window, document, HTMLElement */

'use strict';

var test = require('tape');
var is = require('../index.js');

var forEach = require('foreach');
var toStr = Object.prototype.toString;

test('is.type', function (t) {
  var booleans = [true, false];
  forEach(booleans, function (boolean) {
    t.ok(is.type(boolean, 'boolean'), '"' + boolean + '" is a boolean');
  });

  var numbers = [1, 0 / 1, 0 / -1, NaN, Infinity, -Infinity];
  forEach(numbers, function (number) {
    t.ok(is.type(number, 'number'), '"' + number + '" is a number');
  });

  var objects = [{}, null, new Date()];
  forEach(objects, function (object) {
    t.ok(is.type(object, 'object'), '"' + object + '" is an object');
  });

  var strings = ['', 'abc'];
  forEach(strings, function (string) {
    t.ok(is.type(string, 'string'), '"' + string + '" is a string');
  });

  t.ok(is.type(undefined, 'undefined'), 'undefined is undefined');

  t.end();
});

test('is.undef', function (t) {
  t.ok(is.undef(), 'absent undefined is undefined');
  t.ok(is.undef(undefined), 'literal undefined is undefined');
  t.notOk(is.undef(null), 'null is not undefined');
  t.notOk(is.undef({}), 'object is not undefined');
  t.end();
});

test('is.defined', function (t) {
  t.notOk(is.defined(), 'undefined is not defined');
  t.ok(is.defined(null), 'null is defined');
  t.ok(is.defined({}), 'object is defined');
  t.end();
});

test('is.empty', function (t) {
  t.ok(is.empty(''), 'empty string is empty');
  t.ok(is.empty(Object('')), 'empty String object is empty');
  t.ok(is.empty([]), 'empty array is empty');
  t.ok(is.empty({}), 'empty object is empty');
  t.ok(is.empty(null), 'null is empty');
  t.ok(is.empty(), 'undefined is empty');
  t.ok(is.empty(undefined), 'undefined is empty');
  t.ok(is.empty(false), 'false is empty');
  t.ok(is.empty(0), '0 is empty');
  t.ok(is.empty(NaN), 'nan is empty');
  (function () {
    t.ok(is.empty(arguments), 'empty arguments is empty');
  }());
  t.notOk(is.empty({ a: 1 }), 'nonempty object is not empty');
  t.notOk(is.empty(true), 'true is not empty');
  t.notOk(is.empty(/a/g), 'regex is not empty');
  t.notOk(is.empty(new Date()), 'date is not empty');
  t.end();
});

test('is.equal', function (t) {
  t.test('primitives', function (pt) {
    var primitives = [true, false, undefined, null, '', 'foo', 0, Infinity, -Infinity];
    pt.plan(primitives.length);
    for (var i = 0; i < primitives.length; ++i) {
      pt.ok(is.equal(primitives[i], primitives[i]), 'primitives are equal to themselves: ' + primitives[i]);
    }
    pt.end();
  });

  t.test('arrays', function (at) {
    at.ok(is.equal([1, 2, 3], [1, 2, 3]), 'arrays are shallowly equal');
    at.ok(is.equal([1, 2, [3, 4]], [1, 2, [3, 4]]), 'arrays are deep equal');
    at.notOk(is.equal([1, 2], [2, 3]), 'inequal arrays are not equal');
    at.notOk(is.equal([1, 2, 3], [2, 3]), 'inequal length arrays are not equal');

    var arr = [1, 2];
    at.ok(is.equal(arr, arr), 'array is equal to itself');

    at.end();
  });

  t.test('dates', function (dt) {
    dt.plan(2);
    var now = new Date();
    dt.ok(is.equal(now, new Date(now.getTime())), 'two equal date objects are equal');
    setTimeout(function () {
      dt.notOk(is.equal(now, new Date()), 'two inequal date objects are not equal');
      dt.end();
    }, 10);
  });

  t.test('plain objects', function (ot) {
    ot.ok(is.equal({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 }), 'objects are shallowly equal');
    ot.ok(is.equal({ a: { b: 1 } }, { a: { b: 1 } }), 'objects are deep equal');
    ot.notOk(is.equal({ a: 1 }, { a: 2 }), 'inequal objects are not equal');
    ot.end();
  });

  t.test('object instances', function (ot) {
    var F = function F() {
      this.foo = 'bar';
    };<commit_msg>Add tests for 2 is.equal bugs. Does not correctly check first element of array and Runs infinite loop on empty arrays.<commit_after>/* globals window, document, HTMLElement */

'use strict';

var test = require('tape');
var is = require('../index.js');

var forEach = require('foreach');
var toStr = Object.prototype.toString;

test('is.type', function (t) {
  var booleans = [true, false];
  forEach(booleans, function (boolean) {
    t.ok(is.type(boolean, 'boolean'), '"' + boolean + '" is a boolean');
  });

  var numbers = [1, 0 / 1, 0 / -1, NaN, Infinity, -Infinity];
  forEach(numbers, function (number) {
    t.ok(is.type(number, 'number'), '"' + number + '" is a number');
  });

  var objects = [{}, null, new Date()];
  forEach(objects, function (object) {
    t.ok(is.type(object, 'object'), '"' + object + '" is an object');
  });

  var strings = ['', 'abc'];
  forEach(strings, function (string) {
    t.ok(is.type(string, 'string'), '"' + string + '" is a string');
  });

  t.ok(is.type(undefined, 'undefined'), 'undefined is undefined');

  t.end();
});

test('is.undef', function (t) {
  t.ok(is.undef(), 'absent undefined is undefined');
  t.ok(is.undef(undefined), 'literal undefined is undefined');
  t.notOk(is.undef(null), 'null is not undefined');
  t.notOk(is.undef({}), 'object is not undefined');
  t.end();
});

test('is.defined', function (t) {
  t.notOk(is.defined(), 'undefined is not defined');
  t.ok(is.defined(null), 'null is defined');
  t.ok(is.defined({}), 'object is defined');
  t.end();
});

test('is.empty', function (t) {
  t.ok(is.empty(''), 'empty string is empty');
  t.ok(is.empty(Object('')), 'empty String object is empty');
  t.ok(is.empty([]), 'empty array is empty');
  t.ok(is.empty({}), 'empty object is empty');
  t.ok(is.empty(null), 'null is empty');
  t.ok(is.empty(), 'undefined is empty');
  t.ok(is.empty(undefined), 'undefined is empty');
  t.ok(is.empty(false), 'false is empty');
  t.ok(is.empty(0), '0 is empty');
  t.ok(is.empty(NaN), 'nan is empty');
  (function () {
    t.ok(is.empty(arguments), 'empty arguments is empty');
  }());
  t.notOk(is.empty({ a: 1 }), 'nonempty object is not empty');
  t.notOk(is.empty(true), 'true is not empty');
  t.notOk(is.empty(/a/g), 'regex is not empty');
  t.notOk(is.empty(new Date()), 'date is not empty');
  t.end();
});

test('is.equal', function (t) {
  t.test('primitives', function (pt) {
    var primitives = [true, false, undefined, null, '', 'foo', 0, Infinity, -Infinity];
    pt.plan(primitives.length);
    for (var i = 0; i < primitives.length; ++i) {
      pt.ok(is.equal(primitives[i], primitives[i]), 'primitives are equal to themselves: ' + primitives[i]);
    }
    pt.end();
  });

  t.test('arrays', function (at) {
    at.ok(is.equal([1, 2, 3], [1, 2, 3]), 'arrays are shallowly equal');
    at.ok(is.equal([1, 2, [3, 4]], [1, 2, [3, 4]]), 'arrays are deep equal');
    at.notOk(is.equal([1, 2, 3], [5, 2, 3]), 'inequal arrays are not equal');
    at.notOk(is.equal([1, 2], [2, 3]), 'inequal arrays are not equal');
    at.notOk(is.equal([1, 2, 3], [2, 3]), 'inequal length arrays are not equal');
    at.ok(is.equal([], []), 'empty arrays are equal');

    var arr = [1, 2];
    at.ok(is.equal(arr, arr), 'array is equal to itself');

    at.end();
  });

  t.test('dates', function (dt) {
    dt.plan(2);
    var now = new Date();
    dt.ok(is.equal(now, new Date(now.getTime())), 'two equal date objects are equal');
    setTimeout(function () {
      dt.notOk(is.equal(now, new Date()), 'two inequal date objects are not equal');
      dt.end();
    }, 10);
  });

  t.test('plain objects', function (ot) {
    ot.ok(is.equal({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 }), 'objects are shallowly equal');
    ot.ok(is.equal({ a: { b: 1 } }, { a: { b: 1 } }), 'objects are deep equal');
    ot.notOk(is.equal({ a: 1 }, { a: 2 }), 'inequal objects are not equal');
    ot.end();
  });

  t.test('object instances', function (ot) {
    var F = function F() {
      this.foo = 'bar';
    };
{'fraction_non_alphanumeric': 0.22274942292895614, 'fraction_numerical': 0.01320851500384714, 'mean_word_length': 3.526407428903076, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1401501', 'n_tokens_mistral': 2945, 'n_tokens_neox': 2831, 'n_words': 794}