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