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