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