"use strict";

var _locale = _interopRequireWildcard(require("../source/locale"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

describe('locale', function () {
  it("should tell if can use Intl for date formatting", function () {
    (0, _locale.intlDateTimeFormatSupportedLocale)('en').should.equal('en');
    (0, _locale.intlDateTimeFormatSupportedLocale)('en-XX').should.equal('en-XX');
    (0, _locale.intlDateTimeFormatSupportedLocale)(['en', 'ru']).should.equal('en');
  });
  it("should choose the most appropriate locale", function () {
    function arrayToObject(array) {
      return array.reduce(function (object, locale) {
        object[locale] = true;
        return object;
      }, {});
    }

    function choose(locale, locales) {
      var defaultLocale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'en';

      if (typeof locale === 'string') {
        locale = [locale];
      }

      locale = locale.concat(defaultLocale);
      return (0, _locale.default)(locale, function (_) {
        return locales.includes(_);
      });
    }

    choose('ru-RU', ['en', 'ru']).should.equal('ru');
    choose('en-GB', ['en', 'ru']).should.equal('en');
    choose('fr-FR', ['en', 'ru']).should.equal('en');
    choose(['fr-FR', 'de-DE'], ['en', 'ru']).should.equal('en');
    choose(['fr-FR', 'de-DE'], ['en', 'de']).should.equal('de');
    choose(['fr-FR', 'de-DE'], ['en', 'de', 'fr']).should.equal('fr');
    choose('fr-FR', ['en', 'fr-FR']).should.equal('fr-FR');
    expect(function () {
      return choose('fr-FR', ['de', 'ru']);
    }).to.throw('No locale data has been registered for any of the locales: fr-FR');
  });
});
//# sourceMappingURL=locale.test.js.map