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