Skip to content
Browse files

Fixes #2134 - Merge branch 'specs' into fix-2134-merge-specs-submodule

Conflicts:
	.gitignore
	.gitmodules
  • Loading branch information...
2 parents fa2a8c8 + 4ebf266 commit f80ca2065f38bc6e356f30a47a630d2332c8f14f @arian arian committed
Showing with 10,389 additions and 1 deletion.
  1. +3 −1 .gitignore
  2. +4 −0 .gitmodules
  3. +326 −0 Specs/1.2/Class/Class.Extras.js
  4. +247 −0 Specs/1.2/Class/Class.js
  5. +40 −0 Specs/1.2/Core/Browser.js
  6. +418 −0 Specs/1.2/Core/Core.js
  7. +69 −0 Specs/1.2/Core/Native.js
  8. +134 −0 Specs/1.2/Element/Element.Dimensions.js
  9. +87 −0 Specs/1.2/Element/Element.Style.js
  10. +1,568 −0 Specs/1.2/Element/Element.js
  11. +207 −0 Specs/1.2/Native/Array.js
  12. +155 −0 Specs/1.2/Native/Function.js
  13. +203 −0 Specs/1.2/Native/Hash.js
  14. +114 −0 Specs/1.2/Native/Number.js
  15. +158 −0 Specs/1.2/Native/String.js
  16. +17 −0 Specs/1.2/Utilities/Cookie.js
  17. +280 −0 Specs/1.3base/Class/Class.js
  18. +480 −0 Specs/1.3base/Core/Core.js
  19. +159 −0 Specs/1.3base/Fx/Fx.js
  20. +271 −0 Specs/1.3base/Types/Array.js
  21. +201 −0 Specs/1.3base/Types/Function.js
  22. +128 −0 Specs/1.3base/Types/Object.js
  23. +15 −0 Specs/1.3base/package.yml
  24. +20 −0 Specs/1.3client/Browser/Browser.js
  25. +183 −0 Specs/1.3client/Class/Class.Extras.js
  26. +56 −0 Specs/1.3client/Core/Core.js
  27. +86 −0 Specs/1.3client/Element/Element.Dimensions.js
  28. +85 −0 Specs/1.3client/Element/Element.Event.js
  29. +38 −0 Specs/1.3client/Element/Element.Style.js
  30. +360 −0 Specs/1.3client/Element/Element.js
  31. +32 −0 Specs/1.3client/Element/IFrame.js
  32. +128 −0 Specs/1.3client/Element/NewElement.js
  33. +58 −0 Specs/1.3client/Fx/Fx.Morph.js
  34. +127 −0 Specs/1.3client/Fx/Fx.Tween.js
  35. +254 −0 Specs/1.3client/Request/Request.HTML.js
  36. +64 −0 Specs/1.3client/Request/Request.JSON.js
  37. +140 −0 Specs/1.3client/Request/Request.js
  38. +29 −0 Specs/1.3client/Types/Object.js
  39. +25 −0 Specs/1.3client/Utilities/Cookie.js
  40. +33 −0 Specs/1.3client/Utilities/DOMReady.js
  41. +453 −0 Specs/1.3client/Utilities/DOMReady.php
  42. +33 −0 Specs/1.3client/Utilities/JSON.js
  43. +26 −0 Specs/1.3client/package.yml
  44. +29 −0 Specs/1.4base/Types/Array.js
  45. +32 −0 Specs/1.4base/Types/Function-nocompat.js
  46. +268 −0 Specs/1.4client/Element/Element.Delegation.html
  47. +58 −0 Specs/1.4client/Element/Element.Delegation.js
  48. +131 −0 Specs/1.4client/Element/Element.Event.change.html
  49. +85 −0 Specs/1.4client/Element/Element.Event.js
  50. +224 −0 Specs/1.4client/Element/Element.js
  51. +46 −0 Specs/1.4client/Fx/Fx.Tween.js
  52. +10 −0 Specs/1.4client/package.yml
  53. +572 −0 Specs/2.0base/Core/Core.js
  54. +291 −0 Specs/2.0base/Types/Array.js
  55. +232 −0 Specs/2.0base/Types/Function.js
  56. +132 −0 Specs/2.0base/Types/Number.js
  57. +176 −0 Specs/2.0base/Types/Object.js
  58. +149 −0 Specs/2.0base/Types/String.js
  59. +21 −0 Specs/2.0client/Browser/Browser.js
  60. +341 −0 Specs/Configuration.js
  61. +48 −0 Specs/README.md
  62. +1 −0 Specs/Runner
  63. +1 −0 Specs/buildMobile
  64. +28 −0 Specs/index.html
