15 var Rules = function(){
16 return this + ' rules';
19 var Args = function(){
20 return [this].concat($A(arguments));
23 describe("Function Methods", {
27 'should return a new function': function(){
28 var fnc = $empty.create();
29 value_of($empty === fnc).should_be_false();
32 'should return a new function with specified argument': function(){
33 var fnc = fn.create({'arguments': 'rocks'});
34 value_of(fnc()).should_be(['rocks']);
37 'should return a new function with multiple arguments': function(){
38 var fnc = fn.create({'arguments': ['MooTools', 'rocks']});
39 value_of(fnc()).should_be(['MooTools', 'rocks']);
42 'should return a new function bound to an object': function(){
43 var fnc = Rules.create({'bind': 'MooTools'});
44 value_of(fnc()).should_be('MooTools rules');
47 'should return a new function as an event': function(){
48 var fnc = fn.create({'arguments': [0, 1], 'event': true});
49 value_of(fnc('an Event occurred')).should_be(['an Event occurred', 0, 1]);
54 'should return the function bound to an object': function(){
55 var fnc = Rules.bind('MooTools');
56 value_of(fnc()).should_be('MooTools rules');
59 'should return the function bound to an object with specified argument': function(){
60 var fnc = Args.bind('MooTools', 'rocks');
61 value_of(fnc()).should_be(['MooTools', 'rocks']);
64 'should return the function bound to an object with multiple arguments': function(){
65 var fnc = Args.bind('MooTools', ['rocks', 'da house']);
66 value_of(fnc()).should_be(['MooTools', 'rocks', 'da house']);
69 'should return the function bound to an object and make the function an event listener': function(){
70 var fnc = Args.bindWithEvent('MooTools');
71 value_of(fnc('an Event ocurred')).should_be(['MooTools', 'an Event ocurred']);
74 'should return the function bound to an object and make the function event listener with multiple arguments': function(){
75 var fnc = Args.bindWithEvent('MooTools', ['rocks', 'da house']);
76 value_of(fnc('an Event ocurred')).should_be(['MooTools', 'an Event ocurred', 'rocks', 'da house']);
81 'should return a function that when called passes the specified arguments to the original function': function(){
82 var fnc = fn.pass('MooTools is beautiful and elegant');
83 value_of(fnc()).should_be(['MooTools is beautiful and elegant']);
86 'should pass multiple arguments and bind the function to a specific object when it is called': function(){
87 var fnc = Args.pass(['rocks', 'da house'], 'MooTools');
88 value_of(fnc()).should_be(['MooTools', 'rocks', 'da house']);
93 'should run the function': function(){
94 var result = fn.run();
95 value_of(result).should_be([]);
98 'should run the function with multiple arguments': function(){
99 var result = fn.run(['MooTools', 'beautiful', 'elegant']);
100 value_of(result).should_be(['MooTools', 'beautiful', 'elegant']);
103 'should run the function with multiple arguments and bind the function to an object': function(){
104 var result = Args.run(['beautiful', 'elegant'], 'MooTools');
105 value_of(result).should_be(['MooTools', 'beautiful', 'elegant']);
110 "should extend the function's properties": function(){
111 var fnc = (function(){}).extend({a: 1, b: 'c'});
112 value_of(fnc.a).should_be(1);
113 value_of(fnc.b).should_be('c');
118 'should call the function without raising an exception': function(){
119 var fnc = function(){
120 this_should_not_work();
125 "should return the function's return value": function(){
126 var fnc = $lambda('hello world!');
127 value_of(fnc.attempt()).should_be('hello world!');
130 'should return null if the function raises an exception': function(){
131 var fnc = function(){
132 this_should_not_work();
134 value_of(fnc.attempt()).should_be_null();
139 'delay should return a timer pointer': function(){
140 var timer = $empty.delay(10000);
141 value_of(Number.type(timer)).should_be_true();
145 // Function.periodical
147 'periodical should return a timer pointer': function(){
148 var timer = $empty.periodical(10000);
149 value_of(Number.type(timer)).should_be_true();