diff options
author | Steven R. Loomis <srl@icu-project.org> | 2014-11-12 17:13:14 -0800 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2015-01-02 16:51:53 -0800 |
commit | a30839576c65b88e93bc915ae97b59874afde8ac (patch) | |
tree | b8fd3d787bf9d3e9204162551e51735d6c5262a1 /test | |
parent | 6a03fce16eaa4ec1085463d94734d40b370f3ea4 (diff) | |
download | node-new-a30839576c65b88e93bc915ae97b59874afde8ac.tar.gz |
build: i18n: add icu config options
Make "--with-intl=none" the default and add "intl-none" option to
vcbuild.bat.
If icu data is missing print a warning unless either --download=all or
--download=icu is set. If set then automatically download, verify (MD5)
and unpack the ICU data if not already available.
There's a "list" of URLs being used, but right now only the first is
picked up. The logic works something like this:
* If there is no directory deps/icu,
* If no zip file (currently icu4c-54_1-src.zip),
* Download zip file (icu-project.org -> sf.net)
* Verify the MD5 sum of the zipfile
* If bad, print error and exit
* Unpack the zipfile into deps/icu
* If deps/icu now exists, use it, else fail with help text
Add the configuration option "--with-icu-source=..."
Usage:
* --with-icu-source=/path/to/my/other/icu
* --with-icu-source=/path/to/icu54.zip
* --with-icu-source=/path/to/icu54.tgz
* --with-icu-source=http://example.com/icu54.tar.bz2
Add the configuration option "--with-icu-locals=...". Allows choosing
which locales are used in the "small-icu" case.
Example:
configure --with-intl=small-icu --with-icu-locales=tlh,grc,nl
(Also note that as of this writing, neither Klingon nor Ancient Greek
are in upstream CLDR data. Serving suggestion only.)
Don't use hard coded ../../out paths on windows. This was suggested by
@misterdjules as it causes test failures. With this fix, "out" is no
longer created on windows and the following can run properly:
python tools/test.py simple
Reduce space by about 1MB with ICU 54 (over without this patch). Also
trims a few other source files, but only conditional on the exact ICU
version used. This is to future-proof - a file that is unneeded now may
be needed in future ICUs.
Also:
* Update distclean to remove icu related files
* Refactor some code into tools/configure.d/nodedownload.py
* Update docs
* Add test
PR-URL: https://github.com/joyent/node/pull/8719
Fixes: https://github.com/joyent/node/issues/7676#issuecomment-64704230
[trev.norris@gmail.com small change to test's whitespace and logic]
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/simple/test-intl.js | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/test/simple/test-intl.js b/test/simple/test-intl.js new file mode 100644 index 0000000000..841239a8d9 --- /dev/null +++ b/test/simple/test-intl.js @@ -0,0 +1,103 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var common = require('../common'); +var assert = require('assert'); + +// does node think that i18n was enabled? +var enablei18n = process.config.variables.v8_enable_i18n_support; +if (enablei18n === undefined) { + enablei18n = false; +} + +// is the Intl object present? +var haveIntl = (global.Intl != undefined); + +// Returns true if no specific locale ids were configured (i.e. "all") +// Else, returns true if loc is in the configured list +// Else, returns false +function haveLocale(loc) { + var locs = process.config.variables.icu_locales.split(','); + return locs.indexOf(loc) !== -1; +} + +if (!haveIntl) { + var erMsg = + '"Intl" object is NOT present but v8_enable_i18n_support is ' + + enablei18n; + assert.equal(enablei18n, false, erMsg); + console.log('Skipping Intl tests because Intl object not present.'); + +} else { + var erMsg = + '"Intl" object is present but v8_enable_i18n_support is ' + + enablei18n + + '. Is this test out of date?'; + assert.equal(enablei18n, true, erMsg); + + // Construct a new date at the beginning of Unix time + var date0 = new Date(0); + + // Use the GMT time zone + var GMT = 'Etc/GMT'; + + // Construct an English formatter. Should format to "Jan 70" + var dtf = + new Intl.DateTimeFormat(['en'], + {timeZone: GMT, month: 'short', year: '2-digit'}); + + // If list is specified and doesn't contain 'en' then return. + if (process.config.variables.icu_locales && !haveLocale('en')) { + console.log('Skipping detailed Intl tests because English is not listed ' + + 'as supported.'); + // Smoke test. Does it format anything, or fail? + console.log('Date(0) formatted to: ' + dtf.format(date0)); + return; + } + + // Check with toLocaleString + var localeString = dtf.format(date0); + assert.equal(localeString, 'Jan 70'); + + // Options to request GMT + var optsGMT = {timeZone: GMT}; + + // Test format + localeString = date0.toLocaleString(['en'], optsGMT); + assert.equal(localeString, '1/1/1970, 12:00:00 AM'); + + // number format + assert.equal(new Intl.NumberFormat(['en']).format(12345.67890), '12,345.679'); + + var collOpts = { sensitivity: 'base', ignorePunctuation: true }; + var coll = new Intl.Collator(['en'], collOpts); + + assert.equal(coll.compare('blackbird', 'black-bird'), 0, + 'ignore punctuation failed'); + assert.equal(coll.compare('blackbird', 'red-bird'), -1, + 'compare less failed'); + assert.equal(coll.compare('bluebird', 'blackbird'), 1, + 'compare greater failed'); + assert.equal(coll.compare('Bluebird', 'bluebird'), 0, + 'ignore case failed'); + assert.equal(coll.compare('\ufb03', 'ffi'), 0, + 'ffi ligature (contraction) failed'); +} |