<commit_before>'use strict';

var test = require('prova')
  , lib = require('../index.js')
  , sinon = require('sinon')

test('#calc', function calcTest(t){
  t.plan(1)

  t.equal(
    typeof lib.calc()
    , 'string'
    , 'returns a string'
  )
})

test('#setWhitelist', function setWhitelistTest(t){
  t.plan(2)

  lib.setWhitelist()
  t.equal(
    lib.internals.whitelist
    , lib.internals.defaultTimezoneWhiteList
    , 'returns the default list if no arguments are passed'
  )

  t.throws(
    lib.setWhitelist.bind(lib, 1)
    , 'throws if a non-array is passed'
  )

})

test('#internals.getFromIntl', function getFromIntlTest(t){
  var aTimezone = 'mytimezone'

  t.plan(2)

  global.Intl = {
    DateTimeFormat: function DateTimeFormat(){
      return {}
    }
  }

  t.equal(
    lib.internals.getFromIntl()
    , undefined
    , 'returns undefined if Intl.DateTimeFormat does not return `resolvedOptions`'
  )

  global.Intl = {
    DateTimeFormat: function DateTimeFormat(){
      return {
        resolvedOptions: function resolvedOptions(){
          return {
            timeZone: aTimezone
          }
        }
      }
    }
  }

  t.equal(
    lib.internals.getFromIntl()
    , aTimezone
    , 'returns a string if Intl is defined'
  )

  delete global.Intl
})

test('#internals.getFromMoment', function getFromMomentTest(t){
  t.plan(1)

  var getCurrentOffset = sinon.stub(lib.internals, 'getCurrentOffset').returns(640)<commit_msg>Don’t run fallback Intl tests if Intl is present<commit_after>'use strict';

var test = require('prova')
  , lib = require('../index.js')
  , sinon = require('sinon')

test('#calc', function calcTest(t){
  t.plan(1)

  t.equal(
    typeof lib.calc()
    , 'string'
    , 'returns a string'
  )
})

test('#setWhitelist', function setWhitelistTest(t){
  t.plan(2)

  lib.setWhitelist()
  t.equal(
    lib.internals.whitelist
    , lib.internals.defaultTimezoneWhiteList
    , 'returns the default list if no arguments are passed'
  )

  t.throws(
    lib.setWhitelist.bind(lib, 1)
    , 'throws if a non-array is passed'
  )

})

test('#internals.getFromIntl', function getFromIntlTest(t){
  var aTimezone = 'mytimezone'

  if (!Intl){
    t.plan(2)
    global.Intl = {
      DateTimeFormat: function DateTimeFormat(){
        return {}
      }
    }

    t.equal(
      lib.internals.getFromIntl()
      , undefined
      , 'returns undefined if Intl.DateTimeFormat does not return `resolvedOptions`'
    )

    global.Intl = {
      DateTimeFormat: function DateTimeFormat(){
        return {
          resolvedOptions: function resolvedOptions(){
            return {
              timeZone: aTimezone
            }
          }
        }
      }
    }
  }
  else {
    t.plan(1)
  }

  t.equal(
    lib.internals.getFromIntl()
    , aTimezone
    , 'returns a string if Intl is defined'
  )

  if (!Intl) delete global.Intl
})

test('#internals.getFromMoment', function getFromMomentTest(t){
  t.plan(1)

  var getCurrentOffset = sinon.stub(lib.internals, 'getCurrentOffset').returns(640)
{'fraction_non_alphanumeric': 0.12746386333771353, 'fraction_numerical': 0.005584756898817346, 'mean_word_length': 2.704379562043796, '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': '7077246', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1020, 'n_words': 213}