<commit_before>var chai = require('chai');
var expect = chai.expect;
var should = chai.should();

var _ = require('../src/util/core.js');


describe('core', function () {

  describe('exception', function () {

    it('should be inheritable', function () {
      var TestError = _.NoPicAdsError.extend({
        name: 'TestError',
        constructor: function (msg) {
          TestError.super.constructor.apply(this, arguments);
        },
      });
      var e = new TestError('test');
      e.name.should.equals('TestError');
      e.message.should.equals('test');
      Object.getPrototypeOf(e).should.equals(TestError.prototype);
      e.constructor.should.equals(TestError);
      TestError.super.should.equals(_.NoPicAdsError.prototype);
      TestError.super.constructor.should.equals(_.NoPicAdsError);
    });

  });

  describe('partial', function () {

    it('should takes function as first parameter', function () {
      _.P.should.throw(_.NoPicAdsError);
      (function () {
        _.P(0);
      }).should.throw(_.NoPicAdsError);
    });

    it('should returns a function', function () {
      _.P(function () {
      }).should.be.a('function');
    });

    it('should receives arguments', function () {
      var p = _.P(function (a, b, c) {
        a.should.equals(1);
        b.should.equals(2);
        c.should.equals(3);
      }, 1, 2);
      p(3);
    });

    it('should returns correct value', function () {
      var p = _.P(function () {
        return '__MAGIC__';
      });
      p().should.equals('__MAGIC__');
    });

  });

  describe('template', function () {

    it('should be a function', function () {
      var tpl = _.T('');
      tpl.should.be.a('function');
    });

    it('should takes exactly one string', function () {
      _.T.should.throw(_.NoPicAdsError);
      _.P(_.T, 0).should.throw(_.NoPicAdsError);
    });

    it('should works with index', function () {
      var tpl = _.T('a {0} c {1} e');
      tpl('b', 'd').should.equals('a b c d e');
    });

    it('should works with key', function () {
      var tpl = _.T('a {b} c {d} e');
      tpl({<commit_msg>Add test cases.<commit_after>var chai = require('chai');
var expect = chai.expect;
var should = chai.should();

var _ = require('../src/util/core.js');


describe('core', function () {

  describe('exception', function () {

    it('should be inheritable', function () {
      var TestError = _.NoPicAdsError.extend({
        name: 'TestError',
        constructor: function (msg) {
          TestError.super.constructor.apply(this, arguments);
        },
      });
      var e = new TestError('test');
      e.name.should.equals('TestError');
      e.message.should.equals('test');
      Object.getPrototypeOf(e).should.equals(TestError.prototype);
      e.constructor.should.equals(TestError);
      TestError.super.should.equals(_.NoPicAdsError.prototype);
      TestError.super.constructor.should.equals(_.NoPicAdsError);
    });

  });

  describe('partial', function () {

    it('should takes function as first parameter', function () {
      _.P.should.throw(_.NoPicAdsError);
      (function () {
        _.P(0);
      }).should.throw(_.NoPicAdsError);
    });

    it('should returns a function', function () {
      _.P(function () {
      }).should.be.a('function');
    });

    it('should receives arguments', function () {
      var p = _.P(function (a, b, c) {
        a.should.equals(1);
        b.should.equals(2);
        c.should.equals(3);
      }, 1, 2);
      p(3);
    });

    it('should returns correct value', function () {
      var p = _.P(function () {
        return '__MAGIC__';
      });
      p().should.equals('__MAGIC__');
    });

  });

  describe('template', function () {

    it('should be a function', function () {
      var tpl = _.T('');
      tpl.should.be.a('function');
    });

    it('should takes exactly one string', function () {
      _.T.should.throw(_.NoPicAdsError);

      (function (){
        _.T(0);
      }).should.throw(_.NoPicAdsError);

      (function (){
        _.T('');
      }).should.not.throw(_.NoPicAdsError);

      (function (){
        var s = new String();
        _.T(s);
      }).should.not.throw(_.NoPicAdsError);
    });

    it('should return original string if no keyword', function () {
      var s = 'input';
      _.T(s)('dummy', 'parameter').should.equals(s);
    });

    it('should escape double brackets', function () {
      var s = '{{}}';
      _.T(s)().should.equals('{}');
    });

    it('should works with index', function () {
      var tpl = _.T('a {0} c {1} e');
      tpl('b', 'd').should.equals('a b c d e');
    });

    it('should works with key', function () {
      var tpl = _.T('a {b} c {d} e');
      tpl({
{'fraction_non_alphanumeric': 0.18698499894358758, 'fraction_numerical': 0.0042256496936403974, 'mean_word_length': 2.4131218457101657, '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': '2586576', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1496, 'n_words': 307}