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