1 // ==========================================================================
  2 // Project:   SproutCore - JavaScript Application Framework
  3 // Copyright: ©2006-2011 Strobe Inc. and contributors.
  4 //            ©2008-2011 Apple Inc. All rights reserved.
  5 // License:   Licensed under MIT license (see license.js)
  6 // ==========================================================================
  7 module("SproutCore Type Checking");
  8 
  9 test("SC.typeOf", function() {
 10 	var a = null,
 11 	    arr = [1,2,3],
 12 	    obj = {},
 13       object = SC.Object.create({ method: function() {} }),
 14       E = SC.Error.extend();
 15 
 16   equals(SC.T_UNDEFINED,  SC.typeOf(undefined),         "item of type undefined");
 17   equals(SC.T_NULL,       SC.typeOf(a),                 "item of type null");
 18 	equals(SC.T_ARRAY,      SC.typeOf(arr),               "item of type array");
 19 	equals(SC.T_HASH,       SC.typeOf(obj),               "item of type hash");
 20 	equals(SC.T_OBJECT,     SC.typeOf(object),            "item of type object");
 21 	equals(SC.T_FUNCTION,   SC.typeOf(object.method),     "item of type function") ;
 22 	equals(SC.T_CLASS,      SC.typeOf(SC.Object),         "item of type class");
 23   equals(SC.T_ERROR,      SC.typeOf(SC.Error.create()), "item of type error");
 24   equals(SC.T_OBJECT,     SC.typeOf(SC.Object.create({ isError: YES })), "sc object with isError property should be of type object");
 25   equals(SC.T_ERROR,      SC.typeOf(E.create()),         "item of type error");
 26   equals(SC.T_HASH,       SC.typeOf({ isObject: YES }),  "hash object with isObject property should be of type hash");
 27 });
 28 
 29 test("SC.none", function() {
 30   var string = "string", fn = function() {};
 31 
 32 	equals(true,  SC.none(null),      "for null");
 33 	equals(true,  SC.none(undefined), "for undefined");
 34   equals(false, SC.none(""),        "for an empty String");
 35   equals(false, SC.none(true),      "for true");
 36   equals(false, SC.none(false),     "for false");
 37   equals(false, SC.none(string),    "for a String");
 38   equals(false, SC.none(fn),        "for a Function");
 39   equals(false, SC.none(0),         "for 0");
 40   equals(false, SC.none([]),        "for an empty Array");
 41   equals(false, SC.none({}),        "for an empty Object");
 42 });
 43 
 44 test("SC.empty", function() {
 45   var string = "string", fn = function() {};
 46 
 47 	equals(true,  SC.empty(null),      "for null");
 48 	equals(true,  SC.empty(undefined), "for undefined");
 49   equals(true,  SC.empty(""),        "for an empty String");
 50   equals(false, SC.empty(true),      "for true");
 51   equals(false, SC.empty(false),     "for false");
 52   equals(false, SC.empty(string),    "for a String");
 53   equals(false, SC.empty(fn),        "for a Function");
 54   equals(false, SC.empty(0),         "for 0");
 55   equals(false, SC.empty([]),        "for an empty Array");
 56   equals(false, SC.empty({}),        "for an empty Object");
 57 });
 58 
 59 test("SC.isArray" ,function(){
 60 	var numarray      = [1,2,3],
 61 	    number        = 23,
 62 	    strarray      = ["Hello", "Hi"],
 63     	string        = "Hello",
 64 	    object   	    = {},
 65       length        = {length: 12},
 66       fn            = function() {};
 67 
 68 	equals( SC.isArray(numarray), true,  "[1,2,3]" );
 69 	equals( SC.isArray(number),   false, "23" );
 70 	equals( SC.isArray(strarray), true,  '["Hello", "Hi"]' );
 71 	equals( SC.isArray(string),   false, '"Hello"' );
 72 	equals( SC.isArray(object),   false, "{}" );
 73   equals( SC.isArray(length),   true,  "{length: 12}" );
 74   equals( SC.isArray(window),   false, "window" );
 75   equals( SC.isArray(fn),       false, "function() {}" );
 76 
 77   if (window.document) {
 78     var nodelist      = document.getElementsByTagName("body");
 79     equals( SC.isArray(nodelist), true, "NodeList" );
 80   }
 81 });
 82