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