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