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