<commit_before>'use strict';

const Buffer = require('buffer').Buffer;
const expect = require('chai').expect;
const BSON = require('../../lib/bson');
const Code = BSON.Code;
const BSONRegExp = BSON.BSONRegExp;
const Binary = BSON.Binary;
const Timestamp = BSON.Timestamp;
const Long = BSON.Long;
const ObjectId = BSON.ObjectId;
const BSONSymbol = BSON.BSONSymbol;
const DBRef = BSON.DBRef;
const Decimal128 = BSON.Decimal128;
const Int32 = BSON.Int32;
const Double = BSON.Double;
const MinKey = BSON.MinKey;
const MaxKey = BSON.MaxKey;
const BinaryParser = require('../binary_parser').BinaryParser;
const vm = require('vm');
const assertBuffersEqual = require('./tools/utils').assertBuffersEqual;

// for tests
BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0;
BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1;
BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
BSON.BSON_BINARY_SUBTYPE_UUID = 3;
BSON.BSON_BINARY_SUBTYPE_MD5 = 4;
BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128;

BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0;
BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1;
BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
BSON.BSON_BINARY_SUBTYPE_UUID = 3;
BSON.BSON_BINARY_SUBTYPE_MD5 = 4;
BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128;

/**
 * Module for parsing an ISO 8601 formatted string into a Date object.
 */
var ISODate = function(string) {
  var match;

  if (typeof string.getTime === 'function') return string;
  else if (
    (match = string.match(
      /^(\d{4})(-(\d{2})(-(\d{2})(T(\d{2}):(\d{2})(:(\d{2})(\.(\d+))?)?(Z|((\+|-)(\d{2}):(\d{2}))))?)?)?$/
    ))
  ) {
    var date = new Date();
    date.setUTCFullYear(Number(match[1]));
    date.setUTCMonth(Number(match[3]) - 1 || 0);
    date.setUTCDate(Number(match[5]) || 0);
    date.setUTCHours(Number(match[7]) || 0);
    date.setUTCMinutes(Number(match[8]) || 0);
    date.setUTCSeconds(Number(match[10]) || 0);
    date.setUTCMilliseconds(Number('.' + match[12]) * 1000 || 0);

    if (match[13] && match[13] !== 'Z') {
      var h = Number(match[16]) || 0,
        m = Number(match[17]) || 0;

      h *= 3600000;
      m *= 60000;

      var offset = h + m;
      if (match[15] === '+') offset = -offset;

      date = new Date(date.valueOf() + offset);
    }

    return date;
  } else throw new Error('Invalid ISO 8601 date given.', __filename);
};

describe('BSON', function() {
  /**
   * @ignore
   */
  it('Should Correctly convert ObjectId to itself', function(done) {
    var myObject, newObject;
    var selfConvertion = function() {
      myObject = new ObjectId();
      newObject = ObjectId(myObject);
    };

    expect(selfConvertion).to.not.throw;
    expect(myObject).to.equal(newObject);
    done();
  });
<commit_msg>test(bson): remove reference to `__filename`<commit_after>'use strict';

const Buffer = require('buffer').Buffer;
const expect = require('chai').expect;
const BSON = require('../../lib/bson');
const Code = BSON.Code;
const BSONRegExp = BSON.BSONRegExp;
const Binary = BSON.Binary;
const Timestamp = BSON.Timestamp;
const Long = BSON.Long;
const ObjectId = BSON.ObjectId;
const BSONSymbol = BSON.BSONSymbol;
const DBRef = BSON.DBRef;
const Decimal128 = BSON.Decimal128;
const Int32 = BSON.Int32;
const Double = BSON.Double;
const MinKey = BSON.MinKey;
const MaxKey = BSON.MaxKey;
const BinaryParser = require('../binary_parser').BinaryParser;
const vm = require('vm');
const assertBuffersEqual = require('./tools/utils').assertBuffersEqual;

// for tests
BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0;
BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1;
BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
BSON.BSON_BINARY_SUBTYPE_UUID = 3;
BSON.BSON_BINARY_SUBTYPE_MD5 = 4;
BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128;

BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0;
BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1;
BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
BSON.BSON_BINARY_SUBTYPE_UUID = 3;
BSON.BSON_BINARY_SUBTYPE_MD5 = 4;
BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128;

/**
 * Module for parsing an ISO 8601 formatted string into a Date object.
 */
const ISO_REGEX = /^(\d{4})(-(\d{2})(-(\d{2})(T(\d{2}):(\d{2})(:(\d{2})(\.(\d+))?)?(Z|((\+|-)(\d{2}):(\d{2}))))?)?)?$/;
var ISODate = function(string) {
  if (typeof string.getTime === 'function') {
    return string;
  }

  const match = string.match(ISO_REGEX);
  if (!match) {
    throw new Error(`Invalid ISO 8601 date given: ${string}`);
  }

  var date = new Date();
  date.setUTCFullYear(Number(match[1]));
  date.setUTCMonth(Number(match[3]) - 1 || 0);
  date.setUTCDate(Number(match[5]) || 0);
  date.setUTCHours(Number(match[7]) || 0);
  date.setUTCMinutes(Number(match[8]) || 0);
  date.setUTCSeconds(Number(match[10]) || 0);
  date.setUTCMilliseconds(Number('.' + match[12]) * 1000 || 0);

  if (match[13] && match[13] !== 'Z') {
    var h = Number(match[16]) || 0,
      m = Number(match[17]) || 0;

    h *= 3600000;
    m *= 60000;

    var offset = h + m;
    if (match[15] === '+') offset = -offset;

    date = new Date(date.valueOf() + offset);
  }

  return date;
};

describe('BSON', function() {
  /**
   * @ignore
   */
  it('Should Correctly convert ObjectId to itself', function(done) {
    var myObject, newObject;
    var selfConvertion = function() {
      myObject = new ObjectId();
      newObject = ObjectId(myObject);
    };

    expect(selfConvertion).to.not.throw;
    expect(myObject).to.equal(newObject);
    done();
  });

{'fraction_non_alphanumeric': 0.17256970610399397, 'fraction_numerical': 0.033157498116051246, 'mean_word_length': 4.1195756991321115, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2846214', 'n_tokens_mistral': 2120, 'n_tokens_neox': 1975, 'n_words': 394}