<commit_before>/*
 * testglobal.js - test the ilib static routines
 * 
 * Copyright © 2012-2015,2017, JEDLSoft
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

if (typeof(ilib) === "undefined") {
    var ilib = require("../.././../lib/ilib.js");
}
if (typeof(Locale) === "undefined") {
    var Locale = require("../.././../lib/Locale.js");
}

module.exports.testglobal = {
    setUp: function(callback) {
        ilib.clearCache();
        callback();
    },

    testNoStubsInModular: function(test) {
        test.expect(55);
        // make sure we don't have stubs defined in the modular tests
        test.ok(typeof(ilib.CType) === "undefined");
        test.ok(typeof(ilib._roundFnc) === "undefined");
        test.ok(typeof(ilib.Date) === "undefined");
        test.ok(typeof(ilib.Cal) === "undefined");
        test.ok(typeof(ilib.Measurement) === "undefined");
        test.ok(typeof(ilib.shallowCopy) === "undefined");
        test.ok(typeof(ilib.deepCopy) === "undefined");
        test.ok(typeof(ilib.mapString) === "undefined");
        test.ok(typeof(ilib.indexOf) === "undefined");
        test.ok(typeof(ilib.toHexString) === "undefined");
        test.ok(typeof(ilib.isDate) === "undefined");
        test.ok(typeof(ilib.merge) === "undefined");
        test.ok(typeof(ilib.isEmpty) === "undefined");
        test.ok(typeof(ilib.hashCode) === "undefined");
        test.ok(typeof(ilib.Locale) === "undefined");
        test.ok(typeof(ilib.mergeLocData) === "undefined");
        test.ok(typeof(ilib.getLocFiles) === "undefined");
        test.ok(typeof(ilib.loadData) === "undefined");
        test.ok(typeof(ilib.LocaleInfo) === "undefined");
        test.ok(typeof(ilib.signum) === "undefined");
        test.ok(typeof(ilib.mod) === "undefined");
        test.ok(typeof(ilib.amod) === "undefined");
        test.ok(typeof(ilib.String) === "undefined");
        test.ok(typeof(ilib.JulianDay) === "undefined");
        test.ok(typeof(ilib.TimeZone) === "undefined");
        test.ok(typeof(ilib.bsearch) === "undefined");
        test.ok(typeof(ilib.bisectionSearch) === "undefined");
        test.ok(typeof(ilib.ResBundle) === "undefined");
        test.ok(typeof(ilib.DateFmt) === "undefined");
        test.ok(typeof(ilib.DateRngFmt) === "undefined");
        test.ok(typeof(ilib.Currency) === "undefined");
        test.ok(typeof(ilib.Number) === "undefined");
        test.ok(typeof(ilib.NumFmt) === "undefined");
        test.ok(typeof(ilib.DurFmt) === "undefined");
        test.ok(typeof(ilib.ScriptInfo) === "undefined");
        test.ok(typeof(ilib.Name) === "undefined");
        test.ok(typeof(ilib.NameFmt) === "undefined");
        test.ok(typeof(ilib.Address) === "undefined");
        test.ok(typeof(ilib.AddressFmt) === "undefined");
        test.ok(typeof(ilib.GlyphString) === "undefined");
        test.ok(typeof(ilib.NormString) === "undefined");
        test.ok(typeof(ilib.CodePointSource) === "undefined");
        test.ok(typeof(ilib.ElementIterator) === "undefined");
        test.ok(typeof(ilib.Collator) === "undefined");
        test.ok(typeof(ilib.LocaleMatcher) === "undefined");
        test.ok(typeof(ilib.CaseMapper) === "undefined");
        test.ok(typeof(ilib.NumPlan) === "undefined");
        test.ok(typeof(ilib.PhoneLoc) === "undefined");
        test.ok(typeof(ilib.StateHandler) === "undefined");
        test.ok(typeof(ilib._handlerFactory) === "undefined");
        test.ok(typeof(ilib.PhoneNumber) === "undefined");
        test.ok(typeof(ilib.PhoneFmt) === "undefined");
        test.ok(typeof(ilib.GeoLocator) === "undefined");
        test.ok(typeof(ilib.Measurement) === "undefined");
        test.ok(typeof(ilib.UnitFmt) === "undefined");
        test.done();
    },
    
    testGetLocaleDefault: function(test) {
        test.expect(1);
        test.equal(ilib.getLocale(), "en-US");
        test.done();
    },
    
    testSetLocale: function(test) {
        test.expect(2);
        test.equal(ilib.getLocale(), "en-US");
        
        ilib.setLocale("it-IT");
        
        test.equal(ilib.getLocale(), "it-IT");
        test.done();
        delete ilib.locale; // clean up
    },
    
    testSetLocaleObject: function(test) {
        test.expect(2);
        test.equal(ilib.getLocale(), "en-US");
        
        ilib.setLocale(new Locale("it-IT"));
    
        // do not change the locale if the arg is not a string
        test.equal(ilib.getLocale(), "en-US");
        test.done();
    },
    
    testSetLocaleEmpty: function(test) {
        test.expect(2);
        test.equal(ilib.getLocale(), "en-US");
        
        ilib.setLocale();
        
        test.equal(ilib.getLocale(), "en-US");
        test.done();
    },
    
    testGetVersion: function(test) {
        test.expect(1);
        test.equal(ilib.getVersion().substring(0,4), "13.3");
        test.done();
    },
    
    testGetTimeZoneDefault: function(test) {
        // use a different test when the Intl object is available
        if (ilib._global("Intl")) {
            test.done();
            return;
        }

        test.expect(1);
        ilib._platform = undefined;
        ilib.tz = undefined;

        if (ilib._getPlatform() === "nodejs") {
            process.env.TZ = "";
        }

        if (ilib._getPlatform() === "browser") {
            navigator.timezone = undefined;
        }
        test.equal(ilib.getTimeZone(), "local");
        test.done();
    },

    testGetTimeZoneDefaultWithIntl: function(test) {
        // only test when the Intl object is available
        if (!ilib._global("Intl")) {
            test.done();
            return;
        }

        test.expect(2);

        var ro = new Intl.DateTimeFormat().resolvedOptions();
        var expected = ro && ro.timeZone;
        test.ok(expected);
        test.equal(ilib.getTimeZone(), expected);
        test.done();
    },

    testSetTimeZone: function(test) {
        // use a different test when the Intl object is available
        if (ilib._global("Intl")) {
            test.done();
            return;
        }

        test.expect(2);
        ilib._platform = undefined;
        ilib.tz = undefined;
        test.equal(ilib.getTimeZone(), "local");

        ilib.setTimeZone("America/Los_Angeles");

        test.equal(ilib.getTimeZone(), "America/Los_Angeles");<commit_msg>Test if the Intl object is acting properly<commit_after>/*
 * testglobal.js - test the ilib static routines
 * 
 * Copyright © 2012-2015,2017, JEDLSoft
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

if (typeof(ilib) === "undefined") {
    var ilib = require("../.././../lib/ilib.js");
}
if (typeof(Locale) === "undefined") {
    var Locale = require("../.././../lib/Locale.js");
}

module.exports.testglobal = {
    setUp: function(callback) {
        ilib.clearCache();
        callback();
    },

    testNoStubsInModular: function(test) {
        test.expect(55);
        // make sure we don't have stubs defined in the modular tests
        test.ok(typeof(ilib.CType) === "undefined");
        test.ok(typeof(ilib._roundFnc) === "undefined");
        test.ok(typeof(ilib.Date) === "undefined");
        test.ok(typeof(ilib.Cal) === "undefined");
        test.ok(typeof(ilib.Measurement) === "undefined");
        test.ok(typeof(ilib.shallowCopy) === "undefined");
        test.ok(typeof(ilib.deepCopy) === "undefined");
        test.ok(typeof(ilib.mapString) === "undefined");
        test.ok(typeof(ilib.indexOf) === "undefined");
        test.ok(typeof(ilib.toHexString) === "undefined");
        test.ok(typeof(ilib.isDate) === "undefined");
        test.ok(typeof(ilib.merge) === "undefined");
        test.ok(typeof(ilib.isEmpty) === "undefined");
        test.ok(typeof(ilib.hashCode) === "undefined");
        test.ok(typeof(ilib.Locale) === "undefined");
        test.ok(typeof(ilib.mergeLocData) === "undefined");
        test.ok(typeof(ilib.getLocFiles) === "undefined");
        test.ok(typeof(ilib.loadData) === "undefined");
        test.ok(typeof(ilib.LocaleInfo) === "undefined");
        test.ok(typeof(ilib.signum) === "undefined");
        test.ok(typeof(ilib.mod) === "undefined");
        test.ok(typeof(ilib.amod) === "undefined");
        test.ok(typeof(ilib.String) === "undefined");
        test.ok(typeof(ilib.JulianDay) === "undefined");
        test.ok(typeof(ilib.TimeZone) === "undefined");
        test.ok(typeof(ilib.bsearch) === "undefined");
        test.ok(typeof(ilib.bisectionSearch) === "undefined");
        test.ok(typeof(ilib.ResBundle) === "undefined");
        test.ok(typeof(ilib.DateFmt) === "undefined");
        test.ok(typeof(ilib.DateRngFmt) === "undefined");
        test.ok(typeof(ilib.Currency) === "undefined");
        test.ok(typeof(ilib.Number) === "undefined");
        test.ok(typeof(ilib.NumFmt) === "undefined");
        test.ok(typeof(ilib.DurFmt) === "undefined");
        test.ok(typeof(ilib.ScriptInfo) === "undefined");
        test.ok(typeof(ilib.Name) === "undefined");
        test.ok(typeof(ilib.NameFmt) === "undefined");
        test.ok(typeof(ilib.Address) === "undefined");
        test.ok(typeof(ilib.AddressFmt) === "undefined");
        test.ok(typeof(ilib.GlyphString) === "undefined");
        test.ok(typeof(ilib.NormString) === "undefined");
        test.ok(typeof(ilib.CodePointSource) === "undefined");
        test.ok(typeof(ilib.ElementIterator) === "undefined");
        test.ok(typeof(ilib.Collator) === "undefined");
        test.ok(typeof(ilib.LocaleMatcher) === "undefined");
        test.ok(typeof(ilib.CaseMapper) === "undefined");
        test.ok(typeof(ilib.NumPlan) === "undefined");
        test.ok(typeof(ilib.PhoneLoc) === "undefined");
        test.ok(typeof(ilib.StateHandler) === "undefined");
        test.ok(typeof(ilib._handlerFactory) === "undefined");
        test.ok(typeof(ilib.PhoneNumber) === "undefined");
        test.ok(typeof(ilib.PhoneFmt) === "undefined");
        test.ok(typeof(ilib.GeoLocator) === "undefined");
        test.ok(typeof(ilib.Measurement) === "undefined");
        test.ok(typeof(ilib.UnitFmt) === "undefined");
        test.done();
    },
    
    testGetLocaleDefault: function(test) {
        test.expect(1);
        test.equal(ilib.getLocale(), "en-US");
        test.done();
    },
    
    testSetLocale: function(test) {
        test.expect(2);
        test.equal(ilib.getLocale(), "en-US");
        
        ilib.setLocale("it-IT");
        
        test.equal(ilib.getLocale(), "it-IT");
        test.done();
        delete ilib.locale; // clean up
    },
    
    testSetLocaleObject: function(test) {
        test.expect(2);
        test.equal(ilib.getLocale(), "en-US");
        
        ilib.setLocale(new Locale("it-IT"));
    
        // do not change the locale if the arg is not a string
        test.equal(ilib.getLocale(), "en-US");
        test.done();
    },
    
    testSetLocaleEmpty: function(test) {
        test.expect(2);
        test.equal(ilib.getLocale(), "en-US");
        
        ilib.setLocale();
        
        test.equal(ilib.getLocale(), "en-US");
        test.done();
    },
    
    testGetVersion: function(test) {
        test.expect(1);
        test.equal(ilib.getVersion().substring(0,4), "13.3");
        test.done();
    },
    
    testGetTimeZoneDefault: function(test) {
        // use a different test when the Intl object is available
        if (ilib._global("Intl")) {
            test.done();
            return;
        }

        test.expect(1);
        ilib._platform = undefined;
        ilib.tz = undefined;

        if (ilib._getPlatform() === "nodejs") {
            process.env.TZ = "";
        }

        if (ilib._getPlatform() === "browser") {
            navigator.timezone = undefined;
        }
        test.equal(ilib.getTimeZone(), "local");
        test.done();
    },

    testGetTimeZoneDefaultWithIntl: function(test) {
        // only test when the Intl object is available
        if (!ilib._global("Intl")) {
            test.done();
            return;
        }

        var ro = new Intl.DateTimeFormat().resolvedOptions();
        var expected = ro && ro.timeZone;
        if (expected) {
            test.expect(1);
            test.equal(ilib.getTimeZone(), expected);
        }
        test.done();
    },

    testSetTimeZone: function(test) {
        // use a different test when the Intl object is available
        if (ilib._global("Intl")) {
            test.done();
            return;
        }

        test.expect(2);
        ilib._platform = undefined;
        ilib.tz = undefined;
        test.equal(ilib.getTimeZone(), "local");

        ilib.setTimeZone("America/Los_Angeles");

        test.equal(ilib.getTimeZone(), "America/Los_Angeles");
{'fraction_non_alphanumeric': 0.1728628592215351, 'fraction_numerical': 0.004510731174972717, 'mean_word_length': 2.507527430466956, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5306546', 'n_tokens_mistral': 4132, 'n_tokens_neox': 4054, 'n_words': 753}