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