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