src/cm/media/js/lib/yui/yui3.0.0/tests/test/tests/arrayassert.html
changeset 0 40c8f766c9b8
equal deleted inserted replaced
-1:000000000000 0:40c8f766c9b8
       
     1 <html>
       
     2 <head>
       
     3 <title>array assert tests</title>
       
     4 <link type="text/css" rel="stylesheet" href="../../../build/logreader/assets/skins/sam/logreader.css" />
       
     5 <script type="text/javascript" src="../../../build/yui/yui.js"></script>
       
     6 </head>
       
     7 <body class="yui-skin-sam">
       
     8     <h1>Array Assert Tests</h1>
       
     9     <div id="c"></div>
       
    10 <script type="text/javascript">  
       
    11     
       
    12 YUI({
       
    13     base: '../../../build/',
       
    14     filter: "debug",
       
    15     logInclude: { TestRunner: true }
       
    16 }).use('test', 'console', function (Y) {
       
    17 
       
    18     Y.namespace("Tests");
       
    19     
       
    20     Y.Tests.ArrayAssert = (function(){
       
    21     
       
    22         var Assert          = Y.Assert,
       
    23             ArrayAssert     = Y.ArrayAssert;
       
    24         
       
    25         //-------------------------------------------------------------------------
       
    26         // Base Test Suite
       
    27         //-------------------------------------------------------------------------
       
    28         
       
    29         var suite = new Y.Test.Suite("Array Assert Tests");
       
    30         
       
    31         //-------------------------------------------------------------------------
       
    32         // Test Case for contains()
       
    33         //-------------------------------------------------------------------------
       
    34         
       
    35         suite.add(new Y.Test.Case({
       
    36         
       
    37             name: "Contains Assert Tests",
       
    38             
       
    39             _should: {
       
    40                 fail: {
       
    41                     "contains() should fail when a similar item exists": new Y.Assert.Error("Value 1 (number) not found in array [1,0,false,text]."),
       
    42                     "contains() should throw a custom error message during failure": new Y.Assert.Error("True should not be there: Value 1 (number) not found in array [1,0,false,text]."),
       
    43                     "contains() should fail when the item doesn't exist": new Y.Assert.Error("Value true (boolean) not found in array [1,0,false,text].")
       
    44                 }
       
    45             },
       
    46             
       
    47             setUp: function(){
       
    48                 this.testArray = ["1", 0, false, "text"];
       
    49             },
       
    50             
       
    51             tearDown: function(){
       
    52                 delete this.testArray;
       
    53             },
       
    54             
       
    55             "contains() should pass when the given item exists": function () {
       
    56                 ArrayAssert.contains("1", this.testArray);
       
    57             },
       
    58             
       
    59             "contains() should fail when a similar item exists": function () {
       
    60                 ArrayAssert.contains(1, this.testArray);
       
    61             },
       
    62             
       
    63             "contains() should fail when the item doesn't exist": function() {
       
    64                 ArrayAssert.contains(true, this.testArray);
       
    65             },
       
    66             
       
    67             "contains() should throw a custom error message during failure": function(){
       
    68                 ArrayAssert.contains(true, this.testArray, "True should not be there: {message}");
       
    69             }
       
    70         }));        
       
    71         
       
    72         //-------------------------------------------------------------------------
       
    73         // Test Case for contains()
       
    74         //-------------------------------------------------------------------------
       
    75             
       
    76         suite.add(new Y.Test.Case({
       
    77         
       
    78             name: "ContainsItems Assert Tests",
       
    79             
       
    80             _should: {
       
    81                 fail: {
       
    82                     testSimilarItems: new Y.Assert.Error("Value 1 (number) not found in array [1,0,false,text]."),
       
    83                     testNonExistingItems: new Y.Assert.Error("Value true (boolean) not found in array [1,0,false,text].")
       
    84                 }
       
    85             },
       
    86             
       
    87             setUp: function(){
       
    88                 this.testArray = ["1", 0, false, "text"];
       
    89             },
       
    90             
       
    91             tearDown: function(){
       
    92                 delete this.testArray;
       
    93             },
       
    94             
       
    95             testExistingItems: function () {
       
    96                 ArrayAssert.containsItems(["1",0], this.testArray);
       
    97             },
       
    98             
       
    99             testSimilarItems: function () {
       
   100                 ArrayAssert.containsItems([1,0], this.testArray);
       
   101             },
       
   102             
       
   103             testNonExistingItems: function() {
       
   104                 ArrayAssert.containsItems([true], this.testArray);
       
   105             }
       
   106         }));
       
   107         
       
   108         //-------------------------------------------------------------------------
       
   109         // Test Case for containsMatch()
       
   110         //-------------------------------------------------------------------------
       
   111         
       
   112         suite.add(new Y.Test.Case({
       
   113         
       
   114             name: "ContainsMatch Assert Tests",
       
   115             
       
   116             _should: {
       
   117                 fail: {
       
   118                     testNonExistingItems: new Y.Assert.Error("No match found in array [1,0,false,text].")
       
   119                 }
       
   120             },
       
   121             
       
   122             setUp: function(){
       
   123                 this.testArray = ["1", 0, false, "text"];
       
   124             },
       
   125             
       
   126             tearDown: function(){
       
   127                 delete this.testArray;
       
   128             },
       
   129             
       
   130             testExistingItems: function () {
       
   131                 ArrayAssert.containsMatch(function(value){
       
   132                     return Y.Lang.isString(value);
       
   133                 }, this.testArray);
       
   134             },
       
   135             
       
   136             testNonExistingItems: function() {
       
   137                 ArrayAssert.containsMatch(function(value){
       
   138                     return Y.Lang.isObject(value);
       
   139                 }, this.testArray);
       
   140             }
       
   141         }));
       
   142         
       
   143         //-------------------------------------------------------------------------
       
   144         // Test Case for itemsAreSame()
       
   145         //-------------------------------------------------------------------------
       
   146         
       
   147         suite.add(new Y.Test.Case({
       
   148         
       
   149             name: "itemsAreSame Assert Tests",
       
   150             
       
   151             _should: {
       
   152                 fail: {
       
   153                     testMissingItem: new Y.Assert.Error("Values in position 3 are not the same."),
       
   154                     testArrayAgainstObject: new Y.Assert.Error("Values in position 0 are not the same.")
       
   155                 }
       
   156             },
       
   157             
       
   158             setUp: function(){
       
   159                 this.testArray = ["1", 0, false, "text"];
       
   160             },
       
   161             
       
   162             tearDown: function(){
       
   163                 delete this.testArray;
       
   164             },
       
   165             
       
   166             testItemsAreSame: function () {
       
   167                 ArrayAssert.itemsAreSame(this.testArray,["1", 0, false, "text"]);
       
   168             },
       
   169             
       
   170             testMissingItem: function() {
       
   171                 ArrayAssert.itemsAreSame(this.testArray, ["1", 0, false]);
       
   172             },
       
   173             
       
   174             testArrayAgainstObject: function(){
       
   175                 ArrayAssert.itemsAreSame(this.testArray, {});
       
   176             }
       
   177         }));
       
   178         
       
   179         //-------------------------------------------------------------------------
       
   180         // Test Case for itemsAreEqual()
       
   181         //-------------------------------------------------------------------------
       
   182         
       
   183         suite.add(new Y.Test.Case({
       
   184         
       
   185             name: "itemsAreEqual Assert Tests",
       
   186             
       
   187             _should: {
       
   188                 fail: {
       
   189                     testMissingItem: new Y.Assert.Error("Values in position 3 are not equal."),
       
   190                     testArrayAgainstObject: new Y.Assert.Error("Values in position 0 are not equal.")
       
   191                 }
       
   192             },
       
   193             
       
   194             setUp: function(){
       
   195                 this.testArray = ["1", 0, false, "text"];
       
   196             },
       
   197             
       
   198             tearDown: function(){
       
   199                 delete this.testArray;
       
   200             },
       
   201             
       
   202             testItemsAreEqual: function () {
       
   203                 ArrayAssert.itemsAreEqual(this.testArray,["1", 0, false, "text"]);
       
   204             },
       
   205             
       
   206             testMissingItem: function() {
       
   207                 ArrayAssert.itemsAreEqual(this.testArray, ["1", 0, false]);
       
   208             },
       
   209             
       
   210             testArrayAgainstObject: function(){
       
   211                 ArrayAssert.itemsAreEqual(this.testArray, {});
       
   212             }
       
   213         }));  
       
   214       
       
   215         //-------------------------------------------------------------------------
       
   216         // Test Case for itemsAreEquivalent()
       
   217         //-------------------------------------------------------------------------
       
   218       
       
   219         suite.add(new Y.Test.Case({
       
   220         
       
   221             name: "itemsAreEquivalent Assert Tests",
       
   222             
       
   223             _should: {
       
   224                 fail: {
       
   225                     testMissingItem: new Y.Assert.Error("Values in position 3 are not equal."),
       
   226                     testArrayAgainstObject: new Y.Assert.Error("Values in position 0 are not equal.")
       
   227                 }
       
   228             },
       
   229             
       
   230             setUp: function(){
       
   231                 this.testArray = ["1", 0, false, "text"];
       
   232                 this.comparator = function(a,b){
       
   233                     return a == b;
       
   234                 };
       
   235             },
       
   236             
       
   237             tearDown: function(){
       
   238                 delete this.testArray;
       
   239                 delete this.comparator;
       
   240             },
       
   241             
       
   242             testItemsAreEqual: function () {
       
   243                 ArrayAssert.itemsAreEquivalent(this.testArray,["1", 0, false, "text"], this.comparator);
       
   244             },
       
   245             
       
   246             testMissingItem: function() {
       
   247                 ArrayAssert.itemsAreEquivalent(this.testArray, ["1", 0, false], this.comparator);
       
   248             },
       
   249             
       
   250             testArrayAgainstObject: function(){
       
   251                 ArrayAssert.itemsAreEquivalent(this.testArray, {}, this.comparator);
       
   252             }
       
   253         }));   
       
   254               
       
   255     
       
   256         //return it
       
   257         return suite;
       
   258     
       
   259     })();
       
   260 
       
   261     
       
   262     var r = new Y.Console({
       
   263         verbose : true,
       
   264         //consoleLimit : 10,
       
   265         newestOnTop : false
       
   266     });
       
   267     
       
   268     r.render('#c');
       
   269     
       
   270     
       
   271     //add to the testrunner and run
       
   272     Y.Test.Runner.add(Y.Tests.ArrayAssert);
       
   273     Y.Test.Runner.run();
       
   274 
       
   275     /*if (parent && parent != window) {
       
   276         YAHOO.tool.TestManager.load();
       
   277     } else {
       
   278         YAHOO.tool.TestRunner.run();
       
   279     }*/
       
   280  
       
   281 });
       
   282 
       
   283 
       
   284 </script>
       
   285 </body>
       
   286 </html>