Changeset 561

Show
Ignore:
Timestamp:
01/23/06 14:08:18 (3 years ago)
Author:
therve@gmail.com
Message:

Update tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mochikit/branches/scriptaculous/tests/Test/Builder.js

    r316 r561  
    2929      : null; 
    3030 
    31 Test.Builder.VERSION = '0.21'; 
     31Test.Builder.VERSION = '0.22'; 
    3232Test.Builder.Instances = []; 
    3333Test.Builder.lineEndingRx = /\r?\n|\r/g; 
  • mochikit/branches/scriptaculous/tests/Test/Harness.js

    r316 r561  
    1515 
    1616Test.Harness = function () {}; 
    17 Test.Harness.VERSION = '0.21'; 
     17Test.Harness.VERSION = '0.22'; 
    1818Test.Harness.Done = 0; 
    1919 
  • mochikit/branches/scriptaculous/tests/Test/Harness/Browser.js

    r316 r561  
    7373    }; 
    7474 
    75     Test.Harness.Browser.VERSION = '0.21'; 
     75    Test.Harness.Browser.VERSION = '0.22'; 
    7676 
    7777    Test.Harness.Browser.runTests = function () { 
     
    9393        // set to display:none. See: 
    9494        // http://www.quirksmode.org/bugreports/archives/2005/02/hidden_iframes.html 
    95         if (/Safari/.test(navigator.userAgent)) { 
     95        if (true || /Safari/.test(navigator.userAgent)) { 
    9696            node.style.visibility = "hidden"; 
    9797            node.style.height = "0";  
  • mochikit/branches/scriptaculous/tests/Test/Harness/Director.js

    r316 r561  
    22 
    33Test.Harness.Director = function () {}; 
    4 Test.Harness.Director.VERSION = '0.21'; 
     4Test.Harness.Director.VERSION = '0.22'; 
    55 
    66Test.Harness.Director.runTests = function () { 
  • mochikit/branches/scriptaculous/tests/Test/More.js

    r316 r561  
    2424]; 
    2525Test.More.EXPORT_TAGS = { ':all': Test.More.EXPORT }; 
    26 Test.More.VERSION     = '0.21'; 
     26Test.More.VERSION     = '0.22'; 
    2727 
    2828Test.More.ShowDiag = true; 
     
    9090    } 
    9191 
    92     // There'es no can() method in JavaScript, but what the hell! 
     92    // There's no can() method in JavaScript, but what the hell! 
    9393    var desc = clas + ".can('" + (arguments.length == 2 ? arguments[1] : '...') + "')"; 
    9494    ok = Test.More.Test.ok(!nok.length, desc); 
  • mochikit/branches/scriptaculous/tests/Test/Simple.js

    r316 r561  
    1414Test.Simple.EXPORT      = ['plan', 'ok']; 
    1515Test.Simple.EXPORT_TAGS = { ':all': Test.Simple.EXPORT }; 
    16 Test.Simple.VERSION     = '0.21'; 
     16Test.Simple.VERSION     = '0.22'; 
    1717 
    1818Test.Simple.plan = function (cmds) { 
  • mochikit/branches/scriptaculous/tests/test_MochiKit-Base.html

    r540 r561  
    88 
    99<pre id="test"> 
     10<script type="text/javascript" src="test_Base.js"></script> 
    1011<script type="text/javascript"> 
    1112try { 
    12          
    1313    // Counting the number of tests is really lame 
    1414    plan({'tests': 134}); 
    15     
    16     // test bind 
    17     var not_self = {"toString": function () { return "not self"; } }; 
    18     var self = {"toString": function () { return "self" } }; 
    19     var func = function (arg) { return this.toString() + " " + arg; }; 
    20     var boundFunc = bind(func, self); 
    21     not_self.boundFunc = boundFunc; 
    22  
    23     is( boundFunc("foo"), "self foo", "boundFunc bound to self properly" ); 
    24     is( not_self.boundFunc("foo"), "self foo", "boundFunc bound to self on another obj" ); 
    25     is( bind(boundFunc, not_self)("foo"), "not self foo", "boundFunc successfully rebound!" ); 
    26     is( bind(boundFunc, undefined, "foo")(), "self foo", "boundFunc partial no self change" ); 
    27     is( bind(boundFunc, not_self, "foo")(), "not self foo", "boundFunc partial self change" ); 
    28  
    29     // test bindMethods 
    30  
    31     var O = function (value) { 
    32         bindMethods(this); 
    33         this.value = value; 
    34     }; 
    35     O.prototype.func = function () { 
    36         return this.value; 
    37     }; 
    38  
    39     var o = new O("boring"); 
    40     var p = {}; 
    41     p.func = o.func; 
    42     var func = o.func; 
    43     is( o.func(), "boring", "bindMethods doesn't break shit" ); 
    44     is( p.func(), "boring", "bindMethods works on other objects" ); 
    45     is( func(), "boring", "bindMethods works on functions" ); 
    46  
    47     var p = clone(o); 
    48     ok( p instanceof O, "cloned correct inheritance" ); 
    49     var q = clone(p); 
    50     ok( q instanceof O, "clone-cloned correct inheritance" ); 
    51     q.foo = "bar"; 
    52     is( p.foo, undefined, "clone-clone is copy-on-write" ); 
    53     p.bar = "foo"; 
    54     is( o.bar, undefined, "clone is copy-on-write" ); 
    55     is( q.bar, "foo", "clone-clone has proper delegation" ); 
    56     // unbind 
    57     p.func = bind(p.func, null); 
    58     is( p.func(), "boring", "clone function calls correct" ); 
    59     q.value = "awesome"; 
    60     is( q.func(), "awesome", "clone really does work" ); 
    61      
    62     // test boring boolean funcs 
    63  
    64     is( isCallable(isCallable), true, "isCallable returns true on itself" ); 
    65     is( isCallable(1), false, "isCallable returns false on numbers" ); 
    66  
    67     is( isUndefined(null), false, "null is not undefined" ); 
    68     is( isUndefined(""), false, "empty string is not undefined" ); 
    69     is( isUndefined(undefined), true, "undefined is undefined" ); 
    70     is( isUndefined({}.foo), true, "missing property is undefined" ); 
    71  
    72     is( isUndefinedOrNull(null), true, "null is undefined or null" ); 
    73     is( isUndefinedOrNull(""), false, "empty string is not undefined or null" ); 
    74     is( isUndefinedOrNull(undefined), true, "undefined is undefined or null" ); 
    75     is( isUndefinedOrNull({}.foo), true, "missing property is undefined or null" ); 
    76  
    77     // test extension of arrays 
    78     var a = []; 
    79     var b = []; 
    80     var three = [1, 2, 3]; 
    81  
    82     extend(a, three, 1); 
    83     ok( objEqual(a, [2, 3]), "extend to an empty array" ); 
    84     extend(a, three, 1) 
    85     ok( objEqual(a, [2, 3, 2, 3]), "extend to a non-empty array" ); 
    86  
    87     extend(b, three); 
    88     ok( objEqual(b, three), "extend of an empty array" ); 
    89  
    90     is( compare(1, 2), -1, "numbers compare lt" ); 
    91     is( compare(2, 1), 1, "numbers compare gt" ); 
    92     is( compare(1, 1), 0, "numbers compare eq" ); 
    93     is( compare([1], [1]), 0, "arrays compare eq" ); 
    94     is( compare([1], [1, 2]), -1, "arrays compare lt (length)" ); 
    95     is( compare([1, 2], [2, 1]), -1, "arrays compare lt (contents)" ); 
    96     is( compare([1, 2], [1]), 1, "arrays compare gt (length)" ); 
    97     is( compare([2, 1], [1, 1]), 1, "arrays compare gt (contents)" ); 
    98      
    99     // test partial application 
    100     var a = []; 
    101     var func = function (a, b) { 
    102         if (arguments.length != 2) { 
    103             return "bad args"; 
    104         } else { 
    105             return this.value + a + b; 
    106         } 
    107     }; 
    108     var self = {"value": 1, "func": func}; 
    109     var self2 = {"value": 2}; 
    110     is( self.func(2, 3), 6, "setup for test is correct" ); 
    111     self.funcTwo = partial(self.func, 2); 
    112     is( self.funcTwo(3), 6, "partial application works" ); 
    113     is( self.funcTwo(3), 6, "partial application works still" ); 
    114     is( bind(self.funcTwo, self2)(3), 7, "rebinding partial works" ); 
    115     self.funcTwo = bind(bind(self.funcTwo, self2), null); 
    116     is( self.funcTwo(3), 6, "re-unbinding partial application works" ); 
    117  
    118      
    119     // nodeWalk test 
    120     // ... looks a lot like a DOM tree on purpose 
    121     var tree = { 
    122         "id": "nodeWalkTestTree", 
    123         "test:int": "1", 
    124         "childNodes": [ 
    125             { 
    126                 "test:int": "2", 
    127                 "childNodes": [ 
    128                     {"test:int": "5"}, 
    129                     "ignored string", 
    130                     {"ignored": "object"}, 
    131                     ["ignored", "list"], 
    132                     { 
    133                         "test:skipchildren": "1", 
    134                         "childNodes": [{"test:int": 6}] 
    135                     } 
    136                 ] 
    137             }, 
    138             {"test:int": "3"}, 
    139             {"test:int": "4"} 
    140         ] 
    141     } 
    142  
    143     var visitedNodes = []; 
    144     nodeWalk(tree, function (node) { 
    145         var attr = node["test:int"]; 
    146         if (attr) { 
    147             visitedNodes.push(attr); 
    148         } 
    149         if (node["test:skipchildren"]) { 
    150                 return; 
    151         } 
    152         return node.childNodes; 
    153     }); 
    154  
    155     ok( objEqual(visitedNodes, ["1", "2", "3", "4", "5"]), "nodeWalk looks like it works"); 
    156      
    157     // test map 
    158     var minusOne = function (x) { return x - 1; }; 
    159     var res = map(minusOne, [1, 2, 3]); 
    160     ok( objEqual(res, [0, 1, 2]), "map works" ); 
    161  
    162     var res2 = xmap(minusOne, 1, 2, 3); 
    163     ok( objEqual(res2, res), "xmap works" ); 
    164  
    165     res = map(operator.add, [1, 2, 3], [2, 4, 6]); 
    166     ok( objEqual(res, [3, 6, 9]), "map(fn, p, q) works" ); 
    167  
    168     res = map(operator.add, [1, 2, 3], [2, 4, 6, 8]); 
    169     ok( objEqual(res, [3, 6, 9]), "map(fn, p, q) works (q long)" ); 
    170  
    171     res = map(operator.add, [1, 2, 3, 4], [2, 4, 6]); 
    172     ok( objEqual(res, [3, 6, 9]), "map(fn, p, q) works (p long)" ); 
    173  
    174     res = map(null, [1, 2, 3], [2, 4, 6]); 
    175     ok( objEqual(res, [[1, 2], [2, 4], [3, 6]]), "map(null, p, q) works" ); 
    176  
    177     res = zip([1, 2, 3], [2, 4, 6]); 
    178     ok( objEqual(res, [[1, 2], [2, 4], [3, 6]]), "zip(p, q) works" ); 
    179  
    180     res = map(null, [1, 2, 3]); 
    181     ok( objEqual(res, [1, 2, 3]), "map(null, lst) works" ); 
    182  
    183  
    184      
    185      
    186     is( isNotEmpty("foo"), true, "3 char string is not empty" ); 
    187     is( isNotEmpty(""), false, "0 char string is empty" ); 
    188     is( isNotEmpty([1, 2, 3]), true, "3 element list is not empty" ); 
    189     is( isNotEmpty([]), false, "0 element list is empty" ); 
    190  
    191     // test filter 
    192     var greaterThanThis = function (x) { return x > this; }; 
    193     var greaterThanOne = function (x) { return x > 1; }; 
    194     var res = filter(greaterThanOne, [-1, 0, 1, 2, 3]); 
    195     ok( objEqual(res, [2, 3]), "filter works" ); 
    196     var res = filter(greaterThanThis, [-1, 0, 1, 2, 3], 1); 
    197     ok( objEqual(res, [2, 3]), "filter self works" ); 
    198     var res2 = xfilter(greaterThanOne, -1, 0, 1, 2, 3); 
    199     ok( objEqual(res2, res), "xfilter works" ); 
    200   
    201     is(objMax(1, 2, 9, 12, 42, -16, 16), 42, "objMax works (with numbers)"); 
    202     is(objMin(1, 2, 9, 12, 42, -16, 16), -16, "objMin works (with numbers)"); 
    203      
    204     // test adapter registry 
    205  
    206     var R = new AdapterRegistry(); 
    207     R.register("callable", isCallable, function () { return "callable"; }); 
    208     R.register("arrayLike", isArrayLike, function () { return "arrayLike"; }); 
    209     is( R.match(function () {}), "callable", "registry found callable" ); 
    210     is( R.match([]), "arrayLike", "registry found ArrayLike" ); 
    211     try { 
    212         R.match(null); 
    213         ok( false, "non-matching didn't raise!" ); 
    214     } catch (e) { 
    215         is( e, NotFound, "non-matching raised correctly" ); 
    216     } 
    217     R.register("undefinedOrNull", isUndefinedOrNull, function () { return "undefinedOrNull" }); 
    218     R.register("undefined", isUndefined, function () { return "undefined" }); 
    219     is( R.match(undefined), "undefinedOrNull", "priorities are as documented" ); 
    220     ok( R.unregister("undefinedOrNull"), "removed adapter" ); 
    221     is( R.match(undefined), "undefined", "adapter was removed" ); 
    222     R.register("undefinedOrNull", isUndefinedOrNull, function () { return "undefinedOrNull" }, true); 
    223     is( R.match(undefined), "undefinedOrNull", "override works" ); 
    224      
    225     var a1 = {"a": 1, "b": 2, "c": 2}; 
    226     var a2 = {"a": 2, "b": 1, "c": 2}; 
    227     is( keyComparator("a")(a1, a2), -1, "keyComparator 1 lt" ); 
    228     is( keyComparator("c")(a1, a2), 0, "keyComparator 1 eq" ); 
    229     is( keyComparator("c", "b")(a1, a2), 1, "keyComparator 2 eq gt" ); 
    230     is( keyComparator("c", "a")(a1, a2), -1, "keyComparator 2 eq lt" ); 
    231     is( reverseKeyComparator("a")(a1, a2), 1, "reverseKeyComparator" ); 
    232     is( compare(concat([1], [2], [3]), [1, 2, 3]), 0, "concat" ); 
    233     is( repr("foo"), '"foo"', "string repr" ); 
    234     is( repr(1), '1', "number repr" ); 
    235     is( listMin([1, 3, 5, 3, -1]), -1, "listMin" ); 
    236     is( objMin(1, 3, 5, 3, -1), -1, "objMin" ); 
    237     is( listMax([1, 3, 5, 3, -1]), 5, "listMax" ); 
    238     is( objMax(1, 3, 5, 3, -1), 5, "objMax" ); 
    239     is( compare(keys(a1).sort(), ["a", "b", "c"]), 0, "keys" ); 
    240     is( compare(items(a1).sort(), [["a", 1], ["b", 2], ["c", 2]]), 0, "items" ); 
    241  
    242     var StringMap = function() {}; 
    243     a = new StringMap(); 
    244     a.foo = "bar"; 
    245     b = new StringMap(); 
    246     b.foo = "bar"; 
    247     try { 
    248         compare(a, b); 
    249         ok( false, "bad comparison registered!?" ); 
    250     } catch (e) { 
    251         ok( e instanceof TypeError, "bad comparison raised TypeError" ); 
    252     } 
    253  
    254     is( repr(a), "[object Object]", "default repr for StringMap" ); 
    255     var isStringMap = function () { 
    256         for (var i = 0; i < arguments.length; i++) { 
    257             if (!(arguments[i] instanceof StringMap)) { 
    258                 return false; 
    259             } 
    260         } 
    261         return true; 
    262     }; 
    263  
    264     registerRepr("stringMap", 
    265         isStringMap, 
    266         function (obj) { 
    267             return "StringMap(" + repr(items(obj)) + ")"; 
    268         } 
    269     ); 
    270  
    271     is( repr(a), 'StringMap([["foo", "bar"]])', "repr worked" ); 
    272  
    273     // not public API 
    274     MochiKit.Base.reprRegistry.unregister("stringMap"); 
    275      
    276     is( repr(a), "[object Object]", "default repr for StringMap" ); 
    277  
    278     registerComparator("stringMap", 
    279         isStringMap, 
    280         function (a, b) { 
    281             // no sorted(...) in base 
    282             a = items(a); 
    283             b = items(b); 
    284             a.sort(compare); 
    285             b.sort(compare); 
    286             return compare(a, b); 
    287         } 
    288     ); 
    289  
    290     is( compare(a, b), 0, "registerComparator" ); 
    291  
    292     update(a, {"foo": "bar"}, {"wibble": "baz"}, undefined, null, {"grr": 1}); 
    293     is( a.foo, "bar", "update worked (first obj)" ); 
    294     is( a.wibble, "baz", "update worked (second obj)" ); 
    295     is( a.grr, 1, "update worked (skipped undefined and null)" ); 
    296     is( compare(a, b), 1, "update worked (comparison)" ); 
    297  
    298  
    299     setdefault(a, {"foo": "unf"}, {"bar": "web taco"} ); 
    300     is( a.foo, "bar", "setdefault worked (skipped existing)" ); 
    301     is( a.bar, "web taco", "setdefault worked (set non-existing)" ); 
    302  
    303     var c = merge({"foo": "bar"}, {"wibble": "baz"}); 
    304     is( compare(items(c).sort(), [["foo", "bar"], ["wibble", "baz"]]), 0, "merge worked" ); 
    305      
    306     // not public API 
    307     MochiKit.Base.comparatorRegistry.unregister("stringMap"); 
    308      
    309     try { 
    310         compare(a, b); 
    311         ok( false, "bad comparison registered!?" ); 
    312     } catch (e) { 
    313         ok( e instanceof TypeError, "bad comparison raised TypeError" ); 
    314     } 
    315      
    316     var o = {"__repr__": function () { return "__repr__"; }}; 
    317     is( repr(o), "__repr__", "__repr__ protocol" ); 
    318     is( repr(MochiKit.Base), MochiKit.Base.__repr__(), "__repr__ protocol when repr is defined" ); 
    319     var o = {"NAME": "NAME"}; 
    320     is( repr(o), "NAME", "NAME protocol (obj)" ); 
    321     o = function () { return "TACO" }; 
    322     o.NAME = "NAME"; 
    323     is( repr(o), "NAME", "NAME protocol (func)" ); 
    324      
    325     is( repr(MochiKit.Base.nameFunctions), "MochiKit.Base.nameFunctions", "test nameFunctions" ); 
    326     // Done! 
    327  
    328     is( urlEncode("1+2=2"), "1%2B2%3D2", "urlEncode" ); 
    329     is( queryString(["a", "b"], [1, "two"]), "a=1&b=two", "queryString"); 
    330     is( queryString({"a": 1}), "a=1", "one item alternate form queryString" ); 
    331     var o = {"a": 1, "b": 2, "c": function() {}}; 
    332     var res = queryString(o).split("&"); 
    333     res.sort(); 
    334     is( res.join("&"), "a=1&b=2", "two item alternate form queryString, function skip" ); 
    335     var res = parseQueryString("1+1=2&b=3%3D2"); 
    336     is( res["1 1"], "2", "parseQueryString pathological name" ); 
    337     is( res.b, "3=2", "parseQueryString second name:value pair" ); 
    338     var res = parseQueryString("foo=one&foo=two", true); 
    339     is( res["foo"].join(" "), "one two", "parseQueryString useArrays" ); 
    340  
    341     is( serializeJSON("foo\n\r\b\f\t"), "\"foo\\n\\r\\b\\f\\t\"", "string JSON" ); 
    342     is( serializeJSON(null), "null", "null JSON"); 
    343     is( serializeJSON(undefined), "undefined", "undefined JSON"); 
    344     is( serializeJSON(1), "1", "1 JSON"); 
    345     is( serializeJSON(1.23), "1.23", "1.23 JSON"); 
    346     is( serializeJSON(serializeJSON), null, "function JSON (null, not string)" ); 
    347     is( serializeJSON([1, "2", 3.3]), "[1, \"2\", 3.3]", "array JSON" ); 
    348     var res = evalJSON(serializeJSON({"a":1, "b":2})); 
    349     is( res.a, 1, "evalJSON on an object (1)" ); 
    350     is( res.b, 2, "evalJSON on an object (2)" ); 
    351     var res = {"a": 1, "b": 2, "json": function () { return this; }}; 
    352     var res = evalJSON(serializeJSON(res)); 
    353     is( res.a, 1, "evalJSON on an object that jsons self (1)" ); 
    354     is( res.b, 2, "evalJSON on an object that jsons self (2)" ); 
    355     var strJSON = {"a": 1, "b": 2, "json": function () { return "json"; }}; 
    356     is( serializeJSON(strJSON), "\"json\"", "json serialization calling" ); 
    357     is( serializeJSON([strJSON]), "[\"json\"]", "json serialization calling in a structure" ); 
    358     registerJSON("isDateLike", 
    359         isDateLike, 
    360         function (d) { 
    361             return "this was a date"; 
    362         } 
    363     ); 
    364     is( serializeJSON(new Date()), "\"this was a date\"", "json registry" ); 
    365     MochiKit.Base.jsonRegistry.unregister("isDateLike"); 
    366  
    367     var a = {"foo": {"bar": 12, "wibble": 13}}; 
    368     var b = {"foo": {"baz": 4, "bar": 16}, "bar": 4}; 
    369     updatetree(a, b); 
    370     var expect = [["bar", 16], ["baz", 4], ["wibble", 13]]; 
    371     var got = items(a.foo); 
    372     got.sort(compare); 
    373     is( repr(got), repr(expect), "updatetree merge" ); 
    374     is( a.bar, 4, "updatetree insert" ); 
    375      
    376     var c = counter(); 
    377     is( c(), 1, "counter starts at 1" ); 
    378     is( c(), 2, "counter increases" ); 
    379     c = counter(2); 
    380     is( c(), 2, "counter starts at 2" ); 
    381     is( c(), 3, "counter increases" ); 
    382  
    383     is( find([1, 2, 3], 4), -1, "find returns -1 on not found"); 
    384     is( find([1, 2, 3], 1), 0, "find returns correct index"); 
    385     is( find([1, 2, 3], 1, 1), -1, "find honors start"); 
    386     is( find([1, 2, 3], 2, 0, 1), -1, "find honors end"); 
    387     is( findIdentical([1, 2, 3], 4), -1, "findIdentical returns -1"); 
    388     is( findIdentical([1, 2, 3], 1), 0, "findIdentical returns correct index"); 
    389     is( findIdentical([1, 2, 3], 1, 1), -1, "findIdentical honors start"); 
    390     is( findIdentical([1, 2, 3], 2, 0, 1), -1, "findIdentical honors end"); 
    391   
     15    tests.test_Base({ok:ok,is:is}); 
    39216    ok( true, "test suite finished!"); 
    393      
    39417} catch (err) { 
    395      
    39618    var s = "test suite failure!\n"; 
    39719    var o = {}; 
     
    40527    } 
    40628    ok ( false, s ); 
    407  
    40829} 
    40930</script> 
  • mochikit/branches/scriptaculous/tests/test_MochiKit-Color.html

    r464 r561  
    1010    <style type="text/css">.redtext {color: red}</style> 
    1111</head> 
    12 <body onload="runtest()"> 
     12<body> 
     13<div style="position:absolute; top: 0px; left:0px; width:0px; height:0px"> 
     14    <span style="color: red" id="c_direct"></span> 
     15    <span class="redtext" id="c_indirect"></span> 
     16</div> 
    1317<pre id="test"> 
     18<script type="text/javascript" src="test_Color.js"></script> 
    1419<script type="text/javascript"> 
    15 function runtest() { 
    1620try { 
    1721         
    1822    // Counting the number of tests is really lame 
    1923    plan({'tests': 80}); 
    20  
    21     var approx = function (a, b, msg) { 
    22         return is(a.toPrecision(4), b.toPrecision(4), msg); 
    23     }; 
    24     
    25     is( Color.whiteColor().toHexString(), "#ffffff", "whiteColor has right hex" ); 
    26     is( Color.blackColor().toHexString(), "#000000", "blackColor has right hex" ); 
    27     is( Color.blueColor().toHexString(), "#0000ff", "blueColor has right hex" ); 
    28     is( Color.redColor().toHexString(), "#ff0000", "redColor has right hex" ); 
    29     is( Color.greenColor().toHexString(), "#00ff00", "greenColor has right hex" ); 
    30     is( compare(Color.whiteColor(), Color.whiteColor()), 0, "default colors compare right" ); 
    31     ok( Color.whiteColor() == Color.whiteColor(), "default colors are interned" ); 
    32     ok( Color.whiteColor().toRGBString(), "rgb(255,255,255)", "toRGBString white" ); 
    33     ok( Color.blueColor().toRGBString(), "rgb(0,0,255)", "toRGBString blue" ); 
    34     is( Color.fromRGB(190/255, 222/255, 173/255).toHexString(), "#bedead", "fromRGB works" ); 
    35     is( Color.fromRGB({r:190/255,g:222/255,b:173/255}).toHexString(), "#bedead", "alt fromRGB works" ); 
    36     is( Color.fromHexString("#bedead").toHexString(), "#bedead", "round-trip hex" ); 
    37     is( Color.fromString("#bedead").toHexString(), "#bedead", "round-trip string(hex)" ); 
    38     is( Color.fromRGBString("rgb(190,222,173)").toHexString(), "#bedead", "round-trip rgb" ); 
    39     is( Color.fromString("rgb(190,222,173)").toHexString(), "#bedead", "round-trip rgb" ); 
    40  
    41     var hsl = Color.redColor().asHSL(); 
    42     approx( hsl.h, 0.0, "red hsl.h" ); 
    43     approx( hsl.s, 1.0, "red hsl.s" ); 
    44     approx( hsl.l, 0.5, "red hsl.l" ); 
    45     hsl = Color.fromRGB(0, 0, 0.5).asHSL(); 
    46     approx( hsl.h, 2/3, "darkblue hsl.h" ); 
    47     approx( hsl.s, 1.0, "darkblue hsl.s" ); 
    48     approx( hsl.l, 0.25, "darkblue hsl.l" ); 
    49     hsl = Color.fromString("#4169E1").asHSL(); 
    50     approx( hsl.h, (5/8), "4169e1 h"); 
    51     approx( hsl.s, (8/11), "4169e1 s"); 
    52     approx( hsl.l, (29/51), "4169e1 l"); 
    53     hsl = Color.fromString("#555544").asHSL(); 
    54     approx( hsl.h, (1/6), "555544 h" ); 
    55     approx( hsl.s, (1/9), "555544 s" ); 
    56     approx( hsl.l, (3/10), "555544 l" ); 
    57     hsl = Color.fromRGB(0.5, 1, 0.5).asHSL(); 
    58     approx( hsl.h, 1/3, "aqua hsl.h" ); 
    59     approx( hsl.s, 1.0, "aqua hsl.s" ); 
    60     approx( hsl.l, 0.75, "aqua hsl.l" ); 
    61     is( 
    62         Color.fromHSL(hsl.h, hsl.s, hsl.l).toHexString(), 
    63         Color.fromRGB(0.5, 1, 0.5).toHexString(), 
    64         "fromHSL works with components" 
    65     ); 
    66     is( 
    67         Color.fromHSL(hsl).toHexString(), 
    68         Color.fromRGB(0.5, 1, 0.5).toHexString(), 
    69         "fromHSL alt form" 
    70     ); 
    71     is( 
    72         Color.fromString("hsl(120,100%,75%)").toHexString(), 
    73         "#80ff80", 
    74         "fromHSLString" 
    75     ); 
    76     is(  
    77         Color.fromRGB(0.5, 1, 0.5).toHSLString(), 
    78         "hsl(120,100.0%,75.00%)", 
    79         "toHSLString" 
    80     ); 
    81     is( Color.fromHSL(0, 0, 0).toHexString(), "#000000", "fromHSL to black" ); 
    82     hsl = Color.blackColor().asHSL(); 
    83     approx( hsl.h, 0.0, "black hsl.h" ); 
    84     approx( hsl.s, 0.0, "black hsl.s" ); 
    85     approx( hsl.l, 0.0, "black hsl.l" ); 
    86     hsl.h = 1.0; 
    87     hsl = Color.blackColor().asHSL(); 
    88     approx( hsl.h, 0.0, "asHSL returns copy" ); 
    89     var rgb = Color.brownColor().asRGB(); 
    90     approx( rgb.r, 153/255, "brown rgb.r" ); 
    91     approx( rgb.g, 102/255, "brown rgb.g" ); 
    92     approx( rgb.b, 51/255, "brown rgb.b" ); 
    93     rgb.r = 0; 
    94     rgb = Color.brownColor().asRGB(); 
    95     approx( rgb.r, 153/255, "asRGB returns copy" ); 
    96  
    97     is( Color.fromName("aqua").toHexString(), "#00ffff", "aqua fromName" ); 
    98     is( Color.fromString("aqua").toHexString(), "#00ffff", "aqua fromString" ); 
    99     is( Color.fromName("transparent"), Color.transparentColor(), "transparent fromName" ); 
    100     is( Color.fromString("transparent"), Color.transparentColor(), "transparent fromString" ); 
    101     is( Color.transparentColor().toRGBString(), "rgba(0,0,0,0)", "transparent toRGBString" ); 
    102     is( Color.fromRGBString("rgba( 0, 255, 255, 50%)").asRGB().a, 0.5, "rgba parsing alpha correctly" ); 
    103     is( Color.fromRGBString("rgba( 0, 255, 255, 50%)").toRGBString(), "rgba(0,255,255,0.5)", "rgba output correctly" ); 
    104     is( Color.fromRGBString("rgba( 0, 255, 255, 1)").toHexString(), "#00ffff", "fromRGBString with spaces and alpha" ); 
    105     is( Color.fromRGBString("rgb( 0, 255, 255)").toHexString(), "#00ffff", "fromRGBString with spaces" ); 
    106     is( Color.fromRGBString("rgb( 0, 100%, 255)").toHexString(), "#00ffff", "fromRGBString with percents" ); 
    107      
    108  
    109     var hsv = Color.redColor().asHSV(); 
    110     approx( hsv.h, 0.0, "red hsv.h" ); 
    111     approx( hsv.s, 1.0, "red hsv.s" ); 
    112     approx( hsv.v, 1.0, "red hsv.v" ); 
    113     is( Color.fromHSV(hsv).toHexString(), Color.redColor().toHexString(), "red hexstring" ); 
    114     hsv = Color.fromRGB(0, 0, 0.5).asHSV(); 
    115     approx( hsv.h, 2/3, "darkblue hsv.h" ); 
    116     approx( hsv.s, 1.0, "darkblue hsv.s" ); 
    117     approx( hsv.v, 0.5, "darkblue hsv.v" ); 
    118     is( Color.fromHSV(hsv).toHexString(), Color.fromRGB(0, 0, 0.5).toHexString(), "darkblue hexstring" ); 
    119     hsv = Color.fromString("#4169E1").asHSV(); 
    120     approx( hsv.h, 5/8, "4169e1 h"); 
    121     approx( hsv.s, 32/45, "4169e1 s"); 
    122     approx( hsv.v, 15/17, "4169e1 l"); 
    123     is( Color.fromHSV(hsv).toHexString(), "#4169e1", "4169e1 hexstring" ); 
    124     hsv = Color.fromString("#555544").asHSV(); 
    125     approx( hsv.h, 1/6, "555544 h" ); 
    126     approx( hsv.s, 1/5, "555544 s" ); 
    127     approx( hsv.v, 1/3, "555544 l" ); 
    128     is( Color.fromHSV(hsv).toHexString(), "#555544", "555544 hexstring" ); 
    129     hsv = Color.fromRGB(0.5, 1, 0.5).asHSV(); 
    130     approx( hsv.h, 1/3, "aqua hsv.h" ); 
    131     approx( hsv.s, 0.5, "aqua hsv.s" ); 
    132     approx( hsv.v, 1, "aqua hsv.v" ); 
    133     is( 
    134         Color.fromHSV(hsv.h, hsv.s, hsv.v).toHexString(), 
    135         Color.fromRGB(0.5, 1, 0.5).toHexString(), 
    136         "fromHSV works with components" 
    137     ); 
    138     is( 
    139         Color.fromHSV(hsv).toHexString(), 
    140         Color.fromRGB(0.5, 1, 0.5).toHexString(), 
    141         "fromHSV alt form" 
    142     ); 
    143  
     24    var t = {ok:ok, is:is}; 
     25    tests.test_Color({ok:ok, is:is}); 
    14426    is( 
    14527        Color.fromText(SPAN()).toHexString(), 
     
    19274 
    19375} 
    194 } 
    19576</script> 
    19677</pre> 
    197 <div> 
    198     <span style="color: red" id="c_direct"></span> 
    199     <span class="redtext" id="c_indirect"></span> 
    200 </div> 
    20178</body> 
    20279</html> 
  • mochikit/branches/scriptaculous/tests/test_MochiKit-DateTime.html

    r418 r561  
    99 
    1010<pre id="test"> 
     11<script type="text/javascript" src="test_DateTime.js"></script> 
    1112<script type="text/javascript"> 
    1213try { 
     
    1415    // Counting the number of tests is really lame 
    1516    plan({'tests': 22}); 
    16     
    17     var testDate = isoDate('2005-2-3'); 
    18     is(testDate.getFullYear(), 2005, "isoDate year ok"); 
    19     is(testDate.getDate(), 3, "isoDate day ok"); 
    20     is(testDate.getMonth(), 1, "isoDate month ok"); 
    21     ok(objEqual(testDate, new Date("February 3, 2005")), "matches string date"); 
    22     is(toISODate(testDate), '2005-02-03', 'toISODate ok'); 
    23  
    24     var testDate = isoDate('2005-06-08'); 
    25     is(testDate.getFullYear(), 2005, "isoDate year ok"); 
    26     is(testDate.getDate(), 8, "isoDate day ok"); 
    27     is(testDate.getMonth(), 5, "isoDate month ok"); 
    28     ok(objEqual(testDate, new Date("June 8, 2005")), "matches string date"); 
    29     is(toISODate(testDate), '2005-06-08', 'toISODate ok'); 
    30  
    31     is(compare(new Date("February 3, 2005"), new Date(2005, 1, 3)), 0, "dates compare eq"); 
    32     is(compare(new Date("February 3, 2005"), new Date(2005, 2, 3)), -1, "dates compare lt"); 
    33     is(compare(new Date("February 3, 2005"), new Date(2005, 0, 3)), 1, "dates compare gt"); 
    34  
    35     var testDate = isoDate('2005-2-3'); 
    36     is(compare(americanDate('2/3/2005'), testDate), 0, "americanDate eq"); 
    37     is(compare('2/3/2005', toAmericanDate(testDate)), 0, "toAmericanDate eq"); 
    38  
    39     var testTimestamp = isoTimestamp('2005-2-3 22:01:03'); 
    40     is(compare(testTimestamp, new Date(2005,1,3,22,1,3)), 0, "isoTimestamp eq"); 
    41     is(compare(testTimestamp, isoTimestamp('2005-2-3T22:01:03')), 0, "isoTimestamp (real ISO) eq"); 
    42     is(compare(toISOTimestamp(testTimestamp), '2005-02-03 22:01:03'), 0, "toISOTimestamp eq"); 
    43     testTimestamp = isoTimestamp('2005-2-3T22:01:03Z'); 
    44     is(toISOTimestamp(testTimestamp, true), '2005-02-03T22:01:03Z', "toISOTimestamp (real ISO) eq"); 
    45  
    46     var localTZ = Math.round((new Date()).getTimezoneOffset()/60) 
    47     var direction = (localTZ < 0) ? "+" : "-"; 
    48     localTZ = Math.abs(localTZ); 
    49     localTZ = direction + ((localTZ < 10) ? "0" : "") + localTZ; 
    50     testTimestamp = isoTimestamp("2005-2-3T22:01:03" + localTZ); 
    51     var testDateTimestamp = new Date(2005,1,3,22,1,3); 
    52     is(compare(testTimestamp, testDateTimestamp), 0, "equal with local tz"); 
    53     testTimestamp = isoTimestamp("2005-2-3T17:01:03-05"); 
    54     var testDateTimestamp = new Date(Date.UTC(2005,1,3,22,1,3)); 
    55     is(compare(testTimestamp, testDateTimestamp), 0, "equal with specific tz"); 
    56      
    57     // Done! 
    58  
     17    tests.test_DateTime({ok:ok, is:is}); 
    5918    ok( true, "test suite finished!"); 
    6019     
  • mochikit/branches/scriptaculous/tests/test_MochiKit-Format.html

    r434 r561  
    99 
    1010<pre id="test"> 
     11<script type="text/javascript" src="test_Format.js"></script> 
    1112<script type="text/javascript"> 
    1213try { 
     
    1415    // Counting the number of tests is really lame 
    1516    plan({'tests': 53}); 
    16     
    17     is( truncToFixed(0.1234, 3), "0.123", "truncToFixed truncate" ); 
    18     is( truncToFixed(0.12, 3), "0.120", "truncToFixed trailing zeros" ); 
    19     is( truncToFixed(0.15, 1), "0.1", "truncToFixed no round" ); 
    20     is( truncToFixed(0.15, 0), "0", "truncToFixed zero (edge case)" ); 
    21  
    22     is( roundToFixed(0.1234, 3), "0.123", "roundToFixed truncate" ); 
    23     is( roundToFixed(0.12, 3), "0.120", "roundToFixed trailing zeros" ); 
    24     is( roundToFixed(0.15, 1), "0.2", "roundToFixed round" ); 
    25     is( roundToFixed(0.15, 0), "0", "roundToFixed zero (edge case)" ); 
    26  
    27     is( twoDigitFloat(-0.1234), "-0.12", "twoDigitFloat -0.1234 correct"); 
    28     is( twoDigitFloat(-0.1), "-0.1", "twoDigitFloat -0.1 correct"); 
    29     is( twoDigitFloat(-0), "0", "twoDigitFloat -0 correct"); 
    30     is( twoDigitFloat(0), "0", "twoDigitFloat 0 correct"); 
    31     is( twoDigitFloat(1), "1", "twoDigitFloat 1 correct"); 
    32     is( twoDigitFloat(1.0), "1", "twoDigitFloat 1.0 correct"); 
    33     is( twoDigitFloat(1.2), "1.2", "twoDigitFloat 1.2 correct"); 
    34     is( twoDigitFloat(1.234), "1.23", "twoDigitFloat 1.234 correct"); 
    35     is( percentFormat(123), "12300%", "percentFormat 123 correct"); 
    36     is( percentFormat(1.23), "123%", "percentFormat 123 correct"); 
    37     is( twoDigitAverage(1, 0), "0", "twoDigitAverage dbz correct"); 
    38     is( twoDigitAverage(1, 1), "1", "twoDigitAverage 1 correct"); 
    39     is( twoDigitAverage(1, 10), "0.1", "twoDigitAverage .1 correct"); 
    40     function reprIs(a, b) { 
    41         arguments[0] = repr(a); 
    42         arguments[1] = repr(b); 
    43         is.apply(this, arguments); 
    44     } 
    45     reprIs( lstrip("\r\t\n foo \n\t\r"), "foo \n\t\r", "lstrip whitespace chars" ); 
    46     reprIs( rstrip("\r\t\n foo \n\t\r"), "\r\t\n foo", "rstrip whitespace chars" ); 
    47     reprIs( strip("\r\t\n foo \n\t\r"), "foo", "strip whitespace chars" ); 
    48     reprIs( lstrip("\r\n\t \r", "\r"), "\n\t \r", "lstrip custom chars" ); 
    49     reprIs( rstrip("\r\n\t \r", "\r"), "\r\n\t ", "rstrip custom chars" ); 
    50     reprIs( strip("\r\n\t \r", "\r"), "\n\t ", "strip custom chars" ); 
    51  
    52     var nf = numberFormatter("$###,###.00 footer"); 
    53     is( nf(1000.1), "$1,000.10 footer", "trailing zeros" ); 
    54     is( nf(1000000.1), "$1,000,000.10 footer", "two seps" ); 
    55     is( nf(100), "$100.00 footer", "shorter than sep" ); 
    56     is( nf(100.555), "$100.56 footer", "rounding" ); 
    57     is( nf(-100.555), "$-100.56 footer", "default neg" ); 
    58     nf = numberFormatter("-$###,###.00"); 
    59     is( nf(-100.555), "-$100.56", "custom neg" ); 
    60     nf = numberFormatter("0000.0000"); 
    61     is( nf(0), "0000.0000", "leading and trailing" ); 
    62     is( nf(1.1), "0001.1000", "leading and trailing" ); 
    63     is( nf(12345.12345), "12345.1235", "no need for leading/trailing" ); 
    64     nf = numberFormatter("0000.0000"); 
    65     is( nf("taco"), "", "default placeholder" ); 
    66     nf = numberFormatter("###,###.00", "foo", "de_DE"); 
    67     is( nf("taco"), "foo", "custom placeholder" ); 
    68     is( nf(12345.12345), "12.345,12", "de_DE locale" ); 
    69     nf = numberFormatter("#%"); 
    70     is( nf(1), "100%", "trivial percent" ); 
    71     is( nf(0.55), "55%", "percent" ); 
    72  
    73     var customLocale = { 
    74         separator: " apples and ", 
    75         decimal: " bagels at ", 
    76         percent: "am for breakfast"}; 
    77     var customFormatter = numberFormatter("###,###.0%", "No breakfast", customLocale); 
    78     is( customFormatter(23.458), "2 apples and 345 bagels at 8am for breakfast", "custom locale" ); 
    79  
    80     nf = numberFormatter("###,###"); 
    81     is( nf(123), "123", "large number format" ); 
    82     is( nf(1234), "1,234", "large number format" ); 
    83     is( nf(12345), "12,345", "large number format" ); 
    84     is( nf(123456), "123,456", "large number format" ); 
    85     is( nf(1234567), "1,234,567", "large number format" ); 
    86     is( nf(12345678), "12,345,678", "large number format" ); 
    87     is( nf(123456789), "123,456,789", "large number format" ); 
    88     is( nf(1234567890), "1,234,567,890", "large number format" ); 
    89     is( nf(12345678901), "12,345,678,901", "large number format" ); 
    90     is( nf(123456789012), "123,456,789,012", "large number format" ); 
    91      
    92     // Done! 
    93  
     17    tests.test_Format({ok:ok, is:is}); 
    9418    ok( true, "test suite finished!"); 
    9519     
  • mochikit/branches/scriptaculous/tests/test_MochiKit-Iter.html

    r426 r561  
    99 
    1010<pre id="test"> 
     11<script type="text/javascript" src="test_Iter.js"></script> 
    1112<script type="text/javascript"> 
    1213try { 
     
    1415    // Counting the number of tests is really lame 
    1516    plan({'tests': 66}); 
    16  
    17     is( sum([1, 2, 3, 4, 5]), 15, "sum works on Arrays" ); 
    18     is( compare(list([1, 2, 3]), [1, 2, 3]), 0, "list([x]) == [x]" ); 
    19     is( compare(list(range(6, 0, -1)), [6, 5, 4, 3, 2, 1]), 0, "list(range(6, 0, -1)"); 
    20     is( compare(list(range(6)), [0, 1, 2, 3, 4, 5]), 0, "list(range(6))" ); 
    21     var moreThanTwo = partial(operator.lt, 2); 
    22     is( sum(ifilter(moreThanTwo, range(6))), 12, "sum(ifilter(, range()))" );  
    23     is( sum(ifilterfalse(moreThanTwo, range(6))), 3, "sum(ifilterfalse(, range()))" );  
    24  
    25     var c = count(10); 
    26     is( compare([c.next(), c.next(), c.next()], [10, 11, 12]), 0, "count()" ); 
    27     c = cycle([1, 2]); 
    28     is( compare([c.next(), c.next(), c.next()], [1, 2, 1]), 0, "cycle()" ); 
    29     c = repeat("foo", 3); 
    30     is( compare(list(c), ["foo", "foo", "foo"]), 0, "repeat()" ); 
    31     c = izip([1, 2], [3, 4, 5], repeat("foo")); 
    32     is( compare(list(c), [[1, 3, "foo"], [2, 4, "foo"]]), 0, "izip()" ); 
    33  
    34     is( compare(list(range(5)), [0, 1, 2, 3, 4]), 0, "range(x)" ); 
    35     c = islice(range(10), 0, 10, 2); 
    36     is( compare(list(c), [0, 2, 4, 6, 8]), 0, "islice(x, y, z)" ); 
    37  
    38     c = imap(operator.add, [1, 2, 3], [2, 4, 6]); 
    39     is( compare(list(c), [3, 6, 9]), 0, "imap(fn, p, q)" ); 
    40  
    41     c = filter(partial(operator.lt, 1), iter([1, 2, 3])); 
    42     is( compare(c, [2, 3]), 0, "filter(fn, iterable)" ); 
    43  
    44     c = map(partial(operator.add, -1), iter([1, 2, 3])); 
    45     is( compare(c, [0, 1, 2]), 0, "map(fn, iterable)" ); 
    46  
    47     c = map(operator.add, iter([1, 2, 3]), [2, 4, 6]); 
    48     is( compare(c, [3, 6, 9]), 0, "map(fn, iterable, q)" ); 
    49  
    50     c = map(operator.add, iter([1, 2, 3]), iter([2, 4, 6])); 
    51     is( compare(c, [3, 6, 9]), 0, "map(fn, iterable, iterable)" ); 
    52  
    53     c = applymap(operator.add, [[1, 2], [2, 4], [3, 6]]); 
    54     is( compare(list(c), [3, 6, 9]), 0, "applymap()" ); 
    55  
    56     c = applymap(function (a) { return [this, a]; }, [[1], [2]], 1); 
    57     is( compare(list(c), [[1, 1], [1, 2]]), 0, "applymap(self)" ); 
    58  
    59     c = chain(range(2), range(3)); 
    60     is( compare(list(c), [0, 1, 0, 1, 2]), 0, "chain(p, q)" ); 
    61  
    62     var lessThanFive = partial(operator.gt, 5); 
    63     c = takewhile(lessThanFive, count()); 
    64     is( compare(list(c), [0, 1, 2, 3, 4]), 0, "takewhile()" ); 
    65  
    66     c = dropwhile(lessThanFive, range(10)); 
    67     is( compare(list(c), [5, 6, 7, 8, 9]), 0, "dropwhile()" ); 
    68  
    69     c = tee(range(5), 3); 
    70     is( compare(list(c[0]), list(c[1])), 0, "tee(..., 3) p0 == p1" ); 
    71     is( compare(list(c[2]), [0, 1, 2, 3, 4]), 0, "tee(..., 3) p2 == fixed" ); 
    72  
    73     is( compare(reduce(operator.add, range(10)), 45), 0, "reduce(op.add)" ); 
    74  
    75     try { 
    76         reduce(operator.add, []); 
    77         ok( false, "reduce didn't raise anything with empty list and no start?!" ); 
    78     } catch (e) { 
    79         if (e instanceof TypeError) { 
    80             ok( true, "reduce raised TypeError correctly" ); 
    81         } else { 
    82             ok( false, "reduce raised the wrong exception?" ); 
    83         } 
    84     } 
    85  
    86     is( reduce(operator.add, [], 10), 10, "range initial value OK empty" ); 
    87     is( reduce(operator.add, [1], 10), 11, "range initial value OK populated" ); 
    88  
    89     is( compare(iextend([1], range(2)), [1, 0, 1]), 0, "iextend(...)" ); 
    90  
    91     var x = []; 
    92     exhaust(imap(bind(x.push, x), range(5))); 
    93     is( compare(x, [0, 1, 2, 3, 4]), 0, "exhaust(...)" ); 
    94  
    95     is( every([1, 2, 3, 4, 5, 4], lessThanFive), false, "every false" ); 
    96     is( every([1, 2, 3, 4, 4], lessThanFive), true, "every true" ); 
    97     is( some([1, 2, 3, 4, 4], lessThanFive), true, "some true" ); 
    98     is( some([5, 6, 7, 8, 9], lessThanFive), false, "some false" ); 
    99     is( some([5, 6, 7, 8, 4], lessThanFive), true, "some true" ); 
    100  
    101     var rval = []; 
    102     forEach(range(2), rval.push, rval); 
    103     is( compare(rval, [0, 1]), 0, "forEach works bound" ); 
    104  
    105     function foo(o) { 
    106         rval.push(o); 
    107     } 
    108     forEach(range(2), foo); 
    109     is( compare(rval, [0, 1, 0, 1]), 0, "forEach works unbound" ); 
    110      
    111     is( compare(sorted([3, 2, 1]), [1, 2, 3]), 0, "sorted default" ); 
    112     rval = sorted(["aaa", "bb", "c"], keyComparator("length")); 
    113     is(compare(rval, ["c", "bb", "aaa"]), 0, "sorted custom"); 
    114  
    115     is( compare(reversed(range(4)), [3, 2, 1, 0]), 0, "reversed iterator" ); 
    116     is( compare(reversed([5, 6, 7]), [7, 6, 5]), 0, "reversed list" ); 
    117  
    118     var o = {lst: [1, 2, 3], iterateNext: function () { return this.lst.shift(); }}; 
    119     is( compare(list(o), [1, 2, 3]), 0, "iterateNext" ); 
    120  
    121  
    122     function except(exc, func) { 
    123         try { 
    124             func(); 
    125             Test.More.fail(exc.name + " was not raised."); 
    126         } catch (e) { 
    127             if (e == exc) { 
    128                 ok( true, "raised " + exc.name + " correctly" ); 
    129             } else { 
    130                 ok( false, "raised the wrong exception?" ); 
    131             } 
    132         } 
    133     } 
    134  
    135     odd = partial(operator.and, 1) 
    136  
    137     // empty 
    138     grouped = groupby([]); 
    139     except(StopIteration, grouped.next); 
    140  
    141     // exhaust sub-iterator 
    142     grouped = groupby([2,4,6,7], odd); 
    143     kv = grouped.next(); k = kv[0], subiter = kv[1]; 
    144     is(k, 0, "odd(2) = odd(4) = odd(6) == 0"); 
    145     is(subiter.next(), 2, "sub-iterator.next() == 2"); 
    146     is(subiter.next(), 4, "sub-iterator.next() == 4"); 
    147     is(subiter.next(), 6, "sub-iterator.next() == 6"); 
    148     except(StopIteration, subiter.next); 
    149     kv = grouped.next(); key = kv[0], subiter = kv[1]; 
    150     is(key, 1, "odd(7) == 1"); 
    151     is(subiter.next(), 7, "sub-iterator.next() == 7"); 
    152     except(StopIteration, subiter.next); 
    153  
    154     // not consume sub-iterator 
    155     grouped = groupby([2,4,6,7], odd); 
    156     kv = grouped.next(); key = kv[0], subiter = kv[1]; 
    157     is(key, 0, "0 = odd(2) = odd(4) = odd(6)"); 
    158     kv = grouped.next(); key = kv[0], subiter = kv[1]; 
    159     is(key, 1, "1 = odd(7)"); 
    160     except(StopIteration, grouped.next); 
    161  
    162     // consume sub-iterator partially 
    163     grouped = groupby([3,1,1,2], odd); 
    164     kv = grouped.next(); key = kv[0], subiter = kv[1]; 
    165     is(key, 1, "odd(1) == 1"); 
    166     is(subiter.next(), 3, "sub-iterator.next() == 3"); 
    167     kv = grouped.next(); key = kv[0], v = kv[1]; 
    168     is(key, 0, "skip (1,1),  odd(2) == 0"); 
    169     except(StopIteration, grouped.next); 
    170  
    171     // null 
    172     grouped = groupby([null,null]); 
    173     kv = grouped.next(); k = kv[0], v = kv[1]; 
    174     is(k, null, "null ok"); 
    175  
    176     // groupby - array version 
    177     isSet(groupby_as_array([ ]    ), [                        ], "empty"); 
    178     isSet(groupby_as_array([1,1,1]), [ [1,[1,1,1]]            ], "[1,1,1]: [1,1,1]"); 
    179     isSet(groupby_as_array([1,2,2]), [ [1,[1]    ], [2,[2,2]] ], "[1,2,2]: [1], [2,2]"); 
    180     isSet(groupby_as_array([1,1,2]), [ [1,[1,1]  ], [2,[2  ]] ], "[1,1,2]: [1,1], [2]"); 
    181     isSet(groupby_as_array([null,null] ), [ [null,[null,null]] ], "[null,null]: [null,null]"); 
    182     grouped = groupby_as_array([1,1,3,2,4,6,8], odd); 
    183     isSet(grouped, [[1, [1,1,3]], [0,[2,4,6,8]]], "[1,1,3,2,4,6,7] odd: [1,1,3], [2,4,6,8]"); 
    184  
     17    tests.test_Iter({ok:ok, is:is}); 
    18518    ok( true, "test suite finished!"); 
    18619     
  • mochikit/branches/scriptaculous/tests/test_MochiKit-Logging.html

    r384 r561  
    99 
    1010<pre id="test"> 
     11<script type="text/javascript" src="test_Logging.js"></script> 
    1112<script type="text/javascript"> 
    1213try { 
     
    1415    // Counting the number of tests is really lame 
    1516    plan({'tests': 27}); 
    16     
    17     // just in case 
    18     logger.clear(); 
    19  
    20     is( logLevelAtLeast('DEBUG')('INFO'), false, 'logLevelAtLeast false' ); 
    21     is( logLevelAtLeast('WARNING')('INFO'), false, 'logLevelAtLeast true' ); 
    22     ok( logger instanceof Logger, "global logger installed" ); 
    23  
    24     var allMessages = []; 
    25     logger.addListener("allMessages", null, 
    26         bind(allMessages.push, allMessages)); 
    27  
    28     var fatalMessages = []; 
    29     logger.addListener("fatalMessages", "FATAL", 
    30         bind(fatalMessages.push, fatalMessages)); 
    31  
    32     var firstTwo = []; 
    33     logger.addListener("firstTwo", null, 
    34         bind(firstTwo.push, firstTw