|
|
4c30b8 |
// Copyright (C) 2014 IBM Corporation and Others. All Rights Reserved.
|
|
|
4c30b8 |
// This file is part of the Node.JS ICU enablement work
|
|
|
4c30b8 |
// https://github.com/joyent/node/pull/7719
|
|
|
4c30b8 |
// and is under the same license.
|
|
|
4c30b8 |
//
|
|
|
4c30b8 |
// This is a very, very, very basic test of es402
|
|
|
4c30b8 |
//
|
|
|
4c30b8 |
// URL: https://github.com/srl295/btest402
|
|
|
4c30b8 |
// Author: Steven R. Loomis <srl@icu-project.org>
|
|
|
4c30b8 |
//
|
|
|
4c30b8 |
// for a complete test, see http://test262.ecmascript.org
|
|
|
4c30b8 |
//
|
|
|
4c30b8 |
// Usage: node btest402.js
|
|
|
4c30b8 |
|
|
|
4c30b8 |
try {
|
|
|
4c30b8 |
console.log("You have console.log.");
|
|
|
4c30b8 |
} catch(e) {
|
|
|
4c30b8 |
// this works on d8
|
|
|
4c30b8 |
console = { log: print };
|
|
|
4c30b8 |
console.log("Now you have console.log.");
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
|
|
|
4c30b8 |
function runbtest() {
|
|
|
4c30b8 |
var summary = {};
|
|
|
4c30b8 |
|
|
|
4c30b8 |
try {
|
|
|
4c30b8 |
var i = Intl;
|
|
|
4c30b8 |
summary.haveIntl = true;
|
|
|
4c30b8 |
console.log("+ Congrats, you have the Intl object.");
|
|
|
4c30b8 |
} catch(e) {
|
|
|
4c30b8 |
console.log("You don't have the Intl object: " + e);
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
|
|
|
4c30b8 |
if(summary.haveIntl) {
|
|
|
4c30b8 |
var locs = [ "en", "mt", "ja","tlh"];
|
|
|
4c30b8 |
var d = new Date(196400000);
|
|
|
4c30b8 |
for ( var n=0; n
|
|
|
4c30b8 |
var loc = locs[n];
|
|
|
4c30b8 |
var lsummary = summary[loc] = {};
|
|
|
4c30b8 |
|
|
|
4c30b8 |
console.log(loc+":");
|
|
|
4c30b8 |
var sl=null;
|
|
|
4c30b8 |
try {
|
|
|
4c30b8 |
sl = Intl.DateTimeFormat.supportedLocalesOf([loc]);
|
|
|
4c30b8 |
if( sl.length > 0 ) {
|
|
|
4c30b8 |
lsummary.haveSlo = true;
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
} catch (e) {
|
|
|
4c30b8 |
console.log("SLO err: " + e);
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
var dstr = "ERR";
|
|
|
4c30b8 |
try {
|
|
|
4c30b8 |
lsummary.dstr = d.toLocaleString(loc,{month: "long",day:"numeric",weekday:"long",year:"numeric"});
|
|
|
4c30b8 |
console.log(" date: (supported:"+sl+") " + lsummary.dstr);
|
|
|
4c30b8 |
} catch (e) {
|
|
|
4c30b8 |
console.log(" Date Format err: " + e);
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
try {
|
|
|
4c30b8 |
new Intl.v8BreakIterator();
|
|
|
4c30b8 |
console.log(" Intl.v8BreakIterator:" +
|
|
|
4c30b8 |
Intl.v8BreakIterator.supportedLocalesOf(loc) + " Supported, first()==" +
|
|
|
4c30b8 |
new Intl.v8BreakIterator(loc).first() );
|
|
|
4c30b8 |
lsummary.brkOk = true;
|
|
|
4c30b8 |
} catch ( e) {
|
|
|
4c30b8 |
console.log(" Intl.v8BreakIterator error (NOT part of EcmaScript402): " + e);
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
console.log();
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
|
|
|
4c30b8 |
// print summary
|
|
|
4c30b8 |
console.log();
|
|
|
4c30b8 |
console.log("--------- Analysis ---------");
|
|
|
4c30b8 |
stxt = "";
|
|
|
4c30b8 |
if( summary.haveIntl ) {
|
|
|
4c30b8 |
console.log("* You have the 'Intl' object. Congratulations! You have the possibility of being EcmaScript 402 compliant.");
|
|
|
4c30b8 |
stxt += "Have Intl, ";
|
|
|
4c30b8 |
|
|
|
4c30b8 |
if ( !summary.en.haveSlo ) {
|
|
|
4c30b8 |
stxt += "Date:no EN, ";
|
|
|
4c30b8 |
console.log("* English isn't a supported language by the date formatter. Perhaps the data isn't installed properly?");
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
if ( !summary.tlh.haveSlo ) {
|
|
|
4c30b8 |
stxt += "Date:no 'tlh', ";
|
|
|
4c30b8 |
console.log("* Klingon isn't a supported language by the date formatter. It is without honor!");
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
// now, what is it actually saying
|
|
|
4c30b8 |
if( summary.en.dstr.indexOf("1970") == -1) {
|
|
|
4c30b8 |
stxt += "Date:bad 'en', ";
|
|
|
4c30b8 |
console.log("* the English date format text looks bad to me. Doesn't even have the year.");
|
|
|
4c30b8 |
} else {
|
|
|
4c30b8 |
if( summary.en.dstr.indexOf("Jan") == -1) {
|
|
|
4c30b8 |
stxt += "Date:bad 'en', ";
|
|
|
4c30b8 |
console.log("* The English date format text looks bad to me. Doesn't have the right month.");
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
|
|
|
4c30b8 |
if( summary.mt.dstr == summary.en.dstr ) {
|
|
|
4c30b8 |
stxt += "Date:'mt'=='en', ";
|
|
|
4c30b8 |
console.log("* The English and Maltese look the same to me. Probably a 'small' build.");
|
|
|
4c30b8 |
} else if( summary.mt.dstr.indexOf("1970") == -1) {
|
|
|
4c30b8 |
stxt += "Date:bad 'mt', ";
|
|
|
4c30b8 |
console.log("* the Maltese date format text looks bad to me. Doesn't even have the year. (This data is missing from the Chromium ICU build)");
|
|
|
4c30b8 |
} else {
|
|
|
4c30b8 |
if( summary.mt.dstr.indexOf("Jann") == -1) {
|
|
|
4c30b8 |
stxt += "Date:bad 'mt', ";
|
|
|
4c30b8 |
console.log("* The Maltese date format text looks bad to me. Doesn't have the right month. (This data is missing from the Chromium ICU build)");
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
|
|
|
4c30b8 |
if ( !summary.ja.haveSlo ) {
|
|
|
4c30b8 |
stxt += "Date:no 'ja', ";
|
|
|
4c30b8 |
console.log("* Japanese isn't a supported language by the date formatter. Could be a 'small' build.");
|
|
|
4c30b8 |
} else {
|
|
|
4c30b8 |
if( summary.ja.dstr.indexOf("1970") == -1) {
|
|
|
4c30b8 |
stxt += "Date:bad 'ja', ";
|
|
|
4c30b8 |
console.log("* the Japanese date format text looks bad to me. Doesn't even have the year.");
|
|
|
4c30b8 |
} else {
|
|
|
4c30b8 |
if( summary.ja.dstr.indexOf("日") == -1) {
|
|
|
4c30b8 |
stxt += "Date:bad 'ja', ";
|
|
|
4c30b8 |
console.log("* The Japanese date format text looks bad to me.");
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
if ( summary.en.brkOk ) {
|
|
|
4c30b8 |
stxt += "FYI: v8Brk:have 'en', ";
|
|
|
4c30b8 |
console.log("* You have Intl.v8BreakIterator support. (Note: not part of ES402.)");
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
} else {
|
|
|
4c30b8 |
console.log("* You don't have the 'Intl' object. You aren't EcmaScript 402 compliant.");
|
|
|
4c30b8 |
stxt += " NO Intl. ";
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
|
|
|
4c30b8 |
// 1-liner.
|
|
|
4c30b8 |
console.log();
|
|
|
4c30b8 |
console.log("----------------");
|
|
|
4c30b8 |
console.log( "SUMMARY:" + stxt );
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
|
|
|
4c30b8 |
var dorun = true;
|
|
|
4c30b8 |
|
|
|
4c30b8 |
try {
|
|
|
4c30b8 |
if(btest402_noautorun) {
|
|
|
4c30b8 |
dorun = false;
|
|
|
4c30b8 |
}
|
|
|
4c30b8 |
} catch(e) {}
|
|
|
4c30b8 |
|
|
|
4c30b8 |
if(dorun) {
|
|
|
4c30b8 |
console.log("Running btest..");
|
|
|
4c30b8 |
runbtest();
|
|
|
4c30b8 |
}
|