Browse Source

test: cleanup test-intl.js

Improved variables to be all const.
Enforced assert.strictEqual across all tests.
Modified haveIntl tests to check for int.
Fixed alignment.

PR-URL: https://github.com/nodejs/node/pull/8641
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
v7.x
Alessandro Metta 8 years ago
committed by Ilkka Myller
parent
commit
2eb3fa14f8
  1. 63
      test/parallel/test-intl.js

63
test/parallel/test-intl.js

@ -1,21 +1,21 @@
'use strict'; 'use strict';
const common = require('../common'); const common = require('../common');
var assert = require('assert'); const assert = require('assert');
// does node think that i18n was enabled? // does node think that i18n was enabled?
var enablei18n = process.config.variables.v8_enable_i18n_support; let enablei18n = process.config.variables.v8_enable_i18n_support;
if (enablei18n === undefined) { if (enablei18n === undefined) {
enablei18n = false; enablei18n = 0;
} }
// is the Intl object present? // is the Intl object present?
var haveIntl = (global.Intl != undefined); const haveIntl = (global.Intl !== undefined);
// Returns true if no specific locale ids were configured (i.e. "all") // Returns true if no specific locale ids were configured (i.e. "all")
// Else, returns true if loc is in the configured list // Else, returns true if loc is in the configured list
// Else, returns false // Else, returns false
function haveLocale(loc) { function haveLocale(loc) {
var locs = process.config.variables.icu_locales.split(','); const locs = process.config.variables.icu_locales.split(',');
return locs.indexOf(loc) !== -1; return locs.indexOf(loc) !== -1;
} }
@ -23,7 +23,7 @@ if (!haveIntl) {
const erMsg = const erMsg =
'"Intl" object is NOT present but v8_enable_i18n_support is ' + '"Intl" object is NOT present but v8_enable_i18n_support is ' +
enablei18n; enablei18n;
assert.equal(enablei18n, false, erMsg); assert.strictEqual(enablei18n, 0, erMsg);
common.skip('Intl tests because Intl object not present.'); common.skip('Intl tests because Intl object not present.');
} else { } else {
@ -31,16 +31,16 @@ if (!haveIntl) {
'"Intl" object is present but v8_enable_i18n_support is ' + '"Intl" object is present but v8_enable_i18n_support is ' +
enablei18n + enablei18n +
'. Is this test out of date?'; '. Is this test out of date?';
assert.equal(enablei18n, true, erMsg); assert.strictEqual(enablei18n, 1, erMsg);
// Construct a new date at the beginning of Unix time // Construct a new date at the beginning of Unix time
var date0 = new Date(0); const date0 = new Date(0);
// Use the GMT time zone // Use the GMT time zone
var GMT = 'Etc/GMT'; const GMT = 'Etc/GMT';
// Construct an English formatter. Should format to "Jan 70" // Construct an English formatter. Should format to "Jan 70"
var dtf = const dtf =
new Intl.DateTimeFormat(['en'], new Intl.DateTimeFormat(['en'],
{timeZone: GMT, month: 'short', year: '2-digit'}); {timeZone: GMT, month: 'short', year: '2-digit'});
@ -54,30 +54,33 @@ if (!haveIntl) {
} }
// Check with toLocaleString // Check with toLocaleString
var localeString = dtf.format(date0); {
assert.equal(localeString, 'Jan 70'); const localeString = dtf.format(date0);
assert.strictEqual(localeString, 'Jan 70');
}
// Options to request GMT // Options to request GMT
var optsGMT = {timeZone: GMT}; const optsGMT = {timeZone: GMT};
// Test format // Test format
localeString = date0.toLocaleString(['en'], optsGMT); {
assert.equal(localeString, '1/1/1970, 12:00:00 AM'); const localeString = date0.toLocaleString(['en'], optsGMT);
assert.strictEqual(localeString, '1/1/1970, 12:00:00 AM');
}
// number format // number format
assert.equal(new Intl.NumberFormat(['en']).format(12345.67890), '12,345.679'); const numberFormat = new Intl.NumberFormat(['en']).format(12345.67890);
assert.strictEqual(numberFormat, '12,345.679');
var collOpts = { sensitivity: 'base', ignorePunctuation: true }; const collOpts = { sensitivity: 'base', ignorePunctuation: true };
var coll = new Intl.Collator(['en'], collOpts); const coll = new Intl.Collator(['en'], collOpts);
assert.equal(coll.compare('blackbird', 'black-bird'), 0, assert.strictEqual(coll.compare('blackbird', 'black-bird'), 0,
'ignore punctuation failed'); 'ignore punctuation failed');
assert.equal(coll.compare('blackbird', 'red-bird'), -1, assert.strictEqual(coll.compare('blackbird', 'red-bird'), -1,
'compare less failed'); 'compare less failed');
assert.equal(coll.compare('bluebird', 'blackbird'), 1, assert.strictEqual(coll.compare('bluebird', 'blackbird'), 1,
'compare greater failed'); 'compare greater failed');
assert.equal(coll.compare('Bluebird', 'bluebird'), 0, assert.strictEqual(coll.compare('Bluebird', 'bluebird'), 0,
'ignore case failed'); 'ignore case failed');
assert.equal(coll.compare('\ufb03', 'ffi'), 0, assert.strictEqual(coll.compare('\ufb03', 'ffi'), 0,
'ffi ligature (contraction) failed'); 'ffi ligature (contraction) failed');
} }

Loading…
Cancel
Save