View
4 .gitignore
@@ -1,3 +1,5 @@
mootools-core.js
mootools-core.tmproj
-mootools-core.esproj
+mootools-core.esproj
+mootools-core-mobile.js
+*~
View
4 .gitmodules
@@ -1,3 +1,7 @@
[submodule "Packager"]
path = Packager
url = git://github.com/kamicane/packager.git
+[submodule "Specs/Runner"]
+ path = Specs/Runner
+ url = git://github.com/mootools/mootools-runner.git
+
View
326 Specs/1.2/Class/Class.Extras.js
@@ -0,0 +1,326 @@
+/*
+Script: Class.Extras.js
+ Public specs for Class.Extras.js
+
+License:
+ MIT-style license.
+*/
+
+(function(){
+
+var Local = Local || {};
+
+describe("Chain Class", {
+
+ "before all": function(){
+ Local.Chain = new Class({
+
+ Implements: Chain
+
+ });
+ },
+
+ "callChain should not fail when nothing was added to the chain": function(){
+ var chain = new Local.Chain();
+ chain.callChain();
+ },
+
+ "should pass arguments to the function and return values": function(){
+ var chain = new Local.Chain();
+ var arr = [];
+ chain.chain(function(a, b){
+ var str = "0" + b + a;
+ arr.push(str);
+ return str;
+ });
+ chain.chain(function(a, b){
+ var str = "1" + b + a;
+ arr.push(str);
+ return str;
+ });
+ var ret;
+ expect(arr).toEqual([]);
+ ret = chain.callChain("a", "A");
+ expect(ret).toEqual("0Aa");
+ expect(arr).toEqual(["0Aa"]);
+
+ ret = chain.callChain("b", "B");
+ expect(ret).toEqual("1Bb");
+ expect(arr).toEqual(["0Aa", "1Bb"]);
+
+ ret = chain.callChain();
+ expect(ret).toEqual(false);
+ expect(arr).toEqual(["0Aa", "1Bb"]);
+ },
+
+ "should chain any number of functions": function(){
+ var chain = new Local.Chain();
+ var arr = [];
+
+ chain.chain(function(){
+ arr.push(0);
+ }, function(){
+ arr.push(1);
+ });
+
+ expect(arr).toEqual([]);
+ chain.callChain();
+ expect(arr).toEqual([0]);
+ chain.chain(function(){
+ arr.push(2);
+ });
+ chain.callChain();
+ expect(arr).toEqual([0, 1]);
+ chain.callChain();
+ expect(arr).toEqual([0, 1, 2]);
+ chain.callChain();
+ expect(arr).toEqual([0, 1, 2]);
+ },
+
+ "should allow an array of functions": function(){
+ var chain = new Local.Chain();
+ var arr = [];
+
+ chain.chain([function(){
+ arr.push(0);
+ }, function(){
+ arr.push(1);
+ }, function(){
+ arr.push(2);
+ }]);
+
+ expect(arr).toEqual([]);
+ chain.callChain();
+ expect(arr).toEqual([0]);
+ chain.callChain();
+ expect(arr).toEqual([0, 1]);
+ chain.callChain();
+ expect(arr).toEqual([0, 1, 2]);
+ chain.callChain();
+ expect(arr).toEqual([0, 1, 2]);
+ },
+
+ "each instance should have its own chain": function(){
+ var foo = new Local.Chain();
+ var bar = new Local.Chain();
+ foo.val = "F";
+ bar.val = "B";
+ foo.chain(function(){
+ this.val += 'OO';
+ });
+ bar.chain(function(){
+ this.val += 'AR';
+ });
+ expect(foo.val).toEqual('F');
+ expect(bar.val).toEqual('B');
+ foo.callChain();
+ bar.callChain();
+ expect(foo.val).toEqual('FOO');
+ expect(bar.val).toEqual('BAR');
+ },
+
+ "should be able to clear the chain": function(){
+ var called;
+ var fn = function(){
+ called = true;
+ };
+
+ var chain = new Local.Chain();
+ chain.chain(fn, fn, fn, fn);
+
+ chain.callChain();
+ expect(called).toBeTruthy();
+ called = false;
+
+ chain.clearChain();
+
+ chain.callChain();
+ expect(called).toBeFalsy();
+ called = false;
+ },
+
+ "should be able to clear the chain from within": function(){
+ var foo = new Local.Chain();
+
+ var test = 0;
+ foo.chain(function(){
+ test++;
+ foo.clearChain();
+ }).chain(function(){
+ test++;
+ }).callChain();
+
+ expect(test).toEqual(1);
+ }
+
+});
+
+var fire = 'fireEvent';
+
+var runEventSpecs = function(type, create){
+ describe('1.2 Events API: ' + type.capitalize(), {
+
+ 'before each': function(){
+ Local.called = 0;
+ Local.fn = function(){
+ return Local.called++;
+ };
+ },
+
+ 'should add an Event to the Class': function(){
+ var object = create();
+
+ object.addEvent('event', Local.fn)[fire]('event');
+
+ expect(Local.called).toEqual(1);
+ },
+
+ 'should add multiple Events to the Class': function(){
+ create().addEvents({
+ event1: Local.fn,
+ event2: Local.fn
+ })[fire]('event1')[fire]('event2');
+
+ expect(Local.called).toEqual(2);
+ },
+
+ // TODO 2.0only
+ /*'should be able to remove event during firing': function(){
+ create().addEvent('event', Local.fn).addEvent('event', function(){
+ Local.fn();
+ this.removeEvent('event', arguments.callee);
+ }).addEvent('event', function(){ Local.fn(); })[fire]('event')[fire]('event');
+
+ expect(Local.called).toEqual(5);
+ },*/
+
+ 'should remove a specific method for an event': function(){
+ var object = create();
+ var x = 0, fn = function(){ x++; };
+
+ object.addEvent('event', Local.fn).addEvent('event', fn).removeEvent('event', Local.fn)[fire]('event');
+
+ expect(x).toEqual(1);
+ expect(Local.called).toEqual(0);
+ },
+
+ 'should remove an event and its methods': function(){
+ var object = create();
+ var x = 0, fn = function(){ x++; };
+
+ object.addEvent('event', Local.fn).addEvent('event', fn).removeEvents('event')[fire]('event');
+
+ expect(x).toEqual(0);
+ expect(Local.called).toEqual(0);
+ },
+
+ 'should remove all events': function(){
+ var object = create();
+ var x = 0, fn = function(){ x++; };
+
+ object.addEvent('event1', Local.fn).addEvent('event2', fn).removeEvents();
+ object[fire]('event1')[fire]('event2');
+
+ expect(x).toEqual(0);
+ expect(Local.called).toEqual(0);
+ },
+
+ 'should remove events with an object': function(){
+ var object = create();
+ var events = {
+ event1: Local.fn,
+ event2: Local.fn
+ };
+
+ object.addEvent('event1', function(){ Local.fn(); }).addEvents(events)[fire]('event1');
+ expect(Local.called).toEqual(2);
+
+ object.removeEvents(events);
+ object[fire]('event1');
+ expect(Local.called).toEqual(3);
+
+ object[fire]('event2');
+ expect(Local.called).toEqual(3);
+ }
+
+ });
+};
+
+runEventSpecs('mixin', function(){
+ return new Events
+});
+
+runEventSpecs('element', function(){
+ return new Element('div');
+});
+
+describe("Options Class", {
+
+ "before all": function(){
+ Local.OptionsTest = new Class({
+ Implements: [Options, Events],
+
+ options: {
+ a: 1,
+ b: 2
+ },
+
+ initialize: function(options){
+ this.setOptions(options);
+ }
+ });
+ },
+
+ "should set options": function(){
+ var myTest = new Local.OptionsTest({a: 1, b: 3});
+ expect(myTest.options).not.toEqual(undefined);
+ },
+
+ "should override default options": function(){
+ var myTest = new Local.OptionsTest({a: 3, b: 4});
+ expect(myTest.options.a).toEqual(3);
+ expect(myTest.options.b).toEqual(4);
+ }
+
+});
+
+describe("Options Class with Events", {
+
+ "before all": function(){
+ Local.OptionsTest = new Class({
+ Implements: [Options, Events],
+
+ options: {
+ onEvent1: function(){
+ return true;
+ },
+ onEvent2: function(){
+ return false;
+ }
+ },
+
+ initialize: function(options){
+ this.setOptions(options);
+ }
+ });
+ },
+
+ "should add events in the options object if class has implemented the Events class": function(){
+ var myTest = new Local.OptionsTest({
+ onEvent2: function(){
+ return true;
+ },
+
+ onEvent3: function(){
+ return true;
+ }
+ });
+
+ expect(myTest.$events.event1.length).toEqual(1);
+ expect(myTest.$events.event2.length).toEqual(1);
+ expect(myTest.$events.event3.length).toEqual(1);
+ }
+
+});
+
+})();
View
247 Specs/1.2/Class/Class.js
@@ -0,0 +1,247 @@
+/*
+Script: Class.js
+ Specs for Class.js
+
+License:
+ MIT-style license.
+*/
+
+(function(){
+
+var Animal = new Class({
+
+ initialized: false,
+
+ initialize: function(name, sound){
+ this.name = name;
+ this.sound = sound || '';
+ this.initialized = true;
+ },
+
+ eat: function(){
+ return 'animal:eat:' + this.name;
+ },
+
+ say: function(){
+ return 'animal:say:' + this.name;
+ }
+
+});
+
+var Cat = new Class({
+
+ Extends: Animal,
+
+ ferocious: false,
+
+ initialize: function(name, sound){
+ this.parent(name, sound || 'miao');
+ },
+
+ eat: function(){
+ return 'cat:eat:' + this.name;
+ },
+
+ play: function(){
+ return 'cat:play:' + this.name;
+ }
+
+});
+
+var Lion = new Class({
+
+ Extends: Cat,
+
+ ferocious: true,
+
+ initialize: function(name){
+ this.parent(name, 'rarr');
+ },
+
+ eat: function(){
+ return 'lion:eat:' + this.name;
+ }
+
+});
+
+var Actions = new Class({
+
+ jump: function(){
+ return 'actions:jump:' + this.name;
+ },
+
+ sleep: function(){
+ return 'actions:sleep:' + this.name;
+ }
+
+});
+
+var Attributes = new Class({
+
+ color: function(){
+ return 'attributes:color:' + this.name;
+ },
+
+ size: function(){
+ return 'attributes:size:' + this.name;
+ }
+
+});
+
+
+describe('Class creation', {
+
+ "Classes should be of type 'class'": function(){
+ expect($type(Animal)).toEqual('class');
+ expect(Class.type(Animal)).toBeTruthy();
+ },
+
+ "should call initialize upon instantiation": function(){
+ var animal = new Animal('lamina');
+ expect(animal.name).toEqual('lamina');
+ expect(animal.initialized).toBeTruthy();
+ expect(animal.say()).toEqual('animal:say:lamina');
+ },
+
+ "should use 'Extend' property to extend another class": function(){
+ var cat = new Cat('fluffy');
+ expect(cat.name).toEqual('fluffy');
+ expect(cat.sound).toEqual('miao');
+ expect(cat.ferocious).toBeFalsy();
+ expect(cat.say()).toEqual('animal:say:fluffy');
+ expect(cat.eat()).toEqual('cat:eat:fluffy');
+ expect(cat.play()).toEqual('cat:play:fluffy');
+ },
+
+ "should use 'Extend' property to extend an extended class": function(){
+ var leo = new Lion('leo');
+ expect(leo.name).toEqual('leo');
+ expect(leo.sound).toEqual('rarr');
+ expect(leo.ferocious).toBeTruthy();
+ expect(leo.say()).toEqual('animal:say:leo');
+ expect(leo.eat()).toEqual('lion:eat:leo');
+ expect(leo.play()).toEqual('cat:play:leo');
+ },
+
+ "should use 'Implements' property to implement another class": function(){
+ var Dog = new Class({
+ Implements: Animal
+ });
+
+ var rover = new Dog('rover');
+ expect(rover.name).toEqual('rover');
+ expect(rover.initialized).toBeTruthy();
+ expect(rover.eat()).toEqual('animal:eat:rover');
+ },
+
+ "should use 'Implements' property to implement any number of classes": function(){
+ var Dog = new Class({
+ Extends: Animal,
+ Implements: [Actions, Attributes]
+ });
+
+ var rover = new Dog('rover');
+ expect(rover.initialized).toBeTruthy();
+ expect(rover.eat()).toEqual('animal:eat:rover');
+ expect(rover.say()).toEqual('animal:say:rover');
+ expect(rover.jump()).toEqual('actions:jump:rover');
+ expect(rover.sleep()).toEqual('actions:sleep:rover');
+ expect(rover.size()).toEqual('attributes:size:rover');
+ expect(rover.color()).toEqual('attributes:color:rover');
+ },
+
+ "should alter the Class's prototype when implementing new methods": function(){
+ var Dog = new Class({
+ Extends: Animal
+ });
+
+ var rover = new Dog('rover');
+
+ Dog.implement({
+ jump: function(){
+ return 'dog:jump:' + this.name;
+ }
+ });
+
+ var spot = new Dog('spot');
+
+ expect(spot.jump()).toEqual('dog:jump:spot');
+ expect(rover.jump()).toEqual('dog:jump:rover');
+ },
+
+ "should alter the Class's prototype when implementing new methods into the super class": function(){
+ var Dog = new Class({
+ Extends: Animal
+ });
+
+ var rover = new Dog('rover');
+
+ Animal.implement({
+ jump: function(){
+ return 'animal:jump:' + this.name;
+ }
+ });
+
+ var spot = new Dog('spot');
+
+ expect(spot.jump()).toEqual('animal:jump:spot');
+ expect(rover.jump()).toEqual('animal:jump:rover');
+ },
+
+ "should alter the Class's prototype when overwriting methods in the super class": function(){
+ var Dog = new Class({
+ Extends: Animal
+ });
+
+ var rover = new Dog('rover');
+ expect(rover.say()).toEqual('animal:say:rover');
+
+ Animal.implement({
+ say: function(){
+ return 'NEW:animal:say:' + this.name;
+ }
+ });
+
+ var spot = new Dog('spot');
+
+ expect(spot.say()).toEqual('NEW:animal:say:spot');
+ expect(rover.say()).toEqual('NEW:animal:say:rover');
+ }
+
+});
+
+describe('Class::implement', {
+
+ 'should implement an object': function(){
+ var Dog = new Class({
+ Extends: Animal
+ });
+
+ Dog.implement(new Actions);
+
+ var rover = new Dog('rover');
+
+ expect(rover.name).toEqual('rover');
+ expect(rover.jump()).toEqual('actions:jump:rover');
+ expect(rover.sleep()).toEqual('actions:sleep:rover');
+ },
+
+ 'should implement any number of objects': function(){
+ var Dog = new Class({
+ Extends: Animal
+ });
+
+ Dog.implement(new Actions).implement(new Attributes);
+
+ var rover = new Dog('rover');
+
+ expect(rover.name).toEqual('rover');
+ expect(rover.jump()).toEqual('actions:jump:rover');
+ expect(rover.sleep()).toEqual('actions:sleep:rover');
+ expect(rover.size()).toEqual('attributes:size:rover');
+ expect(rover.color()).toEqual('attributes:color:rover');
+ }
+
+});
+
+})();
View
40 Specs/1.2/Core/Browser.js
@@ -0,0 +1,40 @@
+/*
+Script: Browser.js
+ Public Specs for Browser.js 1.2
+
+License:
+ MIT-style license.
+*/
+
+describe('$exec', {
+
+ 'should evaluate on global scope': function(){
+ $exec.call($exec, 'var execSpec = 42');
+ expect(window.execSpec).toEqual(42);
+ },
+
+ 'should return the evaluated script': function(){
+ expect($exec('$empty();')).toEqual('$empty();');
+ }
+
+});
+
+describe('Document', {
+
+ 'should hold the parent window': function(){
+ expect(document.window).toEqual(window);
+ },
+
+ 'should hold the head element': function(){
+ expect(document.head.tagName.toLowerCase()).toEqual('head');
+ }
+
+});
+
+describe('Window', {
+
+ 'should set the Element prototype': function(){
+ expect($defined(window.Element.prototype)).toBeTruthy();
+ }
+
+});
View
418 Specs/1.2/Core/Core.js
@@ -0,0 +1,418 @@
+/*
+Script: Core.js
+ Public Specs for Core.js 1.2
+
+License:
+ MIT-style license.
+*/
+
+describe('$A', {
+
+ 'should return a copy for an array': function(){
+ var arr1 = [1,2,3];
+ var arr2 = $A(arr1);
+ expect(arr1 !== arr2).toBeTruthy();
+ },
+
+ 'should return an array for an Elements collection': function(){
+ var div1 = document.createElement('div');
+ var div2 = document.createElement('div');
+ var div3 = document.createElement('div');
+
+ div1.appendChild(div2);
+ div1.appendChild(div3);
+
+ var array = $A(div1.getElementsByTagName('*'));
+ expect(Array.type(array)).toBeTruthy();
+ },
+
+ 'should return an array for arguments': function(){
+ var fnTest = function(){
+ return $A(arguments);
+ };
+ var arr = fnTest(1,2,3);
+ expect(Array.type(arr)).toBeTruthy();
+ expect(arr.length).toEqual(3);
+ }
+
+});
+
+describe('$arguments', {
+
+ 'should return the argument passed according to the index': function(){
+ expect($arguments(0)('a','b','c','d')).toEqual('a');
+ expect($arguments(1)('a','b','c','d')).toEqual('b');
+ expect($arguments(2)('a','b','c','d')).toEqual('c');
+ expect($arguments(3)('a','b','c','d')).toEqual('d');
+ }
+
+});
+
+describe('$chk', {
+
+ 'should return false on false': function(){
+ expect($chk(false)).toBeFalsy();
+ },
+
+ 'should return false on null': function(){
+ expect($chk(null)).toBeFalsy();
+ },
+
+ 'should return false on undefined': function(){
+ expect($chk(undefined)).toBeFalsy();
+ },
+
+ 'should return true on 0': function(){
+ expect($chk(0)).toBeTruthy();
+ },
+
+ 'should return true for any truthsie': function(){
+ expect($chk(1)).toBeTruthy();
+ expect($chk({})).toBeTruthy();
+ expect($chk(true)).toBeTruthy();
+ }
+
+});
+
+describe('$clear', {
+
+ 'should clear timeouts': function(){
+ var timeout = setTimeout(function(){}, 100);
+ expect($clear(timeout)).toBeNull();
+ },
+
+ 'should clear intervals': function(){
+ var interval = setInterval(function(){}, 100);
+ expect($clear(interval)).toBeNull();
+ }
+
+});
+
+describe('$defined', {
+
+ 'should return true on 0': function(){
+ expect($defined(0)).toBeTruthy();
+ },
+
+ 'should return true on false': function(){
+ expect($defined(false)).toBeTruthy();
+ },
+
+ 'should return false on null': function(){
+ expect($defined(null)).toBeFalsy();
+ },
+
+ 'should return false on undefined': function(){
+ expect($defined(undefined)).toBeFalsy();
+ }
+
+});
+
+describe('$each', {
+
+ 'should call the function for each item in Function arguments': function(){
+ var daysArr = [];
+ (function(){
+ $each(arguments, function(value, key){
+ daysArr[key] = value;
+ });
+ })('Sun','Mon','Tue');
+
+ expect(daysArr).toEqual(['Sun','Mon','Tue']);
+ },
+
+ 'should call the function for each item in the array': function(){
+ var daysArr = [];
+ $each(['Sun','Mon','Tue'], function(value, key){
+ daysArr[key] = value;
+ });
+
+ expect(daysArr).toEqual(['Sun','Mon','Tue']);
+ },
+
+ 'should call the function for each item in the object': function(){
+ var daysObj = {};
+ $each({first: "Sunday", second: "Monday", third: "Tuesday"}, function(value, key){
+ daysObj[key] = value;
+ });
+
+ expect(daysObj).toEqual({first: 'Sunday', second: 'Monday', third: 'Tuesday'});
+ }
+
+});
+
+describe('$extend', {
+
+ 'should extend two objects': function(){
+ var obj1 = {a: 1, b: 2};
+ var obj2 = {b: 3, c: 4};
+ $extend(obj1, obj2);
+ expect(obj1).toEqual({a: 1, b: 3, c: 4});
+ },
+
+ 'should overwrite properties': function(){
+ var obj1 = {a: 1, b: 2};
+ var obj2 = {b: 3, c: 4, a: 5};
+ $extend(obj1, obj2);
+ expect(obj1).toEqual({a: 5, b: 3, c: 4});
+ },
+
+ 'should not extend with null argument': function(){
+ var obj1 = {a: 1, b: 2};
+ $extend(obj1);
+ expect(obj1).toEqual({a: 1, b: 2});
+ }
+
+});
+
+describe('$lambda', {
+
+ 'if a function is passed in that function should be returned': function(){
+ var fn = function(a,b){ return a; };
+ expect($lambda(fn)).toEqual(fn);
+ },
+
+ 'should return a function that returns the value passed when called': function(){
+ expect($lambda('hello world!')()).toEqual('hello world!');
+ }
+
+});
+
+describe('$merge', {
+
+ 'should dereference objects': function(){
+ var obj1 = {a: 1, b: 2};
+ var obj2 = $merge(obj1);
+ expect(obj1 === obj2).toBeFalsy();
+ },
+
+ 'should merge any arbitrary number of nested objects': function(){
+ var obj1 = {a: {a: 1, b: 2, c: 3}, b: 2};
+ var obj2 = {a: {a: 2, b: 8, c: 3, d: 8}, b: 3, c: 4};
+ var obj3 = {a: {a: 3}, b: 3, c: false};
+ expect($merge(obj1, obj2, obj3)).toEqual({a: {a: 3, b: 8, c: 3, d: 8}, b: 3, c: false});
+ }
+
+});
+
+describe('$pick', {
+
+ 'should return the first false argument': function(){
+ var picked1 = $pick(null, undefined, false, [1,2,3], {});
+ expect(picked1).toBeFalsy();
+ },
+
+ 'should return the first defined argument': function(){
+ var picked1 = $pick(null, undefined, null, [1,2,3], {});
+ expect(picked1).toEqual([1,2,3]);
+ }
+
+});
+
+describe('$random', {
+
+ 'should return a number between two numbers specified': function(){
+ var rand = $random(1, 3);
+ expect((rand <= 3 && rand >= 1)).toBeTruthy();
+ }
+
+});
+
+describe('$splat', {
+
+ 'should transform a non array into an array': function(){
+ expect($splat(1)).toEqual([1]);
+ },
+
+ 'should transforum an undefined or null into an empty array': function(){
+ expect($splat(null)).toEqual([]);
+ expect($splat(undefined)).toEqual([]);
+ },
+
+ 'should ignore and return an array': function(){
+ expect($splat([1,2,3])).toEqual([1,2,3]);
+ }
+
+});
+
+describe('$time', {
+
+ 'should return a timestamp': function(){
+ expect(Number.type($time())).toBeTruthy();
+ },
+
+ 'should be within a reasonable range': function(){
+ expect($time() < 1e13 && $time() > 1e12).toBeTruthy();
+ }
+
+});
+
+describe('$try', {
+
+ 'should return the result of the first successful function without executing successive functions': function(){
+ var calls = 0;
+ var attempt = $try(function(){
+ calls++;
+ throw new Exception();
+ }, function(){
+ calls++;
+ return 'success';
+ }, function(){
+ calls++;
+ return 'moo';
+ });
+ expect(calls).toEqual(2);
+ expect(attempt).toEqual('success');
+ },
+
+ 'should return null when no function succeeded': function(){
+ var calls = 0;
+ var attempt = $try(function(){
+ calls++;
+ return I_invented_this();
+ }, function(){
+ calls++;
+ return uninstall_ie();
+ });
+ expect(calls).toEqual(2);
+ expect(attempt).toBeNull();
+ }
+
+});
+
+describe('$type', {
+
+ "should return 'array' for Array objects": function(){
+ expect($type([1,2])).toEqual('array');
+ },
+
+ "should return 'string' for String objects": function(){
+ expect($type('ciao')).toEqual('string');
+ },
+
+ "should return 'regexp' for RegExp objects": function(){
+ expect($type(/_/)).toEqual('regexp');
+ },
+
+ "should return 'function' for Function objects": function(){
+ expect($type(function(){})).toEqual('function');
+ },
+
+ "should return 'number' for Number objects": function(){
+ expect($type(10)).toEqual('number');
+ expect($type(NaN)).not.toEqual('number');
+ },
+
+ "should return 'boolean' for Boolean objects": function(){
+ expect($type(true)).toEqual('boolean');
+ expect($type(false)).toEqual('boolean');
+ },
+
+ "should return 'object' for Object objects": function(){
+ expect($type({a:2})).toEqual('object');
+ },
+
+ "should return 'arguments' for Function arguments": function(){
+ if (window.opera){ // Seems like the Opera guys can't decide on this
+ var type = $type(arguments);
+ expect(type == 'array' || type == 'arguments').toBeTruthy();
+ return;
+ }
+
+ expect($type(arguments)).toEqual('arguments');
+ },
+
+ "should return false for null objects": function(){
+ expect($type(null)).toBeFalsy();
+ },
+
+ "should return false for undefined objects": function(){
+ expect($type(undefined)).toBeFalsy();
+ },
+
+ "should return 'collection' for HTMLElements collections": function(){
+ expect($type(document.getElementsByTagName('*'))).toEqual('collection');
+ },
+
+ "should return 'element' for an Element": function(){
+ var div = document.createElement('div');
+ expect($type(div)).toEqual('element');
+ },
+
+ "should return 'array' for Elements": function(){
+ expect($type(new Elements)).toEqual('array');
+ },
+
+ "should return 'window' for the window object": function(){
+ expect($type(window)).toEqual('window');
+ },
+
+ "should return 'document' for the document object": function(){
+ expect($type(document)).toEqual('document');
+ }
+
+});
+
+describe('$unlink', {
+
+ "should unlink an object recursivly": function(){
+ var inner = {b: 2};
+ var obj = {a: 1, inner: inner};
+ var copy = $unlink(obj);
+ obj.a = 10;
+ inner.b = 20;
+
+ expect(obj.a).toEqual(10);
+ expect(obj.inner.b).toEqual(20);
+ expect($type(obj)).toEqual('object');
+
+ expect(copy.a).toEqual(1);
+ expect(copy.inner.b).toEqual(2);
+ expect($type(copy)).toEqual('object');
+ },
+
+ "should unlink an Hash": function(){
+ var hash = new Hash({a: 'one'});
+ var copy = $unlink(hash);
+
+ expect($type(hash)).toEqual('hash');
+ expect($type(copy)).toEqual('hash');
+
+ copy.set('a', 'two');
+
+ expect(hash.get('a')).toEqual('one');
+ expect(copy.get('a')).toEqual('two');
+ }
+
+});
+
+describe('Hash.getLength', {
+
+ "should return the number of items in it": function(){
+ var hash = new Hash({});
+ expect(hash.getLength()).toEqual(0);
+ hash.set('mootools', 'awesome');
+ hash.milk = 'yummy';
+ expect(hash.getLength()).toEqual(2);
+ },
+
+ "should not fail when length is set": function(){
+ var hash = new Hash({'length': 10});
+ expect(hash.getLength()).toEqual(1);
+ },
+
+ "should work as a generic on objects": function(){
+ expect(Hash.getLength({})).toEqual(0);
+ expect(Hash.getLength({'': '', '0': '0', 'length': 99})).toEqual(3);
+ }
+
+});
+
+describe('$H', {
+
+ "should create a new hash": function(){
+ var hash = $H({});
+ expect($type(hash)).toEqual('hash');
+ }
+
+});
View
69 Specs/1.2/Core/Native.js
@@ -0,0 +1,69 @@
+/*
+Script: Core.js
+ Private Specs for Core.js 1.2
+
+License:
+ MIT-style license.
+*/
+
+(function(){
+
+var Instrument = new Native({
+
+ name: 'instrument',
+
+ initialize: function(name){
+ this.name = name;
+ }
+
+});
+
+Instrument.implement({
+
+ method: function(){
+ return this.property + ' ' + this.name;
+ },
+
+ property: 'stuff'
+
+});
+
+var Car = new Native({
+
+ name: 'car',
+
+ initialize: function(name){
+ this.name = name;
+ }
+
+});
+
+Car.implement({
+
+ property: 'stuff',
+
+ method: function(){
+ return this.name + '_' + this.property;
+ }
+
+});
+
+describe('Native (private)', {
+
+ 'should allow implementation over existing methods when browser option is not set': function(){
+ Instrument.implement({ property: 'staff' });
+ var myInstrument = new Instrument('xeelophone');
+ expect(myInstrument.method()).toEqual('staff xeelophone');
+ },
+
+ 'should allow generic calls': function(){
+ expect(Car.method({name: 'ciccio', property: 'bello'})).toEqual('ciccio_bello');
+ },
+
+ "should have a 'native' type": function(){
+ expect(Native.type(Car)).toBeTruthy();
+ }
+
+});
+
+})();
View
134 Specs/1.2/Element/Element.Dimensions.js
@@ -0,0 +1,134 @@
+/*
+Script: Element.Dimensions.js
+ Specs for Element.Dimensions.js
+
+License:
+ MIT-style license.
+*/
+
+describe('Element.Dimensions', function(){
+
+ var div, relDiv, absDiv, scrollDiv, tallDiv;
+
+ beforeEach(function(){
+ div = new Element('div', {
+ id: 'ElementDimensionsTest',
+ styles: {
+ width: 100,
+ height: 100,
+ margin: 2,
+ padding: 3,
+ border: '1px solid black',
+ visibility: 'hidden',
+ display: 'block',
+ position: 'absolute',
+ top: 100,
+ left: 100,
+ overflow: 'hidden',
+ zIndex: 1
+ }
+ }).inject($(document.body));
+
+ relDiv = new Element('div', {
+ styles: {
+ width: 50,
+ height: 50,
+ margin: 5,
+ padding: 5,
+ border: '1px solid green',
+ visibility: 'hidden',
+ position: 'relative',
+ overflow: 'hidden',
+ 'float': 'left',
+ 'display': 'inline'
+ }
+ }).inject(div);
+
+ absDiv = new Element('div', {
+ styles: {
+ width: 10,
+ height: 10,
+ margin: 5,
+ padding: 5,
+ border: '1px solid red',
+ visibility: 'hidden',
+ position: 'absolute',
+ top: 10,
+ left: 10,
+ overflow: 'hidden'
+ }
+ }).inject(relDiv);
+
+ scrollDiv = new Element('div', {
+ styles: {
+ width: 100,
+ height: 100,
+ overflow: 'scroll',
+ visibility: 'hidden',
+ position: 'absolute',
+ top: 0,
+ left: 0
+ }
+ }).inject($(document.body));
+
+ tallDiv = new Element('div', {
+ styles: {
+ width: 200,
+ height: 200,
+ visibility: 'hidden'
+ }
+ }).inject(scrollDiv);
+ });
+
+ describe('Element.getSize', function(){
+
+ it('should measure the width and height of the element', function(){
+ expect(div.getSize().x).toEqual(108);
+ expect(div.getSize().y).toEqual(108);
+ });
+
+ });
+
+ describe('Element.getPosition', function(){
+
+ it('should measure the x and y position of the element', function(){
+ expect(div.getPosition()).toEqual({x: 102, y: 102});
+ });
+
+ it('should measure the x and y position of the element relative to another', function(){
+ expect(relDiv.getPosition(div)).toEqual({x: 8, y: 8});
+ });
+
+ });
+
+ describe('Element.getCoordinates', function(){
+
+ it('should return the coordinates relative to parent', function(){
+ expect(absDiv.getCoordinates(relDiv)).toEqual({left:15, top:15, width:22, height:22, right:37, bottom:37});
+ });
+
+ });
+
+ describe('Element.getScrollSize', function(){
+
+ it('should return the scrollSize', function(){
+ expect(scrollDiv.getScrollSize()).toEqual({x:200, y:200});
+ });
+
+ });
+
+ describe('Element.scrollTo', function(){
+
+ it('should scroll the element', function(){
+ expect(scrollDiv.scrollTo(20, 20).getScroll()).toEqual({x:20, y:20});
+ });
+
+ });
+
+ afterEach(function(){
+ [div, relDiv, absDiv, scrollDiv, tallDiv].each(function(el){
+ $(el).destroy();
+ });
+ });
+
+});
View
87 Specs/1.2/Element/Element.Style.js
@@ -0,0 +1,87 @@
+/*
+Script: Element.Style.js
+ Specification Examples of Element.Style.js.
+
+License:
+ MIT-style license.
+*/
+
+describe('Element.set `opacity`', {
+
+ 'should set the opacity of an Element': function() {
+ var el = new Element('div').set('opacity', 0.4);
+ if (document.html.style.opacity != null)
+ expect(el.style.opacity == 0.4).toBeTruthy();
+ else if (document.html.style.filter != null)
+ expect(el.style.filter).toEqual('alpha(opacity=40)');
+ else
+ expect(el.getStyle('opacity')).toEqual(0.4);
+ },
+
+ 'should return the opacity of an Element': function() {
+ var div = new Element('div').set('opacity', 0.4);
+ expect(div.get('opacity') == 0.4).toBeTruthy();
+ div.set('opacity', 0);
+ expect(div.get('opacity') == 0).toBeTruthy();
+ }
+
+});
+
+
+
+describe('Element.getStyle', {
+
+ 'should get a six digit hex code from a three digit hex code': function() {
+ var el = new Element('div').set('html', '<div style="color:#00ff00"></div>');
+ expect(el.getElement('div').getStyle('color')).toEqual('#00ff00');
+ },
+
+ 'should getStyle a six digit hex code from an RGB value': function() {
+ var el = new Element('div').set('html', '<div style="color:rgb(0, 255, 0)"></div>');
+ expect(el.getElement('div').getStyle('color')).toEqual('#00ff00');
+ },
+
+ 'should `getStyle` with a dash in it': function() {
+ var el = new Element('div').set('html', '<div style="list-style-type:square"></div>');
+ expect(el.getElement('div').getStyle('list-style-type')).toEqual('square');
+ },
+
+ 'should `getStyle` padding': function() {
+ var el = new Element('div').set('html', '<div style="padding:20px"></div>');
+ expect(el.getElement('div').getStyle('padding-left')).toEqual('20px');
+ }
+
+});
+
+describe('Element.setStyle', {
+
+ 'should set the `styles` property on an Element using the Element constructor': function() {
+ expect(new Element('div', {styles:{'color':'#00ff00'}}).getStyle('color')).toEqual('#00ff00');
+ },
+
+ 'should `setStyle` on an Element': function() {
+ expect(new Element('div').setStyle('color','#00ff00').getStyle('color')).toEqual('#00ff00');
+ },
+
+ 'should properly `setStyle` for a property with a dash in it': function() {
+ expect(new Element('div').setStyle('list-style-type', 'square').getStyle('list-style-type')).toEqual('square');
+ }
+
+});
+
+describe('Element.getStyles', {
+
+ 'should return multiple styles': function() {
+ var el = new Element('div').set('html', '<div style="color:#00ff00;list-style-type:square"></div>');
+ expect(el.getElement('div').getStyles('color', 'list-style-type')).toEqual({color:'#00ff00', 'list-style-type':'square'});
+ }
+
+});
+
+describe('Element.setStyles', {
+
+ 'should set multiple styles': function() {
+ expect(new Element('div').setStyles({'list-style-type':'square', 'color':'#00ff00'}).getStyles('list-style-type', 'color')).toEqual({'list-style-type':'square', color:'#00ff00'});
+ }
+
+});
View
1,568 Specs/1.2/Element/Element.js
1,568 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
207 Specs/1.2/Native/Array.js
@@ -0,0 +1,207 @@
+/*
+Script: Array.js
+ Specs for Array.js
+
+License:
+ MIT-style license.
+*/
+
+describe("Array Methods", {
+
+ // Array.flatten
+
+ 'should flatten a multidimensional array': function(){
+ var arr = [1,2,3,[4,5,[6,7,[8]]], [[[[[9]]]]]];
+ expect(arr.flatten()).toEqual([1,2,3,4,5,6,7,8,9]);
+ },
+
+ 'should flatten arguments': function(){
+ var test = function(){
+ return Array.flatten(arguments);
+ };
+ expect(test(1,2,3)).toEqual([1,2,3]);
+ expect(test([1,2,3])).toEqual([1,2,3]);
+ expect(test(1,2,[3])).toEqual([1,2,3]);
+ },
+
+ // Array.filter
+
+ 'should filter an array': function(){
+ var array = [1,2,3,0,0,0];
+ var arr = array.concat([false, null, 4]).filter(Number.type);
+ expect(arr).toEqual(array.concat(4));
+ },
+
+ // Array.clean
+
+ 'should clean an array from undefined and null values': function(){
+ var array = [null, 1, 0, true, false, "foo", undefined];
+ var arr = array.clean();
+ expect(arr).toEqual([1, 0, true, false, "foo"]);
+ },
+
+ // Array.map
+
+ 'should return a mapping of an array': function(){
+ var arr = [1,2,3,0,0,0].map(function(item){
+ return (item + 1);
+ });
+
+ expect(arr).toEqual([2,3,4,1,1,1]);
+ },
+
+ // Array.every
+
+ 'should return true if every item matches the comparator, otherwise false': function(){
+ expect([1,2,3,0,0,0].every(Number.type)).toBeTruthy();
+
+ expect(['1',2,3,0].every(Number.type)).toBeFalsy();
+ },
+
+ // Array.some
+
+ 'should return true if some of the items in the array match the comparator, otherwise false': function(){
+ expect(['1',2,3,0].some(Number.type)).toBeTruthy();
+
+ expect([1,2,3,0,0,0].map(String).some(Number.type)).toBeFalsy();
+ },
+
+ // Array.indexOf
+
+ 'should return the index of the item': function(){
+ expect([1,2,3,0,0,0].indexOf(0)).toEqual(3);
+ },
+
+ 'should return -1 if the item is not found in the array': function(){
+ expect([1,2,3,0,0,0].indexOf('not found')).toEqual(-1);
+ },
+
+ // Array.erase
+
+ 'should remove all items in the array that match the specified item': function(){
+ var arr = [1,2,3,0,0,0].erase(0);
+ expect(arr).toEqual([1,2,3]);
+ },
+
+ // Array.contains
+
+ 'should return true if the array contains the specified item': function(){
+ expect([1,2,3,0,0,0].contains(0)).toBeTruthy();
+ },
+
+ 'should return false if the array does not contain the specified item': function(){
+ expect([0,1,2].contains('not found')).toBeFalsy();
+ },
+
+ // Array.associate
+
+ 'should associate an array with a specified array': function(){
+ var obj = [1,2,3,0,0,0].associate(['a', 'b', 'c', 'd']);
+ expect(obj).toEqual({a:1, b:2, c:3, d:0});
+ },
+
+ // Array.link
+
+ 'should link an array items to a new object according to the specified matchers': function(){
+ var el = document.createElement('div');
+ var assoc2 = [100, 'Hello', {foo: 'bar'}, el, false].link({
+ myNumber: Number.type,
+ myElement: Element.type,
+ myObject: Object.type,
+ myString: String.type,
+ myBoolean: $defined
+ });
+
+ expect(assoc2).toEqual({
+ myNumber: 100,
+ myElement: el,
+ myObject: {foo: 'bar'},
+ myString: 'Hello',
+ myBoolean: false
+ });
+ },
+
+ // Array.extend
+
+ 'should extend an array': function(){
+ var a = [1,2,4];
+ var b = [2,3,4,5];
+ a.extend(b);
+ expect(a).toEqual([1,2,4,2,3,4,5]);
+ expect(b).toEqual([2,3,4,5]);
+ },
+
+ // Array.combine
+
+ 'should combine an array': function(){
+ var arr = [1,2,3,4].combine([3,1,4,5,6,7]);
+ expect(arr).toEqual([1,2,3,4,5,6,7]);
+ },
+
+ // Array.include
+
+ 'should include only new items': function(){
+ var arr = [1,2,3,4].include(1).include(5);
+ expect(arr).toEqual([1,2,3,4,5]);
+ },
+
+ // Array.getLast
+
+ 'should return the last item in the array': function(){
+ expect([1,2,3,0,0,0].getLast()).toEqual(0);
+ expect([3].getLast()).toEqual(3);
+ },
+
+ 'should return null if there are no items': function(){
+ expect([].getLast()).toEqual(null);
+ },
+
+ // Array.empty
+
+ 'should empty the array': function(){
+ var arr = [1,2,3,4].empty();
+ expect(arr).toEqual([]);
+ }
+
+});
+
+describe("Array Color Methods", {
+
+ // Array.hexToRgb
+
+ 'should return null if the length of the array is not 3': function(){
+ expect([].hexToRgb()).toBeNull();
+ },
+
+ 'should return a CSS rgb string': function(){
+ expect(['0','0','0'].hexToRgb()).toEqual('rgb(0,0,0)');
+ },
+
+ 'should support shorthand hex': function(){
+ expect(['c','c','c'].hexToRgb()).toEqual('rgb(204,204,204)');
+ },
+
+ 'should return an array with 16-based numbers when passed true': function(){
+ expect(['ff','ff','ff'].hexToRgb(true)).toEqual([255,255,255]);
+ },
+
+ // Array.rgbToHex
+
+ 'should return null if the array does not have at least 3 times': function(){
+ expect([0,1].rgbToHex()).toBeNull();
+ },
+
+ 'should return a css hexadecimal string': function(){
+ expect(['255', '0', '0'].rgbToHex()).toEqual('#ff0000');
+ expect([0,0,255].rgbToHex()).toEqual('#0000ff');
+ },
+
+ 'should return an array with hexadecimal string items': function(){
+ expect([0,255,0].rgbToHex(true)).toEqual(['00', 'ff', '00']);
+ },
+
+ 'should return `transparent` if the fourth item is 0 and first param is not true': function(){
+ expect([0,0,0,0].rgbToHex()).toEqual('transparent');
+ }
+
+});
View
155 Specs/1.2/Native/Function.js
@@ -0,0 +1,155 @@
+/*
+Script: Function.js
+ Specs for Function.js
+
+License:
+ MIT-style license.
+*/
+
+(function(){
+
+var fn = function(){
+ return $A(arguments);
+};
+
+var Rules = function(){
+ return this + ' rules';
+};
+
+var Args = function(){
+ return [this].concat($A(arguments));
+};
+
+describe("Function Methods", {
+
+ // Function.create
+
+ 'should return a new function': function(){
+ var fnc = $empty.create();
+ expect($empty === fnc).toBeFalsy();
+ },
+
+ 'should return a new function with specified argument': function(){
+ var fnc = fn.create({'arguments': 'rocks'});
+ expect(fnc()).toEqual(['rocks']);
+ },
+
+ 'should return a new function with multiple arguments': function(){
+ var fnc = fn.create({'arguments': ['MooTools', 'rocks']});
+ expect(fnc()).toEqual(['MooTools', 'rocks']);
+ },
+
+ 'should return a new function bound to an object': function(){
+ var fnc = Rules.create({'bind': 'MooTools'});
+ expect(fnc()).toEqual('MooTools rules');
+ },
+
+ 'should return a new function as an event': function(){
+ var fnc = fn.create({'arguments': [0, 1], 'event': true});
+ expect(fnc('an Event occurred')).toEqual(['an Event occurred', 0, 1]);
+ },
+
+ // Function.bind
+
+ 'should return the function bound to an object': function(){
+ var fnc = Rules.bind('MooTools');
+ expect(fnc()).toEqual('MooTools rules');
+ },
+
+ 'should return the function bound to an object with specified argument': function(){
+ var fnc = Args.bind('MooTools', 'rocks');
+ expect(fnc()).toEqual(['MooTools', 'rocks']);
+ },
+
+ 'should return the function bound to an object with multiple arguments': function(){
+ var fnc = Args.bind('MooTools', ['rocks', 'da house']);
+ expect(fnc()).toEqual(['MooTools', 'rocks', 'da house']);
+ },
+
+ 'should return the function bound to an object and make the function an event listener': function(){
+ var fnc = Args.bindWithEvent('MooTools');
+ expect(fnc('an Event ocurred')).toEqual(['MooTools', 'an Event ocurred']);
+ },
+
+ 'should return the function bound to an object and make the function event listener with multiple arguments': function(){
+ var fnc = Args.bindWithEvent('MooTools', ['rocks', 'da house']);
+ expect(fnc('an Event ocurred')).toEqual(['MooTools', 'an Event ocurred', 'rocks', 'da house']);
+ },
+
+ // Function.pass
+
+ 'should return a function that when called passes the specified arguments to the original function': function(){
+ var fnc = fn.pass('MooTools is beautiful and elegant');
+ expect(fnc()).toEqual(['MooTools is beautiful and elegant']);
+ },
+
+ 'should pass multiple arguments and bind the function to a specific object when it is called': function(){
+ var fnc = Args.pass(['rocks', 'da house'], 'MooTools');
+ expect(fnc()).toEqual(['MooTools', 'rocks', 'da house']);
+ },
+
+ // Function.run
+
+ 'should run the function': function(){
+ var result = fn.run();
+ expect(result).toEqual([]);
+ },
+
+ 'should run the function with multiple arguments': function(){
+ var result = fn.run(['MooTools', 'beautiful', 'elegant']);
+ expect(result).toEqual(['MooTools', 'beautiful', 'elegant']);
+ },
+
+ 'should run the function with multiple arguments and bind the function to an object': function(){
+ var result = Args.run(['beautiful', 'elegant'], 'MooTools');
+ expect(result).toEqual(['MooTools', 'beautiful', 'elegant']);
+ },
+
+ // Function.extend
+
+ "should extend the function's properties": function(){
+ var fnc = (function(){}).extend({a: 1, b: 'c'});
+ expect(fnc.a).toEqual(1);
+ expect(fnc.b).toEqual('c');
+ },
+
+ // Function.attempt
+
+ 'should call the function without raising an exception': function(){
+ var fnc = function(){
+ this_should_not_work();
+ };
+ fnc.attempt();
+ },
+
+ "should return the function's return value": function(){
+ var fnc = $lambda('hello world!');
+ expect(fnc.attempt()).toEqual('hello world!');
+ },
+
+ 'should return null if the function raises an exception': function(){
+ var fnc = function(){
+ this_should_not_work();
+ };
+ expect(fnc.attempt()).toBeNull();
+ },
+
+ // Function.delay
+
+ 'delay should return a timer pointer': function(){
+ var timer = $empty.delay(10000);
+ expect(Number.type(timer)).toBeTruthy();
+ $clear(timer);
+ },
+
+ // Function.periodical
+
+ 'periodical should return a timer pointer': function(){
+ var timer = $empty.periodical(10000);
+ expect(Number.type(timer)).toBeTruthy();
+ $clear(timer);
+ }
+
+});
+
+})();
View
203 Specs/1.2/Native/Hash.js
@@ -0,0 +1,203 @@
+/*
+Script: Hash.js
+ Specs for Hash.js
+
+License:
+ MIT-style license.
+*/
+
+(function(){
+
+var hash2 = new Hash({ a: 'string', b: 233, c: {} });
+
+describe("Hash Methods", {
+
+ // Hash.constructor
+
+ 'should return a new hash': function(){
+ expect(Hash.type(new Hash())).toBeTruthy();
+ },
+
+ 'should return a copy of a hash': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ var copy = new Hash(hash);
+ expect(copy !== hash).toBeTruthy();
+ expect(copy).toEqual(hash);
+ },
+
+ // Hash.erase
+
+ 'should remove a key and its value from the hash': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ expect(hash.erase('a')).toEqual(new Hash({b:2,c:3}));
+ expect(hash.erase('d')).toEqual(new Hash({b:2,c:3}));
+
+ hash = new Hash({a: 1, b: 2, c: 3});
+ expect(hash.erase('a')).toEqual(new Hash({b:2,c:3}));
+ expect(hash.erase('d')).toEqual(new Hash({b:2,c:3}));
+ },
+
+ // Hash.get
+
+ 'should return the value corresponding to the specified key otherwise null': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ expect(hash.get('c')).toEqual(3);
+ expect(hash.get('d')).toBeNull();
+ },
+
+ // Hash.set
+
+ 'should set the key with the corresponding value': function(){
+ var myHash = new Hash({a: 1, b: 2, c: 3}).set('c', 7).set('d', 8);
+ expect(myHash).toEqual(new Hash({a:1,b:2,c:7,d:8}));
+ },
+
+ // Hash.empty
+
+ 'should empty the hash': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ expect(hash.empty()).toEqual(new Hash());
+ },
+
+ // Hash.include
+
+ 'should include a key value if the hash does not have the key otherwise ignore': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ expect(hash.include('e', 7)).toEqual(new Hash({a:1,b:2,c:3,e:7}));
+ expect(hash.include('a', 7)).toEqual(new Hash({a:1,b:2,c:3,e:7}));
+ },
+
+ // Hash.keyOf | Hash.indexOf
+
+ 'should return the key of the value or null if not found': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3, d: 1});
+ expect(hash.keyOf(1)).toEqual('a');
+ expect(hash.keyOf('not found')).toBeNull();
+
+ expect(hash.indexOf(1)).toEqual('a');
+ expect(hash.indexOf('not found')).toBeNull();
+ },
+
+ // Hash.has
+
+ 'should return true if the hash has the key otherwise false': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ expect(hash.has('a')).toBeTruthy();
+ expect(hash.has('d')).toBeFalsy();
+ },
+
+ // Hash.hasValue | Hash.contains
+
+ 'should return true if the hash hasValue otherwise false': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ expect(hash.hasValue(1)).toBeTruthy();
+ expect(hash.hasValue('not found')).toBeFalsy();
+
+ expect(hash.contains(1)).toBeTruthy();
+ expect(hash.contains('not found')).toBeFalsy();
+ },
+
+ // Hash.getClean
+
+ 'should getClean JavaScript object': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ expect(hash.getClean()).toEqual({a:1,b:2,c:3});
+ },
+
+ // Hash.extend
+
+ 'should extend a Hash with an object': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ expect(hash.extend({a:4,d:7,e:8})).toEqual(new Hash({a:4,b:2,c:3,d:7,e:8}));
+ },
+
+ 'should extend a Hash with another Hash': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ expect(hash.extend(new Hash({a:4,d:7,e:8}))).toEqual(new Hash({a:4,b:2,c:3,d:7,e:8}));
+ },
+
+ // Hash.combine
+
+ 'should merge a Hash with an object': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ expect(hash.combine({a:4,d:7,e:8})).toEqual(new Hash({a:1,b:2,c:3,d:7,e:8}));
+ },
+
+ 'should merge a Hash with another Hash': function(){
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ expect(hash.combine(new Hash({a:4,d:7,e:8}))).toEqual(new Hash({a:1,b:2,c:3,d:7,e:8}));
+ },
+
+ // Hash.each
+
+ 'should iterate through each property': function(){
+ var newHash = new Hash();
+ var hash = new Hash({a: 1, b: 2, c: 3});
+ hash.each(function(value, key){
+ newHash.set(key, value);
+ });
+ expect(newHash).toEqual(hash);
+ },
+
+ // Hash.map
+
+ 'should map a new Hash according to the comparator': function(){
+ expect(hash2.map(Number.type)).toEqual(new Hash({a:false,b:true,c:false}));
+ },
+
+ // Hash.filter
+
+ 'should filter the Hash according to the comparator': function(){
+ expect(hash2.filter(Number.type)).toEqual(new Hash({b:233}));
+ },
+
+ // Hash.every
+
+ 'should return true if every value matches the comparator, otherwise false': function(){
+ expect(hash2.every($defined)).toBeTruthy();
+ expect(hash2.every(Number.type)).toBeFalsy();
+ },
+
+ // Hash.some
+
+ 'should return true if some of the values match the comparator, otherwise false': function(){
+ expect(hash2.some(Number.type)).toBeTruthy();
+ expect(hash2.some(Array.type)).toBeFalsy();
+ },
+
+ // Hash.getKeys
+
+ 'getKeys should return an empty array': function(){
+ expect(new Hash().getKeys()).toEqual([]);
+ },
+
+ 'should return an array containing the keys of the hash': function(){
+ expect(hash2.getKeys()).toEqual(['a', 'b', 'c']);
+ },
+
+ // Hash.getValues
+
+ 'getValues should return an empty array': function(){
+ expect(new Hash().getValues()).toEqual([]);
+ },
+
+ 'should return an array with the values of the hash': function(){
+ expect(hash2.getValues()).toEqual(['string', 233, {}]);
+ },
+
+ // Hash.toQueryString
+
+ 'should return a query string': function(){
+ var myHash = new Hash({apple: "red", lemon: "yellow"});
+ expect(myHash.toQueryString()).toEqual('apple=red&lemon=yellow');
+
+ var myHash2 = new Hash({apple: ['red', 'yellow'], lemon: ['green', 'yellow']});
+ expect(myHash2.toQueryString()).toEqual('apple[0]=red&apple[1]=yellow&lemon[0]=green&lemon[1]=yellow');
+
+ var myHash3 = new Hash({fruits: {apple: ['red', 'yellow'], lemon: ['green', 'yellow']}});
+ expect(myHash3.toQueryString()).toEqual('fruits[apple][0]=red&fruits[apple][1]=yellow&fruits[lemon][0]=green&fruits[lemon][1]=yellow');
+ }
+
+});
+
+})();
View
114 Specs/1.2/Native/Number.js
@@ -0,0 +1,114 @@
+/*
+Script: Number.js
+ Specs for Number.js
+
+License:
+ MIT-style license.
+*/
+
+describe("Number Methods", {
+
+ // Number.toInt
+
+ 'should convert a number to an integer': function(){
+ expect((111).toInt()).toEqual(111);
+ },
+
+ 'should convert a number depending on the radix provided': function(){
+ expect((111).toInt(2)).toEqual(7);
+ expect((0x16).toInt(10)).toEqual(22); //ECMA standard, radix is optional so if starts with 0x then parsed as hexadecimal
+ expect((016).toInt(10)).toEqual(14); //ECMA standard, radix is optional so if starts with 0 then parsed as octal
+ },
+
+ // Number.toFloat
+
+ 'should convert a number to a float': function(){
+ expect((1.00).toFloat()).toEqual(1);
+ expect((1.12 - 0.12).toFloat()).toEqual(1);
+ expect((0.0010).toFloat()).toEqual(0.001);
+ expect((Number.MIN_VALUE).toFloat()).toEqual(Number.MIN_VALUE);
+ },
+
+ // Number.limit
+
+ 'should limit a number within a range': function(){
+ expect((-1).limit(0, 1)).toEqual(0);
+ expect((3).limit(1, 2)).toEqual(2);
+ },
+
+ 'should not limit a number if within the range': function(){
+ expect((2).limit(0,4)).toEqual(2);
+ },
+
+ // Number.round
+
+ 'should round a number to the nearest whole number if units place is not specified': function(){
+ expect((0.01).round()).toEqual(0);
+ },
+
+ 'should round a number according the units place specified': function(){
+ expect((0.01).round(2)).toEqual(0.01);
+ expect((1).round(3)).toEqual(1);
+ expect((-1.01).round()).toEqual(-1);
+ expect((-1.01).round(2)).toEqual(-1.01);
+ expect((111).round(-1)).toEqual(110);
+ expect((-111).round(-2)).toEqual(-100);
+ expect((100).round(-5)).toEqual(0);
+ },
+
+ // Number.times
+
+ 'should call the function for the specified number of times': function(){
+ var found = 0;
+ (3).times(function(i){
+ found = i;
+ });
+
+ var found2 = -1;
+ (0).times(function(i){
+ found2 = i;
+ });
+
+ expect(found).toEqual(2);
+ expect(found2).toEqual(-1);
+ },
+
+ 'should bind and call the function for the specified number of times': function(){
+ var aTest = 'hi';
+ var found3 = false;
+ (1).times(function(i){
+ found3 = (this == aTest);
+ }, aTest);
+ expect(found3).toBeTruthy();
+ }
+
+});
+
+(function(math){
+ var examples = {};
+ new Hash(math).each(function(value, key){
+ var example = {};
+ var b = value.test[1];
+ examples['should return the ' + value.title + ' value of the number' + ((b) ? ' and the passed number' : '')] = function(){
+ expect(value.test[0][key](b)).toEqual(Math[key].apply(null, value.test));
+ };
+ });
+ describe("Number Math Methods", examples);
+})({
+ abs: { test: [-1], title: 'absolute' },
+ acos: { test: [0], title: 'arc cosine' },
+ asin: { test: [0.5], title: 'arc sine' },
+ atan: { test: [0.5], title: 'arc tangent' },
+ atan2: { test: [0.1, 0.5], title: 'arc tangent' },
+ ceil: { test: [0.6], title: 'number closest to and not less than the' },
+ cos: { test: [30], title: 'cosine' },
+ exp: { test: [2], title: 'exponent' },
+ floor: { test: [2.4], title: 'integer closet to and not greater than' },
+ log: { test: [2], title: 'log' },
+ max: { test: [5, 3], title: 'maximum' },
+ min: { test: [-4, 2], title: 'minimum' },
+ pow: { test: [2, 2], title: 'power' },
+ sin: { test: [0.5], title: 'sine' },
+ sqrt: { test: [4], title: 'square root' },
+ tan: { test: [0.3], title: 'tangent' }
+});
View
158 Specs/1.2/Native/String.js
@@ -0,0 +1,158 @@
+/*
+Script: String.js
+ Specs for String.js
+
+License:
+ MIT-style license.
+*/
+
+describe("String Methods", {
+
+ // String.capitalize
+
+ 'should capitalize each word': function(){
+ expect('i like cookies'.capitalize()).toEqual('I Like Cookies');
+ expect('I Like cOOKIES'.capitalize()).toEqual('I Like COOKIES');
+ },
+
+ // String.camelCase
+
+ 'should convert a hyphenated string into a camel cased string': function(){
+ expect('i-like-cookies'.camelCase()).toEqual('iLikeCookies');
+ expect('I-Like-Cookies'.camelCase()).toEqual('ILikeCookies');
+ },
+
+ // String.hyphenate
+
+ 'should convert a camel cased string into a hyphenated string': function(){
+ expect('iLikeCookies'.hyphenate()).toEqual('i-like-cookies');
+ expect('ILikeCookies'.hyphenate()).toEqual('-i-like-cookies');
+ },
+
+ // String.clean
+
+ 'should clean all extraneous whitespace from the string': function(){
+ expect(' i like cookies '.clean()).toEqual("i like cookies");
+ expect(' i\nlike \n cookies \n\t '.clean()).toEqual("i like cookies");
+ },
+
+ // String.trim
+
+ 'should trim left and right whitespace from the string': function(){
+ expect(' i like cookies '.trim()).toEqual('i like cookies');
+ expect(' i \tlike cookies '.trim()).toEqual('i \tlike cookies');
+ },
+
+ // String.contains
+
+ 'should return true if the string contains a string otherwise false': function(){
+ expect('i like cookies'.contains('cookies')).toBeTruthy();
+ expect('i,like,cookies'.contains('cookies')).toBeTruthy();
+ expect('mootools'.contains('inefficient javascript')).toBeFalsy();
+ },
+
+ 'should return true if the string constains the string and separator otherwise false': function(){
+ expect('i like cookies'.contains('cookies', ' ')).toBeTruthy();
+ expect('i like cookies'.contains('cookies', ',')).toBeFalsy();
+
+ expect('i,like,cookies'.contains('cookies', ' ')).toBeFalsy();
+ expect('i,like,cookies'.contains('cookies', ',')).toBeTruthy();
+ },
+
+ // String.test
+
+ 'should return true if the test matches the string otherwise false': function(){
+ expect('i like teh cookies'.test('cookies')).toBeTruthy();
+ expect('i like cookies'.test('ke coo')).toBeTruthy();
+ expect('I LIKE COOKIES'.test('cookie', 'i')).toBeTruthy();
+ expect('i like cookies'.test('cookiez')).toBeFalsy();
+ },
+
+ 'should return true if the regular expression test matches the string otherwise false': function(){
+ expect('i like cookies'.test(/like/)).toBeTruthy();
+ expect('i like cookies'.test(/^l/)).toBeFalsy();
+ },
+
+ // String.toInt
+
+ 'should convert the string into an integer': function(){
+ expect('10'.toInt()).toEqual(10);
+ expect('10px'.toInt()).toEqual(10);
+ expect('10.10em'.toInt()).toEqual(10);
+ },
+
+ 'should convert the string into an integer with a specific base': function(){
+ expect('10'.toInt(5)).toEqual(5);
+ },
+
+ // String.toFloat
+
+ 'should convert the string into a float': function(){
+ expect('10.11'.toFloat()).toEqual(10.11);
+ expect('10.55px'.toFloat()).toEqual(10.55);
+ },
+
+ // String.rgbToHex
+
+ 'should convert the string into a CSS hex string': function(){
+ expect('rgb(255,255,255)'.rgbToHex()).toEqual('#ffffff');
+ expect('rgb(255,255,255,0)'.rgbToHex()).toEqual('transparent');
+ },
+
+ // String.hexToRgb
+
+ 'should convert the CSS hex string into a CSS rgb string': function(){
+ expect('#fff'.hexToRgb()).toEqual('rgb(255,255,255)');
+ expect('ff00'.hexToRgb()).toEqual('rgb(255,0,0)');
+ expect('#000000'.hexToRgb()).toEqual('rgb(0,0,0)');
+ },
+
+ // String.stripScripts
+
+ 'should strip all script tags from a string': function(){