Jump to content

User:PerfektesChaos/js/isbnLib/qunit.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/// PerfektesChaos/js/isbnLib/qunit.js
/// 2018-09-04 PerfektesChaos@de.wikipedia
/// Fingerprint: #0#0#
/// QUNIT for ISBN utility package
/* global window:false                                                 */
/* jshint bitwise:true, curly:true, eqeqeq:true, latedef:true,
          laxbreak:true,
          nocomma:true, strict:true, undef:true, unused:true           */



( function ( mw ) {
   "use strict";
   var LIB        =  "isbnLib",
       Version    =  1.3,
       Signature  =  "ext.gadget.isbnLib",
       Console, Tests;



/// @license GPL [//www.mediawiki.org/w/COPYING] (+GFDL, LGPL, CC-BY-SA)
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program;
 * if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * http://www.gnu.org/copyleft/gpl.html
 */



   function T01 ( assign ) {
      /**
       Add resolvers to default catalogs
       @param   assign  string with language code (not "qqq"), or false
       @version 2016-04-02 PerfektesChaos@de.wikipedia
      */
      var plus  =
         { de: [ "http://gso.gbv.de/DB=2.1/CMD?ACT=SRCHA&IKT=1007&TRM=#"
               ]
         };
      LIB.furnish( plus );
      return LIB.finder( assign );
   }   // T01()



   Tests  =  [
      { f: "factory" },
      { f: "factory",
        a: [ true ] },
      { f: "finder",
        a: [ "de" ] },
      { f: "finder",
        a: [ "en" ] },
      { f: "flip",
        a: [ "3-7891-4161-5" ],
        r: "978-3-7891-4161-4" },
      { f: "flip",
        a: [ "978-3-7891-4161-4" ],
        r: "3-7891-4161-5" },
      { f: "focus",
        a: [ "3-7891-4161-5" ],
        r: "de" },
      { f: "focus",
        a: [ "9129657520" ],
        r: "sv" },
      { f: "format",
        a: [ "9129657520" ],
        r: "91-29-65752-0" },
      { f: T01,
        a: [ "de" ] }
   ];   // 2016-03-22



   function factory () {
      /**
       Callback from library
       @version 2016-04-02 PerfektesChaos@de.wikipedia
      */
      var i, f, r, test, s;
      for ( i = 0;  i < Tests.length;  i++ ) {
         test  =  Tests[ i ];
         switch ( typeof test.f ) {
            case "function":
               f  =  test.f;
               s  =  f.name;
               break;
            case "string":
               s  =  test.f;
               f  =  LIB[ s ];
               break;
            default:
               f  =  false;
         }   // switch typeof test.f
         if ( typeof f  ===  "function" ) {
            if ( typeof test.a  !==  "object" ) {
               test.a  =  null;
            }
            Console.log( "    ....................... " + i + ". "
                         + s + "( " + test.a + " )" );
            try {
               r  =  f.apply( LIB, test.a );
               switch ( typeof r ) {
                  case "boolean":
                  case "number":
                  case "string":
                     Console.log( r );
                     if ( typeof test.r  !==  "undefined" ) {
                        if ( test.r === r ) {
                           Console.log( "    ...   ===" );
                        } else {
                           Console.log( "    !!!!!!!!   !==" );
                        }
                     }
                     break;
                  case "object":
                     if ( r   &&
                          typeof Console.dir  ===  "function" ) {
                        Console.dir( r );
                     } else if ( r ) {
                        Console.log( "{object}" );
                     } else {
                        Console.log( "{null}" );
                     }
                     break;
               }   // switch typeof r
            } catch ( e ) {
               Console.log( "ERROR " + s + "()",
                            test.a );
               Console.log( e );
            }
         } else {
            Console.error( "!!!! isbnLib.QUNIT.factory() f " + i );
         }
      }   // for i
   }   // factory()



   function featuring() {
      /**
       Add external tests
       @version 2016-04-02 PerfektesChaos@de.wikipedia
      */
      var i, test;
      if ( typeof LIB.qunit  ===  "object"
           &&     LIB.qunit   &&
           typeof LIB.qunit.length  ===  "number" ) {
         for ( i = 0;  i < LIB.qunit.length;  i++ ) {
            test  =  LIB.qunit[ i ];
            if ( typeof test  ===  "object"
                 &&     test   &&
                 typeof test.f  ===  "string"
                 &&     test.f ) {
               if ( typeof test.a  !==  "object" ) {
                  test.a  =  null;
               }
               if ( test.a   &&
                    typeof test.a.length  !==  "number" ) {
                  test.a  =  null;
               }
               Tests.push( test );
            } else {
               Console.error( "!!!!!!!! invalid external test #" + i );
            }
         }   // for i
      }
   }   // featuring()



   function fed( application ) {
      /**
       Callback from library
       @version 2016-04-02 PerfektesChaos@de.wikipedia
       @param   application   library object
      */
      if ( typeof application  ===  "object" ) {
         LIB  =  application;
         Console.log( ">>>>>>>>>>>>>>>>>> " + LIB.type + " " + LIB.vsn );
         featuring();
         factory();
      } else {
         Console.error( "isbnLib.QUNIT.fed() "  +  typeof application );
      }
   }   // fed()



   function first() {
      /**
       Internal initialization, last attempt to attach libraries
       @version 2018-09-04 PerfektesChaos@de.wikipedia
      */
      var rls = { };
      rls[ Signature + ".qunit" ] = "ready";
      mw.loader.state( rls );
      if ( typeof window  ===  "object"   &&
           typeof window.console  ===  "object"
           &&     window.console   &&
           typeof window.console.log  ===  "function" ) {
         Console  =  window.console;
         if ( typeof Console.clear  ===  "function" ) {
            Console.clear();
         }
         Console.log( "=========== " + LIB + " " + " QUNIT " + Version );
      }
      if ( Console ) {
         if ( ! mw.loader.getState( Signature ) ) {
            rls = { };
            rls[ Signature ] = "loading";
            mw.loader.load( "https://en.wikipedia.org/w/index.php?"
                            + "title=User:PerfektesChaos/js/"
                            + LIB + "/r.js"
                            + "&bcache=1&maxage=600"
                            + "&action=raw&ctype=text/javascript" );
         }
         mw.hook( LIB + ".ready" ).add( fed );
      }
   }   // first()



   // autoInit onLoad
   first();
}( window.mediaWiki ) );



// Emacs
// Local Variables:
// coding: iso-8859-1-dos
// fill-column: 80
// End:

/// EOF </nowiki>   isbnLib/qunit.js