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