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