prototype: Remove usage of the statement from unit tests.
This commit is contained in:
parent
87ce1533e4
commit
c01cb850c1
|
@ -1,3 +1,5 @@
|
|||
* Remove usage of the `with` statement from unit tests. [Tobie Langel]
|
||||
|
||||
* Complete rewrite of the deprecation helper, now renamed UpdateHelper and useable by third-party libs. [Tobie Langel]
|
||||
|
||||
* Make Element#writeAttribute handle frameborder attribute in IE. Closes #11068. [staaky, Tobie Langel]
|
||||
|
|
|
@ -76,212 +76,212 @@
|
|||
});
|
||||
|
||||
new Test.Unit.Runner({
|
||||
testGetStack: function(){ with(this) {
|
||||
assertMatch(/prototype_update_helper\.html:\d+\n$/, prototypeUpdateHelper.getStack());
|
||||
}},
|
||||
testGetStack: function() {
|
||||
this.assertMatch(/prototype_update_helper\.html:\d+\n$/, prototypeUpdateHelper.getStack());
|
||||
},
|
||||
|
||||
testDisplay: function(){ with(this) {
|
||||
testDisplay: function() {
|
||||
Toggle.display('foo');
|
||||
assertInfoNotified('Toggle.display has been deprecated, please use Element.toggle instead.');
|
||||
this.assertInfoNotified('Toggle.display has been deprecated, please use Element.toggle instead.');
|
||||
|
||||
Element.show('foo', 'bar', 'bla');
|
||||
assertErrorNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' +
|
||||
this.assertErrorNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' +
|
||||
'Use [id_1, id_2, ...].each(Element.show) or $(id_1, id_2, ...).invoke("show") instead.');
|
||||
|
||||
$('foo', 'bar', 'bla').each(Element.hide);
|
||||
assertNotNotified();
|
||||
this.assertNotNotified();
|
||||
|
||||
Element.show('foo');
|
||||
assertNotNotified();
|
||||
this.assertNotNotified();
|
||||
|
||||
Element.hide('foo', 'bar', 'bla');
|
||||
assertErrorNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' +
|
||||
this.assertErrorNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' +
|
||||
'Use [id_1, id_2, ...].each(Element.hide) or $(id_1, id_2, ...).invoke("hide") instead.');
|
||||
|
||||
Element.toggle('foo', 'bar', 'bla');
|
||||
assertErrorNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' +
|
||||
this.assertErrorNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' +
|
||||
'Use [id_1, id_2, ...].each(Element.toggle) or $(id_1, id_2, ...).invoke("toggle") instead.');
|
||||
}},
|
||||
},
|
||||
|
||||
testElementStyle: function(){ with(this) {
|
||||
testElementStyle: function() {
|
||||
Element.setStyle('foo', { 'fontSize': '18px' });
|
||||
assertNotNotified();
|
||||
this.assertNotNotified();
|
||||
|
||||
Element.setStyle('foo', { 'font-size': '18px' });
|
||||
assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +
|
||||
this.assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +
|
||||
'Use either camelized style-property names or a regular CSS string instead (see online documentation).')
|
||||
|
||||
Element.setStyle('foo', 'font-size: 18px;');
|
||||
assertNotNotified();
|
||||
this.assertNotNotified();
|
||||
|
||||
$('foo').setStyle({ 'font-size': '18px' });
|
||||
assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +
|
||||
this.assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +
|
||||
'Use either camelized style-property names or a regular CSS string instead (see online documentation).')
|
||||
}},
|
||||
},
|
||||
|
||||
testClassNames: function(){ with(this) {
|
||||
testClassNames: function() {
|
||||
new Element.ClassNames('foo');
|
||||
assertInfoNotified('Element.ClassNames has been deprecated.')
|
||||
this.assertInfoNotified('Element.ClassNames has been deprecated.')
|
||||
|
||||
$('foo').classNames();
|
||||
assertInfoNotified('Element#classNames has been deprecated.\n' +
|
||||
this.assertInfoNotified('Element#classNames has been deprecated.\n' +
|
||||
'If you need to access CSS class names as an array, try: $w(element.classname).')
|
||||
|
||||
Element.getElementsByClassName('foo', 'className');
|
||||
assertInfoNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.')
|
||||
this.assertInfoNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.')
|
||||
|
||||
document.getElementsByClassName('className');
|
||||
assertInfoNotified('document.getElementsByClassName has been deprecated, please use $$ instead.')
|
||||
}},
|
||||
this.assertInfoNotified('document.getElementsByClassName has been deprecated, please use $$ instead.')
|
||||
},
|
||||
|
||||
testDomSelectors: function(){ with(this) {
|
||||
testDomSelectors: function() {
|
||||
Element.childOf('foo', 'bar');
|
||||
assertInfoNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.');
|
||||
this.assertInfoNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.');
|
||||
|
||||
$('foo').immediateDescendants();
|
||||
assertInfoNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.');
|
||||
this.assertInfoNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.');
|
||||
|
||||
$('foo').getElementsBySelector('a');
|
||||
assertInfoNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.');
|
||||
this.assertInfoNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.');
|
||||
|
||||
$('foo').select('a');
|
||||
assertNotNotified();
|
||||
}},
|
||||
this.assertNotNotified();
|
||||
},
|
||||
|
||||
testField: function(){ with(this) {
|
||||
testField: function() {
|
||||
Field.clear('foo', 'bar', 'bla');
|
||||
assertErrorNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' +
|
||||
this.assertErrorNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' +
|
||||
'Use [id_1, id_2, ...].each(Form.Element.clear) or $(id_1, id_2, ...).invoke("clear") instead.');
|
||||
|
||||
Field.present('foo', 'bar', 'bla');
|
||||
assertErrorNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' +
|
||||
this.assertErrorNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' +
|
||||
'Use [id_1, id_2, ...].each(Form.Element.present) or $(id_1, id_2, ...).invoke("present") instead.');
|
||||
}},
|
||||
},
|
||||
|
||||
testInsertion: function(){ with(this) {
|
||||
testInsertion: function() {
|
||||
Insertion.Before('foo', 'text');
|
||||
assertInfoNotified('Insertion.Before has been deprecated, please use Element#insert instead.');
|
||||
this.assertInfoNotified('Insertion.Before has been deprecated, please use Element#insert instead.');
|
||||
|
||||
Insertion.Top('foo', 'text');
|
||||
assertInfoNotified('Insertion.Top has been deprecated, please use Element#insert instead.');
|
||||
this.assertInfoNotified('Insertion.Top has been deprecated, please use Element#insert instead.');
|
||||
|
||||
Insertion.Bottom('foo', 'text');
|
||||
assertInfoNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.');
|
||||
this.assertInfoNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.');
|
||||
|
||||
Insertion.After('foo', 'text');
|
||||
assertInfoNotified('Insertion.After has been deprecated, please use Element#insert instead.');
|
||||
}},
|
||||
this.assertInfoNotified('Insertion.After has been deprecated, please use Element#insert instead.');
|
||||
},
|
||||
|
||||
testPosition: function(){ with(this) {
|
||||
testPosition: function() {
|
||||
Position.prepare('foo');
|
||||
assertInfoNotified('Position.prepare has been deprecated.');
|
||||
this.assertInfoNotified('Position.prepare has been deprecated.');
|
||||
|
||||
Position.within('foo');
|
||||
assertInfoNotified('Position.within has been deprecated.');
|
||||
this.assertInfoNotified('Position.within has been deprecated.');
|
||||
|
||||
Position.withinIncludingScrolloffsets('foo');
|
||||
assertInfoNotified('Position.withinIncludingScrolloffsets has been deprecated.');
|
||||
this.assertInfoNotified('Position.withinIncludingScrolloffsets has been deprecated.');
|
||||
|
||||
Position.overlap('foo');
|
||||
assertInfoNotified('Position.overlap has been deprecated.');
|
||||
this.assertInfoNotified('Position.overlap has been deprecated.');
|
||||
|
||||
Position.cumulativeOffset('foo');
|
||||
assertInfoNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.');
|
||||
this.assertInfoNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.');
|
||||
|
||||
Position.positionedOffset('foo');
|
||||
assertInfoNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.');
|
||||
this.assertInfoNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.');
|
||||
|
||||
Position.absolutize('foo');
|
||||
assertInfoNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.');
|
||||
this.assertInfoNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.');
|
||||
|
||||
Position.relativize('foo');
|
||||
assertInfoNotified('Position.relativize has been deprecated, please use Element#relativize instead.');
|
||||
this.assertInfoNotified('Position.relativize has been deprecated, please use Element#relativize instead.');
|
||||
|
||||
Position.realOffset('foo');
|
||||
assertInfoNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.');
|
||||
this.assertInfoNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.');
|
||||
|
||||
Position.offsetParent('foo');
|
||||
assertInfoNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.');
|
||||
this.assertInfoNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.');
|
||||
|
||||
Position.page('foo');
|
||||
assertInfoNotified('Position.page has been deprecated, please use Element#viewportOffset instead.');
|
||||
this.assertInfoNotified('Position.page has been deprecated, please use Element#viewportOffset instead.');
|
||||
|
||||
Position.clone('foo', 'bar');
|
||||
assertInfoNotified('Position.clone has been deprecated, please use Element#clonePosition instead.');
|
||||
}},
|
||||
this.assertInfoNotified('Position.clone has been deprecated, please use Element#clonePosition instead.');
|
||||
},
|
||||
|
||||
testEvent: function(){ with(this) {
|
||||
testEvent: function() {
|
||||
Event.unloadCache();
|
||||
assertErrorNotified('Event.unloadCache has been deprecated.')
|
||||
}},
|
||||
this.assertErrorNotified('Event.unloadCache has been deprecated.')
|
||||
},
|
||||
|
||||
testHash: function(){ with(this) {
|
||||
testHash: function() {
|
||||
Hash.toQueryString({});
|
||||
assertInfoNotified('Hash.toQueryString has been deprecated.\n' +
|
||||
this.assertInfoNotified('Hash.toQueryString has been deprecated.\n' +
|
||||
'Use the instance method Hash#toQueryString or Object.toQueryString instead.');
|
||||
|
||||
Hash.toJSON({});
|
||||
assertErrorNotified('Hash.toJSON has been removed.\n' +
|
||||
this.assertErrorNotified('Hash.toJSON has been removed.\n' +
|
||||
'Use the instance method Hash#toJSON or Object.toJSON instead.');
|
||||
|
||||
var h = $H({ foo: 2 });
|
||||
|
||||
h.remove('foo');
|
||||
assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
|
||||
this.assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
|
||||
'Please note that Hash#unset only accepts one argument.');
|
||||
|
||||
h.merge('foo');
|
||||
assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');
|
||||
this.assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');
|
||||
|
||||
h['foo'];
|
||||
assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
|
||||
this.assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
|
||||
'Please use Hash#get(\'foo\') instead.')
|
||||
|
||||
h.foo = 3;
|
||||
assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
|
||||
this.assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
|
||||
'Please use Hash#set(\'foo\', 3) instead.')
|
||||
|
||||
h.bar = 'bar';
|
||||
h.toJSON();
|
||||
assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
|
||||
this.assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
|
||||
'Please use Hash#set(\'bar\', \'bar\') instead.')
|
||||
|
||||
h.bar;
|
||||
assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
|
||||
this.assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
|
||||
'Please use Hash#get(\'bar\') instead.')
|
||||
|
||||
h.baz = 'baz';
|
||||
h.bar;
|
||||
assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
|
||||
this.assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
|
||||
'Please use Hash#set(\'baz\', \'baz\') instead.')
|
||||
|
||||
h.set('toJSON', 'arg'); // make sure hash methods are not overwritten
|
||||
assertRespondsTo('toJSON', h)
|
||||
}},
|
||||
this.assertRespondsTo('toJSON', h)
|
||||
},
|
||||
|
||||
testClass: function(){ with(this) {
|
||||
testClass: function() {
|
||||
Class.create();
|
||||
assertInfoNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' +
|
||||
this.assertInfoNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' +
|
||||
'You can find more about it here: http://prototypejs.org/learn/class-inheritance');
|
||||
Class.create({});
|
||||
assertNotNotified();
|
||||
}},
|
||||
this.assertNotNotified();
|
||||
},
|
||||
|
||||
testLogDeprecationOption: function(){ with(this) {
|
||||
testLogDeprecationOption: function() {
|
||||
prototypeUpdateHelper.logLevel = UpdateHelper.Warn;
|
||||
var h = $H({ foo: 2 });
|
||||
|
||||
h.merge({ foo: 3 });
|
||||
assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');
|
||||
this.assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');
|
||||
|
||||
h.remove('foo');
|
||||
assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
|
||||
this.assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
|
||||
'Please note that Hash#unset only accepts one argument.');
|
||||
|
||||
document.getElementsByClassName('className');
|
||||
assertNotNotified();
|
||||
this.assertNotNotified();
|
||||
prototypeUpdateHelper.logLevel = UpdateHelper.Info;
|
||||
}}
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
|
|
@ -81,88 +81,88 @@
|
|||
var message = 'You must be running your tests from rake to test this feature.';
|
||||
|
||||
new Test.Unit.Runner({
|
||||
setup: function(){
|
||||
setup: function() {
|
||||
$('content').update('');
|
||||
$('content2').update('');
|
||||
},
|
||||
|
||||
teardown: function(){
|
||||
teardown: function() {
|
||||
// hack to cleanup responders
|
||||
Ajax.Responders.responders = [Ajax.Responders.responders[0]];
|
||||
},
|
||||
|
||||
testSynchronousRequest: function() {with(this) {
|
||||
assertEqual("", $("content").innerHTML);
|
||||
testSynchronousRequest: function() {
|
||||
this.assertEqual("", $("content").innerHTML);
|
||||
|
||||
assertEqual(0, Ajax.activeRequestCount);
|
||||
this.assertEqual(0, Ajax.activeRequestCount);
|
||||
new Ajax.Request("fixtures/hello.js", {
|
||||
asynchronous: false,
|
||||
method: 'GET',
|
||||
evalJS: 'force'
|
||||
});
|
||||
assertEqual(0, Ajax.activeRequestCount);
|
||||
this.assertEqual(0, Ajax.activeRequestCount);
|
||||
|
||||
var h2 = $("content").firstChild;
|
||||
assertEqual("Hello world!", h2.innerHTML);
|
||||
}},
|
||||
this.assertEqual("Hello world!", h2.innerHTML);
|
||||
},
|
||||
|
||||
testAsynchronousRequest: function() {with(this) {
|
||||
assertEqual("", $("content").innerHTML);
|
||||
testAsynchronousRequest: function() {
|
||||
this.assertEqual("", $("content").innerHTML);
|
||||
|
||||
new Ajax.Request("fixtures/hello.js", {
|
||||
asynchronous: true,
|
||||
method: 'get',
|
||||
evalJS: 'force'
|
||||
});
|
||||
wait(1000, function() {
|
||||
this.wait(1000, function() {
|
||||
var h2 = $("content").firstChild;
|
||||
assertEqual("Hello world!", h2.innerHTML);
|
||||
this.assertEqual("Hello world!", h2.innerHTML);
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testUpdater: function() {with(this) {
|
||||
assertEqual("", $("content").innerHTML);
|
||||
testUpdater: function() {
|
||||
this.assertEqual("", $("content").innerHTML);
|
||||
|
||||
new Ajax.Updater("content", "fixtures/content.html", { method:'get' });
|
||||
|
||||
wait(1000, function() {
|
||||
assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
|
||||
this.wait(1000, function() {
|
||||
this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
|
||||
|
||||
$('content').update('');
|
||||
assertEqual("", $("content").innerHTML);
|
||||
this.assertEqual("", $("content").innerHTML);
|
||||
|
||||
new Ajax.Updater({ success:"content", failure:"content2" },
|
||||
"fixtures/content.html", { method:'get', parameters:{ pet:'monkey' } });
|
||||
|
||||
new Ajax.Updater("", "fixtures/content.html", { method:'get', parameters:"pet=monkey" });
|
||||
|
||||
wait(1000, function() {
|
||||
assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
|
||||
assertEqual("", $("content2").innerHTML);
|
||||
this.wait(1000, function() {
|
||||
this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
|
||||
this.assertEqual("", $("content2").innerHTML);
|
||||
});
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testUpdaterWithInsertion: function() {with(this) {
|
||||
testUpdaterWithInsertion: function() {
|
||||
$('content').update();
|
||||
new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: Insertion.Top });
|
||||
wait(1000, function() {
|
||||
assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
|
||||
this.wait(1000, function() {
|
||||
this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
|
||||
$('content').update();
|
||||
new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: 'bottom' });
|
||||
wait(1000, function() {
|
||||
assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
|
||||
this.wait(1000, function() {
|
||||
this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
|
||||
|
||||
$('content').update();
|
||||
new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: 'after' });
|
||||
wait(1000, function() {
|
||||
assertEqual('five dozen', $("content").next().innerHTML.strip().toLowerCase());
|
||||
this.wait(1000, function() {
|
||||
this.assertEqual('five dozen', $("content").next().innerHTML.strip().toLowerCase());
|
||||
});
|
||||
});
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testUpdaterOptions: function() {with(this) {
|
||||
testUpdaterOptions: function() {
|
||||
var options = {
|
||||
method: 'get',
|
||||
asynchronous: false,
|
||||
|
@ -171,26 +171,26 @@
|
|||
}
|
||||
var request = new Ajax.Updater("content", "fixtures/hello.js", options);
|
||||
request.options.onComplete = function() {};
|
||||
assertIdentical(Prototype.emptyFunction, options.onComplete);
|
||||
}},
|
||||
this.assertIdentical(Prototype.emptyFunction, options.onComplete);
|
||||
},
|
||||
|
||||
testResponders: function(){with(this) {
|
||||
testResponders: function(){
|
||||
// check for internal responder
|
||||
assertEqual(1, Ajax.Responders.responders.length);
|
||||
this.assertEqual(1, Ajax.Responders.responders.length);
|
||||
|
||||
var dummyResponder = {
|
||||
onComplete: function(req) { /* dummy */ }
|
||||
};
|
||||
|
||||
Ajax.Responders.register(dummyResponder);
|
||||
assertEqual(2, Ajax.Responders.responders.length);
|
||||
this.assertEqual(2, Ajax.Responders.responders.length);
|
||||
|
||||
// don't add twice
|
||||
Ajax.Responders.register(dummyResponder);
|
||||
assertEqual(2, Ajax.Responders.responders.length);
|
||||
this.assertEqual(2, Ajax.Responders.responders.length);
|
||||
|
||||
Ajax.Responders.unregister(dummyResponder);
|
||||
assertEqual(1, Ajax.Responders.responders.length);
|
||||
this.assertEqual(1, Ajax.Responders.responders.length);
|
||||
|
||||
var responder = {
|
||||
onCreate: function(req){ responderCounter++ },
|
||||
|
@ -199,66 +199,66 @@
|
|||
};
|
||||
Ajax.Responders.register(responder);
|
||||
|
||||
assertEqual(0, responderCounter);
|
||||
assertEqual(0, Ajax.activeRequestCount);
|
||||
this.assertEqual(0, responderCounter);
|
||||
this.assertEqual(0, Ajax.activeRequestCount);
|
||||
new Ajax.Request("fixtures/content.html", { method:'get', parameters:"pet=monkey" });
|
||||
assertEqual(1, responderCounter);
|
||||
assertEqual(1, Ajax.activeRequestCount);
|
||||
this.assertEqual(1, responderCounter);
|
||||
this.assertEqual(1, Ajax.activeRequestCount);
|
||||
|
||||
wait(1000,function() {
|
||||
assertEqual(3, responderCounter);
|
||||
assertEqual(0, Ajax.activeRequestCount);
|
||||
this.wait(1000,function() {
|
||||
this.assertEqual(3, responderCounter);
|
||||
this.assertEqual(0, Ajax.activeRequestCount);
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testEvalResponseShouldBeCalledBeforeOnComplete: function() {with(this) {
|
||||
if (isRunningFromRake) {
|
||||
assertEqual("", $("content").innerHTML);
|
||||
testEvalResponseShouldBeCalledBeforeOnComplete: function() {
|
||||
if (this.isRunningFromRake) {
|
||||
this.assertEqual("", $("content").innerHTML);
|
||||
|
||||
assertEqual(0, Ajax.activeRequestCount);
|
||||
this.assertEqual(0, Ajax.activeRequestCount);
|
||||
new Ajax.Request("fixtures/hello.js", extendDefault({
|
||||
onComplete: function(response) { assertNotEqual("", $("content").innerHTML) }
|
||||
onComplete: function(response) { this.assertNotEqual("", $("content").innerHTML) }.bind(this)
|
||||
}));
|
||||
assertEqual(0, Ajax.activeRequestCount);
|
||||
this.assertEqual(0, Ajax.activeRequestCount);
|
||||
|
||||
var h2 = $("content").firstChild;
|
||||
assertEqual("Hello world!", h2.innerHTML);
|
||||
this.assertEqual("Hello world!", h2.innerHTML);
|
||||
} else {
|
||||
info(message);
|
||||
this.info(message);
|
||||
}
|
||||
}},
|
||||
},
|
||||
|
||||
testContentTypeSetForSimulatedVerbs: function() {with(this) {
|
||||
if (isRunningFromRake) {
|
||||
testContentTypeSetForSimulatedVerbs: function() {
|
||||
if (this.isRunningFromRake) {
|
||||
new Ajax.Request('/inspect', extendDefault({
|
||||
method: 'put',
|
||||
contentType: 'application/bogus',
|
||||
onComplete: function(response) {
|
||||
assertEqual('application/bogus; charset=UTF-8', response.responseJSON.headers['content-type']);
|
||||
}
|
||||
this.assertEqual('application/bogus; charset=UTF-8', response.responseJSON.headers['content-type']);
|
||||
}.bind(this)
|
||||
}));
|
||||
} else {
|
||||
info(message);
|
||||
this.info(message);
|
||||
}
|
||||
}},
|
||||
},
|
||||
|
||||
testOnCreateCallback: function() {with(this) {
|
||||
testOnCreateCallback: function() {
|
||||
new Ajax.Request("fixtures/content.html", extendDefault({
|
||||
onCreate: function(transport) { assertEqual(0, transport.readyState) },
|
||||
onComplete: function(transport) { assertNotEqual(0, transport.readyState) }
|
||||
onCreate: function(transport) { this.assertEqual(0, transport.readyState) }.bind(this),
|
||||
onComplete: function(transport) { this.assertNotEqual(0, transport.readyState) }.bind(this)
|
||||
}));
|
||||
}},
|
||||
},
|
||||
|
||||
testEvalJS: function() {with(this) {
|
||||
if (isRunningFromRake) {
|
||||
testEvalJS: function() {
|
||||
if (this.isRunningFromRake) {
|
||||
|
||||
$('content').update();
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
parameters: Fixtures.js,
|
||||
onComplete: function(transport) {
|
||||
var h2 = $("content").firstChild;
|
||||
assertEqual("Hello world!", h2.innerHTML);
|
||||
}
|
||||
this.assertEqual("Hello world!", h2.innerHTML);
|
||||
}.bind(this)
|
||||
}));
|
||||
|
||||
$('content').update();
|
||||
|
@ -266,11 +266,11 @@
|
|||
evalJS: false,
|
||||
parameters: Fixtures.js,
|
||||
onComplete: function(transport) {
|
||||
assertEqual("", $("content").innerHTML);
|
||||
}
|
||||
this.assertEqual("", $("content").innerHTML);
|
||||
}.bind(this)
|
||||
}));
|
||||
} else {
|
||||
info(message);
|
||||
this.info(message);
|
||||
}
|
||||
|
||||
$('content').update();
|
||||
|
@ -278,14 +278,14 @@
|
|||
evalJS: 'force',
|
||||
onComplete: function(transport) {
|
||||
var h2 = $("content").firstChild;
|
||||
assertEqual("Hello world!", h2.innerHTML);
|
||||
}
|
||||
this.assertEqual("Hello world!", h2.innerHTML);
|
||||
}.bind(this)
|
||||
}));
|
||||
}},
|
||||
},
|
||||
|
||||
testCallbacks: function() {with(this) {
|
||||
testCallbacks: function() {
|
||||
var options = extendDefault({
|
||||
onCreate: function(transport) { assertInstanceOf(Ajax.Response, transport) }
|
||||
onCreate: function(transport) { this.assertInstanceOf(Ajax.Response, transport) }.bind(this)
|
||||
});
|
||||
|
||||
Ajax.Request.Events.each(function(state){
|
||||
|
@ -293,36 +293,36 @@
|
|||
});
|
||||
|
||||
new Ajax.Request("fixtures/content.html", options);
|
||||
}},
|
||||
},
|
||||
|
||||
testResponseText: function() {with(this) {
|
||||
testResponseText: function() {
|
||||
new Ajax.Request("fixtures/empty.html", extendDefault({
|
||||
onComplete: function(transport) { assertEqual('', transport.responseText) }
|
||||
onComplete: function(transport) { this.assertEqual('', transport.responseText) }.bind(this)
|
||||
}));
|
||||
|
||||
new Ajax.Request("fixtures/content.html", extendDefault({
|
||||
onComplete: function(transport) { assertEqual(sentence, transport.responseText.toLowerCase()) }
|
||||
onComplete: function(transport) { this.assertEqual(sentence, transport.responseText.toLowerCase()) }.bind(this)
|
||||
}));
|
||||
}},
|
||||
},
|
||||
|
||||
testResponseXML: function() {with(this) {
|
||||
if (isRunningFromRake) {
|
||||
testResponseXML: function() {
|
||||
if (this.isRunningFromRake) {
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
parameters: Fixtures.xml,
|
||||
onComplete: function(transport) {
|
||||
assertEqual('foo', transport.responseXML.getElementsByTagName('name')[0].getAttribute('attr'))
|
||||
}
|
||||
this.assertEqual('foo', transport.responseXML.getElementsByTagName('name')[0].getAttribute('attr'))
|
||||
}.bind(this)
|
||||
}));
|
||||
} else {
|
||||
info(message);
|
||||
this.info(message);
|
||||
}
|
||||
}},
|
||||
},
|
||||
|
||||
testResponseJSON: function() {with(this) {
|
||||
if (isRunningFromRake) {
|
||||
testResponseJSON: function() {
|
||||
if (this.isRunningFromRake) {
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
parameters: Fixtures.json,
|
||||
onComplete: function(transport) { assertEqual(123, transport.responseJSON.test) }
|
||||
onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this)
|
||||
}));
|
||||
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
|
@ -330,95 +330,95 @@
|
|||
'Content-Length': 0,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
onComplete: function(transport) { assertNull(transport.responseJSON) }
|
||||
onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this)
|
||||
}));
|
||||
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
evalJSON: false,
|
||||
parameters: Fixtures.json,
|
||||
onComplete: function(transport) { assertNull(transport.responseJSON) }
|
||||
onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this)
|
||||
}));
|
||||
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
parameters: Fixtures.jsonWithoutContentType,
|
||||
onComplete: function(transport) { assertNull(transport.responseJSON) }
|
||||
onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this)
|
||||
}));
|
||||
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
sanitizeJSON: true,
|
||||
parameters: Fixtures.invalidJson,
|
||||
onException: function(request, error) {
|
||||
assert(error.message.include('Badly formed JSON string'));
|
||||
assertInstanceOf(Ajax.Request, request);
|
||||
}
|
||||
this.assert(error.message.include('Badly formed JSON string'));
|
||||
this.assertInstanceOf(Ajax.Request, request);
|
||||
}.bind(this)
|
||||
}));
|
||||
} else {
|
||||
info(message);
|
||||
this.info(message);
|
||||
}
|
||||
|
||||
new Ajax.Request("fixtures/data.json", extendDefault({
|
||||
evalJSON: 'force',
|
||||
onComplete: function(transport) { assertEqual(123, transport.responseJSON.test) }
|
||||
onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this)
|
||||
}));
|
||||
}},
|
||||
},
|
||||
|
||||
testHeaderJSON: function() {with(this) {
|
||||
if (isRunningFromRake) {
|
||||
testHeaderJSON: function() {
|
||||
if (this.isRunningFromRake) {
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
parameters: Fixtures.headerJson,
|
||||
onComplete: function(transport, json) {
|
||||
assertEqual('hello #éà', transport.headerJSON.test);
|
||||
assertEqual('hello #éà', json.test);
|
||||
}
|
||||
this.assertEqual('hello #éà', transport.headerJSON.test);
|
||||
this.assertEqual('hello #éà', json.test);
|
||||
}.bind(this)
|
||||
}));
|
||||
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
onComplete: function(transport, json) {
|
||||
assertNull(transport.headerJSON)
|
||||
assertNull(json)
|
||||
}
|
||||
this.assertNull(transport.headerJSON)
|
||||
this.assertNull(json)
|
||||
}.bind(this)
|
||||
}));
|
||||
} else {
|
||||
info(message);
|
||||
this.info(message);
|
||||
}
|
||||
}},
|
||||
},
|
||||
|
||||
testGetHeader: function() {with(this) {
|
||||
if (isRunningFromRake) {
|
||||
testGetHeader: function() {
|
||||
if (this.isRunningFromRake) {
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
parameters: { 'X-TEST': 'some value' },
|
||||
onComplete: function(transport) {
|
||||
assertEqual('some value', transport.getHeader('X-Test'));
|
||||
assertNull(transport.getHeader('X-Inexistant'));
|
||||
}
|
||||
this.assertEqual('some value', transport.getHeader('X-Test'));
|
||||
this.assertNull(transport.getHeader('X-Inexistant'));
|
||||
}.bind(this)
|
||||
}));
|
||||
} else {
|
||||
info(message);
|
||||
this.info(message);
|
||||
}
|
||||
}},
|
||||
},
|
||||
|
||||
testParametersCanBeHash: function() {with(this) {
|
||||
if (isRunningFromRake) {
|
||||
testParametersCanBeHash: function() {
|
||||
if (this.isRunningFromRake) {
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
parameters: $H({ "one": "two", "three": "four" }),
|
||||
onComplete: function(transport) {
|
||||
assertEqual("two", transport.getHeader("one"));
|
||||
assertEqual("four", transport.getHeader("three"));
|
||||
assertNull(transport.getHeader("toObject"));
|
||||
}
|
||||
this.assertEqual("two", transport.getHeader("one"));
|
||||
this.assertEqual("four", transport.getHeader("three"));
|
||||
this.assertNull(transport.getHeader("toObject"));
|
||||
}.bind(this)
|
||||
}));
|
||||
} else {
|
||||
info(message);
|
||||
this.info(message);
|
||||
}
|
||||
}},
|
||||
},
|
||||
|
||||
testIsSameOriginMethod: function() {with(this) {
|
||||
testIsSameOriginMethod: function() {
|
||||
var isSameOrigin = Ajax.Request.prototype.isSameOrigin;
|
||||
assert(isSameOrigin.call({ url: '/foo/bar.html' }), '/foo/bar.html');
|
||||
assert(isSameOrigin.call({ url: window.location.toString() }), window.location);
|
||||
assert(!isSameOrigin.call({ url: 'http://example.com' }), 'http://example.com');
|
||||
this.assert(isSameOrigin.call({ url: '/foo/bar.html' }), '/foo/bar.html');
|
||||
this.assert(isSameOrigin.call({ url: window.location.toString() }), window.location);
|
||||
this.assert(!isSameOrigin.call({ url: 'http://example.com' }), 'http://example.com');
|
||||
|
||||
if (isRunningFromRake) {
|
||||
if (this.isRunningFromRake) {
|
||||
Ajax.Request.prototype.isSameOrigin = function() {
|
||||
return false
|
||||
};
|
||||
|
@ -427,29 +427,29 @@
|
|||
new Ajax.Request("/response", extendDefault({
|
||||
parameters: Fixtures.js,
|
||||
onComplete: function(transport) {
|
||||
assertEqual("same origin policy", $("content").innerHTML);
|
||||
}
|
||||
this.assertEqual("same origin policy", $("content").innerHTML);
|
||||
}.bind(this)
|
||||
}));
|
||||
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
parameters: Fixtures.invalidJson,
|
||||
onException: function(request, error) {
|
||||
assert(error.message.include('Badly formed JSON string'));
|
||||
}
|
||||
this.assert(error.message.include('Badly formed JSON string'));
|
||||
}.bind(this)
|
||||
}));
|
||||
|
||||
new Ajax.Request("/response", extendDefault({
|
||||
parameters: { 'X-JSON': '{});window.attacked = true;({}' },
|
||||
onException: function(request, error) {
|
||||
assert(error.message.include('Badly formed JSON string'));
|
||||
}
|
||||
this.assert(error.message.include('Badly formed JSON string'));
|
||||
}.bind(this)
|
||||
}));
|
||||
|
||||
Ajax.Request.prototype.isSameOrigin = isSameOrigin;
|
||||
} else {
|
||||
info(message);
|
||||
this.info(message);
|
||||
}
|
||||
}}
|
||||
}
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
|
|
|
@ -32,191 +32,191 @@
|
|||
var globalArgsTest = 'nothing to see here';
|
||||
|
||||
new Test.Unit.Runner({
|
||||
test$A: function(){ with(this) {
|
||||
assertEnumEqual([], $A({}));
|
||||
}},
|
||||
test$A: function(){
|
||||
this.assertEnumEqual([], $A({}));
|
||||
},
|
||||
|
||||
testToArrayOnArguments: function(){ with(this) {
|
||||
testToArrayOnArguments: function(){
|
||||
function toArrayOnArguments(){
|
||||
globalArgsTest = $A(arguments);
|
||||
}
|
||||
toArrayOnArguments();
|
||||
assertEnumEqual([], globalArgsTest);
|
||||
this.assertEnumEqual([], globalArgsTest);
|
||||
toArrayOnArguments('foo');
|
||||
assertEnumEqual(['foo'], globalArgsTest);
|
||||
this.assertEnumEqual(['foo'], globalArgsTest);
|
||||
toArrayOnArguments('foo','bar');
|
||||
assertEnumEqual(['foo','bar'], globalArgsTest);
|
||||
}},
|
||||
this.assertEnumEqual(['foo','bar'], globalArgsTest);
|
||||
},
|
||||
|
||||
testToArrayOnNodeList: function(){ with(this) {
|
||||
testToArrayOnNodeList: function(){
|
||||
// direct HTML
|
||||
assertEqual(3, $A($('test_node').childNodes).length);
|
||||
this.assertEqual(3, $A($('test_node').childNodes).length);
|
||||
|
||||
// DOM
|
||||
var element = document.createElement('div');
|
||||
element.appendChild(document.createTextNode('22'));
|
||||
(2).times(function(){ element.appendChild(document.createElement('span')) });
|
||||
assertEqual(3, $A(element.childNodes).length);
|
||||
this.assertEqual(3, $A(element.childNodes).length);
|
||||
|
||||
// HTML String
|
||||
element = document.createElement('div');
|
||||
$(element).update('22<span></span><span></span');
|
||||
assertEqual(3, $A(element.childNodes).length);
|
||||
}},
|
||||
this.assertEqual(3, $A(element.childNodes).length);
|
||||
},
|
||||
|
||||
testClear: function(){ with(this) {
|
||||
assertEnumEqual([], [].clear());
|
||||
assertEnumEqual([], [1].clear());
|
||||
assertEnumEqual([], [1,2].clear());
|
||||
}},
|
||||
testClear: function(){
|
||||
this.assertEnumEqual([], [].clear());
|
||||
this.assertEnumEqual([], [1].clear());
|
||||
this.assertEnumEqual([], [1,2].clear());
|
||||
},
|
||||
|
||||
testClone: function(){ with(this) {
|
||||
assertEnumEqual([], [].clone());
|
||||
assertEnumEqual([1], [1].clone());
|
||||
assertEnumEqual([1,2], [1,2].clone());
|
||||
assertEnumEqual([0,1,2], [0,1,2].clone());
|
||||
testClone: function(){
|
||||
this.assertEnumEqual([], [].clone());
|
||||
this.assertEnumEqual([1], [1].clone());
|
||||
this.assertEnumEqual([1,2], [1,2].clone());
|
||||
this.assertEnumEqual([0,1,2], [0,1,2].clone());
|
||||
var a = [0,1,2];
|
||||
var b = a;
|
||||
assertIdentical(a, b);
|
||||
this.assertIdentical(a, b);
|
||||
b = a.clone();
|
||||
assertNotIdentical(a, b);
|
||||
}},
|
||||
this.assertNotIdentical(a, b);
|
||||
},
|
||||
|
||||
testFirst: function(){ with(this) {
|
||||
assertUndefined([].first());
|
||||
assertEqual(1, [1].first());
|
||||
assertEqual(1, [1,2].first());
|
||||
}},
|
||||
testFirst: function(){
|
||||
this.assertUndefined([].first());
|
||||
this.assertEqual(1, [1].first());
|
||||
this.assertEqual(1, [1,2].first());
|
||||
},
|
||||
|
||||
testLast: function(){ with(this) {
|
||||
assertUndefined([].last());
|
||||
assertEqual(1, [1].last());
|
||||
assertEqual(2, [1,2].last());
|
||||
}},
|
||||
testLast: function(){
|
||||
this.assertUndefined([].last());
|
||||
this.assertEqual(1, [1].last());
|
||||
this.assertEqual(2, [1,2].last());
|
||||
},
|
||||
|
||||
testCompact: function(){ with(this) {
|
||||
assertEnumEqual([], [].compact());
|
||||
assertEnumEqual([1,2,3], [1,2,3].compact());
|
||||
assertEnumEqual([0,1,2,3], [0,null,1,2,undefined,3].compact());
|
||||
assertEnumEqual([1,2,3], [null,1,2,3,null].compact());
|
||||
}},
|
||||
testCompact: function(){
|
||||
this.assertEnumEqual([], [].compact());
|
||||
this.assertEnumEqual([1,2,3], [1,2,3].compact());
|
||||
this.assertEnumEqual([0,1,2,3], [0,null,1,2,undefined,3].compact());
|
||||
this.assertEnumEqual([1,2,3], [null,1,2,3,null].compact());
|
||||
},
|
||||
|
||||
testFlatten: function(){ with(this) {
|
||||
assertEnumEqual([], [].flatten());
|
||||
assertEnumEqual([1,2,3], [1,2,3].flatten());
|
||||
assertEnumEqual([1,2,3], [1,[[[2,3]]]].flatten());
|
||||
assertEnumEqual([1,2,3], [[1],[2],[3]].flatten());
|
||||
assertEnumEqual([1,2,3], [[[[[[[1]]]]]],2,3].flatten());
|
||||
}},
|
||||
testFlatten: function(){
|
||||
this.assertEnumEqual([], [].flatten());
|
||||
this.assertEnumEqual([1,2,3], [1,2,3].flatten());
|
||||
this.assertEnumEqual([1,2,3], [1,[[[2,3]]]].flatten());
|
||||
this.assertEnumEqual([1,2,3], [[1],[2],[3]].flatten());
|
||||
this.assertEnumEqual([1,2,3], [[[[[[[1]]]]]],2,3].flatten());
|
||||
},
|
||||
|
||||
testIndexOf: function(){ with(this) {
|
||||
assertEqual(-1, [].indexOf(1));
|
||||
assertEqual(-1, [0].indexOf(1));
|
||||
assertEqual(0, [1].indexOf(1));
|
||||
assertEqual(1, [0,1,2].indexOf(1));
|
||||
assertEqual(0, [1,2,1].indexOf(1));
|
||||
assertEqual(2, [1,2,1].indexOf(1, -1));
|
||||
assertEqual(1, [undefined,null].indexOf(null));
|
||||
}},
|
||||
testIndexOf: function(){
|
||||
this.assertEqual(-1, [].indexOf(1));
|
||||
this.assertEqual(-1, [0].indexOf(1));
|
||||
this.assertEqual(0, [1].indexOf(1));
|
||||
this.assertEqual(1, [0,1,2].indexOf(1));
|
||||
this.assertEqual(0, [1,2,1].indexOf(1));
|
||||
this.assertEqual(2, [1,2,1].indexOf(1, -1));
|
||||
this.assertEqual(1, [undefined,null].indexOf(null));
|
||||
},
|
||||
|
||||
testLastIndexOf: function(){ with(this) {
|
||||
assertEqual(-1,[].lastIndexOf(1));
|
||||
assertEqual(-1, [0].lastIndexOf(1));
|
||||
assertEqual(0, [1].lastIndexOf(1));
|
||||
assertEqual(2, [0,2,4,6].lastIndexOf(4));
|
||||
assertEqual(3, [4,4,2,4,6].lastIndexOf(4));
|
||||
assertEqual(3, [0,2,4,6].lastIndexOf(6,3));
|
||||
assertEqual(-1, [0,2,4,6].lastIndexOf(6,2));
|
||||
assertEqual(0, [6,2,4,6].lastIndexOf(6,2));
|
||||
testLastIndexOf: function(){
|
||||
this.assertEqual(-1,[].lastIndexOf(1));
|
||||
this.assertEqual(-1, [0].lastIndexOf(1));
|
||||
this.assertEqual(0, [1].lastIndexOf(1));
|
||||
this.assertEqual(2, [0,2,4,6].lastIndexOf(4));
|
||||
this.assertEqual(3, [4,4,2,4,6].lastIndexOf(4));
|
||||
this.assertEqual(3, [0,2,4,6].lastIndexOf(6,3));
|
||||
this.assertEqual(-1, [0,2,4,6].lastIndexOf(6,2));
|
||||
this.assertEqual(0, [6,2,4,6].lastIndexOf(6,2));
|
||||
|
||||
var fixture = [1,2,3,4,3];
|
||||
assertEqual(4, fixture.lastIndexOf(3));
|
||||
assertEnumEqual([1,2,3,4,3],fixture);
|
||||
this.assertEqual(4, fixture.lastIndexOf(3));
|
||||
this.assertEnumEqual([1,2,3,4,3],fixture);
|
||||
|
||||
//tests from http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:lastIndexOf
|
||||
var array = [2, 5, 9, 2];
|
||||
assertEqual(3,array.lastIndexOf(2));
|
||||
assertEqual(-1,array.lastIndexOf(7));
|
||||
assertEqual(3,array.lastIndexOf(2,3));
|
||||
assertEqual(0,array.lastIndexOf(2,2));
|
||||
assertEqual(0,array.lastIndexOf(2,-2));
|
||||
assertEqual(3,array.lastIndexOf(2,-1));
|
||||
}},
|
||||
this.assertEqual(3,array.lastIndexOf(2));
|
||||
this.assertEqual(-1,array.lastIndexOf(7));
|
||||
this.assertEqual(3,array.lastIndexOf(2,3));
|
||||
this.assertEqual(0,array.lastIndexOf(2,2));
|
||||
this.assertEqual(0,array.lastIndexOf(2,-2));
|
||||
this.assertEqual(3,array.lastIndexOf(2,-1));
|
||||
},
|
||||
|
||||
testInspect: function(){ with(this) {
|
||||
assertEqual('[]',[].inspect());
|
||||
assertEqual('[1]',[1].inspect());
|
||||
assertEqual('[\'a\']',['a'].inspect());
|
||||
assertEqual('[\'a\', 1]',['a',1].inspect());
|
||||
}},
|
||||
testInspect: function(){
|
||||
this.assertEqual('[]',[].inspect());
|
||||
this.assertEqual('[1]',[1].inspect());
|
||||
this.assertEqual('[\'a\']',['a'].inspect());
|
||||
this.assertEqual('[\'a\', 1]',['a',1].inspect());
|
||||
},
|
||||
|
||||
testIntersect: function(){ with(this) {
|
||||
assertEnumEqual([1,3], [1,1,3,5].intersect([1,2,3]));
|
||||
assertEnumEqual([1], [1,1].intersect([1,1]));
|
||||
assertEnumEqual([], [1,1,3,5].intersect([4]));
|
||||
assertEnumEqual([], [1].intersect(['1']));
|
||||
testIntersect: function(){
|
||||
this.assertEnumEqual([1,3], [1,1,3,5].intersect([1,2,3]));
|
||||
this.assertEnumEqual([1], [1,1].intersect([1,1]));
|
||||
this.assertEnumEqual([], [1,1,3,5].intersect([4]));
|
||||
this.assertEnumEqual([], [1].intersect(['1']));
|
||||
|
||||
assertEnumEqual(
|
||||
this.assertEnumEqual(
|
||||
['B','C','D'],
|
||||
$R('A','Z').toArray().intersect($R('B','D').toArray())
|
||||
);
|
||||
}},
|
||||
},
|
||||
|
||||
testToJSON: function(){ with(this) {
|
||||
assertEqual('[]', [].toJSON());
|
||||
assertEqual('[\"a\"]', ['a'].toJSON());
|
||||
assertEqual('[\"a\", 1]', ['a', 1].toJSON());
|
||||
assertEqual('[\"a\", {\"b\": null}]', ['a', {'b': null}].toJSON());
|
||||
}},
|
||||
testToJSON: function(){
|
||||
this.assertEqual('[]', [].toJSON());
|
||||
this.assertEqual('[\"a\"]', ['a'].toJSON());
|
||||
this.assertEqual('[\"a\", 1]', ['a', 1].toJSON());
|
||||
this.assertEqual('[\"a\", {\"b\": null}]', ['a', {'b': null}].toJSON());
|
||||
},
|
||||
|
||||
testReduce: function(){ with(this) {
|
||||
assertUndefined([].reduce());
|
||||
assertNull([null].reduce());
|
||||
assertEqual(1, [1].reduce());
|
||||
assertEnumEqual([1,2,3], [1,2,3].reduce());
|
||||
assertEnumEqual([1,null,3], [1,null,3].reduce());
|
||||
}},
|
||||
testReduce: function(){
|
||||
this.assertUndefined([].reduce());
|
||||
this.assertNull([null].reduce());
|
||||
this.assertEqual(1, [1].reduce());
|
||||
this.assertEnumEqual([1,2,3], [1,2,3].reduce());
|
||||
this.assertEnumEqual([1,null,3], [1,null,3].reduce());
|
||||
},
|
||||
|
||||
testReverse: function(){ with(this) {
|
||||
assertEnumEqual([], [].reverse());
|
||||
assertEnumEqual([1], [1].reverse());
|
||||
assertEnumEqual([2,1], [1,2].reverse());
|
||||
assertEnumEqual([3,2,1], [1,2,3].reverse());
|
||||
}},
|
||||
testReverse: function(){
|
||||
this.assertEnumEqual([], [].reverse());
|
||||
this.assertEnumEqual([1], [1].reverse());
|
||||
this.assertEnumEqual([2,1], [1,2].reverse());
|
||||
this.assertEnumEqual([3,2,1], [1,2,3].reverse());
|
||||
},
|
||||
|
||||
testSize: function(){ with(this) {
|
||||
assertEqual(4, [0, 1, 2, 3].size());
|
||||
assertEqual(0, [].size());
|
||||
}},
|
||||
testSize: function(){
|
||||
this.assertEqual(4, [0, 1, 2, 3].size());
|
||||
this.assertEqual(0, [].size());
|
||||
},
|
||||
|
||||
testUniq: function(){ with(this) {
|
||||
assertEnumEqual([1], [1, 1, 1].uniq());
|
||||
assertEnumEqual([1], [1].uniq());
|
||||
assertEnumEqual([], [].uniq());
|
||||
assertEnumEqual([0, 1, 2, 3], [0, 1, 2, 2, 3, 0, 2].uniq());
|
||||
assertEnumEqual([0, 1, 2, 3], [0, 0, 1, 1, 2, 3, 3, 3].uniq(true));
|
||||
}},
|
||||
testUniq: function(){
|
||||
this.assertEnumEqual([1], [1, 1, 1].uniq());
|
||||
this.assertEnumEqual([1], [1].uniq());
|
||||
this.assertEnumEqual([], [].uniq());
|
||||
this.assertEnumEqual([0, 1, 2, 3], [0, 1, 2, 2, 3, 0, 2].uniq());
|
||||
this.assertEnumEqual([0, 1, 2, 3], [0, 0, 1, 1, 2, 3, 3, 3].uniq(true));
|
||||
},
|
||||
|
||||
testWithout: function(){ with(this) {
|
||||
assertEnumEqual([], [].without(0));
|
||||
assertEnumEqual([], [0].without(0));
|
||||
assertEnumEqual([1], [0,1].without(0));
|
||||
assertEnumEqual([1,2], [0,1,2].without(0));
|
||||
}},
|
||||
testWithout: function(){
|
||||
this.assertEnumEqual([], [].without(0));
|
||||
this.assertEnumEqual([], [0].without(0));
|
||||
this.assertEnumEqual([1], [0,1].without(0));
|
||||
this.assertEnumEqual([1,2], [0,1,2].without(0));
|
||||
},
|
||||
|
||||
test$w: function(){ with(this) {
|
||||
assertEnumEqual(['a', 'b', 'c', 'd'], $w('a b c d'));
|
||||
assertEnumEqual([], $w(' '));
|
||||
assertEnumEqual([], $w(''));
|
||||
assertEnumEqual([], $w(null));
|
||||
assertEnumEqual([], $w(undefined));
|
||||
assertEnumEqual([], $w());
|
||||
assertEnumEqual([], $w(10));
|
||||
assertEnumEqual(['a'], $w('a'));
|
||||
assertEnumEqual(['a'], $w('a '));
|
||||
assertEnumEqual(['a'], $w(' a'));
|
||||
assertEnumEqual(['a', 'b', 'c', 'd'], $w(' a b\nc\t\nd\n'));
|
||||
}}
|
||||
test$w: function(){
|
||||
this.assertEnumEqual(['a', 'b', 'c', 'd'], $w('a b c d'));
|
||||
this.assertEnumEqual([], $w(' '));
|
||||
this.assertEnumEqual([], $w(''));
|
||||
this.assertEnumEqual([], $w(null));
|
||||
this.assertEnumEqual([], $w(undefined));
|
||||
this.assertEnumEqual([], $w());
|
||||
this.assertEnumEqual([], $w(10));
|
||||
this.assertEnumEqual(['a'], $w('a'));
|
||||
this.assertEnumEqual(['a'], $w('a '));
|
||||
this.assertEnumEqual(['a'], $w(' a'));
|
||||
this.assertEnumEqual(['a', 'b', 'c', 'd'], $w(' a b\nc\t\nd\n'));
|
||||
}
|
||||
|
||||
});
|
||||
// ]]>
|
||||
|
|
|
@ -140,64 +140,64 @@
|
|||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
testFunctionArgumentNames: function() { with(this) {
|
||||
assertEnumEqual([], (function() {}).argumentNames());
|
||||
assertEnumEqual(["one"], (function(one) {}).argumentNames());
|
||||
assertEnumEqual(["one", "two", "three"], (function(one, two, three) {}).argumentNames());
|
||||
assertEqual("$super", (function($super) {}).argumentNames().first());
|
||||
testFunctionArgumentNames: function() {
|
||||
this.assertEnumEqual([], (function() {}).argumentNames());
|
||||
this.assertEnumEqual(["one"], (function(one) {}).argumentNames());
|
||||
this.assertEnumEqual(["one", "two", "three"], (function(one, two, three) {}).argumentNames());
|
||||
this.assertEqual("$super", (function($super) {}).argumentNames().first());
|
||||
|
||||
function named1() {};
|
||||
assertEnumEqual([], named1.argumentNames());
|
||||
this.assertEnumEqual([], named1.argumentNames());
|
||||
function named2(one) {};
|
||||
assertEnumEqual(["one"], named2.argumentNames());
|
||||
this.assertEnumEqual(["one"], named2.argumentNames());
|
||||
function named3(one, two, three) {};
|
||||
assertEnumEqual(["one", "two", "three"], named3.argumentNames());
|
||||
}},
|
||||
this.assertEnumEqual(["one", "two", "three"], named3.argumentNames());
|
||||
},
|
||||
|
||||
testFunctionBind: function() { with(this) {
|
||||
testFunctionBind: function() {
|
||||
function methodWithoutArguments() { return this.hi };
|
||||
function methodWithArguments() { return this.hi + ',' + $A(arguments).join(',') };
|
||||
var func = Prototype.emptyFunction;
|
||||
|
||||
assertIdentical(func, func.bind());
|
||||
assertIdentical(func, func.bind(undefined));
|
||||
assertNotIdentical(func, func.bind(null));
|
||||
this.assertIdentical(func, func.bind());
|
||||
this.assertIdentical(func, func.bind(undefined));
|
||||
this.assertNotIdentical(func, func.bind(null));
|
||||
|
||||
assertEqual('without', methodWithoutArguments.bind({ hi: 'without' })());
|
||||
assertEqual('with,arg1,arg2', methodWithArguments.bind({ hi: 'with' })('arg1','arg2'));
|
||||
assertEqual('withBindArgs,arg1,arg2',
|
||||
this.assertEqual('without', methodWithoutArguments.bind({ hi: 'without' })());
|
||||
this.assertEqual('with,arg1,arg2', methodWithArguments.bind({ hi: 'with' })('arg1','arg2'));
|
||||
this.assertEqual('withBindArgs,arg1,arg2',
|
||||
methodWithArguments.bind({ hi: 'withBindArgs' }, 'arg1', 'arg2')());
|
||||
assertEqual('withBindArgsAndArgs,arg1,arg2,arg3,arg4',
|
||||
this.assertEqual('withBindArgsAndArgs,arg1,arg2,arg3,arg4',
|
||||
methodWithArguments.bind({ hi: 'withBindArgsAndArgs' }, 'arg1', 'arg2')('arg3', 'arg4'));
|
||||
}},
|
||||
},
|
||||
|
||||
testFunctionCurry: function() { with(this) {
|
||||
testFunctionCurry: function() {
|
||||
var split = function(delimiter, string) { return string.split(delimiter); };
|
||||
var splitOnColons = split.curry(":");
|
||||
assertNotIdentical(split, splitOnColons);
|
||||
assertEnumEqual(split(":", "0:1:2:3:4:5"), splitOnColons("0:1:2:3:4:5"));
|
||||
assertIdentical(split, split.curry());
|
||||
}},
|
||||
this.assertNotIdentical(split, splitOnColons);
|
||||
this.assertEnumEqual(split(":", "0:1:2:3:4:5"), splitOnColons("0:1:2:3:4:5"));
|
||||
this.assertIdentical(split, split.curry());
|
||||
},
|
||||
|
||||
testFunctionDelay: function() { with(this) {
|
||||
testFunctionDelay: function() {
|
||||
window.delayed = undefined;
|
||||
var delayedFunction = function() { window.delayed = true; };
|
||||
var delayedFunctionWithArgs = function() { window.delayedWithArgs = $A(arguments).join(' '); };
|
||||
delayedFunction.delay(0.8);
|
||||
delayedFunctionWithArgs.delay(0.8, 'hello', 'world');
|
||||
assertUndefined(window.delayed);
|
||||
wait(1000, function() {
|
||||
assert(window.delayed);
|
||||
assertEqual('hello world', window.delayedWithArgs);
|
||||
this.assertUndefined(window.delayed);
|
||||
this.wait(1000, function() {
|
||||
this.assert(window.delayed);
|
||||
this.assertEqual('hello world', window.delayedWithArgs);
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testFunctionWrap: function() { with(this) {
|
||||
testFunctionWrap: function() {
|
||||
function sayHello(){
|
||||
return 'hello world';
|
||||
};
|
||||
|
||||
assertEqual('HELLO WORLD', sayHello.wrap(function(proceed) {
|
||||
this.assertEqual('HELLO WORLD', sayHello.wrap(function(proceed) {
|
||||
return proceed().toUpperCase();
|
||||
})());
|
||||
|
||||
|
@ -208,198 +208,198 @@
|
|||
}).join(' ');
|
||||
return proceed();
|
||||
});
|
||||
assertEqual('Hello world', 'hello world'.capitalize());
|
||||
assertEqual('Hello World', 'hello world'.capitalize(true));
|
||||
assertEqual('Hello', 'hello'.capitalize());
|
||||
this.assertEqual('Hello world', 'hello world'.capitalize());
|
||||
this.assertEqual('Hello World', 'hello world'.capitalize(true));
|
||||
this.assertEqual('Hello', 'hello'.capitalize());
|
||||
String.prototype.capitalize = temp;
|
||||
}},
|
||||
},
|
||||
|
||||
testFunctionDefer: function() { with(this) {
|
||||
testFunctionDefer: function() {
|
||||
window.deferred = undefined;
|
||||
var deferredFunction = function() { window.deferred = true; };
|
||||
deferredFunction.defer();
|
||||
assertUndefined(window.deferred);
|
||||
wait(50, function() {
|
||||
assert(window.deferred);
|
||||
this.assertUndefined(window.deferred);
|
||||
this.wait(50, function() {
|
||||
this.assert(window.deferred);
|
||||
|
||||
window.deferredValue = 0;
|
||||
var deferredFunction2 = function(arg) { window.deferredValue = arg; };
|
||||
deferredFunction2.defer('test');
|
||||
wait(50, function() {
|
||||
assertEqual('test', window.deferredValue);
|
||||
this.wait(50, function() {
|
||||
this.assertEqual('test', window.deferredValue);
|
||||
});
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testFunctionMethodize: function() { with(this) {
|
||||
testFunctionMethodize: function() {
|
||||
var Foo = { bar: function(baz) { return baz } };
|
||||
var baz = { quux: Foo.bar.methodize() };
|
||||
|
||||
assertEqual(Foo.bar.methodize(), baz.quux);
|
||||
assertEqual(baz, Foo.bar(baz));
|
||||
assertEqual(baz, baz.quux());
|
||||
}},
|
||||
this.assertEqual(Foo.bar.methodize(), baz.quux);
|
||||
this.assertEqual(baz, Foo.bar(baz));
|
||||
this.assertEqual(baz, baz.quux());
|
||||
},
|
||||
|
||||
testObjectExtend: function() { with(this) {
|
||||
testObjectExtend: function() {
|
||||
var object = {foo: 'foo', bar: [1, 2, 3]};
|
||||
assertIdentical(object, Object.extend(object));
|
||||
assertHashEqual({foo: 'foo', bar: [1, 2, 3]}, object);
|
||||
assertIdentical(object, Object.extend(object, {bla: 123}));
|
||||
assertHashEqual({foo: 'foo', bar: [1, 2, 3], bla: 123}, object);
|
||||
assertHashEqual({foo: 'foo', bar: [1, 2, 3], bla: null},
|
||||
this.assertIdentical(object, Object.extend(object));
|
||||
this.assertHashEqual({foo: 'foo', bar: [1, 2, 3]}, object);
|
||||
this.assertIdentical(object, Object.extend(object, {bla: 123}));
|
||||
this.assertHashEqual({foo: 'foo', bar: [1, 2, 3], bla: 123}, object);
|
||||
this.assertHashEqual({foo: 'foo', bar: [1, 2, 3], bla: null},
|
||||
Object.extend(object, {bla: null}));
|
||||
}},
|
||||
},
|
||||
|
||||
testObjectToQueryString: function() { with(this) {
|
||||
assertEqual('a=A&b=B&c=C&d=D%23', Object.toQueryString({a: 'A', b: 'B', c: 'C', d: 'D#'}));
|
||||
}},
|
||||
testObjectToQueryString: function() {
|
||||
this.assertEqual('a=A&b=B&c=C&d=D%23', Object.toQueryString({a: 'A', b: 'B', c: 'C', d: 'D#'}));
|
||||
},
|
||||
|
||||
testObjectClone: function() { with(this) {
|
||||
testObjectClone: function() {
|
||||
var object = {foo: 'foo', bar: [1, 2, 3]};
|
||||
assertNotIdentical(object, Object.clone(object));
|
||||
assertHashEqual(object, Object.clone(object));
|
||||
assertHashEqual({}, Object.clone());
|
||||
this.assertNotIdentical(object, Object.clone(object));
|
||||
this.assertHashEqual(object, Object.clone(object));
|
||||
this.assertHashEqual({}, Object.clone());
|
||||
var clone = Object.clone(object);
|
||||
delete clone.bar;
|
||||
assertHashEqual({foo: 'foo'}, clone,
|
||||
this.assertHashEqual({foo: 'foo'}, clone,
|
||||
"Optimizing Object.clone perf using prototyping doesn't allow properties to be deleted.");
|
||||
}},
|
||||
},
|
||||
|
||||
testObjectInspect: function() { with(this) {
|
||||
assertEqual('undefined', Object.inspect());
|
||||
assertEqual('undefined', Object.inspect(undefined));
|
||||
assertEqual('null', Object.inspect(null));
|
||||
assertEqual("'foo\\\\b\\\'ar'", Object.inspect('foo\\b\'ar'));
|
||||
assertEqual('[]', Object.inspect([]));
|
||||
assertNothingRaised(function() { Object.inspect(window.Node) });
|
||||
}},
|
||||
testObjectInspect: function() {
|
||||
this.assertEqual('undefined', Object.inspect());
|
||||
this.assertEqual('undefined', Object.inspect(undefined));
|
||||
this.assertEqual('null', Object.inspect(null));
|
||||
this.assertEqual("'foo\\\\b\\\'ar'", Object.inspect('foo\\b\'ar'));
|
||||
this.assertEqual('[]', Object.inspect([]));
|
||||
this.assertNothingRaised(function() { Object.inspect(window.Node) });
|
||||
},
|
||||
|
||||
testObjectToJSON: function() { with(this) {
|
||||
assertUndefined(Object.toJSON(undefined));
|
||||
assertUndefined(Object.toJSON(Prototype.K));
|
||||
assertEqual('\"\"', Object.toJSON(''));
|
||||
assertEqual('[]', Object.toJSON([]));
|
||||
assertEqual('[\"a\"]', Object.toJSON(['a']));
|
||||
assertEqual('[\"a\", 1]', Object.toJSON(['a', 1]));
|
||||
assertEqual('[\"a\", {\"b\": null}]', Object.toJSON(['a', {'b': null}]));
|
||||
assertEqual('{\"a\": \"hello!\"}', Object.toJSON({a: 'hello!'}));
|
||||
assertEqual('{}', Object.toJSON({}));
|
||||
assertEqual('{}', Object.toJSON({a: undefined, b: undefined, c: Prototype.K}));
|
||||
assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}',
|
||||
testObjectToJSON: function() {
|
||||
this.assertUndefined(Object.toJSON(undefined));
|
||||
this.assertUndefined(Object.toJSON(Prototype.K));
|
||||
this.assertEqual('\"\"', Object.toJSON(''));
|
||||
this.assertEqual('[]', Object.toJSON([]));
|
||||
this.assertEqual('[\"a\"]', Object.toJSON(['a']));
|
||||
this.assertEqual('[\"a\", 1]', Object.toJSON(['a', 1]));
|
||||
this.assertEqual('[\"a\", {\"b\": null}]', Object.toJSON(['a', {'b': null}]));
|
||||
this.assertEqual('{\"a\": \"hello!\"}', Object.toJSON({a: 'hello!'}));
|
||||
this.assertEqual('{}', Object.toJSON({}));
|
||||
this.assertEqual('{}', Object.toJSON({a: undefined, b: undefined, c: Prototype.K}));
|
||||
this.assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}',
|
||||
Object.toJSON({'b': [undefined, false, true, undefined], c: {a: 'hello!'}}));
|
||||
assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}',
|
||||
this.assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}',
|
||||
Object.toJSON($H({'b': [undefined, false, true, undefined], c: {a: 'hello!'}})));
|
||||
assertEqual('true', Object.toJSON(true));
|
||||
assertEqual('false', Object.toJSON(false));
|
||||
assertEqual('null', Object.toJSON(null));
|
||||
this.assertEqual('true', Object.toJSON(true));
|
||||
this.assertEqual('false', Object.toJSON(false));
|
||||
this.assertEqual('null', Object.toJSON(null));
|
||||
var sam = new Person('sam');
|
||||
assertEqual('-sam', Object.toJSON(sam));
|
||||
assertEqual('-sam', sam.toJSON());
|
||||
this.assertEqual('-sam', Object.toJSON(sam));
|
||||
this.assertEqual('-sam', sam.toJSON());
|
||||
var element = $('test');
|
||||
assertUndefined(Object.toJSON(element));
|
||||
this.assertUndefined(Object.toJSON(element));
|
||||
element.toJSON = function(){return 'I\'m a div with id test'};
|
||||
assertEqual('I\'m a div with id test', Object.toJSON(element));
|
||||
}},
|
||||
this.assertEqual('I\'m a div with id test', Object.toJSON(element));
|
||||
},
|
||||
|
||||
testObjectToHTML: function() { with(this) {
|
||||
assertIdentical('', Object.toHTML());
|
||||
assertIdentical('', Object.toHTML(''));
|
||||
assertIdentical('', Object.toHTML(null));
|
||||
assertIdentical('0', Object.toHTML(0));
|
||||
assertIdentical('123', Object.toHTML(123));
|
||||
assertEqual('hello world', Object.toHTML('hello world'));
|
||||
assertEqual('hello world', Object.toHTML({toHTML: function() { return 'hello world' }}));
|
||||
}},
|
||||
testObjectToHTML: function() {
|
||||
this.assertIdentical('', Object.toHTML());
|
||||
this.assertIdentical('', Object.toHTML(''));
|
||||
this.assertIdentical('', Object.toHTML(null));
|
||||
this.assertIdentical('0', Object.toHTML(0));
|
||||
this.assertIdentical('123', Object.toHTML(123));
|
||||
this.assertEqual('hello world', Object.toHTML('hello world'));
|
||||
this.assertEqual('hello world', Object.toHTML({toHTML: function() { return 'hello world' }}));
|
||||
},
|
||||
|
||||
testObjectIsArray: function() { with(this) {
|
||||
assert(Object.isArray([]));
|
||||
assert(Object.isArray([0]));
|
||||
assert(Object.isArray([0, 1]));
|
||||
assert(!Object.isArray({}));
|
||||
assert(!Object.isArray($('list').childNodes));
|
||||
assert(!Object.isArray());
|
||||
assert(!Object.isArray(''));
|
||||
assert(!Object.isArray('foo'));
|
||||
assert(!Object.isArray(0));
|
||||
assert(!Object.isArray(1));
|
||||
assert(!Object.isArray(null));
|
||||
assert(!Object.isArray(true));
|
||||
assert(!Object.isArray(false));
|
||||
assert(!Object.isArray(undefined));
|
||||
}},
|
||||
testObjectIsArray: function() {
|
||||
this.assert(Object.isArray([]));
|
||||
this.assert(Object.isArray([0]));
|
||||
this.assert(Object.isArray([0, 1]));
|
||||
this.assert(!Object.isArray({}));
|
||||
this.assert(!Object.isArray($('list').childNodes));
|
||||
this.assert(!Object.isArray());
|
||||
this.assert(!Object.isArray(''));
|
||||
this.assert(!Object.isArray('foo'));
|
||||
this.assert(!Object.isArray(0));
|
||||
this.assert(!Object.isArray(1));
|
||||
this.assert(!Object.isArray(null));
|
||||
this.assert(!Object.isArray(true));
|
||||
this.assert(!Object.isArray(false));
|
||||
this.assert(!Object.isArray(undefined));
|
||||
},
|
||||
|
||||
testObjectIsHash: function() { with(this) {
|
||||
assert(Object.isHash($H()));
|
||||
assert(Object.isHash(new Hash()));
|
||||
assert(!Object.isHash({}));
|
||||
}},
|
||||
testObjectIsHash: function() {
|
||||
this.assert(Object.isHash($H()));
|
||||
this.assert(Object.isHash(new Hash()));
|
||||
this.assert(!Object.isHash({}));
|
||||
},
|
||||
|
||||
testObjectIsElement: function() { with(this) {
|
||||
assert(Object.isElement(document.createElement('div')));
|
||||
assert(Object.isElement(new Element('div')));
|
||||
assert(Object.isElement($('testlog')));
|
||||
assert(!Object.isElement(document.createTextNode('bla')));
|
||||
}},
|
||||
testObjectIsElement: function() {
|
||||
this.assert(Object.isElement(document.createElement('div')));
|
||||
this.assert(Object.isElement(new Element('div')));
|
||||
this.assert(Object.isElement($('testlog')));
|
||||
this.assert(!Object.isElement(document.createTextNode('bla')));
|
||||
},
|
||||
|
||||
testObjectIsFunction: function() { with(this) {
|
||||
assert(Object.isFunction(function() { }));
|
||||
assert(Object.isFunction(Class.create()));
|
||||
assert(!Object.isFunction("a string"));
|
||||
assert(!Object.isFunction($("testlog")));
|
||||
assert(!Object.isFunction([]));
|
||||
assert(!Object.isFunction({}));
|
||||
assert(!Object.isFunction(0));
|
||||
assert(!Object.isFunction(false));
|
||||
assert(!Object.isFunction(undefined));
|
||||
}},
|
||||
testObjectIsFunction: function() {
|
||||
this.assert(Object.isFunction(function() { }));
|
||||
this.assert(Object.isFunction(Class.create()));
|
||||
this.assert(!Object.isFunction("a string"));
|
||||
this.assert(!Object.isFunction($("testlog")));
|
||||
this.assert(!Object.isFunction([]));
|
||||
this.assert(!Object.isFunction({}));
|
||||
this.assert(!Object.isFunction(0));
|
||||
this.assert(!Object.isFunction(false));
|
||||
this.assert(!Object.isFunction(undefined));
|
||||
},
|
||||
|
||||
testObjectIsString: function() { with(this) {
|
||||
assert(!Object.isString(function() { }));
|
||||
assert(Object.isString("a string"));
|
||||
assert(!Object.isString(0));
|
||||
assert(!Object.isString([]));
|
||||
assert(!Object.isString({}));
|
||||
assert(!Object.isString(false));
|
||||
assert(!Object.isString(undefined));
|
||||
}},
|
||||
testObjectIsString: function() {
|
||||
this.assert(!Object.isString(function() { }));
|
||||
this.assert(Object.isString("a string"));
|
||||
this.assert(!Object.isString(0));
|
||||
this.assert(!Object.isString([]));
|
||||
this.assert(!Object.isString({}));
|
||||
this.assert(!Object.isString(false));
|
||||
this.assert(!Object.isString(undefined));
|
||||
},
|
||||
|
||||
testObjectIsNumber: function() { with(this) {
|
||||
assert(Object.isNumber(0));
|
||||
assert(Object.isNumber(1.0));
|
||||
assert(!Object.isNumber(function() { }));
|
||||
assert(!Object.isNumber("a string"));
|
||||
assert(!Object.isNumber([]));
|
||||
assert(!Object.isNumber({}));
|
||||
assert(!Object.isNumber(false));
|
||||
assert(!Object.isNumber(undefined));
|
||||
}},
|
||||
testObjectIsNumber: function() {
|
||||
this.assert(Object.isNumber(0));
|
||||
this.assert(Object.isNumber(1.0));
|
||||
this.assert(!Object.isNumber(function() { }));
|
||||
this.assert(!Object.isNumber("a string"));
|
||||
this.assert(!Object.isNumber([]));
|
||||
this.assert(!Object.isNumber({}));
|
||||
this.assert(!Object.isNumber(false));
|
||||
this.assert(!Object.isNumber(undefined));
|
||||
},
|
||||
|
||||
testObjectIsUndefined: function() { with(this) {
|
||||
assert(Object.isUndefined(undefined));
|
||||
assert(!Object.isUndefined(null));
|
||||
assert(!Object.isUndefined(false));
|
||||
assert(!Object.isUndefined(0));
|
||||
assert(!Object.isUndefined(""));
|
||||
assert(!Object.isUndefined(function() { }));
|
||||
assert(!Object.isUndefined([]));
|
||||
assert(!Object.isUndefined({}));
|
||||
}},
|
||||
testObjectIsUndefined: function() {
|
||||
this.assert(Object.isUndefined(undefined));
|
||||
this.assert(!Object.isUndefined(null));
|
||||
this.assert(!Object.isUndefined(false));
|
||||
this.assert(!Object.isUndefined(0));
|
||||
this.assert(!Object.isUndefined(""));
|
||||
this.assert(!Object.isUndefined(function() { }));
|
||||
this.assert(!Object.isUndefined([]));
|
||||
this.assert(!Object.isUndefined({}));
|
||||
},
|
||||
|
||||
// sanity check
|
||||
testDoesntExtendObjectPrototype: function() {with(this) {
|
||||
testDoesntExtendObjectPrototype: function() {
|
||||
// for-in is supported with objects
|
||||
var iterations = 0, obj = { a: 1, b: 2, c: 3 };
|
||||
for(property in obj) iterations++;
|
||||
assertEqual(3, iterations);
|
||||
this.assertEqual(3, iterations);
|
||||
|
||||
// for-in is not supported with arrays
|
||||
iterations = 0;
|
||||
var arr = [1,2,3];
|
||||
for(property in arr) iterations++;
|
||||
assert(iterations > 3);
|
||||
}},
|
||||
this.assert(iterations > 3);
|
||||
},
|
||||
|
||||
testPeriodicalExecuterStop: function() {with(this) {
|
||||
testPeriodicalExecuterStop: function() {
|
||||
var peEventCount = 0;
|
||||
function peEventFired(pe) {
|
||||
if (++peEventCount > 2) pe.stop();
|
||||
|
@ -408,10 +408,10 @@
|
|||
// peEventFired will stop the PeriodicalExecuter after 3 callbacks
|
||||
new PeriodicalExecuter(peEventFired, 0.05);
|
||||
|
||||
wait(600, function() {
|
||||
assertEqual(3, peEventCount);
|
||||
this.wait(600, function() {
|
||||
this.assertEqual(3, peEventCount);
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testBindAsEventListener: function() {
|
||||
for( var i = 0; i < 10; ++i ){
|
||||
|
@ -429,52 +429,52 @@
|
|||
}
|
||||
},
|
||||
|
||||
testDateToJSON: function() {with(this) {
|
||||
assertEqual('\"1970-01-01T00:00:00Z\"', new Date(Date.UTC(1970, 0, 1)).toJSON());
|
||||
}},
|
||||
testDateToJSON: function() {
|
||||
this.assertEqual('\"1970-01-01T00:00:00Z\"', new Date(Date.UTC(1970, 0, 1)).toJSON());
|
||||
},
|
||||
|
||||
testRegExpEscape: function() {with(this) {
|
||||
assertEqual('word', RegExp.escape('word'));
|
||||
assertEqual('\\/slashes\\/', RegExp.escape('/slashes/'));
|
||||
assertEqual('\\\\backslashes\\\\', RegExp.escape('\\backslashes\\'));
|
||||
assertEqual('\\\\border of word', RegExp.escape('\\border of word'));
|
||||
testRegExpEscape: function() {
|
||||
this.assertEqual('word', RegExp.escape('word'));
|
||||
this.assertEqual('\\/slashes\\/', RegExp.escape('/slashes/'));
|
||||
this.assertEqual('\\\\backslashes\\\\', RegExp.escape('\\backslashes\\'));
|
||||
this.assertEqual('\\\\border of word', RegExp.escape('\\border of word'));
|
||||
|
||||
assertEqual('\\(\\?\\:non-capturing\\)', RegExp.escape('(?:non-capturing)'));
|
||||
assertEqual('non-capturing', new RegExp(RegExp.escape('(?:') + '([^)]+)').exec('(?:non-capturing)')[1]);
|
||||
this.assertEqual('\\(\\?\\:non-capturing\\)', RegExp.escape('(?:non-capturing)'));
|
||||
this.assertEqual('non-capturing', new RegExp(RegExp.escape('(?:') + '([^)]+)').exec('(?:non-capturing)')[1]);
|
||||
|
||||
assertEqual('\\(\\?\\=positive-lookahead\\)', RegExp.escape('(?=positive-lookahead)'));
|
||||
assertEqual('positive-lookahead', new RegExp(RegExp.escape('(?=') + '([^)]+)').exec('(?=positive-lookahead)')[1]);
|
||||
this.assertEqual('\\(\\?\\=positive-lookahead\\)', RegExp.escape('(?=positive-lookahead)'));
|
||||
this.assertEqual('positive-lookahead', new RegExp(RegExp.escape('(?=') + '([^)]+)').exec('(?=positive-lookahead)')[1]);
|
||||
|
||||
assertEqual('\\(\\?<\\=positive-lookbehind\\)', RegExp.escape('(?<=positive-lookbehind)'));
|
||||
assertEqual('positive-lookbehind', new RegExp(RegExp.escape('(?<=') + '([^)]+)').exec('(?<=positive-lookbehind)')[1]);
|
||||
this.assertEqual('\\(\\?<\\=positive-lookbehind\\)', RegExp.escape('(?<=positive-lookbehind)'));
|
||||
this.assertEqual('positive-lookbehind', new RegExp(RegExp.escape('(?<=') + '([^)]+)').exec('(?<=positive-lookbehind)')[1]);
|
||||
|
||||
assertEqual('\\(\\?\\!negative-lookahead\\)', RegExp.escape('(?!negative-lookahead)'));
|
||||
assertEqual('negative-lookahead', new RegExp(RegExp.escape('(?!') + '([^)]+)').exec('(?!negative-lookahead)')[1]);
|
||||
this.assertEqual('\\(\\?\\!negative-lookahead\\)', RegExp.escape('(?!negative-lookahead)'));
|
||||
this.assertEqual('negative-lookahead', new RegExp(RegExp.escape('(?!') + '([^)]+)').exec('(?!negative-lookahead)')[1]);
|
||||
|
||||
assertEqual('\\(\\?<\\!negative-lookbehind\\)', RegExp.escape('(?<!negative-lookbehind)'));
|
||||
assertEqual('negative-lookbehind', new RegExp(RegExp.escape('(?<!') + '([^)]+)').exec('(?<!negative-lookbehind)')[1]);
|
||||
this.assertEqual('\\(\\?<\\!negative-lookbehind\\)', RegExp.escape('(?<!negative-lookbehind)'));
|
||||
this.assertEqual('negative-lookbehind', new RegExp(RegExp.escape('(?<!') + '([^)]+)').exec('(?<!negative-lookbehind)')[1]);
|
||||
|
||||
assertEqual('\\[\\\\w\\]\\+', RegExp.escape('[\\w]+'));
|
||||
assertEqual('character class', new RegExp(RegExp.escape('[') + '([^\\]]+)').exec('[character class]')[1]);
|
||||
this.assertEqual('\\[\\\\w\\]\\+', RegExp.escape('[\\w]+'));
|
||||
this.assertEqual('character class', new RegExp(RegExp.escape('[') + '([^\\]]+)').exec('[character class]')[1]);
|
||||
|
||||
assertEqual('<div>', new RegExp(RegExp.escape('<div>')).exec('<td><div></td>')[0]);
|
||||
this.assertEqual('<div>', new RegExp(RegExp.escape('<div>')).exec('<td><div></td>')[0]);
|
||||
|
||||
assertEqual('false', RegExp.escape(false));
|
||||
assertEqual('undefined', RegExp.escape());
|
||||
assertEqual('null', RegExp.escape(null));
|
||||
assertEqual('42', RegExp.escape(42));
|
||||
this.assertEqual('false', RegExp.escape(false));
|
||||
this.assertEqual('undefined', RegExp.escape());
|
||||
this.assertEqual('null', RegExp.escape(null));
|
||||
this.assertEqual('42', RegExp.escape(42));
|
||||
|
||||
assertEqual('\\\\n\\\\r\\\\t', RegExp.escape('\\n\\r\\t'));
|
||||
assertEqual('\n\r\t', RegExp.escape('\n\r\t'));
|
||||
assertEqual('\\{5,2\\}', RegExp.escape('{5,2}'));
|
||||
this.assertEqual('\\\\n\\\\r\\\\t', RegExp.escape('\\n\\r\\t'));
|
||||
this.assertEqual('\n\r\t', RegExp.escape('\n\r\t'));
|
||||
this.assertEqual('\\{5,2\\}', RegExp.escape('{5,2}'));
|
||||
|
||||
assertEqual(
|
||||
this.assertEqual(
|
||||
'\\/\\(\\[\\.\\*\\+\\?\\^\\=\\!\\:\\$\\{\\}\\(\\)\\|\\[\\\\\\]\\\\\\\/\\\\\\\\\\]\\)\\/g',
|
||||
RegExp.escape('/([.*+?^=!:${}()|[\\]\\/\\\\])/g')
|
||||
);
|
||||
}},
|
||||
},
|
||||
|
||||
testBrowserDetection: function() {with(this) {
|
||||
testBrowserDetection: function() {
|
||||
var results = $H(Prototype.Browser).map(function(engine){
|
||||
return engine;
|
||||
}).partition(function(engine){
|
||||
|
@ -482,76 +482,76 @@
|
|||
});
|
||||
var trues = results[0], falses = results[1];
|
||||
|
||||
info('User agent string is: ' + navigator.userAgent);
|
||||
this.info('User agent string is: ' + navigator.userAgent);
|
||||
|
||||
assert(trues.size() == 0 || trues.size() == 1,
|
||||
this.assert(trues.size() == 0 || trues.size() == 1,
|
||||
'There should be only one or no browser detected.');
|
||||
|
||||
// we should have definite trues or falses here
|
||||
trues.each(function(result){
|
||||
assert(result[1] === true);
|
||||
});
|
||||
falses.each(function(result){
|
||||
assert(result[1] === false);
|
||||
});
|
||||
trues.each(function(result) {
|
||||
this.assert(result[1] === true);
|
||||
}, this);
|
||||
falses.each(function(result) {
|
||||
this.assert(result[1] === false);
|
||||
}, this);
|
||||
|
||||
if(navigator.userAgent.indexOf('AppleWebKit/') > -1) {
|
||||
info('Running on WebKit');
|
||||
assert(Prototype.Browser.WebKit);
|
||||
this.info('Running on WebKit');
|
||||
this.assert(Prototype.Browser.WebKit);
|
||||
}
|
||||
|
||||
if(!!window.opera) {
|
||||
info('Running on Opera');
|
||||
assert(Prototype.Browser.Opera);
|
||||
this.info('Running on Opera');
|
||||
this.assert(Prototype.Browser.Opera);
|
||||
}
|
||||
|
||||
if(!!(window.attachEvent && !window.opera)) {
|
||||
info('Running on IE');
|
||||
assert(Prototype.Browser.IE);
|
||||
this.info('Running on IE');
|
||||
this.assert(Prototype.Browser.IE);
|
||||
}
|
||||
|
||||
if(navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1) {
|
||||
info('Running on Gecko');
|
||||
assert(Prototype.Browser.Gecko);
|
||||
this.info('Running on Gecko');
|
||||
this.assert(Prototype.Browser.Gecko);
|
||||
}
|
||||
}},
|
||||
},
|
||||
|
||||
testClassCreate: function() { with(this) {
|
||||
assert(Object.isFunction(Animal), 'Animal is not a constructor');
|
||||
assertEnumEqual([Cat, Mouse, Dog, Ox], Animal.subclasses);
|
||||
testClassCreate: function() {
|
||||
this.assert(Object.isFunction(Animal), 'Animal is not a constructor');
|
||||
this.assertEnumEqual([Cat, Mouse, Dog, Ox], Animal.subclasses);
|
||||
Animal.subclasses.each(function(subclass) {
|
||||
assertEqual(Animal, subclass.superclass);
|
||||
});
|
||||
this.assertEqual(Animal, subclass.superclass);
|
||||
}, this);
|
||||
|
||||
var Bird = Class.create(Animal);
|
||||
assertEqual(Bird, Animal.subclasses.last());
|
||||
this.assertEqual(Bird, Animal.subclasses.last());
|
||||
// for..in loop (for some reason) doesn't iterate over the constructor property in top-level classes
|
||||
assertEnumEqual(Object.keys(new Animal).sort(), Object.keys(new Bird).without('constructor').sort());
|
||||
}},
|
||||
this.assertEnumEqual(Object.keys(new Animal).sort(), Object.keys(new Bird).without('constructor').sort());
|
||||
},
|
||||
|
||||
testClassInstantiation: function() { with(this) {
|
||||
testClassInstantiation: function() {
|
||||
var pet = new Animal("Nibbles");
|
||||
assertEqual("Nibbles", pet.name, "property not initialized");
|
||||
assertEqual('Nibbles: Hi!', pet.say('Hi!'));
|
||||
assertEqual(Animal, pet.constructor, "bad constructor reference");
|
||||
assertUndefined(pet.superclass);
|
||||
this.assertEqual("Nibbles", pet.name, "property not initialized");
|
||||
this.assertEqual('Nibbles: Hi!', pet.say('Hi!'));
|
||||
this.assertEqual(Animal, pet.constructor, "bad constructor reference");
|
||||
this.assertUndefined(pet.superclass);
|
||||
|
||||
var Empty = Class.create();
|
||||
assert('object', typeof new Empty);
|
||||
}},
|
||||
this.assert('object', typeof new Empty);
|
||||
},
|
||||
|
||||
testInheritance: function() { with(this) {
|
||||
testInheritance: function() {
|
||||
var tom = new Cat('Tom');
|
||||
assertEqual(Cat, tom.constructor, "bad constructor reference");
|
||||
assertEqual(Animal, tom.constructor.superclass, 'bad superclass reference');
|
||||
assertEqual('Tom', tom.name);
|
||||
assertEqual('Tom: meow', tom.say('meow'));
|
||||
assertEqual('Tom: Yuk! I only eat mice.', tom.eat(new Animal));
|
||||
}},
|
||||
this.assertEqual(Cat, tom.constructor, "bad constructor reference");
|
||||
this.assertEqual(Animal, tom.constructor.superclass, 'bad superclass reference');
|
||||
this.assertEqual('Tom', tom.name);
|
||||
this.assertEqual('Tom: meow', tom.say('meow'));
|
||||
this.assertEqual('Tom: Yuk! I only eat mice.', tom.eat(new Animal));
|
||||
},
|
||||
|
||||
testSuperclassMethodCall: function() { with(this) {
|
||||
testSuperclassMethodCall: function() {
|
||||
var tom = new Cat('Tom');
|
||||
assertEqual('Tom: Yum!', tom.eat(new Mouse));
|
||||
this.assertEqual('Tom: Yum!', tom.eat(new Mouse));
|
||||
|
||||
// augment the constructor and test
|
||||
var Dodo = Class.create(Animal, {
|
||||
|
@ -566,12 +566,12 @@
|
|||
});
|
||||
|
||||
var gonzo = new Dodo('Gonzo');
|
||||
assertEqual('Gonzo', gonzo.name);
|
||||
assert(gonzo.extinct, 'Dodo birds should be extinct');
|
||||
assertEqual("Gonzo: hello honk honk", gonzo.say("hello"));
|
||||
}},
|
||||
this.assertEqual('Gonzo', gonzo.name);
|
||||
this.assert(gonzo.extinct, 'Dodo birds should be extinct');
|
||||
this.assertEqual("Gonzo: hello honk honk", gonzo.say("hello"));
|
||||
},
|
||||
|
||||
testClassAddMethods: function() { with(this) {
|
||||
testClassAddMethods: function() {
|
||||
var tom = new Cat('Tom');
|
||||
var jerry = new Mouse('Jerry');
|
||||
|
||||
|
@ -590,12 +590,12 @@
|
|||
}
|
||||
});
|
||||
|
||||
assertEqual('Tom: ZZZ', tom.sleep(), "added instance method not available to subclass");
|
||||
assertEqual("Jerry: ZZZ ... no, can't sleep! Gotta steal cheese!", jerry.sleep());
|
||||
assertEqual("Jerry: (from a mousehole) Take that, Tom!", jerry.escape(tom));
|
||||
this.assertEqual('Tom: ZZZ', tom.sleep(), "added instance method not available to subclass");
|
||||
this.assertEqual("Jerry: ZZZ ... no, can't sleep! Gotta steal cheese!", jerry.sleep());
|
||||
this.assertEqual("Jerry: (from a mousehole) Take that, Tom!", jerry.escape(tom));
|
||||
// insure that a method has not propagated *up* the prototype chain:
|
||||
assertUndefined(tom.escape);
|
||||
assertUndefined(new Animal().escape);
|
||||
this.assertUndefined(tom.escape);
|
||||
this.assertUndefined(new Animal().escape);
|
||||
|
||||
Animal.addMethods({
|
||||
sleep: function() {
|
||||
|
@ -603,42 +603,36 @@
|
|||
}
|
||||
});
|
||||
|
||||
assertEqual("Jerry: zZzZ ... no, can't sleep! Gotta steal cheese!", jerry.sleep());
|
||||
}},
|
||||
this.assertEqual("Jerry: zZzZ ... no, can't sleep! Gotta steal cheese!", jerry.sleep());
|
||||
},
|
||||
|
||||
testBaseClassWithMixin: function() { with(this) {
|
||||
testBaseClassWithMixin: function() {
|
||||
var grass = new Plant('grass', 3);
|
||||
assertRespondsTo('getValue', grass);
|
||||
assertEqual('#<Plant: grass>', grass.inspect());
|
||||
}},
|
||||
this.assertRespondsTo('getValue', grass);
|
||||
this.assertEqual('#<Plant: grass>', grass.inspect());
|
||||
},
|
||||
|
||||
testSubclassWithMixin: function() { with(this) {
|
||||
testSubclassWithMixin: function() {
|
||||
var snoopy = new Dog('Snoopy', 12, 'male');
|
||||
assertRespondsTo('reproduce', snoopy);
|
||||
}},
|
||||
this.assertRespondsTo('reproduce', snoopy);
|
||||
},
|
||||
|
||||
testSubclassWithMixins: function() { with(this) {
|
||||
testSubclassWithMixins: function() {
|
||||
var cow = new Ox('cow', 400, 'female');
|
||||
assertEqual('#<Ox: cow>', cow.inspect());
|
||||
assertRespondsTo('reproduce', cow);
|
||||
assertRespondsTo('getValue', cow);
|
||||
}},
|
||||
this.assertEqual('#<Ox: cow>', cow.inspect());
|
||||
this.assertRespondsTo('reproduce', cow);
|
||||
this.assertRespondsTo('getValue', cow);
|
||||
},
|
||||
|
||||
testClassWithToStringAndValueOfMethods: function() { with(this) {
|
||||
var Foo = Class.create({
|
||||
toString: function() {
|
||||
return "toString";
|
||||
},
|
||||
|
||||
valueOf: function() {
|
||||
return "valueOf";
|
||||
}
|
||||
});
|
||||
|
||||
assertEqual("toString", new Foo().toString());
|
||||
assertEqual("valueOf", new Foo().valueOf());
|
||||
}}
|
||||
|
||||
testClassWithToStringAndValueOfMethods: function() {
|
||||
var Foo = Class.create({
|
||||
toString: function() { return "toString" },
|
||||
valueOf: function() { return "valueOf" }
|
||||
});
|
||||
|
||||
this.assertEqual("toString", new Foo().toString());
|
||||
this.assertEqual("valueOf", new Foo().valueOf());
|
||||
}
|
||||
});
|
||||
|
||||
// ]]>
|
||||
|
|
1354
test/unit/dom.html
1354
test/unit/dom.html
File diff suppressed because it is too large
Load Diff
|
@ -36,36 +36,36 @@ Form.Element.Methods.coffee = Prototype.K;
|
|||
Element.addMethods();
|
||||
|
||||
new Test.Unit.Runner({
|
||||
testInput: function() {with(this) {
|
||||
assert($("input").present != null);
|
||||
assert(typeof $("input").present == 'function');
|
||||
assert($("input").select != null);
|
||||
assertRespondsTo('present', Form.Element);
|
||||
assertRespondsTo('present', Form.Element.Methods);
|
||||
assertRespondsTo('coffee', $('input'));
|
||||
assertIdentical(Prototype.K, Form.Element.coffee);
|
||||
assertIdentical(Prototype.K, Form.Element.Methods.coffee);
|
||||
}},
|
||||
testInput: function() {
|
||||
this.assert($("input").present != null);
|
||||
this.assert(typeof $("input").present == 'function');
|
||||
this.assert($("input").select != null);
|
||||
this.assertRespondsTo('present', Form.Element);
|
||||
this.assertRespondsTo('present', Form.Element.Methods);
|
||||
this.assertRespondsTo('coffee', $('input'));
|
||||
this.assertIdentical(Prototype.K, Form.Element.coffee);
|
||||
this.assertIdentical(Prototype.K, Form.Element.Methods.coffee);
|
||||
},
|
||||
|
||||
testForm: function() {with(this) {
|
||||
assert($("form").reset != null);
|
||||
assert($("form").getInputs().length == 2);
|
||||
}},
|
||||
testForm: function() {
|
||||
this.assert($("form").reset != null);
|
||||
this.assert($("form").getInputs().length == 2);
|
||||
},
|
||||
|
||||
testEvent: function() {with(this) {
|
||||
assert($("form").observe != null)
|
||||
testEvent: function() {
|
||||
this.assert($("form").observe != null)
|
||||
// Can't really test this one with TestUnit...
|
||||
$('form').observe("submit", function(e) {
|
||||
alert("yeah!");
|
||||
Event.stop(e);
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testCollections: function() {with(this) {
|
||||
assert($$("input").all(function(input) {
|
||||
testCollections: function() {
|
||||
this.assert($$("input").all(function(input) {
|
||||
return (input.focus != null);
|
||||
}));
|
||||
}}
|
||||
}
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
|
|
|
@ -66,261 +66,261 @@
|
|||
}
|
||||
|
||||
new Test.Unit.Runner({
|
||||
testEachBreak: function() {with(this) {
|
||||
testEachBreak: function() {
|
||||
var result = 0;
|
||||
Fixtures.Basic.each(function(value) {
|
||||
if ((result = value) == 2) throw $break;
|
||||
});
|
||||
|
||||
assertEqual(2, result);
|
||||
}},
|
||||
this.assertEqual(2, result);
|
||||
},
|
||||
|
||||
testEachReturnActsAsContinue: function() {with(this) {
|
||||
testEachReturnActsAsContinue: function() {
|
||||
var results = [];
|
||||
Fixtures.Basic.each(function(value) {
|
||||
if (value == 2) return;
|
||||
results.push(value);
|
||||
});
|
||||
|
||||
assertEqual('1, 3', results.join(', '));
|
||||
}},
|
||||
this.assertEqual('1, 3', results.join(', '));
|
||||
},
|
||||
|
||||
testEachChaining: function() {with(this) {
|
||||
assertEqual(Fixtures.Primes, Fixtures.Primes.each(Prototype.emptyFunction));
|
||||
assertEqual(3, Fixtures.Basic.each(Prototype.emptyFunction).length);
|
||||
}},
|
||||
testEachChaining: function() {
|
||||
this.assertEqual(Fixtures.Primes, Fixtures.Primes.each(Prototype.emptyFunction));
|
||||
this.assertEqual(3, Fixtures.Basic.each(Prototype.emptyFunction).length);
|
||||
},
|
||||
|
||||
testEnumContext: function() {with(this) {
|
||||
testEnumContext: function() {
|
||||
var results = [];
|
||||
Fixtures.Basic.each(function(value) {
|
||||
results.push(value * this.i);
|
||||
}, { i: 2 });
|
||||
|
||||
assertEqual('2 4 6', results.join(' '));
|
||||
this.assertEqual('2 4 6', results.join(' '));
|
||||
|
||||
assert(Fixtures.Basic.all(function(value){
|
||||
this.assert(Fixtures.Basic.all(function(value){
|
||||
return value >= this.min && value <= this.max;
|
||||
}, { min: 1, max: 3 }));
|
||||
assert(!Fixtures.Basic.all(function(value){
|
||||
this.assert(!Fixtures.Basic.all(function(value){
|
||||
return value >= this.min && value <= this.max;
|
||||
}));
|
||||
assert(Fixtures.Basic.any(function(value){
|
||||
this.assert(Fixtures.Basic.any(function(value){
|
||||
return value == this.target_value;
|
||||
}, { target_value: 2 }));
|
||||
}},
|
||||
},
|
||||
|
||||
testAny: function() {with(this) {
|
||||
assert(!([].any()));
|
||||
testAny: function() {
|
||||
this.assert(!([].any()));
|
||||
|
||||
assert([true, true, true].any());
|
||||
assert([true, false, false].any());
|
||||
assert(![false, false, false].any());
|
||||
this.assert([true, true, true].any());
|
||||
this.assert([true, false, false].any());
|
||||
this.assert(![false, false, false].any());
|
||||
|
||||
assert(Fixtures.Basic.any(function(value) {
|
||||
this.assert(Fixtures.Basic.any(function(value) {
|
||||
return value > 2;
|
||||
}));
|
||||
assert(!Fixtures.Basic.any(function(value) {
|
||||
this.assert(!Fixtures.Basic.any(function(value) {
|
||||
return value > 5;
|
||||
}));
|
||||
}},
|
||||
},
|
||||
|
||||
testAll: function() {with(this) {
|
||||
assert([].all());
|
||||
testAll: function() {
|
||||
this.assert([].all());
|
||||
|
||||
assert([true, true, true].all());
|
||||
assert(![true, false, false].all());
|
||||
assert(![false, false, false].all());
|
||||
this.assert([true, true, true].all());
|
||||
this.assert(![true, false, false].all());
|
||||
this.assert(![false, false, false].all());
|
||||
|
||||
assert(Fixtures.Basic.all(function(value) {
|
||||
this.assert(Fixtures.Basic.all(function(value) {
|
||||
return value > 0;
|
||||
}));
|
||||
assert(!Fixtures.Basic.all(function(value) {
|
||||
this.assert(!Fixtures.Basic.all(function(value) {
|
||||
return value > 1;
|
||||
}));
|
||||
}},
|
||||
},
|
||||
|
||||
testCollect: function() {with(this) {
|
||||
assertEqual(Fixtures.Nicknames.join(', '),
|
||||
testCollect: function() {
|
||||
this.assertEqual(Fixtures.Nicknames.join(', '),
|
||||
Fixtures.People.collect(function(person) {
|
||||
return person.nickname;
|
||||
}).join(", "));
|
||||
|
||||
assertEqual(26, Fixtures.Primes.map().length);
|
||||
}},
|
||||
this.assertEqual(26, Fixtures.Primes.map().length);
|
||||
},
|
||||
|
||||
testDetect: function() {with(this) {
|
||||
assertEqual('Marcel Molina Jr.',
|
||||
testDetect: function() {
|
||||
this.assertEqual('Marcel Molina Jr.',
|
||||
Fixtures.People.detect(function(person) {
|
||||
return person.nickname.match(/no/);
|
||||
}).name);
|
||||
}},
|
||||
},
|
||||
|
||||
testEachSlice: function() {with(this) {
|
||||
assertEnumEqual([], [].eachSlice(2));
|
||||
assertEqual(1, [1].eachSlice(1).length);
|
||||
assertEnumEqual([1], [1].eachSlice(1)[0]);
|
||||
assertEqual(2, Fixtures.Basic.eachSlice(2).length);
|
||||
assertEnumEqual(
|
||||
testEachSlice: function() {
|
||||
this.assertEnumEqual([], [].eachSlice(2));
|
||||
this.assertEqual(1, [1].eachSlice(1).length);
|
||||
this.assertEnumEqual([1], [1].eachSlice(1)[0]);
|
||||
this.assertEqual(2, Fixtures.Basic.eachSlice(2).length);
|
||||
this.assertEnumEqual(
|
||||
[3, 2, 1, 11, 7, 5, 19, 17, 13, 31, 29, 23, 43, 41, 37, 59, 53, 47, 71, 67, 61, 83, 79, 73, 97, 89],
|
||||
Fixtures.Primes.eachSlice( 3, function(slice){ return slice.reverse() }).flatten()
|
||||
);
|
||||
assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(-10));
|
||||
assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(0));
|
||||
assertNotIdentical(Fixtures.Basic, Fixtures.Basic.eachSlice(0));
|
||||
}},
|
||||
this.assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(-10));
|
||||
this.assertEnumEqual(Fixtures.Basic, Fixtures.Basic.eachSlice(0));
|
||||
this.assertNotIdentical(Fixtures.Basic, Fixtures.Basic.eachSlice(0));
|
||||
},
|
||||
|
||||
testEachWithIndex: function() {with(this) {
|
||||
testEachWithIndex: function() {
|
||||
var nicknames = [], indexes = [];
|
||||
Fixtures.People.each(function(person, index) {
|
||||
nicknames.push(person.nickname);
|
||||
indexes.push(index);
|
||||
});
|
||||
|
||||
assertEqual(Fixtures.Nicknames.join(', '),
|
||||
this.assertEqual(Fixtures.Nicknames.join(', '),
|
||||
nicknames.join(', '));
|
||||
assertEqual('0, 1, 2, 3', indexes.join(', '));
|
||||
}},
|
||||
this.assertEqual('0, 1, 2, 3', indexes.join(', '));
|
||||
},
|
||||
|
||||
testFindAll: function() {with(this) {
|
||||
assertEqual(Fixtures.Primes.join(', '),
|
||||
testFindAll: function() {
|
||||
this.assertEqual(Fixtures.Primes.join(', '),
|
||||
Fixtures.Z.findAll(prime).join(', '));
|
||||
}},
|
||||
},
|
||||
|
||||
testGrep: function() {with(this) {
|
||||
assertEqual('noradio, htonl',
|
||||
testGrep: function() {
|
||||
this.assertEqual('noradio, htonl',
|
||||
Fixtures.Nicknames.grep(/o/).join(", "));
|
||||
|
||||
assertEqual('NORADIO, HTONL',
|
||||
this.assertEqual('NORADIO, HTONL',
|
||||
Fixtures.Nicknames.grep(/o/, function(nickname) {
|
||||
return nickname.toUpperCase();
|
||||
}).join(", "))
|
||||
|
||||
assertEnumEqual($('grepHeader', 'grepCell'),
|
||||
this.assertEnumEqual($('grepHeader', 'grepCell'),
|
||||
$('grepTable', 'grepTBody', 'grepRow', 'grepHeader', 'grepCell').grep(new Selector('.cell')));
|
||||
}},
|
||||
},
|
||||
|
||||
testInclude: function() {with(this) {
|
||||
assert(Fixtures.Nicknames.include('sam-'));
|
||||
assert(Fixtures.Nicknames.include('noradio'));
|
||||
assert(!Fixtures.Nicknames.include('gmosx'));
|
||||
assert(Fixtures.Basic.include(2));
|
||||
assert(Fixtures.Basic.include('2'));
|
||||
assert(!Fixtures.Basic.include('4'));
|
||||
}},
|
||||
testInclude: function() {
|
||||
this.assert(Fixtures.Nicknames.include('sam-'));
|
||||
this.assert(Fixtures.Nicknames.include('noradio'));
|
||||
this.assert(!Fixtures.Nicknames.include('gmosx'));
|
||||
this.assert(Fixtures.Basic.include(2));
|
||||
this.assert(Fixtures.Basic.include('2'));
|
||||
this.assert(!Fixtures.Basic.include('4'));
|
||||
},
|
||||
|
||||
testInGroupsOf: function() { with(this) {
|
||||
assertEnumEqual([], [].inGroupsOf(3));
|
||||
testInGroupsOf: function() {
|
||||
this.assertEnumEqual([], [].inGroupsOf(3));
|
||||
|
||||
var arr = [1, 2, 3, 4, 5, 6].inGroupsOf(3);
|
||||
assertEqual(2, arr.length);
|
||||
assertEnumEqual([1, 2, 3], arr[0]);
|
||||
assertEnumEqual([4, 5, 6], arr[1]);
|
||||
this.assertEqual(2, arr.length);
|
||||
this.assertEnumEqual([1, 2, 3], arr[0]);
|
||||
this.assertEnumEqual([4, 5, 6], arr[1]);
|
||||
|
||||
arr = [1, 2, 3, 4, 5, 6].inGroupsOf(4);
|
||||
assertEqual(2, arr.length);
|
||||
assertEnumEqual([1, 2, 3, 4], arr[0]);
|
||||
assertEnumEqual([5, 6, null, null], arr[1]);
|
||||
this.assertEqual(2, arr.length);
|
||||
this.assertEnumEqual([1, 2, 3, 4], arr[0]);
|
||||
this.assertEnumEqual([5, 6, null, null], arr[1]);
|
||||
|
||||
var basic = Fixtures.Basic
|
||||
|
||||
arr = basic.inGroupsOf(4,'x');
|
||||
assertEqual(1, arr.length);
|
||||
assertEnumEqual([1, 2, 3, 'x'], arr[0]);
|
||||
this.assertEqual(1, arr.length);
|
||||
this.assertEnumEqual([1, 2, 3, 'x'], arr[0]);
|
||||
|
||||
assertEnumEqual([1,2,3,'a'], basic.inGroupsOf(2, 'a').flatten());
|
||||
this.assertEnumEqual([1,2,3,'a'], basic.inGroupsOf(2, 'a').flatten());
|
||||
|
||||
arr = basic.inGroupsOf(5, '');
|
||||
assertEqual(1, arr.length);
|
||||
assertEnumEqual([1, 2, 3, '', ''], arr[0]);
|
||||
this.assertEqual(1, arr.length);
|
||||
this.assertEnumEqual([1, 2, 3, '', ''], arr[0]);
|
||||
|
||||
assertEnumEqual([1,2,3,0], basic.inGroupsOf(2, 0).flatten());
|
||||
assertEnumEqual([1,2,3,false], basic.inGroupsOf(2, false).flatten());
|
||||
}},
|
||||
this.assertEnumEqual([1,2,3,0], basic.inGroupsOf(2, 0).flatten());
|
||||
this.assertEnumEqual([1,2,3,false], basic.inGroupsOf(2, false).flatten());
|
||||
},
|
||||
|
||||
testInject: function() {with(this) {
|
||||
assertEqual(1061,
|
||||
testInject: function() {
|
||||
this.assertEqual(1061,
|
||||
Fixtures.Primes.inject(0, function(sum, value) {
|
||||
return sum + value;
|
||||
}));
|
||||
}},
|
||||
},
|
||||
|
||||
testInvoke: function() {with(this) {
|
||||
testInvoke: function() {
|
||||
var result = [[2, 1, 3], [6, 5, 4]].invoke('sort');
|
||||
assertEqual(2, result.length);
|
||||
assertEqual('1, 2, 3', result[0].join(', '));
|
||||
assertEqual('4, 5, 6', result[1].join(', '));
|
||||
this.assertEqual(2, result.length);
|
||||
this.assertEqual('1, 2, 3', result[0].join(', '));
|
||||
this.assertEqual('4, 5, 6', result[1].join(', '));
|
||||
|
||||
result = result.invoke('invoke', 'toString', 2);
|
||||
assertEqual('1, 10, 11', result[0].join(', '));
|
||||
assertEqual('100, 101, 110', result[1].join(', '));
|
||||
}},
|
||||
this.assertEqual('1, 10, 11', result[0].join(', '));
|
||||
this.assertEqual('100, 101, 110', result[1].join(', '));
|
||||
},
|
||||
|
||||
testMax: function() {with(this) {
|
||||
assertEqual(100, Fixtures.Z.max());
|
||||
assertEqual(97, Fixtures.Primes.max());
|
||||
assertEqual(2, [ -9, -8, -7, -6, -4, -3, -2, 0, -1, 2 ].max());
|
||||
assertEqual('sam-', Fixtures.Nicknames.max()); // ?s > ?U
|
||||
}},
|
||||
testMax: function() {
|
||||
this.assertEqual(100, Fixtures.Z.max());
|
||||
this.assertEqual(97, Fixtures.Primes.max());
|
||||
this.assertEqual(2, [ -9, -8, -7, -6, -4, -3, -2, 0, -1, 2 ].max());
|
||||
this.assertEqual('sam-', Fixtures.Nicknames.max()); // ?s > ?U
|
||||
},
|
||||
|
||||
testMin: function() {with(this) {
|
||||
assertEqual(1, Fixtures.Z.min());
|
||||
assertEqual(0, [ 1, 2, 3, 4, 5, 6, 7, 8, 0, 9 ].min());
|
||||
assertEqual('Ulysses', Fixtures.Nicknames.min()); // ?U < ?h
|
||||
}},
|
||||
testMin: function() {
|
||||
this.assertEqual(1, Fixtures.Z.min());
|
||||
this.assertEqual(0, [ 1, 2, 3, 4, 5, 6, 7, 8, 0, 9 ].min());
|
||||
this.assertEqual('Ulysses', Fixtures.Nicknames.min()); // ?U < ?h
|
||||
},
|
||||
|
||||
testPartition: function() {with(this) {
|
||||
testPartition: function() {
|
||||
var result = Fixtures.People.partition(function(person) {
|
||||
return person.name.length < 15;
|
||||
}).invoke('pluck', 'nickname');
|
||||
|
||||
assertEqual(2, result.length);
|
||||
assertEqual('sam-, htonl', result[0].join(', '));
|
||||
assertEqual('noradio, Ulysses', result[1].join(', '));
|
||||
}},
|
||||
this.assertEqual(2, result.length);
|
||||
this.assertEqual('sam-, htonl', result[0].join(', '));
|
||||
this.assertEqual('noradio, Ulysses', result[1].join(', '));
|
||||
},
|
||||
|
||||
testPluck: function() {with(this) {
|
||||
assertEqual(Fixtures.Nicknames.join(', '),
|
||||
testPluck: function() {
|
||||
this.assertEqual(Fixtures.Nicknames.join(', '),
|
||||
Fixtures.People.pluck('nickname').join(', '));
|
||||
}},
|
||||
},
|
||||
|
||||
testReject: function() {with(this) {
|
||||
assertEqual(0,
|
||||
testReject: function() {
|
||||
this.assertEqual(0,
|
||||
Fixtures.Nicknames.reject(Prototype.K).length);
|
||||
|
||||
assertEqual('sam-, noradio, htonl',
|
||||
this.assertEqual('sam-, noradio, htonl',
|
||||
Fixtures.Nicknames.reject(function(nickname) {
|
||||
return nickname != nickname.toLowerCase();
|
||||
}).join(', '));
|
||||
}},
|
||||
},
|
||||
|
||||
testSortBy: function() {with(this) {
|
||||
assertEqual('htonl, noradio, sam-, Ulysses',
|
||||
testSortBy: function() {
|
||||
this.assertEqual('htonl, noradio, sam-, Ulysses',
|
||||
Fixtures.People.sortBy(function(value) {
|
||||
return value.nickname.toLowerCase();
|
||||
}).pluck('nickname').join(', '));
|
||||
}},
|
||||
},
|
||||
|
||||
testToArray: function() {with(this) {
|
||||
testToArray: function() {
|
||||
var result = Fixtures.People.toArray();
|
||||
assert(result != Fixtures.People); // they're different objects...
|
||||
assertEqual(Fixtures.Nicknames.join(', '),
|
||||
this.assert(result != Fixtures.People); // they're different objects...
|
||||
this.assertEqual(Fixtures.Nicknames.join(', '),
|
||||
result.pluck('nickname').join(', ')); // but the values are the same
|
||||
}},
|
||||
},
|
||||
|
||||
testZip: function() {with(this) {
|
||||
testZip: function() {
|
||||
var result = [1, 2, 3].zip([4, 5, 6], [7, 8, 9]);
|
||||
assertEqual('[[1, 4, 7], [2, 5, 8], [3, 6, 9]]', result.inspect());
|
||||
this.assertEqual('[[1, 4, 7], [2, 5, 8], [3, 6, 9]]', result.inspect());
|
||||
|
||||
result = [1, 2, 3].zip([4, 5, 6], [7, 8, 9], function(array) { return array.reverse() });
|
||||
assertEqual('[[7, 4, 1], [8, 5, 2], [9, 6, 3]]', result.inspect());
|
||||
}},
|
||||
this.assertEqual('[[7, 4, 1], [8, 5, 2], [9, 6, 3]]', result.inspect());
|
||||
},
|
||||
|
||||
testSize: function() {with(this) {
|
||||
assertEqual(4, Fixtures.People.size());
|
||||
assertEqual(4, Fixtures.Nicknames.size());
|
||||
assertEqual(26, Fixtures.Primes.size());
|
||||
assertEqual(0, [].size());
|
||||
}}
|
||||
testSize: function() {
|
||||
this.assertEqual(4, Fixtures.People.size());
|
||||
this.assertEqual(4, Fixtures.Nicknames.size());
|
||||
this.assertEqual(26, Fixtures.Primes.size());
|
||||
this.assertEqual(0, [].size());
|
||||
}
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
|
|
|
@ -37,47 +37,47 @@
|
|||
new Test.Unit.Runner({
|
||||
|
||||
// test firing an event and observing it on the element it's fired from
|
||||
testCustomEventFiring: function() { with(this) {
|
||||
testCustomEventFiring: function() {
|
||||
var span = $("span"), fired = false, observer = function(event) {
|
||||
assertEqual(span, event.element());
|
||||
assertEqual(1, event.memo.index);
|
||||
this.assertEqual(span, event.element());
|
||||
this.assertEqual(1, event.memo.index);
|
||||
fired = true;
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
span.observe("test:somethingHappened", observer);
|
||||
span.fire("test:somethingHappened", { index: 1 });
|
||||
assert(fired);
|
||||
this.assert(fired);
|
||||
|
||||
fired = false;
|
||||
span.fire("test:somethingElseHappened");
|
||||
assert(!fired);
|
||||
this.assert(!fired);
|
||||
|
||||
span.stopObserving("test:somethingHappened", observer);
|
||||
span.fire("test:somethingHappened");
|
||||
assert(!fired);
|
||||
}},
|
||||
this.assert(!fired);
|
||||
},
|
||||
|
||||
// test firing an event and observing it on a containing element
|
||||
testCustomEventBubbling: function() { with(this) {
|
||||
testCustomEventBubbling: function() {
|
||||
var span = $("span"), outer = $("outer"), fired = false, observer = function(event) {
|
||||
assertEqual(span, event.element());
|
||||
this.assertEqual(span, event.element());
|
||||
fired = true;
|
||||
};
|
||||
}.bind(this);
|
||||
|
||||
outer.observe("test:somethingHappened", observer);
|
||||
span.fire("test:somethingHappened");
|
||||
assert(fired);
|
||||
this.assert(fired);
|
||||
|
||||
fired = false;
|
||||
span.fire("test:somethingElseHappened");
|
||||
assert(!fired);
|
||||
this.assert(!fired);
|
||||
|
||||
outer.stopObserving("test:somethingHappened", observer);
|
||||
span.fire("test:somethingHappened");
|
||||
assert(!fired);
|
||||
}},
|
||||
this.assert(!fired);
|
||||
},
|
||||
|
||||
testCustomEventCanceling: function() { with(this) {
|
||||
testCustomEventCanceling: function() {
|
||||
var span = $("span"), outer = $("outer"), inner = $("inner");
|
||||
var fired = false, stopped = false;
|
||||
|
||||
|
@ -93,161 +93,161 @@
|
|||
inner.observe("test:somethingHappened", innerObserver);
|
||||
outer.observe("test:somethingHappened", outerObserver);
|
||||
span.fire("test:somethingHappened");
|
||||
assert(stopped);
|
||||
assert(!fired);
|
||||
this.assert(stopped);
|
||||
this.assert(!fired);
|
||||
|
||||
fired = stopped = false;
|
||||
inner.stopObserving("test:somethingHappened", innerObserver);
|
||||
span.fire("test:somethingHappened");
|
||||
assert(!stopped);
|
||||
assert(fired);
|
||||
this.assert(!stopped);
|
||||
this.assert(fired);
|
||||
|
||||
outer.stopObserving("test:somethingHappened", outerObserver);
|
||||
}},
|
||||
},
|
||||
|
||||
testEventObjectIsExtended: function() { with(this) {
|
||||
testEventObjectIsExtended: function() {
|
||||
var span = $("span"), event, observedEvent, observer = function(e) { observedEvent = e };
|
||||
span.observe("test:somethingHappened", observer);
|
||||
event = span.fire("test:somethingHappened");
|
||||
assertEqual(event, observedEvent);
|
||||
assertEqual(Event.Methods.stop.methodize(), event.stop);
|
||||
this.assertEqual(event, observedEvent);
|
||||
this.assertEqual(Event.Methods.stop.methodize(), event.stop);
|
||||
span.stopObserving("test:somethingHappened", observer);
|
||||
|
||||
event = span.fire("test:somethingHappenedButNoOneIsListening");
|
||||
assertEqual(Event.Methods.stop.methodize(), event.stop);
|
||||
}},
|
||||
this.assertEqual(Event.Methods.stop.methodize(), event.stop);
|
||||
},
|
||||
|
||||
testEventObserversAreBoundToTheObservedElement: function() { with(this) {
|
||||
testEventObserversAreBoundToTheObservedElement: function() {
|
||||
var span = $("span"), target, observer = function() { target = this };
|
||||
|
||||
span.observe("test:somethingHappened", observer);
|
||||
span.fire("test:somethingHappened");
|
||||
span.stopObserving("test:somethingHappened", observer);
|
||||
assertEqual(span, target);
|
||||
this.assertEqual(span, target);
|
||||
target = null;
|
||||
|
||||
var outer = $("outer");
|
||||
outer.observe("test:somethingHappened", observer);
|
||||
span.fire("test:somethingHappened");
|
||||
outer.stopObserving("test:somethingHappened", observer);
|
||||
assertEqual(outer, target);
|
||||
}},
|
||||
this.assertEqual(outer, target);
|
||||
},
|
||||
|
||||
testMultipleCustomEventObserversWithTheSameHandler: function() { with(this) {
|
||||
testMultipleCustomEventObserversWithTheSameHandler: function() {
|
||||
var span = $("span"), count = 0, observer = function() { count++ };
|
||||
|
||||
span.observe("test:somethingHappened", observer);
|
||||
span.observe("test:somethingElseHappened", observer);
|
||||
span.fire("test:somethingHappened");
|
||||
assertEqual(1, count);
|
||||
this.assertEqual(1, count);
|
||||
span.fire("test:somethingElseHappened");
|
||||
assertEqual(2, count);
|
||||
}},
|
||||
this.assertEqual(2, count);
|
||||
},
|
||||
|
||||
testStopObservingWithoutArguments: function() { with(this) {
|
||||
testStopObservingWithoutArguments: function() {
|
||||
var span = $("span"), count = 0, observer = function() { count++ };
|
||||
|
||||
span.observe("test:somethingHappened", observer);
|
||||
span.observe("test:somethingElseHappened", observer);
|
||||
span.stopObserving();
|
||||
span.fire("test:somethingHappened");
|
||||
assertEqual(0, count);
|
||||
this.assertEqual(0, count);
|
||||
span.fire("test:somethingElseHappened");
|
||||
assertEqual(0, count);
|
||||
}},
|
||||
this.assertEqual(0, count);
|
||||
},
|
||||
|
||||
testStopObservingWithoutHandlerArgument: function() { with(this) {
|
||||
testStopObservingWithoutHandlerArgument: function() {
|
||||
var span = $("span"), count = 0, observer = function() { count++ };
|
||||
|
||||
span.observe("test:somethingHappened", observer);
|
||||
span.observe("test:somethingElseHappened", observer);
|
||||
span.stopObserving("test:somethingHappened");
|
||||
span.fire("test:somethingHappened");
|
||||
assertEqual(0, count);
|
||||
this.assertEqual(0, count);
|
||||
span.fire("test:somethingElseHappened");
|
||||
assertEqual(1, count);
|
||||
this.assertEqual(1, count);
|
||||
span.stopObserving("test:somethingElseHappened");
|
||||
span.fire("test:somethingElseHappened");
|
||||
assertEqual(1, count);
|
||||
}},
|
||||
this.assertEqual(1, count);
|
||||
},
|
||||
|
||||
testStopObservingRemovesHandlerFromCache: function() { with(this) {
|
||||
testStopObservingRemovesHandlerFromCache: function() {
|
||||
var span = $("span"), observer = function() { }, eventID;
|
||||
|
||||
span.observe("test:somethingHappened", observer);
|
||||
eventID = span._prototypeEventID;
|
||||
|
||||
assert(Event.cache[eventID]);
|
||||
assert(Object.isArray(Event.cache[eventID]["test:somethingHappened"]));
|
||||
assertEqual(1, Event.cache[eventID]["test:somethingHappened"].length);
|
||||
this.assert(Event.cache[eventID]);
|
||||
this.assert(Object.isArray(Event.cache[eventID]["test:somethingHappened"]));
|
||||
this.assertEqual(1, Event.cache[eventID]["test:somethingHappened"].length);
|
||||
|
||||
span.stopObserving("test:somethingHappened", observer);
|
||||
assert(Event.cache[eventID]);
|
||||
assert(Object.isArray(Event.cache[eventID]["test:somethingHappened"]));
|
||||
assertEqual(0, Event.cache[eventID]["test:somethingHappened"].length);
|
||||
}},
|
||||
this.assert(Event.cache[eventID]);
|
||||
this.assert(Object.isArray(Event.cache[eventID]["test:somethingHappened"]));
|
||||
this.assertEqual(0, Event.cache[eventID]["test:somethingHappened"].length);
|
||||
},
|
||||
|
||||
testObserveAndStopObservingAreChainable: function() { with(this) {
|
||||
testObserveAndStopObservingAreChainable: function() {
|
||||
var span = $("span"), observer = function() { };
|
||||
|
||||
assertEqual(span, span.observe("test:somethingHappened", observer));
|
||||
assertEqual(span, span.stopObserving("test:somethingHappened", observer));
|
||||
this.assertEqual(span, span.observe("test:somethingHappened", observer));
|
||||
this.assertEqual(span, span.stopObserving("test:somethingHappened", observer));
|
||||
|
||||
span.observe("test:somethingHappened", observer);
|
||||
assertEqual(span, span.stopObserving("test:somethingHappened"));
|
||||
this.assertEqual(span, span.stopObserving("test:somethingHappened"));
|
||||
|
||||
span.observe("test:somethingHappened", observer);
|
||||
assertEqual(span, span.stopObserving());
|
||||
assertEqual(span, span.stopObserving()); // assert it again, after there are no observers
|
||||
this.assertEqual(span, span.stopObserving());
|
||||
this.assertEqual(span, span.stopObserving()); // assert it again, after there are no observers
|
||||
|
||||
span.observe("test:somethingHappened", observer);
|
||||
assertEqual(span, span.observe("test:somethingHappened", observer)); // try to reuse the same observer
|
||||
this.assertEqual(span, span.observe("test:somethingHappened", observer)); // try to reuse the same observer
|
||||
span.stopObserving();
|
||||
}},
|
||||
},
|
||||
|
||||
testDocumentLoaded: function() { with(this) {
|
||||
assert(!documentLoaded);
|
||||
assert(document.loaded);
|
||||
}},
|
||||
testDocumentLoaded: function() {
|
||||
this.assert(!documentLoaded);
|
||||
this.assert(document.loaded);
|
||||
},
|
||||
|
||||
testDocumentContentLoadedEventFiresBeforeWindowLoad: function() { with(this) {
|
||||
assert(eventResults.contentLoaded, "contentLoaded");
|
||||
assert(eventResults.contentLoaded.endOfDocument, "contentLoaded.endOfDocument");
|
||||
assert(!eventResults.contentLoaded.windowLoad, "!contentLoaded.windowLoad");
|
||||
assert(eventResults.windowLoad, "windowLoad");
|
||||
assert(eventResults.windowLoad.endOfDocument, "windowLoad.endOfDocument");
|
||||
assert(eventResults.windowLoad.contentLoaded, "windowLoad.contentLoaded");
|
||||
}},
|
||||
testDocumentContentLoadedEventFiresBeforeWindowLoad: function() {
|
||||
this.assert(eventResults.contentLoaded, "contentLoaded");
|
||||
this.assert(eventResults.contentLoaded.endOfDocument, "contentLoaded.endOfDocument");
|
||||
this.assert(!eventResults.contentLoaded.windowLoad, "!contentLoaded.windowLoad");
|
||||
this.assert(eventResults.windowLoad, "windowLoad");
|
||||
this.assert(eventResults.windowLoad.endOfDocument, "windowLoad.endOfDocument");
|
||||
this.assert(eventResults.windowLoad.contentLoaded, "windowLoad.contentLoaded");
|
||||
},
|
||||
|
||||
testEventStopped: function() { with(this) {
|
||||
testEventStopped: function() {
|
||||
var span = $("span"), event;
|
||||
|
||||
span.observe("test:somethingHappened", function() { });
|
||||
event = span.fire("test:somethingHappened");
|
||||
assert(!event.stopped, "event.stopped should be false with an empty observer");
|
||||
this.assert(!event.stopped, "event.stopped should be false with an empty observer");
|
||||
span.stopObserving("test:somethingHappened");
|
||||
|
||||
span.observe("test:somethingHappened", function(e) { e.stop() });
|
||||
event = span.fire("test:somethingHappened");
|
||||
assert(event.stopped, "event.stopped should be true for an observer that calls stop");
|
||||
this.assert(event.stopped, "event.stopped should be true for an observer that calls stop");
|
||||
span.stopObserving("test:somethingHappened");
|
||||
}},
|
||||
},
|
||||
|
||||
testEventFindElement: function() { with(this) {
|
||||
testEventFindElement: function() {
|
||||
var span = $("span"), event;
|
||||
event = span.fire("test:somethingHappened");
|
||||
assertElementMatches(event.findElement(), 'span#span');
|
||||
assertElementMatches(event.findElement('span'), 'span#span');
|
||||
assertElementMatches(event.findElement('p'), 'p#inner');
|
||||
assertEqual(null, event.findElement('div.does_not_exist'));
|
||||
assertElementMatches(event.findElement('.does_not_exist, span'), 'span#span');
|
||||
}},
|
||||
this.assertElementMatches(event.findElement(), 'span#span');
|
||||
this.assertElementMatches(event.findElement('span'), 'span#span');
|
||||
this.assertElementMatches(event.findElement('p'), 'p#inner');
|
||||
this.assertEqual(null, event.findElement('div.does_not_exist'));
|
||||
this.assertElementMatches(event.findElement('.does_not_exist, span'), 'span#span');
|
||||
},
|
||||
|
||||
testEventIDDuplication: function() { with(this) {
|
||||
testEventIDDuplication: function() {
|
||||
$('container').down().observe("test:somethingHappened", Prototype.emptyFunction);
|
||||
$('container').innerHTML += $('container').innerHTML;
|
||||
assertUndefined($('container').down(1)._prototypeEventID);
|
||||
}}
|
||||
this.assertUndefined($('container').down(1)._prototypeEventID);
|
||||
}
|
||||
});
|
||||
|
||||
document.observe("dom:loaded", function(event) {
|
||||
|
|
|
@ -149,29 +149,29 @@
|
|||
|
||||
// Make sure to set defaults in the test forms, as some browsers override this
|
||||
// with previously entered values on page reload
|
||||
setup: function(){ with(this) {
|
||||
setup: function(){
|
||||
$$('form').each(function(f){ f.reset() });
|
||||
// hidden value does not reset (for some reason)
|
||||
$('bigform')['tf_hidden'].value = '';
|
||||
}},
|
||||
},
|
||||
|
||||
testDollarF: function(){ with(this) {
|
||||
assertEqual("4", $F("input_enabled"));
|
||||
}},
|
||||
testDollarF: function(){
|
||||
this.assertEqual("4", $F("input_enabled"));
|
||||
},
|
||||
|
||||
testFormElementEventObserver: function(){ with(this) {
|
||||
testFormElementEventObserver: function(){
|
||||
var callbackCounter = 0;
|
||||
var observer = new Form.Element.EventObserver('input_enabled', function(){
|
||||
callbackCounter++;
|
||||
});
|
||||
|
||||
assertEqual(0, callbackCounter);
|
||||
this.assertEqual(0, callbackCounter);
|
||||
$('input_enabled').value = 'boo!';
|
||||
observer.onElementEvent(); // can't test the event directly, simulating
|
||||
assertEqual(1, callbackCounter);
|
||||
}},
|
||||
this.assertEqual(1, callbackCounter);
|
||||
},
|
||||
|
||||
testFormElementObserver: function(){ with(this) {
|
||||
testFormElementObserver: function(){
|
||||
var timedCounter = 0;
|
||||
// First part: regular field
|
||||
var observer = new Form.Element.Observer('input_enabled', 0.5, function() {
|
||||
|
@ -179,18 +179,18 @@
|
|||
});
|
||||
|
||||
// Test it's unchanged yet
|
||||
assertEqual(0, timedCounter);
|
||||
this.assertEqual(0, timedCounter);
|
||||
// Test it doesn't change on first check
|
||||
wait(550, function() {
|
||||
assertEqual(0, timedCounter);
|
||||
this.wait(550, function() {
|
||||
this.assertEqual(0, timedCounter);
|
||||
// Change, test it doesn't immediately change
|
||||
$('input_enabled').value = 'yowza!';
|
||||
assertEqual(0, timedCounter);
|
||||
this.assertEqual(0, timedCounter);
|
||||
// Test it changes on next check, but not again on the next
|
||||
wait(550, function() {
|
||||
assertEqual(1, timedCounter);
|
||||
wait(550, function() {
|
||||
assertEqual(1, timedCounter);
|
||||
this.wait(550, function() {
|
||||
this.assertEqual(1, timedCounter);
|
||||
this.wait(550, function() {
|
||||
this.assertEqual(1, timedCounter);
|
||||
observer.stop();
|
||||
});
|
||||
});
|
||||
|
@ -206,27 +206,27 @@
|
|||
});
|
||||
|
||||
// Test it's unchanged yet
|
||||
assertEqual(0, timedCounter);
|
||||
this.assertEqual(0, timedCounter);
|
||||
// Test it doesn't change on first check
|
||||
wait(550, function() {
|
||||
assertEqual(0, timedCounter);
|
||||
this.wait(550, function() {
|
||||
this.assertEqual(0, timedCounter);
|
||||
// Change, test it doesn't immediately change
|
||||
// NOTE: it is important that the 3rd be re-selected, for the
|
||||
// serialize form to obtain the expected value :-)
|
||||
$('multiSel1_opt3').selected = true;
|
||||
assertEqual(0, timedCounter);
|
||||
this.assertEqual(0, timedCounter);
|
||||
// Test it changes on next check, but not again on the next
|
||||
wait(550, function() {
|
||||
assertEqual(1, timedCounter);
|
||||
wait(550, function() {
|
||||
assertEqual(1, timedCounter);
|
||||
this.wait(550, function() {
|
||||
this.assertEqual(1, timedCounter);
|
||||
this.wait(550, function() {
|
||||
this.assertEqual(1, timedCounter);
|
||||
observer.stop();
|
||||
});
|
||||
});
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testFormObserver: function(){ with(this) {
|
||||
testFormObserver: function(){
|
||||
var timedCounter = 0;
|
||||
// should work the same way was Form.Element.Observer
|
||||
var observer = new Form.Observer('form', 0.5, function(form, value) {
|
||||
|
@ -234,69 +234,69 @@
|
|||
});
|
||||
|
||||
// Test it's unchanged yet
|
||||
assertEqual(0, timedCounter);
|
||||
this.assertEqual(0, timedCounter);
|
||||
// Test it doesn't change on first check
|
||||
wait(550, function() {
|
||||
assertEqual(0, timedCounter);
|
||||
this.wait(550, function() {
|
||||
this.assertEqual(0, timedCounter);
|
||||
// Change, test it doesn't immediately change
|
||||
$('input_enabled').value = 'yowza!';
|
||||
assertEqual(0, timedCounter);
|
||||
this.assertEqual(0, timedCounter);
|
||||
// Test it changes on next check, but not again on the next
|
||||
wait(550, function() {
|
||||
assertEqual(1, timedCounter);
|
||||
wait(550, function() {
|
||||
assertEqual(1, timedCounter);
|
||||
this.wait(550, function() {
|
||||
this.assertEqual(1, timedCounter);
|
||||
this.wait(550, function() {
|
||||
this.assertEqual(1, timedCounter);
|
||||
observer.stop();
|
||||
});
|
||||
});
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testFormEnabling: function(){ with(this) {
|
||||
testFormEnabling: function(){
|
||||
var form = $('bigform')
|
||||
var input1 = $('dummy_disabled');
|
||||
var input2 = $('focus_text');
|
||||
|
||||
assertDisabled(input1);
|
||||
assertEnabled(input2);
|
||||
this.assertDisabled(input1);
|
||||
this.assertEnabled(input2);
|
||||
|
||||
form.disable();
|
||||
assertDisabled(input1, input2);
|
||||
this.assertDisabled(input1, input2);
|
||||
form.enable();
|
||||
assertEnabled(input1, input2);
|
||||
this.assertEnabled(input1, input2);
|
||||
input1.disable();
|
||||
assertDisabled(input1);
|
||||
this.assertDisabled(input1);
|
||||
|
||||
// non-form elements:
|
||||
var fieldset = $('selects_fieldset');
|
||||
var fields = fieldset.immediateDescendants();
|
||||
fields.each(function(select) { assertEnabled(select) });
|
||||
fields.each(function(select) { this.assertEnabled(select) }, this);
|
||||
|
||||
Form.disable(fieldset)
|
||||
fields.each(function(select) { assertDisabled(select) });
|
||||
fields.each(function(select) { this.assertDisabled(select) }, this);
|
||||
|
||||
Form.enable(fieldset)
|
||||
fields.each(function(select) { assertEnabled(select) });
|
||||
}},
|
||||
fields.each(function(select) { this.assertEnabled(select) }, this);
|
||||
},
|
||||
|
||||
testFormElementEnabling: function(){ with(this) {
|
||||
testFormElementEnabling: function(){
|
||||
var field = $('input_disabled');
|
||||
field.enable();
|
||||
assertEnabled(field);
|
||||
this.assertEnabled(field);
|
||||
field.disable();
|
||||
assertDisabled(field);
|
||||
this.assertDisabled(field);
|
||||
|
||||
var field = $('input_enabled');
|
||||
assertEnabled(field);
|
||||
this.assertEnabled(field);
|
||||
field.disable();
|
||||
assertDisabled(field);
|
||||
this.assertDisabled(field);
|
||||
field.enable();
|
||||
assertEnabled(field);
|
||||
}},
|
||||
this.assertEnabled(field);
|
||||
},
|
||||
|
||||
// due to the lack of a DOM hasFocus() API method,
|
||||
// we're simulating things here a little bit
|
||||
testFormActivating: function(){ with(this) {
|
||||
testFormActivating: function(){
|
||||
// Firefox, IE, and Safari 2+
|
||||
function getSelection(element){
|
||||
try {
|
||||
|
@ -311,52 +311,52 @@
|
|||
|
||||
// Form.focusFirstElement shouldn't focus disabled elements
|
||||
var element = Form.findFirstElement('bigform');
|
||||
assertEqual('submit', element.id);
|
||||
this.assertEqual('submit', element.id);
|
||||
|
||||
// Test IE doesn't select text on buttons
|
||||
Form.focusFirstElement('bigform');
|
||||
if(document.selection) assertEqual('', getSelection(element));
|
||||
if(document.selection) this.assertEqual('', getSelection(element));
|
||||
|
||||
// Form.Element.activate shouldn't select text on buttons
|
||||
element = $('focus_text');
|
||||
assertEqual('', getSelection(element));
|
||||
this.assertEqual('', getSelection(element));
|
||||
|
||||
// Form.Element.activate should select text on text input elements
|
||||
element.activate();
|
||||
assertEqual('Hello', getSelection(element));
|
||||
this.assertEqual('Hello', getSelection(element));
|
||||
|
||||
// Form.Element.activate shouldn't raise an exception when the form or field is hidden
|
||||
assertNothingRaised(function() {
|
||||
this.assertNothingRaised(function() {
|
||||
$('form_focus_hidden').focusFirstElement();
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testFormGetElements: function() {with(this) {
|
||||
testFormGetElements: function() {
|
||||
var elements = Form.getElements('various'),
|
||||
names = $w('tf_selectOne tf_textarea tf_checkbox tf_selectMany tf_text tf_radio tf_hidden tf_password');
|
||||
assertEnumEqual(names, elements.pluck('name'))
|
||||
}},
|
||||
this.assertEnumEqual(names, elements.pluck('name'))
|
||||
},
|
||||
|
||||
testFormGetInputs: function() {with(this){
|
||||
testFormGetInputs: function() {
|
||||
var form = $('form');
|
||||
[form.getInputs(), Form.getInputs(form)].each(function(inputs){
|
||||
assertEqual(inputs.length, 5);
|
||||
assert(inputs instanceof Array);
|
||||
assert(inputs.all(function(input) { return (input.tagName == "INPUT"); }));
|
||||
});
|
||||
}},
|
||||
this.assertEqual(inputs.length, 5);
|
||||
this.assert(inputs instanceof Array);
|
||||
this.assert(inputs.all(function(input) { return (input.tagName == "INPUT"); }));
|
||||
}, this);
|
||||
},
|
||||
|
||||
testFormFindFirstElement: function() {with(this) {
|
||||
assertEqual($('ffe_checkbox'), $('ffe').findFirstElement());
|
||||
assertEqual($('ffe_ti_submit'), $('ffe_ti').findFirstElement());
|
||||
assertEqual($('ffe_ti2_checkbox'), $('ffe_ti2').findFirstElement());
|
||||
}},
|
||||
testFormFindFirstElement: function() {
|
||||
this.assertEqual($('ffe_checkbox'), $('ffe').findFirstElement());
|
||||
this.assertEqual($('ffe_ti_submit'), $('ffe_ti').findFirstElement());
|
||||
this.assertEqual($('ffe_ti2_checkbox'), $('ffe_ti2').findFirstElement());
|
||||
},
|
||||
|
||||
testFormSerialize: function() {with(this){
|
||||
testFormSerialize: function() {
|
||||
// form is initially empty
|
||||
var form = $('bigform');
|
||||
var expected = { tf_selectOne:'', tf_textarea:'', tf_text:'', tf_hidden:'', tf_password:'' };
|
||||
assertHashEqual(expected, Form.serialize('various', true));
|
||||
this.assertHashEqual(expected, Form.serialize('various', true));
|
||||
|
||||
// set up some stuff
|
||||
form['tf_selectOne'].selectedIndex = 1;
|
||||
|
@ -370,48 +370,48 @@
|
|||
tf_hidden:"moo%hoo&test", tf_password:'sekrit code', tf_checkbox:'on', tf_radio:'on' }
|
||||
|
||||
// return params
|
||||
assertHashEqual(expected, Form.serialize('various', true));
|
||||
this.assertHashEqual(expected, Form.serialize('various', true));
|
||||
// return string
|
||||
assertEnumEqual(Object.toQueryString(expected).split('&').sort(),
|
||||
this.assertEnumEqual(Object.toQueryString(expected).split('&').sort(),
|
||||
Form.serialize('various').split('&').sort());
|
||||
assertEqual('string', typeof $('form').serialize({ hash:false }));
|
||||
this.assertEqual('string', typeof $('form').serialize({ hash:false }));
|
||||
|
||||
// Checks that disabled element is not included in serialized form.
|
||||
$('input_enabled').enable();
|
||||
assertHashEqual({ val1:4, action:'blah', first_submit:'Commit it!' },
|
||||
this.assertHashEqual({ val1:4, action:'blah', first_submit:'Commit it!' },
|
||||
$('form').serialize(true));
|
||||
|
||||
// should not eat empty values for duplicate names
|
||||
$('checkbox_hack').checked = false;
|
||||
var data = Form.serialize('value_checks', true);
|
||||
assertEnumEqual(['', 'siamese'], data['twin']);
|
||||
assertEqual('0', data['checky']);
|
||||
this.assertEnumEqual(['', 'siamese'], data['twin']);
|
||||
this.assertEqual('0', data['checky']);
|
||||
|
||||
$('checkbox_hack').checked = true;
|
||||
assertEnumEqual($w('1 0'), Form.serialize('value_checks', true)['checky']);
|
||||
this.assertEnumEqual($w('1 0'), Form.serialize('value_checks', true)['checky']);
|
||||
|
||||
// all kinds of SELECT controls
|
||||
var params = Form.serialize('selects_fieldset', true);
|
||||
var expected = { 'nvm[]':['One', 'Three'], evu:'', 'evm[]':['', 'Three'] };
|
||||
assertHashEqual(expected, params);
|
||||
this.assertHashEqual(expected, params);
|
||||
params = Form.serialize('selects_wrapper', true);
|
||||
assertHashEqual(Object.extend(expected, { vu:1, 'vm[]':[1, 3], nvu:'One' }), params);
|
||||
this.assertHashEqual(Object.extend(expected, { vu:1, 'vm[]':[1, 3], nvu:'One' }), params);
|
||||
|
||||
// explicit submit button
|
||||
assertHashEqual({ val1:4, action:'blah', second_submit:'Delete it!' },
|
||||
this.assertHashEqual({ val1:4, action:'blah', second_submit:'Delete it!' },
|
||||
$('form').serialize({ submit: 'second_submit' }));
|
||||
assertHashEqual({ val1:4, action:'blah' },
|
||||
this.assertHashEqual({ val1:4, action:'blah' },
|
||||
$('form').serialize({ submit: false }));
|
||||
assertHashEqual({ val1:4, action:'blah' },
|
||||
this.assertHashEqual({ val1:4, action:'blah' },
|
||||
$('form').serialize({ submit: 'inexistent' }));
|
||||
|
||||
}},
|
||||
},
|
||||
|
||||
testFormMethodsOnExtendedElements: function() {with(this) {
|
||||
testFormMethodsOnExtendedElements: function() {
|
||||
var form = $('form');
|
||||
assertEqual(Form.serialize('form'), form.serialize());
|
||||
assertEqual(Form.Element.serialize('input_enabled'), $('input_enabled').serialize());
|
||||
assertNotEqual(form.serialize, $('input_enabled').serialize);
|
||||
this.assertEqual(Form.serialize('form'), form.serialize());
|
||||
this.assertEqual(Form.Element.serialize('input_enabled'), $('input_enabled').serialize());
|
||||
this.assertNotEqual(form.serialize, $('input_enabled').serialize);
|
||||
|
||||
Element.addMethods('INPUT', { anInputMethod: function(input) { return 'input' } });
|
||||
Element.addMethods('SELECT', { aSelectMethod: function(select) { return 'select' } });
|
||||
|
@ -420,74 +420,73 @@
|
|||
var input = form['tf_text'], select = form['tf_selectOne'];
|
||||
input._extendedByPrototype = select._extendedByPrototype = false;
|
||||
|
||||
assert($(input).anInputMethod);
|
||||
assert(!input.aSelectMethod);
|
||||
assertEqual('input', input.anInputMethod());
|
||||
this.assert($(input).anInputMethod);
|
||||
this.assert(!input.aSelectMethod);
|
||||
this.assertEqual('input', input.anInputMethod());
|
||||
|
||||
assert($(select).aSelectMethod);
|
||||
assert(!select.anInputMethod);
|
||||
assertEqual('select', select.aSelectMethod());
|
||||
}},
|
||||
this.assert($(select).aSelectMethod);
|
||||
this.assert(!select.anInputMethod);
|
||||
this.assertEqual('select', select.aSelectMethod());
|
||||
},
|
||||
|
||||
testFormRequest: function() {with(this) {
|
||||
testFormRequest: function() {
|
||||
request = $("form").request();
|
||||
assert($("form").hasAttribute("method"));
|
||||
assert(request.url.include("fixtures/empty.js?val1=4"));
|
||||
assertEqual("get", request.method);
|
||||
this.assert($("form").hasAttribute("method"));
|
||||
this.assert(request.url.include("fixtures/empty.js?val1=4"));
|
||||
this.assertEqual("get", request.method);
|
||||
|
||||
request = $("form").request({ method: "put", parameters: {val2: "hello"} });
|
||||
assert(request.url.endsWith("fixtures/empty.js"));
|
||||
assertEqual(4, request.options.parameters['val1']);
|
||||
assertEqual('hello', request.options.parameters['val2']);
|
||||
assertEqual("post", request.method);
|
||||
assertEqual("put", request.parameters['_method']);
|
||||
this.assert(request.url.endsWith("fixtures/empty.js"));
|
||||
this.assertEqual(4, request.options.parameters['val1']);
|
||||
this.assertEqual('hello', request.options.parameters['val2']);
|
||||
this.assertEqual("post", request.method);
|
||||
this.assertEqual("put", request.parameters['_method']);
|
||||
|
||||
// with empty action attribute
|
||||
request = $("ffe").request({ method: 'post' });
|
||||
assert(request.url.include("unit/form.html"),
|
||||
this.assert(request.url.include("unit/form.html"),
|
||||
'wrong default action for form element with empty action attribute');
|
||||
}},
|
||||
},
|
||||
|
||||
testFormElementMethodsChaining: function(){ with(this) {
|
||||
testFormElementMethodsChaining: function(){
|
||||
var methods = $w('clear activate disable enable'),
|
||||
formElements = $('form').getElements();
|
||||
methods.each(function(method){
|
||||
formElements.each(function(element){
|
||||
var returned = element[method]();
|
||||
assertIdentical(element, returned);
|
||||
});
|
||||
});
|
||||
}},
|
||||
this.assertIdentical(element, returned);
|
||||
}, this);
|
||||
}, this);
|
||||
},
|
||||
|
||||
testSetValue: function(){ with(this) {
|
||||
testSetValue: function(){
|
||||
// text input
|
||||
var input = $('input_enabled'), oldValue = input.getValue();
|
||||
assertEqual(input, input.setValue('foo'), 'setValue chaining is broken');
|
||||
assertEqual('foo', input.getValue(), 'value improperly set');
|
||||
this.assertEqual(input, input.setValue('foo'), 'setValue chaining is broken');
|
||||
this.assertEqual('foo', input.getValue(), 'value improperly set');
|
||||
input.setValue(oldValue);
|
||||
assertEqual(oldValue, input.getValue(), 'value improperly restored to original');
|
||||
this.assertEqual(oldValue, input.getValue(), 'value improperly restored to original');
|
||||
|
||||
// checkbox
|
||||
input = $('checkbox_hack');
|
||||
input.setValue(false);
|
||||
assertEqual(null, input.getValue(), 'checkbox should be unchecked');
|
||||
this.assertEqual(null, input.getValue(), 'checkbox should be unchecked');
|
||||
input.setValue(true);
|
||||
assertEqual("1", input.getValue(), 'checkbox should be checked');
|
||||
this.assertEqual("1", input.getValue(), 'checkbox should be checked');
|
||||
// selectbox
|
||||
input = $('bigform')['vu'];
|
||||
input.setValue('3');
|
||||
assertEqual('3', input.getValue(), 'single select option improperly set');
|
||||
this.assertEqual('3', input.getValue(), 'single select option improperly set');
|
||||
input.setValue('1');
|
||||
assertEqual('1', input.getValue());
|
||||
this.assertEqual('1', input.getValue());
|
||||
// multiple select
|
||||
input = $('bigform')['vm[]'];
|
||||
input.setValue(['2', '3']);
|
||||
assertEnumEqual(['2', '3'], input.getValue(),
|
||||
this.assertEnumEqual(['2', '3'], input.getValue(),
|
||||
'multiple select options improperly set');
|
||||
input.setValue(['1', '3']);
|
||||
assertEnumEqual(['1', '3'], input.getValue());
|
||||
}}
|
||||
|
||||
this.assertEnumEqual(['1', '3'], input.getValue());
|
||||
}
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
|
|
|
@ -54,177 +54,177 @@
|
|||
};
|
||||
|
||||
new Test.Unit.Runner({
|
||||
testSet: function(){ with(this) {
|
||||
testSet: function() {
|
||||
var h = $H({a: 'A'})
|
||||
|
||||
assertEqual('B', h.set('b', 'B'));
|
||||
assertHashEqual({a: 'A', b: 'B'}, h);
|
||||
this.assertEqual('B', h.set('b', 'B'));
|
||||
this.assertHashEqual({a: 'A', b: 'B'}, h);
|
||||
|
||||
assertUndefined(h.set('c'));
|
||||
assertHashEqual({a: 'A', b: 'B', c: undefined}, h);
|
||||
}},
|
||||
this.assertUndefined(h.set('c'));
|
||||
this.assertHashEqual({a: 'A', b: 'B', c: undefined}, h);
|
||||
},
|
||||
|
||||
testGet: function(){ with(this) {
|
||||
testGet: function() {
|
||||
var h = $H({a: 'A'});
|
||||
assertEqual('A', h.get('a'));
|
||||
assertUndefined(h.a);
|
||||
assertUndefined($H({}).get('a'));
|
||||
}},
|
||||
this.assertEqual('A', h.get('a'));
|
||||
this.assertUndefined(h.a);
|
||||
this.assertUndefined($H({}).get('a'));
|
||||
},
|
||||
|
||||
testUnset: function(){ with(this) {
|
||||
testUnset: function() {
|
||||
var hash = $H(Fixtures.many);
|
||||
assertEqual('B', hash.unset('b'));
|
||||
assertHashEqual({a:'A', c: 'C', d:'D#'}, hash);
|
||||
assertUndefined(hash.unset('z'));
|
||||
assertHashEqual({a:'A', c: 'C', d:'D#'}, hash);
|
||||
this.assertEqual('B', hash.unset('b'));
|
||||
this.assertHashEqual({a:'A', c: 'C', d:'D#'}, hash);
|
||||
this.assertUndefined(hash.unset('z'));
|
||||
this.assertHashEqual({a:'A', c: 'C', d:'D#'}, hash);
|
||||
// not equivalent to Hash#remove
|
||||
assertEqual('A', hash.unset('a', 'c'));
|
||||
assertHashEqual({c: 'C', d:'D#'}, hash);
|
||||
}},
|
||||
this.assertEqual('A', hash.unset('a', 'c'));
|
||||
this.assertHashEqual({c: 'C', d:'D#'}, hash);
|
||||
},
|
||||
|
||||
testToObject: function(){ with(this) {
|
||||
testToObject: function() {
|
||||
var hash = $H(Fixtures.many), object = hash.toObject();
|
||||
assertInstanceOf(Object, object);
|
||||
assertHashEqual(Fixtures.many, object);
|
||||
assertNotIdentical(Fixtures.many, object);
|
||||
this.assertInstanceOf(Object, object);
|
||||
this.assertHashEqual(Fixtures.many, object);
|
||||
this.assertNotIdentical(Fixtures.many, object);
|
||||
hash.set('foo', 'bar');
|
||||
assertHashNotEqual(object, hash.toObject());
|
||||
}},
|
||||
this.assertHashNotEqual(object, hash.toObject());
|
||||
},
|
||||
|
||||
testConstruct: function(){ with(this) {
|
||||
testConstruct: function() {
|
||||
var object = Object.clone(Fixtures.one);
|
||||
var h = new Hash(object), h2 = $H(object);
|
||||
assertInstanceOf(Hash, h);
|
||||
assertInstanceOf(Hash, h2);
|
||||
this.assertInstanceOf(Hash, h);
|
||||
this.assertInstanceOf(Hash, h2);
|
||||
|
||||
assertHashEqual({}, new Hash());
|
||||
assertHashEqual(object, h);
|
||||
assertHashEqual(object, h2);
|
||||
this.assertHashEqual({}, new Hash());
|
||||
this.assertHashEqual(object, h);
|
||||
this.assertHashEqual(object, h2);
|
||||
|
||||
h.set('foo', 'bar');
|
||||
assertHashNotEqual(object, h);
|
||||
this.assertHashNotEqual(object, h);
|
||||
|
||||
var clone = $H(h);
|
||||
assertInstanceOf(Hash, clone);
|
||||
assertHashEqual(h, clone);
|
||||
this.assertInstanceOf(Hash, clone);
|
||||
this.assertHashEqual(h, clone);
|
||||
h.set('foo', 'foo');
|
||||
assertHashNotEqual(h, clone);
|
||||
assertIdentical($H, Hash.from);
|
||||
}},
|
||||
this.assertHashNotEqual(h, clone);
|
||||
this.assertIdentical($H, Hash.from);
|
||||
},
|
||||
|
||||
testKeys: function(){ with(this) {
|
||||
assertEnumEqual([], $H({}).keys());
|
||||
assertEnumEqual(['a'], $H(Fixtures.one).keys());
|
||||
assertEnumEqual($w('a b c d'), $H(Fixtures.many).keys().sort());
|
||||
assertEnumEqual($w('plus quad'), $H(Fixtures.functions).keys().sort());
|
||||
}},
|
||||
testKeys: function() {
|
||||
this.assertEnumEqual([], $H({}).keys());
|
||||
this.assertEnumEqual(['a'], $H(Fixtures.one).keys());
|
||||
this.assertEnumEqual($w('a b c d'), $H(Fixtures.many).keys().sort());
|
||||
this.assertEnumEqual($w('plus quad'), $H(Fixtures.functions).keys().sort());
|
||||
},
|
||||
|
||||
testValues: function(){ with(this) {
|
||||
assertEnumEqual([], $H({}).values());
|
||||
assertEnumEqual(['A#'], $H(Fixtures.one).values());
|
||||
assertEnumEqual($w('A B C D#'), $H(Fixtures.many).values().sort());
|
||||
assertEnumEqual($w('function function'),
|
||||
testValues: function() {
|
||||
this.assertEnumEqual([], $H({}).values());
|
||||
this.assertEnumEqual(['A#'], $H(Fixtures.one).values());
|
||||
this.assertEnumEqual($w('A B C D#'), $H(Fixtures.many).values().sort());
|
||||
this.assertEnumEqual($w('function function'),
|
||||
$H(Fixtures.functions).values().map(function(i){ return typeof i }));
|
||||
assertEqual(9, $H(Fixtures.functions).get('quad')(3));
|
||||
assertEqual(6, $H(Fixtures.functions).get('plus')(3));
|
||||
}},
|
||||
this.assertEqual(9, $H(Fixtures.functions).get('quad')(3));
|
||||
this.assertEqual(6, $H(Fixtures.functions).get('plus')(3));
|
||||
},
|
||||
|
||||
testIndex: function(){ with(this) {
|
||||
assertUndefined($H().index('foo'));
|
||||
testIndex: function() {
|
||||
this.assertUndefined($H().index('foo'));
|
||||
|
||||
assert('a', $H(Fixtures.one).index('A#'));
|
||||
assert('a', $H(Fixtures.many).index('A'));
|
||||
assertUndefined($H(Fixtures.many).index('Z'))
|
||||
this.assert('a', $H(Fixtures.one).index('A#'));
|
||||
this.assert('a', $H(Fixtures.many).index('A'));
|
||||
this.assertUndefined($H(Fixtures.many).index('Z'))
|
||||
|
||||
var hash = $H({a:1,b:'2',c:1});
|
||||
assert(['a','c'].include(hash.index(1)));
|
||||
assertUndefined(hash.index('1'));
|
||||
}},
|
||||
this.assert(['a','c'].include(hash.index(1)));
|
||||
this.assertUndefined(hash.index('1'));
|
||||
},
|
||||
|
||||
testMerge: function(){ with(this) {
|
||||
testMerge: function() {
|
||||
var h = $H(Fixtures.many);
|
||||
assertNotIdentical(h, h.merge());
|
||||
assertNotIdentical(h, h.merge({}));
|
||||
assertInstanceOf(Hash, h.merge());
|
||||
assertInstanceOf(Hash, h.merge({}));
|
||||
assertHashEqual(h, h.merge());
|
||||
assertHashEqual(h, h.merge({}));
|
||||
assertHashEqual(h, h.merge($H()));
|
||||
assertHashEqual({a:'A', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.merge({aaa: 'AAA'}));
|
||||
assertHashEqual({a:'A#', b:'B', c:'C', d:'D#' }, h.merge(Fixtures.one));
|
||||
}},
|
||||
this.assertNotIdentical(h, h.merge());
|
||||
this.assertNotIdentical(h, h.merge({}));
|
||||
this.assertInstanceOf(Hash, h.merge());
|
||||
this.assertInstanceOf(Hash, h.merge({}));
|
||||
this.assertHashEqual(h, h.merge());
|
||||
this.assertHashEqual(h, h.merge({}));
|
||||
this.assertHashEqual(h, h.merge($H()));
|
||||
this.assertHashEqual({a:'A', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.merge({aaa: 'AAA'}));
|
||||
this.assertHashEqual({a:'A#', b:'B', c:'C', d:'D#' }, h.merge(Fixtures.one));
|
||||
},
|
||||
|
||||
testUpdate: function(){ with(this) {
|
||||
testUpdate: function() {
|
||||
var h = $H(Fixtures.many);
|
||||
assertIdentical(h, h.update());
|
||||
assertIdentical(h, h.update({}));
|
||||
assertHashEqual(h, h.update());
|
||||
assertHashEqual(h, h.update({}));
|
||||
assertHashEqual(h, h.update($H()));
|
||||
assertHashEqual({a:'A', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.update({aaa: 'AAA'}));
|
||||
assertHashEqual({a:'A#', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.update(Fixtures.one));
|
||||
}},
|
||||
this.assertIdentical(h, h.update());
|
||||
this.assertIdentical(h, h.update({}));
|
||||
this.assertHashEqual(h, h.update());
|
||||
this.assertHashEqual(h, h.update({}));
|
||||
this.assertHashEqual(h, h.update($H()));
|
||||
this.assertHashEqual({a:'A', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.update({aaa: 'AAA'}));
|
||||
this.assertHashEqual({a:'A#', b:'B', c:'C', d:'D#', aaa:'AAA' }, h.update(Fixtures.one));
|
||||
},
|
||||
|
||||
testToQueryString: function(){ with(this) {
|
||||
assertEqual('', $H({}).toQueryString());
|
||||
assertEqual('a%23=A', $H({'a#': 'A'}).toQueryString());
|
||||
assertEqual('a=A%23', $H(Fixtures.one).toQueryString());
|
||||
assertEqual('a=A&b=B&c=C&d=D%23', $H(Fixtures.many).toQueryString());
|
||||
assertEqual("a=b&c", $H(Fixtures.value_undefined).toQueryString());
|
||||
assertEqual("a=b&c", $H("a=b&c".toQueryParams()).toQueryString());
|
||||
assertEqual("a=b&c=", $H(Fixtures.value_null).toQueryString());
|
||||
assertEqual("a=b&c=0", $H(Fixtures.value_zero).toQueryString());
|
||||
assertEqual("color=r&color=g&color=b", $H(Fixtures.multiple).toQueryString());
|
||||
assertEqual("color=r&color=&color=g&color&color=0", $H(Fixtures.multiple_nil).toQueryString());
|
||||
assertEqual("color=&color", $H(Fixtures.multiple_all_nil).toQueryString());
|
||||
assertEqual("", $H(Fixtures.multiple_empty).toQueryString());
|
||||
assertEqual("stuff%5B%5D=%24&stuff%5B%5D=a&stuff%5B%5D=%3B", $H(Fixtures.multiple_special).toQueryString());
|
||||
assertHashEqual(Fixtures.multiple_special, $H(Fixtures.multiple_special).toQueryString().toQueryParams());
|
||||
assertIdentical(Object.toQueryString, Hash.toQueryString);
|
||||
}},
|
||||
testToQueryString: function() {
|
||||
this.assertEqual('', $H({}).toQueryString());
|
||||
this.assertEqual('a%23=A', $H({'a#': 'A'}).toQueryString());
|
||||
this.assertEqual('a=A%23', $H(Fixtures.one).toQueryString());
|
||||
this.assertEqual('a=A&b=B&c=C&d=D%23', $H(Fixtures.many).toQueryString());
|
||||
this.assertEqual("a=b&c", $H(Fixtures.value_undefined).toQueryString());
|
||||
this.assertEqual("a=b&c", $H("a=b&c".toQueryParams()).toQueryString());
|
||||
this.assertEqual("a=b&c=", $H(Fixtures.value_null).toQueryString());
|
||||
this.assertEqual("a=b&c=0", $H(Fixtures.value_zero).toQueryString());
|
||||
this.assertEqual("color=r&color=g&color=b", $H(Fixtures.multiple).toQueryString());
|
||||
this.assertEqual("color=r&color=&color=g&color&color=0", $H(Fixtures.multiple_nil).toQueryString());
|
||||
this.assertEqual("color=&color", $H(Fixtures.multiple_all_nil).toQueryString());
|
||||
this.assertEqual("", $H(Fixtures.multiple_empty).toQueryString());
|
||||
this.assertEqual("stuff%5B%5D=%24&stuff%5B%5D=a&stuff%5B%5D=%3B", $H(Fixtures.multiple_special).toQueryString());
|
||||
this.assertHashEqual(Fixtures.multiple_special, $H(Fixtures.multiple_special).toQueryString().toQueryParams());
|
||||
this.assertIdentical(Object.toQueryString, Hash.toQueryString);
|
||||
},
|
||||
|
||||
testInspect: function(){ with(this) {
|
||||
assertEqual('#<Hash:{}>', $H({}).inspect());
|
||||
assertEqual("#<Hash:{'a': 'A#'}>", $H(Fixtures.one).inspect());
|
||||
assertEqual("#<Hash:{'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D#'}>", $H(Fixtures.many).inspect());
|
||||
}},
|
||||
testInspect: function() {
|
||||
this.assertEqual('#<Hash:{}>', $H({}).inspect());
|
||||
this.assertEqual("#<Hash:{'a': 'A#'}>", $H(Fixtures.one).inspect());
|
||||
this.assertEqual("#<Hash:{'a': 'A', 'b': 'B', 'c': 'C', 'd': 'D#'}>", $H(Fixtures.many).inspect());
|
||||
},
|
||||
|
||||
testClone: function(){ with(this) {
|
||||
testClone: function() {
|
||||
var h = $H(Fixtures.many);
|
||||
assertHashEqual(h, h.clone());
|
||||
assertInstanceOf(Hash, h.clone());
|
||||
assertNotIdentical(h, h.clone());
|
||||
}},
|
||||
this.assertHashEqual(h, h.clone());
|
||||
this.assertInstanceOf(Hash, h.clone());
|
||||
this.assertNotIdentical(h, h.clone());
|
||||
},
|
||||
|
||||
testToJSON: function(){ with(this) {
|
||||
assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}',
|
||||
testToJSON: function() {
|
||||
this.assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}',
|
||||
$H({'b': [undefined, false, true, undefined], c: {a: 'hello!'}}).toJSON());
|
||||
}},
|
||||
},
|
||||
|
||||
testAbilityToContainAnyKey: function(){ with(this) {
|
||||
testAbilityToContainAnyKey: function() {
|
||||
var h = $H({ _each: 'E', map: 'M', keys: 'K', pluck: 'P', unset: 'U' });
|
||||
assertEnumEqual($w('_each keys map pluck unset'), h.keys().sort());
|
||||
assertEqual('U', h.unset('unset'));
|
||||
assertHashEqual({ _each: 'E', map: 'M', keys: 'K', pluck: 'P' }, h);
|
||||
}},
|
||||
this.assertEnumEqual($w('_each keys map pluck unset'), h.keys().sort());
|
||||
this.assertEqual('U', h.unset('unset'));
|
||||
this.assertHashEqual({ _each: 'E', map: 'M', keys: 'K', pluck: 'P' }, h);
|
||||
},
|
||||
|
||||
testHashToTemplateReplacements: function() { with(this) {
|
||||
testHashToTemplateReplacements: function() {
|
||||
var template = new Template("#{a} #{b}"), hash = $H({ a: "hello", b: "world" });
|
||||
assertEqual("hello world", template.evaluate(hash.toObject()));
|
||||
assertEqual("hello world", template.evaluate(hash));
|
||||
assertEqual("hello", "#{a}".interpolate(hash));
|
||||
}},
|
||||
this.assertEqual("hello world", template.evaluate(hash.toObject()));
|
||||
this.assertEqual("hello world", template.evaluate(hash));
|
||||
this.assertEqual("hello", "#{a}".interpolate(hash));
|
||||
},
|
||||
|
||||
testPreventIterationOverShadowedProperties: function() { with(this) {
|
||||
testPreventIterationOverShadowedProperties: function() {
|
||||
// redundant now that object is systematically cloned.
|
||||
var FooMaker = function(value) {
|
||||
this.key = value;
|
||||
};
|
||||
FooMaker.prototype.key = 'foo';
|
||||
var foo = new FooMaker('bar');
|
||||
assertEqual("key=bar", new Hash(foo).toQueryString());
|
||||
assertEqual("key=bar", new Hash(new Hash(foo)).toQueryString());
|
||||
}}
|
||||
this.assertEqual("key=bar", new Hash(foo).toQueryString());
|
||||
this.assertEqual("key=bar", new Hash(new Hash(foo)).toQueryString());
|
||||
}
|
||||
|
||||
});
|
||||
// ]]>
|
||||
|
|
|
@ -29,37 +29,37 @@
|
|||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
testNumberMathMethods: function() {with(this) {
|
||||
assertEqual(1, (0.9).round());
|
||||
assertEqual(-2, (-1.9).floor());
|
||||
assertEqual(-1, (-1.9).ceil());
|
||||
testNumberMathMethods: function() {
|
||||
this.assertEqual(1, (0.9).round());
|
||||
this.assertEqual(-2, (-1.9).floor());
|
||||
this.assertEqual(-1, (-1.9).ceil());
|
||||
|
||||
$w('abs floor round ceil').each( function(method){
|
||||
assertEqual(Math[method](Math.PI), Math.PI[method]());
|
||||
});
|
||||
}},
|
||||
$w('abs floor round ceil').each(function(method) {
|
||||
this.assertEqual(Math[method](Math.PI), Math.PI[method]());
|
||||
}, this);
|
||||
},
|
||||
|
||||
testNumberToColorPart: function() {with(this) {
|
||||
assertEqual('00', (0).toColorPart());
|
||||
assertEqual('0a', (10).toColorPart());
|
||||
assertEqual('ff', (255).toColorPart());
|
||||
}},
|
||||
testNumberToColorPart: function() {
|
||||
this.assertEqual('00', (0).toColorPart());
|
||||
this.assertEqual('0a', (10).toColorPart());
|
||||
this.assertEqual('ff', (255).toColorPart());
|
||||
},
|
||||
|
||||
testNumberToPaddedString: function() {with(this) {
|
||||
assertEqual('00', (0).toPaddedString(2, 16));
|
||||
assertEqual('0a', (10).toPaddedString(2, 16));
|
||||
assertEqual('ff', (255).toPaddedString(2, 16));
|
||||
assertEqual('000', (0).toPaddedString(3));
|
||||
assertEqual('010', (10).toPaddedString(3));
|
||||
assertEqual('100', (100).toPaddedString(3));
|
||||
assertEqual('1000', (1000).toPaddedString(3));
|
||||
}},
|
||||
testNumberToPaddedString: function() {
|
||||
this.assertEqual('00', (0).toPaddedString(2, 16));
|
||||
this.assertEqual('0a', (10).toPaddedString(2, 16));
|
||||
this.assertEqual('ff', (255).toPaddedString(2, 16));
|
||||
this.assertEqual('000', (0).toPaddedString(3));
|
||||
this.assertEqual('010', (10).toPaddedString(3));
|
||||
this.assertEqual('100', (100).toPaddedString(3));
|
||||
this.assertEqual('1000', (1000).toPaddedString(3));
|
||||
},
|
||||
|
||||
testNumberToJSON: function() {with(this) {
|
||||
assertEqual('null', Number.NaN.toJSON());
|
||||
assertEqual('0', (0).toJSON());
|
||||
assertEqual('-293', (-293).toJSON());
|
||||
}}
|
||||
testNumberToJSON: function() {
|
||||
this.assertEqual('null', Number.NaN.toJSON());
|
||||
this.assertEqual('0', (0).toJSON());
|
||||
this.assertEqual('-293', (-293).toJSON());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -53,34 +53,33 @@
|
|||
Position.includeScrollOffsets = false;
|
||||
},
|
||||
|
||||
testPrepare: function() {with(this) {
|
||||
testPrepare: function() {
|
||||
Position.prepare();
|
||||
assertEqual(0, Position.deltaX);
|
||||
assertEqual(0, Position.deltaY);
|
||||
this.assertEqual(0, Position.deltaX);
|
||||
this.assertEqual(0, Position.deltaY);
|
||||
scrollTo(20,30);
|
||||
Position.prepare();
|
||||
assertEqual(20, Position.deltaX);
|
||||
assertEqual(30, Position.deltaY);
|
||||
}},
|
||||
this.assertEqual(20, Position.deltaX);
|
||||
this.assertEqual(30, Position.deltaY);
|
||||
},
|
||||
|
||||
testWithin: function() {with(this) {
|
||||
testWithin: function() {
|
||||
[true, false].each(function(withScrollOffsets) {
|
||||
Position.includeScrollOffsets = withScrollOffsets;
|
||||
assert(!Position.within($('body_absolute'), 9, 9), 'outside left/top');
|
||||
assert(Position.within($('body_absolute'), 10, 10), 'left/top corner');
|
||||
assert(Position.within($('body_absolute'), 10, 19), 'left/bottom corner');
|
||||
assert(!Position.within($('body_absolute'), 10, 20), 'outside bottom');
|
||||
});
|
||||
this.assert(!Position.within($('body_absolute'), 9, 9), 'outside left/top');
|
||||
this.assert(Position.within($('body_absolute'), 10, 10), 'left/top corner');
|
||||
this.assert(Position.within($('body_absolute'), 10, 19), 'left/bottom corner');
|
||||
this.assert(!Position.within($('body_absolute'), 10, 20), 'outside bottom');
|
||||
}, this);
|
||||
|
||||
scrollTo(20,30);
|
||||
Position.prepare();
|
||||
Position.includeScrollOffsets = true;
|
||||
assert(!Position.within($('body_absolute'), 9, 9), 'outside left/top');
|
||||
assert(Position.within($('body_absolute'), 10, 10), 'left/top corner');
|
||||
assert(Position.within($('body_absolute'), 10, 19), 'left/bottom corner');
|
||||
assert(!Position.within($('body_absolute'), 10, 20), 'outside bottom');
|
||||
}}
|
||||
|
||||
this.assert(!Position.within($('body_absolute'), 9, 9), 'outside left/top');
|
||||
this.assert(Position.within($('body_absolute'), 10, 10), 'left/top corner');
|
||||
this.assert(Position.within($('body_absolute'), 10, 19), 'left/bottom corner');
|
||||
this.assert(!Position.within($('body_absolute'), 10, 20), 'outside bottom');
|
||||
}
|
||||
});
|
||||
|
||||
// ]]>
|
||||
|
|
|
@ -28,64 +28,61 @@
|
|||
// <![CDATA[
|
||||
new Test.Unit.Runner({
|
||||
|
||||
testInclude: function() {with(this) {
|
||||
assert(!$R(0, 0, true).include(0));
|
||||
assert($R(0, 0, false).include(0));
|
||||
testInclude: function() {
|
||||
this.assert(!$R(0, 0, true).include(0));
|
||||
this.assert($R(0, 0, false).include(0));
|
||||
|
||||
assert($R(0, 5, true).include(0));
|
||||
assert($R(0, 5, true).include(4));
|
||||
assert(!$R(0, 5, true).include(5));
|
||||
this.assert($R(0, 5, true).include(0));
|
||||
this.assert($R(0, 5, true).include(4));
|
||||
this.assert(!$R(0, 5, true).include(5));
|
||||
|
||||
assert($R(0, 5, false).include(0));
|
||||
assert($R(0, 5, false).include(5));
|
||||
assert(!$R(0, 5, false).include(6));
|
||||
}},
|
||||
this.assert($R(0, 5, false).include(0));
|
||||
this.assert($R(0, 5, false).include(5));
|
||||
this.assert(!$R(0, 5, false).include(6));
|
||||
},
|
||||
|
||||
testEach: function() {with(this) {
|
||||
testEach: function() {
|
||||
var results = [];
|
||||
$R(0, 0, true).each(function(value) {
|
||||
results.push(value);
|
||||
});
|
||||
|
||||
assertEnumEqual([], results);
|
||||
this.assertEnumEqual([], results);
|
||||
|
||||
results = [];
|
||||
$R(0, 3, false).each(function(value) {
|
||||
results.push(value);
|
||||
});
|
||||
|
||||
assertEnumEqual([0, 1, 2, 3], results);
|
||||
}},
|
||||
this.assertEnumEqual([0, 1, 2, 3], results);
|
||||
},
|
||||
|
||||
testAny: function() {with(this) {
|
||||
assert(!$R(1, 1, true).any());
|
||||
assert($R(0, 3, false).any(function(value) {
|
||||
testAny: function() {
|
||||
this.assert(!$R(1, 1, true).any());
|
||||
this.assert($R(0, 3, false).any(function(value) {
|
||||
return value == 3;
|
||||
}));
|
||||
}},
|
||||
},
|
||||
|
||||
testAll: function() {with(this) {
|
||||
assert($R(1, 1, true).all());
|
||||
assert($R(0, 3, false).all(function(value) {
|
||||
testAll: function() {
|
||||
this.assert($R(1, 1, true).all());
|
||||
this.assert($R(0, 3, false).all(function(value) {
|
||||
return value <= 3;
|
||||
}));
|
||||
}},
|
||||
},
|
||||
|
||||
testToArray: function() {with(this) {
|
||||
assertEnumEqual([], $R(0, 0, true).toArray());
|
||||
assertEnumEqual([0], $R(0, 0, false).toArray());
|
||||
assertEnumEqual([0], $R(0, 1, true).toArray());
|
||||
assertEnumEqual([0, 1], $R(0, 1, false).toArray());
|
||||
assertEnumEqual([-3, -2, -1, 0, 1, 2], $R(-3, 3, true).toArray());
|
||||
assertEnumEqual([-3, -2, -1, 0, 1, 2, 3], $R(-3, 3, false).toArray());
|
||||
}},
|
||||
|
||||
testDefaultsToNotExclusive: function() {with(this) {
|
||||
assertEnumEqual(
|
||||
$R(-3,3), $R(-3,3,false)
|
||||
);
|
||||
}}
|
||||
testToArray: function() {
|
||||
this.assertEnumEqual([], $R(0, 0, true).toArray());
|
||||
this.assertEnumEqual([0], $R(0, 0, false).toArray());
|
||||
this.assertEnumEqual([0], $R(0, 1, true).toArray());
|
||||
this.assertEnumEqual([0, 1], $R(0, 1, false).toArray());
|
||||
this.assertEnumEqual([-3, -2, -1, 0, 1, 2], $R(-3, 3, true).toArray());
|
||||
this.assertEnumEqual([-3, -2, -1, 0, 1, 2, 3], $R(-3, 3, false).toArray());
|
||||
},
|
||||
|
||||
testDefaultsToNotExclusive: function() {
|
||||
this.assertEnumEqual($R(-3,3), $R(-3,3,false));
|
||||
}
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
|
|
|
@ -103,337 +103,337 @@
|
|||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
testSelectorWithTagName: function() {with(this) {
|
||||
assertEnumEqual($A(document.getElementsByTagName('li')), $$('li'));
|
||||
assertEnumEqual([$('strong')], $$('strong'));
|
||||
assertEnumEqual([], $$('nonexistent'));
|
||||
testSelectorWithTagName: function() {
|
||||
this.assertEnumEqual($A(document.getElementsByTagName('li')), $$('li'));
|
||||
this.assertEnumEqual([$('strong')], $$('strong'));
|
||||
this.assertEnumEqual([], $$('nonexistent'));
|
||||
|
||||
var allNodes = $A(document.getElementsByTagName('*')).select( function(node) {
|
||||
return node.tagName !== '!';
|
||||
});
|
||||
assertEnumEqual(allNodes, $$('*'));
|
||||
}},
|
||||
this.assertEnumEqual(allNodes, $$('*'));
|
||||
},
|
||||
|
||||
testSelectorWithId: function() {with(this) {
|
||||
assertEnumEqual([$('fixtures')], $$('#fixtures'));
|
||||
assertEnumEqual([], $$('#nonexistent'));
|
||||
assertEnumEqual([$('troubleForm')], $$('#troubleForm'));
|
||||
}},
|
||||
testSelectorWithId: function() {
|
||||
this.assertEnumEqual([$('fixtures')], $$('#fixtures'));
|
||||
this.assertEnumEqual([], $$('#nonexistent'));
|
||||
this.assertEnumEqual([$('troubleForm')], $$('#troubleForm'));
|
||||
},
|
||||
|
||||
testSelectorWithClassName: function() {with(this) {
|
||||
assertEnumEqual($('p', 'link_1', 'item_1'), $$('.first'));
|
||||
assertEnumEqual([], $$('.second'));
|
||||
}},
|
||||
testSelectorWithClassName: function() {
|
||||
this.assertEnumEqual($('p', 'link_1', 'item_1'), $$('.first'));
|
||||
this.assertEnumEqual([], $$('.second'));
|
||||
},
|
||||
|
||||
testSelectorWithTagNameAndId: function() {with(this) {
|
||||
assertEnumEqual([$('strong')], $$('strong#strong'));
|
||||
assertEnumEqual([], $$('p#strong'));
|
||||
}},
|
||||
testSelectorWithTagNameAndId: function() {
|
||||
this.assertEnumEqual([$('strong')], $$('strong#strong'));
|
||||
this.assertEnumEqual([], $$('p#strong'));
|
||||
},
|
||||
|
||||
testSelectorWithTagNameAndClassName: function() {with(this) {
|
||||
assertEnumEqual($('link_1', 'link_2'), $$('a.internal'));
|
||||
assertEnumEqual([$('link_2')], $$('a.internal.highlight'));
|
||||
assertEnumEqual([$('link_2')], $$('a.highlight.internal'));
|
||||
assertEnumEqual([], $$('a.highlight.internal.nonexistent'));
|
||||
}},
|
||||
testSelectorWithTagNameAndClassName: function() {
|
||||
this.assertEnumEqual($('link_1', 'link_2'), $$('a.internal'));
|
||||
this.assertEnumEqual([$('link_2')], $$('a.internal.highlight'));
|
||||
this.assertEnumEqual([$('link_2')], $$('a.highlight.internal'));
|
||||
this.assertEnumEqual([], $$('a.highlight.internal.nonexistent'));
|
||||
},
|
||||
|
||||
testSelectorWithIdAndClassName: function() {with(this) {
|
||||
assertEnumEqual([$('link_2')], $$('#link_2.internal'));
|
||||
assertEnumEqual([$('link_2')], $$('.internal#link_2'));
|
||||
assertEnumEqual([$('link_2')], $$('#link_2.internal.highlight'));
|
||||
assertEnumEqual([], $$('#link_2.internal.nonexistent'));
|
||||
}},
|
||||
testSelectorWithIdAndClassName: function() {
|
||||
this.assertEnumEqual([$('link_2')], $$('#link_2.internal'));
|
||||
this.assertEnumEqual([$('link_2')], $$('.internal#link_2'));
|
||||
this.assertEnumEqual([$('link_2')], $$('#link_2.internal.highlight'));
|
||||
this.assertEnumEqual([], $$('#link_2.internal.nonexistent'));
|
||||
},
|
||||
|
||||
testSelectorWithTagNameAndIdAndClassName: function() {with(this) {
|
||||
assertEnumEqual([$('link_2')], $$('a#link_2.internal'));
|
||||
assertEnumEqual([$('link_2')], $$('a.internal#link_2'));
|
||||
assertEnumEqual([$('item_1')], $$('li#item_1.first'));
|
||||
assertEnumEqual([], $$('li#item_1.nonexistent'));
|
||||
assertEnumEqual([], $$('li#item_1.first.nonexistent'));
|
||||
}},
|
||||
testSelectorWithTagNameAndIdAndClassName: function() {
|
||||
this.assertEnumEqual([$('link_2')], $$('a#link_2.internal'));
|
||||
this.assertEnumEqual([$('link_2')], $$('a.internal#link_2'));
|
||||
this.assertEnumEqual([$('item_1')], $$('li#item_1.first'));
|
||||
this.assertEnumEqual([], $$('li#item_1.nonexistent'));
|
||||
this.assertEnumEqual([], $$('li#item_1.first.nonexistent'));
|
||||
},
|
||||
|
||||
test$$MatchesAncestryWithTokensSeparatedByWhitespace: function() {with(this) {
|
||||
assertEnumEqual($('em2', 'em', 'span'), $$('#fixtures a *'));
|
||||
assertEnumEqual([$('p')], $$('div#fixtures p'));
|
||||
}},
|
||||
test$$MatchesAncestryWithTokensSeparatedByWhitespace: function() {
|
||||
this.assertEnumEqual($('em2', 'em', 'span'), $$('#fixtures a *'));
|
||||
this.assertEnumEqual([$('p')], $$('div#fixtures p'));
|
||||
},
|
||||
|
||||
test$$CombinesResultsWhenMultipleExpressionsArePassed: function() {with(this) {
|
||||
assertEnumEqual($('link_1', 'link_2', 'item_1', 'item_2', 'item_3'), $$('#p a', ' ul#list li '));
|
||||
}},
|
||||
test$$CombinesResultsWhenMultipleExpressionsArePassed: function() {
|
||||
this.assertEnumEqual($('link_1', 'link_2', 'item_1', 'item_2', 'item_3'), $$('#p a', ' ul#list li '));
|
||||
},
|
||||
|
||||
testSelectorWithTagNameAndAttributeExistence: function() {with(this) {
|
||||
assertEnumEqual($$('#fixtures h1'), $$('h1[class]'), 'h1[class]');
|
||||
assertEnumEqual($$('#fixtures h1'), $$('h1[CLASS]'), 'h1[CLASS]');
|
||||
assertEnumEqual([$('item_3')], $$('li#item_3[class]'), 'li#item_3[class]');
|
||||
}},
|
||||
testSelectorWithTagNameAndAttributeExistence: function() {
|
||||
this.assertEnumEqual($$('#fixtures h1'), $$('h1[class]'), 'h1[class]');
|
||||
this.assertEnumEqual($$('#fixtures h1'), $$('h1[CLASS]'), 'h1[CLASS]');
|
||||
this.assertEnumEqual([$('item_3')], $$('li#item_3[class]'), 'li#item_3[class]');
|
||||
},
|
||||
|
||||
testSelectorWithTagNameAndSpecificAttributeValue: function() {with(this) {
|
||||
assertEnumEqual($('link_1', 'link_2', 'link_3'), $$('a[href="#"]'));
|
||||
assertEnumEqual($('link_1', 'link_2', 'link_3'), $$('a[href=#]'));
|
||||
}},
|
||||
testSelectorWithTagNameAndSpecificAttributeValue: function() {
|
||||
this.assertEnumEqual($('link_1', 'link_2', 'link_3'), $$('a[href="#"]'));
|
||||
this.assertEnumEqual($('link_1', 'link_2', 'link_3'), $$('a[href=#]'));
|
||||
},
|
||||
|
||||
testSelectorWithTagNameAndWhitespaceTokenizedAttributeValue: function() {with(this) {
|
||||
assertEnumEqual($('link_1', 'link_2'), $$('a[class~="internal"]'));
|
||||
assertEnumEqual($('link_1', 'link_2'), $$('a[class~=internal]'));
|
||||
}},
|
||||
testSelectorWithTagNameAndWhitespaceTokenizedAttributeValue: function() {
|
||||
this.assertEnumEqual($('link_1', 'link_2'), $$('a[class~="internal"]'));
|
||||
this.assertEnumEqual($('link_1', 'link_2'), $$('a[class~=internal]'));
|
||||
},
|
||||
|
||||
testSelectorWithAttributeAndNoTagName: function() {with(this) {
|
||||
assertEnumEqual($(document.body).select('a[href]'), $(document.body).select('[href]'));
|
||||
assertEnumEqual($$('a[class~="internal"]'), $$('[class~=internal]'));
|
||||
assertEnumEqual($$('*[id]'), $$('[id]'));
|
||||
assertEnumEqual($('checked_radio', 'unchecked_radio'), $$('[type=radio]'));
|
||||
assertEnumEqual($$('*[type=checkbox]'), $$('[type=checkbox]'));
|
||||
assertEnumEqual($('with_title', 'commaParent'), $$('[title]'));
|
||||
assertEnumEqual($$('#troubleForm *[type=radio]'), $$('#troubleForm [type=radio]'));
|
||||
assertEnumEqual($$('#troubleForm *[type]'), $$('#troubleForm [type]'));
|
||||
}},
|
||||
testSelectorWithAttributeAndNoTagName: function() {
|
||||
this.assertEnumEqual($(document.body).select('a[href]'), $(document.body).select('[href]'));
|
||||
this.assertEnumEqual($$('a[class~="internal"]'), $$('[class~=internal]'));
|
||||
this.assertEnumEqual($$('*[id]'), $$('[id]'));
|
||||
this.assertEnumEqual($('checked_radio', 'unchecked_radio'), $$('[type=radio]'));
|
||||
this.assertEnumEqual($$('*[type=checkbox]'), $$('[type=checkbox]'));
|
||||
this.assertEnumEqual($('with_title', 'commaParent'), $$('[title]'));
|
||||
this.assertEnumEqual($$('#troubleForm *[type=radio]'), $$('#troubleForm [type=radio]'));
|
||||
this.assertEnumEqual($$('#troubleForm *[type]'), $$('#troubleForm [type]'));
|
||||
},
|
||||
|
||||
testSelectorWithUniversalAndHyphenTokenizedAttributeValue: function() {with(this) {
|
||||
assertEnumEqual([$('item_3')], $$('*[xml:lang|="es"]'));
|
||||
assertEnumEqual([$('item_3')], $$('*[xml:lang|="ES"]'));
|
||||
}},
|
||||
testSelectorWithUniversalAndHyphenTokenizedAttributeValue: function() {
|
||||
this.assertEnumEqual([$('item_3')], $$('*[xml:lang|="es"]'));
|
||||
this.assertEnumEqual([$('item_3')], $$('*[xml:lang|="ES"]'));
|
||||
},
|
||||
|
||||
testSelectorWithTagNameAndNegatedAttributeValue: function() {with(this) {
|
||||
assertEnumEqual([], $$('a[href!=#]'));
|
||||
}},
|
||||
testSelectorWithTagNameAndNegatedAttributeValue: function() {
|
||||
this.assertEnumEqual([], $$('a[href!=#]'));
|
||||
},
|
||||
|
||||
testSelectorWithBracketAttributeValue: function() {with(this) {
|
||||
assertEnumEqual($('chk_1', 'chk_2'), $$('#troubleForm2 input[name="brackets[5][]"]'));
|
||||
assertEnumEqual([$('chk_1')], $$('#troubleForm2 input[name="brackets[5][]"]:checked'));
|
||||
assertEnumEqual([$('chk_2')], $$('#troubleForm2 input[name="brackets[5][]"][value=2]'));
|
||||
assertEnumEqual([], $$('#troubleForm2 input[name=brackets[5][]]'));
|
||||
}},
|
||||
testSelectorWithBracketAttributeValue: function() {
|
||||
this.assertEnumEqual($('chk_1', 'chk_2'), $$('#troubleForm2 input[name="brackets[5][]"]'));
|
||||
this.assertEnumEqual([$('chk_1')], $$('#troubleForm2 input[name="brackets[5][]"]:checked'));
|
||||
this.assertEnumEqual([$('chk_2')], $$('#troubleForm2 input[name="brackets[5][]"][value=2]'));
|
||||
this.assertEnumEqual([], $$('#troubleForm2 input[name=brackets[5][]]'));
|
||||
},
|
||||
|
||||
test$$WithNestedAttributeSelectors: function() {with(this) {
|
||||
assertEnumEqual([$('strong')], $$('div[style] p[id] strong'));
|
||||
}},
|
||||
test$$WithNestedAttributeSelectors: function() {
|
||||
this.assertEnumEqual([$('strong')], $$('div[style] p[id] strong'));
|
||||
},
|
||||
|
||||
testSelectorWithMultipleConditions: function() {with(this) {
|
||||
assertEnumEqual([$('link_3')], $$('a[class~=external][href="#"]'));
|
||||
assertEnumEqual([], $$('a[class~=external][href!="#"]'));
|
||||
}},
|
||||
testSelectorWithMultipleConditions: function() {
|
||||
this.assertEnumEqual([$('link_3')], $$('a[class~=external][href="#"]'));
|
||||
this.assertEnumEqual([], $$('a[class~=external][href!="#"]'));
|
||||
},
|
||||
|
||||
testSelectorMatchElements: function() {with(this) {
|
||||
assertElementsMatch(Selector.matchElements($('list').descendants(), 'li'), '#item_1', '#item_2', '#item_3');
|
||||
assertElementsMatch(Selector.matchElements($('fixtures').descendants(), 'a.internal'), '#link_1', '#link_2');
|
||||
assertEnumEqual([], Selector.matchElements($('fixtures').descendants(), 'p.last'));
|
||||
assertElementsMatch(Selector.matchElements($('fixtures').descendants(), '.inexistant, a.internal'), '#link_1', '#link_2');
|
||||
}},
|
||||
testSelectorMatchElements: function() {
|
||||
this.assertElementsMatch(Selector.matchElements($('list').descendants(), 'li'), '#item_1', '#item_2', '#item_3');
|
||||
this.assertElementsMatch(Selector.matchElements($('fixtures').descendants(), 'a.internal'), '#link_1', '#link_2');
|
||||
this.assertEnumEqual([], Selector.matchElements($('fixtures').descendants(), 'p.last'));
|
||||
this.assertElementsMatch(Selector.matchElements($('fixtures').descendants(), '.inexistant, a.internal'), '#link_1', '#link_2');
|
||||
},
|
||||
|
||||
testSelectorFindElement: function() {with(this) {
|
||||
assertElementMatches(Selector.findElement($('list').descendants(), 'li'), 'li#item_1.first');
|
||||
assertElementMatches(Selector.findElement($('list').descendants(), 'li', 1), 'li#item_2');
|
||||
assertElementMatches(Selector.findElement($('list').descendants(), 'li#item_3'), 'li');
|
||||
assertEqual(undefined, Selector.findElement($('list').descendants(), 'em'));
|
||||
}},
|
||||
testSelectorFindElement: function() {
|
||||
this.assertElementMatches(Selector.findElement($('list').descendants(), 'li'), 'li#item_1.first');
|
||||
this.assertElementMatches(Selector.findElement($('list').descendants(), 'li', 1), 'li#item_2');
|
||||
this.assertElementMatches(Selector.findElement($('list').descendants(), 'li#item_3'), 'li');
|
||||
this.assertEqual(undefined, Selector.findElement($('list').descendants(), 'em'));
|
||||
},
|
||||
|
||||
testElementMatch: function() {with(this) {
|
||||
testElementMatch: function() {
|
||||
var span = $('dupL1');
|
||||
|
||||
// tests that should pass
|
||||
assert(span.match('span'));
|
||||
assert(span.match('span#dupL1'));
|
||||
assert(span.match('div > span'), 'child combinator');
|
||||
assert(span.match('#dupContainer span'), 'descendant combinator');
|
||||
assert(span.match('#dupL1'), 'ID only');
|
||||
assert(span.match('span.span_foo'), 'class name 1');
|
||||
assert(span.match('span.span_bar'), 'class name 2');
|
||||
assert(span.match('span:first-child'), 'first-child pseudoclass');
|
||||
this.assert(span.match('span'));
|
||||
this.assert(span.match('span#dupL1'));
|
||||
this.assert(span.match('div > span'), 'child combinator');
|
||||
this.assert(span.match('#dupContainer span'), 'descendant combinator');
|
||||
this.assert(span.match('#dupL1'), 'ID only');
|
||||
this.assert(span.match('span.span_foo'), 'class name 1');
|
||||
this.assert(span.match('span.span_bar'), 'class name 2');
|
||||
this.assert(span.match('span:first-child'), 'first-child pseudoclass');
|
||||
|
||||
assert(!span.match('span.span_wtf'), 'bogus class name');
|
||||
assert(!span.match('#dupL2'), 'different ID');
|
||||
assert(!span.match('div'), 'different tag name');
|
||||
assert(!span.match('span span'), 'different ancestry');
|
||||
assert(!span.match('span > span'), 'different parent');
|
||||
assert(!span.match('span:nth-child(5)'), 'different pseudoclass');
|
||||
this.assert(!span.match('span.span_wtf'), 'bogus class name');
|
||||
this.assert(!span.match('#dupL2'), 'different ID');
|
||||
this.assert(!span.match('div'), 'different tag name');
|
||||
this.assert(!span.match('span span'), 'different ancestry');
|
||||
this.assert(!span.match('span > span'), 'different parent');
|
||||
this.assert(!span.match('span:nth-child(5)'), 'different pseudoclass');
|
||||
|
||||
assert(!$('link_2').match('a[rel^=external]'));
|
||||
assert($('link_1').match('a[rel^=external]'));
|
||||
assert($('link_1').match('a[rel^="external"]'));
|
||||
assert($('link_1').match("a[rel^='external']"));
|
||||
this.assert(!$('link_2').match('a[rel^=external]'));
|
||||
this.assert($('link_1').match('a[rel^=external]'));
|
||||
this.assert($('link_1').match('a[rel^="external"]'));
|
||||
this.assert($('link_1').match("a[rel^='external']"));
|
||||
|
||||
assert(span.match({ match: function(element) { return true }}), 'custom selector');
|
||||
assert(!span.match({ match: function(element) { return false }}), 'custom selector');
|
||||
}},
|
||||
this.assert(span.match({ match: function(element) { return true }}), 'custom selector');
|
||||
this.assert(!span.match({ match: function(element) { return false }}), 'custom selector');
|
||||
},
|
||||
|
||||
testSelectorWithSpaceInAttributeValue: function() {with(this) {
|
||||
assertEnumEqual([$('with_title')], $$('cite[title="hello world!"]'));
|
||||
}},
|
||||
testSelectorWithSpaceInAttributeValue: function() {
|
||||
this.assertEnumEqual([$('with_title')], $$('cite[title="hello world!"]'));
|
||||
},
|
||||
|
||||
// AND NOW COME THOSE NEW TESTS AFTER ANDREW'S REWRITE!
|
||||
|
||||
testSelectorWithNamespacedAttributes: function() { with(this) {
|
||||
testSelectorWithNamespacedAttributes: function() {
|
||||
if (Prototype.BrowserFeatures.XPath) {
|
||||
assertUndefined(new Selector('html[xml:lang]').xpath);
|
||||
assertUndefined(new Selector('body p[xml:lang]').xpath);
|
||||
this.assertUndefined(new Selector('html[xml:lang]').xpath);
|
||||
this.assertUndefined(new Selector('body p[xml:lang]').xpath);
|
||||
} else
|
||||
info("Could not test XPath bypass: no XPath to begin with!");
|
||||
this.info("Could not test XPath bypass: no XPath to begin with!");
|
||||
|
||||
assertElementsMatch($$('[xml:lang]'), 'html', '#item_3');
|
||||
assertElementsMatch($$('*[xml:lang]'), 'html', '#item_3');
|
||||
}},
|
||||
this.assertElementsMatch($$('[xml:lang]'), 'html', '#item_3');
|
||||
this.assertElementsMatch($$('*[xml:lang]'), 'html', '#item_3');
|
||||
},
|
||||
|
||||
testSelectorWithChild: function() { with(this) {
|
||||
assertEnumEqual($('link_1', 'link_2'), $$('p.first > a'));
|
||||
assertEnumEqual($('father', 'uncle'), $$('div#grandfather > div'));
|
||||
assertEnumEqual($('level2_1', 'level2_2'), $$('#level1>span'));
|
||||
assertEnumEqual($('level2_1', 'level2_2'), $$('#level1 > span'));
|
||||
assertEnumEqual($('level3_1', 'level3_2'), $$('#level2_1 > *'));
|
||||
assertEnumEqual([], $$('div > #nonexistent'));
|
||||
$RunBenchmarks && wait(500, function() {
|
||||
benchmark(function() { $$('#level1 > span') }, 1000);
|
||||
testSelectorWithChild: function() {
|
||||
this.assertEnumEqual($('link_1', 'link_2'), $$('p.first > a'));
|
||||
this.assertEnumEqual($('father', 'uncle'), $$('div#grandfather > div'));
|
||||
this.assertEnumEqual($('level2_1', 'level2_2'), $$('#level1>span'));
|
||||
this.assertEnumEqual($('level2_1', 'level2_2'), $$('#level1 > span'));
|
||||
this.assertEnumEqual($('level3_1', 'level3_2'), $$('#level2_1 > *'));
|
||||
this.assertEnumEqual([], $$('div > #nonexistent'));
|
||||
$RunBenchmarks && this.wait(500, function() {
|
||||
this.benchmark(function() { $$('#level1 > span') }, 1000);
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testSelectorWithAdjacence: function() { with(this) {
|
||||
assertEnumEqual([$('uncle')], $$('div.brothers + div.brothers'));
|
||||
assertEnumEqual([$('uncle')], $$('div.brothers + div'));
|
||||
assertEqual($('level2_2'), $$('#level2_1+span').reduce());
|
||||
assertEqual($('level2_2'), $$('#level2_1 + span').reduce());
|
||||
assertEqual($('level2_2'), $$('#level2_1 + *').reduce());
|
||||
assertEnumEqual([], $$('#level2_2 + span'));
|
||||
assertEqual($('level3_2'), $$('#level3_1 + span').reduce());
|
||||
assertEqual($('level3_2'), $$('#level3_1 + *').reduce());
|
||||
assertEnumEqual([], $$('#level3_2 + *'));
|
||||
assertEnumEqual([], $$('#level3_1 + em'));
|
||||
$RunBenchmarks && wait(500, function() {
|
||||
benchmark(function() { $$('#level3_1 + span') }, 1000);
|
||||
testSelectorWithAdjacence: function() {
|
||||
this.assertEnumEqual([$('uncle')], $$('div.brothers + div.brothers'));
|
||||
this.assertEnumEqual([$('uncle')], $$('div.brothers + div'));
|
||||
this.assertEqual($('level2_2'), $$('#level2_1+span').reduce());
|
||||
this.assertEqual($('level2_2'), $$('#level2_1 + span').reduce());
|
||||
this.assertEqual($('level2_2'), $$('#level2_1 + *').reduce());
|
||||
this.assertEnumEqual([], $$('#level2_2 + span'));
|
||||
this.assertEqual($('level3_2'), $$('#level3_1 + span').reduce());
|
||||
this.assertEqual($('level3_2'), $$('#level3_1 + *').reduce());
|
||||
this.assertEnumEqual([], $$('#level3_2 + *'));
|
||||
this.assertEnumEqual([], $$('#level3_1 + em'));
|
||||
$RunBenchmarks && this.wait(500, function() {
|
||||
this.benchmark(function() { $$('#level3_1 + span') }, 1000);
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testSelectorWithLaterSibling: function() { with(this) {
|
||||
assertEnumEqual([$('list')], $$('h1 ~ ul'));
|
||||
assertEqual($('level2_2'), $$('#level2_1 ~ span').reduce());
|
||||
assertEnumEqual($('level2_2', 'level2_3'), $$('#level2_1 ~ *').reduce());
|
||||
assertEnumEqual([], $$('#level2_2 ~ span'));
|
||||
assertEnumEqual([], $$('#level3_2 ~ *'));
|
||||
assertEnumEqual([], $$('#level3_1 ~ em'));
|
||||
assertEnumEqual([$('level3_2')], $$('#level3_1 ~ #level3_2'));
|
||||
assertEnumEqual([$('level3_2')], $$('span ~ #level3_2'));
|
||||
assertEnumEqual([], $$('div ~ #level3_2'));
|
||||
assertEnumEqual([], $$('div ~ #level2_3'));
|
||||
$RunBenchmarks && wait(500, function() {
|
||||
benchmark(function() { $$('#level2_1 ~ span') }, 1000);
|
||||
testSelectorWithLaterSibling: function() {
|
||||
this.assertEnumEqual([$('list')], $$('h1 ~ ul'));
|
||||
this.assertEqual($('level2_2'), $$('#level2_1 ~ span').reduce());
|
||||
this.assertEnumEqual($('level2_2', 'level2_3'), $$('#level2_1 ~ *').reduce());
|
||||
this.assertEnumEqual([], $$('#level2_2 ~ span'));
|
||||
this.assertEnumEqual([], $$('#level3_2 ~ *'));
|
||||
this.assertEnumEqual([], $$('#level3_1 ~ em'));
|
||||
this.assertEnumEqual([$('level3_2')], $$('#level3_1 ~ #level3_2'));
|
||||
this.assertEnumEqual([$('level3_2')], $$('span ~ #level3_2'));
|
||||
this.assertEnumEqual([], $$('div ~ #level3_2'));
|
||||
this.assertEnumEqual([], $$('div ~ #level2_3'));
|
||||
$RunBenchmarks && this.wait(500, function() {
|
||||
this.benchmark(function() { $$('#level2_1 ~ span') }, 1000);
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testSelectorWithNewAttributeOperators: function() { with(this) {
|
||||
assertEnumEqual($('father', 'uncle'), $$('div[class^=bro]'), 'matching beginning of string');
|
||||
assertEnumEqual($('father', 'uncle'), $$('div[class$=men]'), 'matching end of string');
|
||||
assertEnumEqual($('father', 'uncle'), $$('div[class*="ers m"]'), 'matching substring')
|
||||
assertEnumEqual($('level2_1', 'level2_2', 'level2_3'), $$('#level1 *[id^="level2_"]'));
|
||||
assertEnumEqual($('level2_1', 'level2_2', 'level2_3'), $$('#level1 *[id^=level2_]'));
|
||||
assertEnumEqual($('level2_1', 'level3_1'), $$('#level1 *[id$="_1"]'));
|
||||
assertEnumEqual($('level2_1', 'level3_1'), $$('#level1 *[id$=_1]'));
|
||||
assertEnumEqual($('level2_1', 'level3_2', 'level2_2', 'level2_3'), $$('#level1 *[id*="2"]'));
|
||||
assertEnumEqual($('level2_1', 'level3_2', 'level2_2', 'level2_3'), $$('#level1 *[id*=2]'));
|
||||
$RunBenchmarks && wait(500, function() {
|
||||
benchmark(function() { $$('#level1 *[id^=level2_]') }, 1000, '[^=]');
|
||||
benchmark(function() { $$('#level1 *[id$=_1]') }, 1000, '[$=]');
|
||||
benchmark(function() { $$('#level1 *[id*=_2]') }, 1000, '[*=]');
|
||||
testSelectorWithNewAttributeOperators: function() {
|
||||
this.assertEnumEqual($('father', 'uncle'), $$('div[class^=bro]'), 'matching beginning of string');
|
||||
this.assertEnumEqual($('father', 'uncle'), $$('div[class$=men]'), 'matching end of string');
|
||||
this.assertEnumEqual($('father', 'uncle'), $$('div[class*="ers m"]'), 'matching substring')
|
||||
this.assertEnumEqual($('level2_1', 'level2_2', 'level2_3'), $$('#level1 *[id^="level2_"]'));
|
||||
this.assertEnumEqual($('level2_1', 'level2_2', 'level2_3'), $$('#level1 *[id^=level2_]'));
|
||||
this.assertEnumEqual($('level2_1', 'level3_1'), $$('#level1 *[id$="_1"]'));
|
||||
this.assertEnumEqual($('level2_1', 'level3_1'), $$('#level1 *[id$=_1]'));
|
||||
this.assertEnumEqual($('level2_1', 'level3_2', 'level2_2', 'level2_3'), $$('#level1 *[id*="2"]'));
|
||||
this.assertEnumEqual($('level2_1', 'level3_2', 'level2_2', 'level2_3'), $$('#level1 *[id*=2]'));
|
||||
$RunBenchmarks && this.wait(500, function() {
|
||||
this.benchmark(function() { $$('#level1 *[id^=level2_]') }, 1000, '[^=]');
|
||||
this.benchmark(function() { $$('#level1 *[id$=_1]') }, 1000, '[$=]');
|
||||
this.benchmark(function() { $$('#level1 *[id*=_2]') }, 1000, '[*=]');
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testSelectorWithDuplicates: function() { with(this) {
|
||||
assertEnumEqual($$('div div'), $$('div div').uniq());
|
||||
assertEnumEqual($('dupL2', 'dupL3', 'dupL4', 'dupL5'), $$('#dupContainer span span'));
|
||||
$RunBenchmarks && wait(500, function() {
|
||||
benchmark(function() { $$('#dupContainer span span') }, 1000);
|
||||
testSelectorWithDuplicates: function() {
|
||||
this.assertEnumEqual($$('div div'), $$('div div').uniq());
|
||||
this.assertEnumEqual($('dupL2', 'dupL3', 'dupL4', 'dupL5'), $$('#dupContainer span span'));
|
||||
$RunBenchmarks && this.wait(500, function() {
|
||||
this.benchmark(function() { $$('#dupContainer span span') }, 1000);
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testSelectorWithFirstLastOnlyNthNthLastChild: function() { with(this) {
|
||||
assertEnumEqual([$('level2_1')], $$('#level1>*:first-child'));
|
||||
assertEnumEqual($('level2_1', 'level3_1', 'level_only_child'), $$('#level1 *:first-child'));
|
||||
assertEnumEqual([$('level2_3')], $$('#level1>*:last-child'));
|
||||
assertEnumEqual($('level3_2', 'level_only_child', 'level2_3'), $$('#level1 *:last-child'));
|
||||
assertEnumEqual([$('level2_3')], $$('#level1>div:last-child'));
|
||||
assertEnumEqual([$('level2_3')], $$('#level1 div:last-child'));
|
||||
assertEnumEqual([], $$('#level1>div:first-child'));
|
||||
assertEnumEqual([], $$('#level1>span:last-child'));
|
||||
assertEnumEqual($('level2_1', 'level3_1'), $$('#level1 span:first-child'));
|
||||
assertEnumEqual([], $$('#level1:first-child'));
|
||||
assertEnumEqual([], $$('#level1>*:only-child'));
|
||||
assertEnumEqual([$('level_only_child')], $$('#level1 *:only-child'));
|
||||
assertEnumEqual([], $$('#level1:only-child'));
|
||||
assertEnumEqual([$('link_2')], $$('#p *:nth-last-child(2)'), 'nth-last-child');
|
||||
assertEnumEqual([$('link_2')], $$('#p *:nth-child(3)'), 'nth-child');
|
||||
assertEnumEqual([$('link_2')], $$('#p a:nth-child(3)'), 'nth-child');
|
||||
assertEnumEqual($('item_2', 'item_3'), $$('#list > li:nth-child(n+2)'));
|
||||
assertEnumEqual($('item_1', 'item_2'), $$('#list > li:nth-child(-n+2)'));
|
||||
$RunBenchmarks && wait(500, function() {
|
||||
benchmark(function() { $$('#level1 *:first-child') }, 1000, ':first-child');
|
||||
benchmark(function() { $$('#level1 *:last-child') }, 1000, ':last-child');
|
||||
benchmark(function() { $$('#level1 *:only-child') }, 1000, ':only-child');
|
||||
testSelectorWithFirstLastOnlyNthNthLastChild: function() {
|
||||
this.assertEnumEqual([$('level2_1')], $$('#level1>*:first-child'));
|
||||
this.assertEnumEqual($('level2_1', 'level3_1', 'level_only_child'), $$('#level1 *:first-child'));
|
||||
this.assertEnumEqual([$('level2_3')], $$('#level1>*:last-child'));
|
||||
this.assertEnumEqual($('level3_2', 'level_only_child', 'level2_3'), $$('#level1 *:last-child'));
|
||||
this.assertEnumEqual([$('level2_3')], $$('#level1>div:last-child'));
|
||||
this.assertEnumEqual([$('level2_3')], $$('#level1 div:last-child'));
|
||||
this.assertEnumEqual([], $$('#level1>div:first-child'));
|
||||
this.assertEnumEqual([], $$('#level1>span:last-child'));
|
||||
this.assertEnumEqual($('level2_1', 'level3_1'), $$('#level1 span:first-child'));
|
||||
this.assertEnumEqual([], $$('#level1:first-child'));
|
||||
this.assertEnumEqual([], $$('#level1>*:only-child'));
|
||||
this.assertEnumEqual([$('level_only_child')], $$('#level1 *:only-child'));
|
||||
this.assertEnumEqual([], $$('#level1:only-child'));
|
||||
this.assertEnumEqual([$('link_2')], $$('#p *:nth-last-child(2)'), 'nth-last-child');
|
||||
this.assertEnumEqual([$('link_2')], $$('#p *:nth-child(3)'), 'nth-child');
|
||||
this.assertEnumEqual([$('link_2')], $$('#p a:nth-child(3)'), 'nth-child');
|
||||
this.assertEnumEqual($('item_2', 'item_3'), $$('#list > li:nth-child(n+2)'));
|
||||
this.assertEnumEqual($('item_1', 'item_2'), $$('#list > li:nth-child(-n+2)'));
|
||||
$RunBenchmarks && this.wait(500, function() {
|
||||
this.benchmark(function() { $$('#level1 *:first-child') }, 1000, ':first-child');
|
||||
this.benchmark(function() { $$('#level1 *:last-child') }, 1000, ':last-child');
|
||||
this.benchmark(function() { $$('#level1 *:only-child') }, 1000, ':only-child');
|
||||
});
|
||||
}},
|
||||
},
|
||||
|
||||
testSelectorWithFirstLastNthNthLastOfType: function() {with(this) {
|
||||
assertEnumEqual([$('link_2')], $$('#p a:nth-of-type(2)'), 'nth-of-type');
|
||||
assertEnumEqual([$('link_1')], $$('#p a:nth-of-type(1)'), 'nth-of-type');
|
||||
assertEnumEqual([$('link_2')], $$('#p a:nth-last-of-type(1)'), 'nth-last-of-type');
|
||||
assertEnumEqual([$('link_1')], $$('#p a:first-of-type'), 'first-of-type');
|
||||
assertEnumEqual([$('link_2')], $$('#p a:last-of-type'), 'last-of-type');
|
||||
}},
|
||||
testSelectorWithFirstLastNthNthLastOfType: function() {
|
||||
this.assertEnumEqual([$('link_2')], $$('#p a:nth-of-type(2)'), 'nth-of-type');
|
||||
this.assertEnumEqual([$('link_1')], $$('#p a:nth-of-type(1)'), 'nth-of-type');
|
||||
this.assertEnumEqual([$('link_2')], $$('#p a:nth-last-of-type(1)'), 'nth-last-of-type');
|
||||
this.assertEnumEqual([$('link_1')], $$('#p a:first-of-type'), 'first-of-type');
|
||||
this.assertEnumEqual([$('link_2')], $$('#p a:last-of-type'), 'last-of-type');
|
||||
},
|
||||
|
||||
testSelectorWithNot: function() {with(this) {
|
||||
assertEnumEqual([$('link_2')], $$('#p a:not(a:first-of-type)'), 'first-of-type');
|
||||
assertEnumEqual([$('link_1')], $$('#p a:not(a:last-of-type)'), 'last-of-type');
|
||||
assertEnumEqual([$('link_2')], $$('#p a:not(a:nth-of-type(1))'), 'nth-of-type');
|
||||
assertEnumEqual([$('link_1')], $$('#p a:not(a:nth-last-of-type(1))'), 'nth-last-of-type');
|
||||
assertEnumEqual([$('link_2')], $$('#p a:not([rel~=nofollow])'), 'attribute 1');
|
||||
assertEnumEqual([$('link_2')], $$('#p a:not(a[rel^=external])'), 'attribute 2');
|
||||
assertEnumEqual([$('link_2')], $$('#p a:not(a[rel$=nofollow])'), 'attribute 3');
|
||||
assertEnumEqual([$('em')], $$('#p a:not(a[rel$="nofollow"]) > em'), 'attribute 4')
|
||||
assertEnumEqual([$('item_2')], $$('#list li:not(#item_1):not(#item_3)'), 'adjacent :not clauses');
|
||||
assertEnumEqual([$('son')], $$('#grandfather > div:not(#uncle) #son'));
|
||||
assertEnumEqual([$('em')], $$('#p a:not(a[rel$="nofollow"]) em'), 'attribute 4 + all descendants');
|
||||
assertEnumEqual([$('em')], $$('#p a:not(a[rel$="nofollow"])>em'), 'attribute 4 (without whitespace)');
|
||||
}},
|
||||
testSelectorWithNot: function() {
|
||||
this.assertEnumEqual([$('link_2')], $$('#p a:not(a:first-of-type)'), 'first-of-type');
|
||||
this.assertEnumEqual([$('link_1')], $$('#p a:not(a:last-of-type)'), 'last-of-type');
|
||||
this.assertEnumEqual([$('link_2')], $$('#p a:not(a:nth-of-type(1))'), 'nth-of-type');
|
||||
this.assertEnumEqual([$('link_1')], $$('#p a:not(a:nth-last-of-type(1))'), 'nth-last-of-type');
|
||||
this.assertEnumEqual([$('link_2')], $$('#p a:not([rel~=nofollow])'), 'attribute 1');
|
||||
this.assertEnumEqual([$('link_2')], $$('#p a:not(a[rel^=external])'), 'attribute 2');
|
||||
this.assertEnumEqual([$('link_2')], $$('#p a:not(a[rel$=nofollow])'), 'attribute 3');
|
||||
this.assertEnumEqual([$('em')], $$('#p a:not(a[rel$="nofollow"]) > em'), 'attribute 4')
|
||||
this.assertEnumEqual([$('item_2')], $$('#list li:not(#item_1):not(#item_3)'), 'adjacent :not clauses');
|
||||
this.assertEnumEqual([$('son')], $$('#grandfather > div:not(#uncle) #son'));
|
||||
this.assertEnumEqual([$('em')], $$('#p a:not(a[rel$="nofollow"]) em'), 'attribute 4 + all descendants');
|
||||
this.assertEnumEqual([$('em')], $$('#p a:not(a[rel$="nofollow"])>em'), 'attribute 4 (without whitespace)');
|
||||
},
|
||||
|
||||
testSelectorWithEnabledDisabledChecked: function() {with(this) {
|
||||
assertEnumEqual([$('disabled_text_field')], $$('#troubleForm > *:disabled'));
|
||||
assertEnumEqual($('troubleForm').getInputs().without($('disabled_text_field')), $$('#troubleForm > *:enabled'));
|
||||
assertEnumEqual($('checked_box', 'checked_radio'), $$('#troubleForm *:checked'));
|
||||
}},
|
||||
testSelectorWithEnabledDisabledChecked: function() {
|
||||
this.assertEnumEqual([$('disabled_text_field')], $$('#troubleForm > *:disabled'));
|
||||
this.assertEnumEqual($('troubleForm').getInputs().without($('disabled_text_field')), $$('#troubleForm > *:enabled'));
|
||||
this.assertEnumEqual($('checked_box', 'checked_radio'), $$('#troubleForm *:checked'));
|
||||
},
|
||||
|
||||
testSelectorWithEmpty: function() {with(this) {
|
||||
testSelectorWithEmpty: function() {
|
||||
$('level3_1').innerHTML = "\t\n\n\r\n\t ";
|
||||
assertEnumEqual($('level3_1', 'level3_2', 'level_only_child', 'level2_3'), $$('#level1 *:empty'));
|
||||
assertEnumEqual([$('level_only_child')], $$('#level_only_child:empty'));
|
||||
}},
|
||||
this.assertEnumEqual($('level3_1', 'level3_2', 'level_only_child', 'level2_3'), $$('#level1 *:empty'));
|
||||
this.assertEnumEqual([$('level_only_child')], $$('#level_only_child:empty'));
|
||||
},
|
||||
|
||||
testIdenticalResultsFromEquivalentSelectors: function() {with(this) {
|
||||
assertEnumEqual($$('div.brothers'), $$('div[class~=brothers]'));
|
||||
assertEnumEqual($$('div.brothers'), $$('div[class~=brothers].brothers'));
|
||||
assertEnumEqual($$('div:not(.brothers)'), $$('div:not([class~=brothers])'));
|
||||
assertEnumEqual($$('li ~ li'), $$('li:not(:first-child)'));
|
||||
assertEnumEqual($$('ul > li'), $$('ul > li:nth-child(n)'));
|
||||
assertEnumEqual($$('ul > li:nth-child(even)'), $$('ul > li:nth-child(2n)'));
|
||||
assertEnumEqual($$('ul > li:nth-child(odd)'), $$('ul > li:nth-child(2n+1)'));
|
||||
assertEnumEqual($$('ul > li:first-child'), $$('ul > li:nth-child(1)'));
|
||||
assertEnumEqual($$('ul > li:last-child'), $$('ul > li:nth-last-child(1)'));
|
||||
assertEnumEqual($$('#troubleForm *:enabled'), $$('#troubleForm *:not(:disabled)'));
|
||||
assertEnumEqual($$('ul > li:nth-child(n-999)'), $$('ul > li'));
|
||||
assertEnumEqual($$('ul>li'), $$('ul > li'));
|
||||
assertEnumEqual($$('#p a:not(a[rel$="nofollow"])>em'), $$('#p a:not(a[rel$="nofollow"]) > em'))
|
||||
}},
|
||||
testIdenticalResultsFromEquivalentSelectors: function() {
|
||||
this.assertEnumEqual($$('div.brothers'), $$('div[class~=brothers]'));
|
||||
this.assertEnumEqual($$('div.brothers'), $$('div[class~=brothers].brothers'));
|
||||
this.assertEnumEqual($$('div:not(.brothers)'), $$('div:not([class~=brothers])'));
|
||||
this.assertEnumEqual($$('li ~ li'), $$('li:not(:first-child)'));
|
||||
this.assertEnumEqual($$('ul > li'), $$('ul > li:nth-child(n)'));
|
||||
this.assertEnumEqual($$('ul > li:nth-child(even)'), $$('ul > li:nth-child(2n)'));
|
||||
this.assertEnumEqual($$('ul > li:nth-child(odd)'), $$('ul > li:nth-child(2n+1)'));
|
||||
this.assertEnumEqual($$('ul > li:first-child'), $$('ul > li:nth-child(1)'));
|
||||
this.assertEnumEqual($$('ul > li:last-child'), $$('ul > li:nth-last-child(1)'));
|
||||
this.assertEnumEqual($$('#troubleForm *:enabled'), $$('#troubleForm *:not(:disabled)'));
|
||||
this.assertEnumEqual($$('ul > li:nth-child(n-999)'), $$('ul > li'));
|
||||
this.assertEnumEqual($$('ul>li'), $$('ul > li'));
|
||||
this.assertEnumEqual($$('#p a:not(a[rel$="nofollow"])>em'), $$('#p a:not(a[rel$="nofollow"]) > em'))
|
||||
},
|
||||
|
||||
testSelectorsThatShouldReturnNothing: function() {with(this) {
|
||||
assertEnumEqual([], $$('span:empty > *'));
|
||||
assertEnumEqual([], $$('div.brothers:not(.brothers)'));
|
||||
assertEnumEqual([], $$('#level2_2 :only-child:not(:last-child)'));
|
||||
assertEnumEqual([], $$('#level2_2 :only-child:not(:first-child)'));
|
||||
}},
|
||||
testSelectorsThatShouldReturnNothing: function() {
|
||||
this.assertEnumEqual([], $$('span:empty > *'));
|
||||
this.assertEnumEqual([], $$('div.brothers:not(.brothers)'));
|
||||
this.assertEnumEqual([], $$('#level2_2 :only-child:not(:last-child)'));
|
||||
this.assertEnumEqual([], $$('#level2_2 :only-child:not(:first-child)'));
|
||||
},
|
||||
|
||||
testCommasFor$$: function() {with(this) {
|
||||
assertEnumEqual($('list', 'p', 'link_1', 'item_1', 'item_3', 'troubleForm'), $$('#list, .first,*[xml:lang="es-us"] , #troubleForm'));
|
||||
assertEnumEqual($('list', 'p', 'link_1', 'item_1', 'item_3', 'troubleForm'), $$('#list, .first,', '*[xml:lang="es-us"] , #troubleForm'));
|
||||
assertEnumEqual($('commaParent', 'commaChild'), $$('form[title*="commas,"], input[value="#commaOne,#commaTwo"]'));
|
||||
assertEnumEqual($('commaParent', 'commaChild'), $$('form[title*="commas,"]', 'input[value="#commaOne,#commaTwo"]'));
|
||||
}},
|
||||
testCommasFor$$: function() {
|
||||
this.assertEnumEqual($('list', 'p', 'link_1', 'item_1', 'item_3', 'troubleForm'), $$('#list, .first,*[xml:lang="es-us"] , #troubleForm'));
|
||||
this.assertEnumEqual($('list', 'p', 'link_1', 'item_1', 'item_3', 'troubleForm'), $$('#list, .first,', '*[xml:lang="es-us"] , #troubleForm'));
|
||||
this.assertEnumEqual($('commaParent', 'commaChild'), $$('form[title*="commas,"], input[value="#commaOne,#commaTwo"]'));
|
||||
this.assertEnumEqual($('commaParent', 'commaChild'), $$('form[title*="commas,"]', 'input[value="#commaOne,#commaTwo"]'));
|
||||
},
|
||||
|
||||
testSelectorExtendsAllNodes: function(){ with(this) {
|
||||
testSelectorExtendsAllNodes: function(){
|
||||
var element = document.createElement('div');
|
||||
(3).times(function(){
|
||||
element.appendChild(document.createElement('div'));
|
||||
|
@ -442,30 +442,30 @@
|
|||
$$('body')[0].appendChild(element);
|
||||
|
||||
var results = $$('#scratch_element div');
|
||||
assert(typeof results[0].show == 'function');
|
||||
assert(typeof results[1].show == 'function');
|
||||
assert(typeof results[2].show == 'function');
|
||||
}},
|
||||
this.assert(typeof results[0].show == 'function');
|
||||
this.assert(typeof results[1].show == 'function');
|
||||
this.assert(typeof results[2].show == 'function');
|
||||
},
|
||||
|
||||
testCountedIsNotAnAttribute: function() { with(this) {
|
||||
testCountedIsNotAnAttribute: function() {
|
||||
var el = $('list');
|
||||
Selector.handlers.mark([el]);
|
||||
assert(!el.innerHTML.include("_counted"));
|
||||
this.assert(!el.innerHTML.include("_counted"));
|
||||
Selector.handlers.unmark([el]);
|
||||
assert(!el.innerHTML.include("_counted"));
|
||||
}},
|
||||
this.assert(!el.innerHTML.include("_counted"));
|
||||
},
|
||||
|
||||
testCopiedNodesGetIncluded: function(){ with(this) {
|
||||
assertElementsMatch(
|
||||
testCopiedNodesGetIncluded: function() {
|
||||
this.assertElementsMatch(
|
||||
Selector.matchElements($('counted_container').descendants(), 'div'),
|
||||
'div.is_counted'
|
||||
);
|
||||
$('counted_container').innerHTML += $('counted_container').innerHTML;
|
||||
assertElementsMatch(
|
||||
this.assertElementsMatch(
|
||||
Selector.matchElements($('counted_container').descendants(), 'div'), 'div.is_counted',
|
||||
'div.is_counted'
|
||||
);
|
||||
}}
|
||||
}
|
||||
});
|
||||
|
||||
// ]]>
|
||||
|
|
|
@ -36,116 +36,116 @@
|
|||
});
|
||||
|
||||
new Test.Unit.Runner({
|
||||
testInterpret: function(){with(this) {
|
||||
assertIdentical('true', String.interpret(true));
|
||||
assertIdentical('123', String.interpret(123));
|
||||
assertIdentical('foo bar', String.interpret('foo bar'));
|
||||
assertIdentical(
|
||||
testInterpret: function(){
|
||||
this.assertIdentical('true', String.interpret(true));
|
||||
this.assertIdentical('123', String.interpret(123));
|
||||
this.assertIdentical('foo bar', String.interpret('foo bar'));
|
||||
this.assertIdentical(
|
||||
'object string',
|
||||
String.interpret({ toString: function(){ return 'object string' } }));
|
||||
|
||||
assertIdentical('0', String.interpret(0));
|
||||
assertIdentical('false', String.interpret(false));
|
||||
assertIdentical('', String.interpret(undefined));
|
||||
assertIdentical('', String.interpret(null));
|
||||
assertIdentical('', String.interpret(''));
|
||||
}},
|
||||
this.assertIdentical('0', String.interpret(0));
|
||||
this.assertIdentical('false', String.interpret(false));
|
||||
this.assertIdentical('', String.interpret(undefined));
|
||||
this.assertIdentical('', String.interpret(null));
|
||||
this.assertIdentical('', String.interpret(''));
|
||||
},
|
||||
|
||||
testGsubWithReplacementFunction: function() {with(this) {
|
||||
testGsubWithReplacementFunction: function() {
|
||||
var source = 'foo boo boz';
|
||||
|
||||
assertEqual('Foo Boo BoZ',
|
||||
this.assertEqual('Foo Boo BoZ',
|
||||
source.gsub(/[^o]+/, function(match) {
|
||||
return match[0].toUpperCase()
|
||||
}));
|
||||
assertEqual('f2 b2 b1z',
|
||||
this.assertEqual('f2 b2 b1z',
|
||||
source.gsub(/o+/, function(match) {
|
||||
return match[0].length;
|
||||
}));
|
||||
assertEqual('f0 b0 b1z',
|
||||
this.assertEqual('f0 b0 b1z',
|
||||
source.gsub(/o+/, function(match) {
|
||||
return match[0].length % 2;
|
||||
}));
|
||||
|
||||
}},
|
||||
},
|
||||
|
||||
testGsubWithReplacementString: function() {with(this) {
|
||||
testGsubWithReplacementString: function() {
|
||||
var source = 'foo boo boz';
|
||||
|
||||
assertEqual('foobooboz',
|
||||
this.assertEqual('foobooboz',
|
||||
source.gsub(/\s+/, ''));
|
||||
assertEqual(' z',
|
||||
this.assertEqual(' z',
|
||||
source.gsub(/(.)(o+)/, ''));
|
||||
|
||||
assertEqual('ウィメンズ2007<br/>クルーズコレクション',
|
||||
this.assertEqual('ウィメンズ2007<br/>クルーズコレクション',
|
||||
'ウィメンズ2007\nクルーズコレクション'.gsub(/\n/,'<br/>'));
|
||||
assertEqual('ウィメンズ2007<br/>クルーズコレクション',
|
||||
this.assertEqual('ウィメンズ2007<br/>クルーズコレクション',
|
||||
'ウィメンズ2007\nクルーズコレクション'.gsub('\n','<br/>'));
|
||||
}},
|
||||
},
|
||||
|
||||
testGsubWithReplacementTemplateString: function() {with(this) {
|
||||
testGsubWithReplacementTemplateString: function() {
|
||||
var source = 'foo boo boz';
|
||||
|
||||
assertEqual('-oo-#{1}- -oo-#{1}- -o-#{1}-z',
|
||||
this.assertEqual('-oo-#{1}- -oo-#{1}- -o-#{1}-z',
|
||||
source.gsub(/(.)(o+)/, '-#{2}-\\#{1}-'));
|
||||
assertEqual('-foo-f- -boo-b- -bo-b-z',
|
||||
this.assertEqual('-foo-f- -boo-b- -bo-b-z',
|
||||
source.gsub(/(.)(o+)/, '-#{0}-#{1}-'));
|
||||
assertEqual('-oo-f- -oo-b- -o-b-z',
|
||||
this.assertEqual('-oo-f- -oo-b- -o-b-z',
|
||||
source.gsub(/(.)(o+)/, '-#{2}-#{1}-'));
|
||||
assertEqual(' z',
|
||||
this.assertEqual(' z',
|
||||
source.gsub(/(.)(o+)/, '#{3}'));
|
||||
}},
|
||||
},
|
||||
|
||||
testSubWithReplacementFunction: function() {with(this) {
|
||||
testSubWithReplacementFunction: function() {
|
||||
var source = 'foo boo boz';
|
||||
|
||||
assertEqual('Foo boo boz',
|
||||
this.assertEqual('Foo boo boz',
|
||||
source.sub(/[^o]+/, function(match) {
|
||||
return match[0].toUpperCase()
|
||||
}), 1);
|
||||
assertEqual('Foo Boo boz',
|
||||
this.assertEqual('Foo Boo boz',
|
||||
source.sub(/[^o]+/, function(match) {
|
||||
return match[0].toUpperCase()
|
||||
}, 2), 2);
|
||||
assertEqual(source,
|
||||
this.assertEqual(source,
|
||||
source.sub(/[^o]+/, function(match) {
|
||||
return match[0].toUpperCase()
|
||||
}, 0), 0);
|
||||
assertEqual(source,
|
||||
this.assertEqual(source,
|
||||
source.sub(/[^o]+/, function(match) {
|
||||
return match[0].toUpperCase()
|
||||
}, -1), -1);
|
||||
}},
|
||||
},
|
||||
|
||||
testSubWithReplacementString: function() {with(this) {
|
||||
testSubWithReplacementString: function() {
|
||||
var source = 'foo boo boz';
|
||||
|
||||
assertEqual('oo boo boz',
|
||||
this.assertEqual('oo boo boz',
|
||||
source.sub(/[^o]+/, ''));
|
||||
assertEqual('oooo boz',
|
||||
this.assertEqual('oooo boz',
|
||||
source.sub(/[^o]+/, '', 2));
|
||||
assertEqual('-f-oo boo boz',
|
||||
this.assertEqual('-f-oo boo boz',
|
||||
source.sub(/[^o]+/, '-#{0}-'));
|
||||
assertEqual('-f-oo- b-oo boz',
|
||||
this.assertEqual('-f-oo- b-oo boz',
|
||||
source.sub(/[^o]+/, '-#{0}-', 2));
|
||||
}},
|
||||
},
|
||||
|
||||
testScan: function() {with(this) {
|
||||
testScan: function() {
|
||||
var source = 'foo boo boz', results = [];
|
||||
var str = source.scan(/[o]+/, function(match) {
|
||||
results.push(match[0].length);
|
||||
});
|
||||
assertEnumEqual([2, 2, 1], results);
|
||||
assertEqual(source, source.scan(/x/, fail));
|
||||
assert(typeof str == 'string');
|
||||
}},
|
||||
this.assertEnumEqual([2, 2, 1], results);
|
||||
this.assertEqual(source, source.scan(/x/, this.fail));
|
||||
this.assert(typeof str == 'string');
|
||||
},
|
||||
|
||||
testToArray: function() {with(this) {
|
||||
assertEnumEqual([],''.toArray());
|
||||
assertEnumEqual(['a'],'a'.toArray());
|
||||
assertEnumEqual(['a','b'],'ab'.toArray());
|
||||
assertEnumEqual(['f','o','o'],'foo'.toArray());
|
||||
}},
|
||||
testToArray: function() {
|
||||
this.assertEnumEqual([],''.toArray());
|
||||
this.assertEnumEqual(['a'],'a'.toArray());
|
||||
this.assertEnumEqual(['a','b'],'ab'.toArray());
|
||||
this.assertEnumEqual(['f','o','o'],'foo'.toArray());
|
||||
},
|
||||
|
||||
/*
|
||||
Note that camelize() differs from its Rails counterpart,
|
||||
|
@ -154,217 +154,213 @@
|
|||
- Looks for dashes, not underscores
|
||||
- CamelCases first word if there is a front dash
|
||||
*/
|
||||
testCamelize: function() {with(this) {
|
||||
assertEqual('', ''.camelize());
|
||||
assertEqual('', '-'.camelize());
|
||||
assertEqual('foo', 'foo'.camelize());
|
||||
assertEqual('foo_bar', 'foo_bar'.camelize());
|
||||
assertEqual('FooBar', '-foo-bar'.camelize());
|
||||
assertEqual('FooBar', 'FooBar'.camelize());
|
||||
testCamelize: function() {
|
||||
this.assertEqual('', ''.camelize());
|
||||
this.assertEqual('', '-'.camelize());
|
||||
this.assertEqual('foo', 'foo'.camelize());
|
||||
this.assertEqual('foo_bar', 'foo_bar'.camelize());
|
||||
this.assertEqual('FooBar', '-foo-bar'.camelize());
|
||||
this.assertEqual('FooBar', 'FooBar'.camelize());
|
||||
|
||||
assertEqual('fooBar', 'foo-bar'.camelize());
|
||||
assertEqual('borderBottomWidth', 'border-bottom-width'.camelize());
|
||||
this.assertEqual('fooBar', 'foo-bar'.camelize());
|
||||
this.assertEqual('borderBottomWidth', 'border-bottom-width'.camelize());
|
||||
|
||||
assertEqual('classNameTest','class-name-test'.camelize());
|
||||
assertEqual('classNameTest','className-test'.camelize());
|
||||
assertEqual('classNameTest','class-nameTest'.camelize());
|
||||
this.assertEqual('classNameTest','class-name-test'.camelize());
|
||||
this.assertEqual('classNameTest','className-test'.camelize());
|
||||
this.assertEqual('classNameTest','class-nameTest'.camelize());
|
||||
|
||||
/* benchmark(function(){
|
||||
/* this.benchmark(function(){
|
||||
'class-name-test'.camelize();
|
||||
},10000); */
|
||||
}},
|
||||
},
|
||||
|
||||
testCapitalize: function() {with(this) {
|
||||
assertEqual('',''.capitalize());
|
||||
assertEqual('Ä','ä'.capitalize());
|
||||
assertEqual('A','A'.capitalize());
|
||||
assertEqual('Hello','hello'.capitalize());
|
||||
assertEqual('Hello','HELLO'.capitalize());
|
||||
assertEqual('Hello','Hello'.capitalize());
|
||||
assertEqual('Hello world','hello WORLD'.capitalize());
|
||||
}},
|
||||
testCapitalize: function() {
|
||||
this.assertEqual('',''.capitalize());
|
||||
this.assertEqual('Ä','ä'.capitalize());
|
||||
this.assertEqual('A','A'.capitalize());
|
||||
this.assertEqual('Hello','hello'.capitalize());
|
||||
this.assertEqual('Hello','HELLO'.capitalize());
|
||||
this.assertEqual('Hello','Hello'.capitalize());
|
||||
this.assertEqual('Hello world','hello WORLD'.capitalize());
|
||||
},
|
||||
|
||||
testUnderscore: function() {with(this) {
|
||||
assertEqual('', ''.underscore());
|
||||
assertEqual('_', '-'.underscore());
|
||||
assertEqual('foo', 'foo'.underscore());
|
||||
assertEqual('foo', 'Foo'.underscore());
|
||||
assertEqual('foo_bar', 'foo_bar'.underscore());
|
||||
assertEqual('border_bottom', 'borderBottom'.underscore());
|
||||
assertEqual('border_bottom_width', 'borderBottomWidth'.underscore());
|
||||
assertEqual('border_bottom_width', 'border-Bottom-Width'.underscore());
|
||||
}},
|
||||
testUnderscore: function() {
|
||||
this.assertEqual('', ''.underscore());
|
||||
this.assertEqual('_', '-'.underscore());
|
||||
this.assertEqual('foo', 'foo'.underscore());
|
||||
this.assertEqual('foo', 'Foo'.underscore());
|
||||
this.assertEqual('foo_bar', 'foo_bar'.underscore());
|
||||
this.assertEqual('border_bottom', 'borderBottom'.underscore());
|
||||
this.assertEqual('border_bottom_width', 'borderBottomWidth'.underscore());
|
||||
this.assertEqual('border_bottom_width', 'border-Bottom-Width'.underscore());
|
||||
},
|
||||
|
||||
testDasherize: function() {with(this) {
|
||||
assertEqual('', ''.dasherize());
|
||||
assertEqual('foo', 'foo'.dasherize());
|
||||
assertEqual('Foo', 'Foo'.dasherize());
|
||||
assertEqual('foo-bar', 'foo-bar'.dasherize());
|
||||
assertEqual('border-bottom-width', 'border_bottom_width'.dasherize());
|
||||
}},
|
||||
testDasherize: function() {
|
||||
this.assertEqual('', ''.dasherize());
|
||||
this.assertEqual('foo', 'foo'.dasherize());
|
||||
this.assertEqual('Foo', 'Foo'.dasherize());
|
||||
this.assertEqual('foo-bar', 'foo-bar'.dasherize());
|
||||
this.assertEqual('border-bottom-width', 'border_bottom_width'.dasherize());
|
||||
},
|
||||
|
||||
testTruncate: function() {with(this) {
|
||||
testTruncate: function() {
|
||||
var source = 'foo boo boz foo boo boz foo boo boz foo boo boz';
|
||||
assertEqual(source, source.truncate(source.length));
|
||||
assertEqual('foo boo boz foo boo boz foo...', source.truncate(0));
|
||||
assertEqual('fo...', source.truncate(5));
|
||||
assertEqual('foo b', source.truncate(5, ''));
|
||||
this.assertEqual(source, source.truncate(source.length));
|
||||
this.assertEqual('foo boo boz foo boo boz foo...', source.truncate(0));
|
||||
this.assertEqual('fo...', source.truncate(5));
|
||||
this.assertEqual('foo b', source.truncate(5, ''));
|
||||
|
||||
assert(typeof 'foo'.truncate(5) == 'string');
|
||||
assert(typeof 'foo bar baz'.truncate(5) == 'string');
|
||||
}},
|
||||
this.assert(typeof 'foo'.truncate(5) == 'string');
|
||||
this.assert(typeof 'foo bar baz'.truncate(5) == 'string');
|
||||
},
|
||||
|
||||
testStrip: function() {with(this) {
|
||||
assertEqual('hello world', ' hello world '.strip());
|
||||
assertEqual('hello world', 'hello world'.strip());
|
||||
assertEqual('hello \n world', ' hello \n world '.strip());
|
||||
assertEqual('', ' '.strip());
|
||||
}},
|
||||
testStrip: function() {
|
||||
this.assertEqual('hello world', ' hello world '.strip());
|
||||
this.assertEqual('hello world', 'hello world'.strip());
|
||||
this.assertEqual('hello \n world', ' hello \n world '.strip());
|
||||
this.assertEqual('', ' '.strip());
|
||||
},
|
||||
|
||||
testStripTags: function() {with(this) {
|
||||
assertEqual('hello world', 'hello world'.stripTags());
|
||||
assertEqual('hello world', 'hello <span>world</span>'.stripTags());
|
||||
assertEqual('hello world', '<a href="#" onclick="moo!">hello</a> world'.stripTags());
|
||||
assertEqual('hello world', 'h<b><em>e</em></b>l<i>l</i>o w<span class="moo" id="x"><b>o</b></span>rld'.stripTags());
|
||||
assertEqual('1\n2', '1\n2'.stripTags());
|
||||
}},
|
||||
testStripTags: function() {
|
||||
this.assertEqual('hello world', 'hello world'.stripTags());
|
||||
this.assertEqual('hello world', 'hello <span>world</span>'.stripTags());
|
||||
this.assertEqual('hello world', '<a href="#" onclick="moo!">hello</a> world'.stripTags());
|
||||
this.assertEqual('hello world', 'h<b><em>e</em></b>l<i>l</i>o w<span class="moo" id="x"><b>o</b></span>rld'.stripTags());
|
||||
this.assertEqual('1\n2', '1\n2'.stripTags());
|
||||
},
|
||||
|
||||
testStripScripts: function() {with(this) {
|
||||
assertEqual('foo bar', 'foo bar'.stripScripts());
|
||||
assertEqual('foo bar', ('foo <script>boo();<'+'/script>bar').stripScripts());
|
||||
assertEqual('foo bar', ('foo <script type="text/javascript">boo();\nmoo();<'+'/script>bar').stripScripts());
|
||||
}},
|
||||
testStripScripts: function() {
|
||||
this.assertEqual('foo bar', 'foo bar'.stripScripts());
|
||||
this.assertEqual('foo bar', ('foo <script>boo();<'+'/script>bar').stripScripts());
|
||||
this.assertEqual('foo bar', ('foo <script type="text/javascript">boo();\nmoo();<'+'/script>bar').stripScripts());
|
||||
},
|
||||
|
||||
testExtractScripts: function() {with(this) {
|
||||
assertEnumEqual([], 'foo bar'.extractScripts());
|
||||
assertEnumEqual(['boo();'], ('foo <script>boo();<'+'/script>bar').extractScripts());
|
||||
assertEnumEqual(['boo();','boo();\nmoo();'],
|
||||
testExtractScripts: function() {
|
||||
this.assertEnumEqual([], 'foo bar'.extractScripts());
|
||||
this.assertEnumEqual(['boo();'], ('foo <script>boo();<'+'/script>bar').extractScripts());
|
||||
this.assertEnumEqual(['boo();','boo();\nmoo();'],
|
||||
('foo <script>boo();<'+'/script><script type="text/javascript">boo();\nmoo();<'+'/script>bar').extractScripts());
|
||||
assertEnumEqual(['boo();','boo();\nmoo();'],
|
||||
this.assertEnumEqual(['boo();','boo();\nmoo();'],
|
||||
('foo <script>boo();<'+'/script>blub\nblub<script type="text/javascript">boo();\nmoo();<'+'/script>bar').extractScripts());
|
||||
}},
|
||||
},
|
||||
|
||||
testEvalScripts: function() {with(this) {
|
||||
assertEqual(0, evalScriptsCounter);
|
||||
testEvalScripts: function() {
|
||||
this.assertEqual(0, evalScriptsCounter);
|
||||
|
||||
('foo <script>evalScriptsCounter++<'+'/script>bar').evalScripts();
|
||||
assertEqual(1, evalScriptsCounter);
|
||||
this.assertEqual(1, evalScriptsCounter);
|
||||
|
||||
var stringWithScripts = '';
|
||||
(3).times(function(){ stringWithScripts += 'foo <script>evalScriptsCounter++<'+'/script>bar' });
|
||||
stringWithScripts.evalScripts();
|
||||
assertEqual(4, evalScriptsCounter);
|
||||
}},
|
||||
this.assertEqual(4, evalScriptsCounter);
|
||||
},
|
||||
|
||||
testEscapeHTML: function() {with(this) {
|
||||
assertEqual('foo bar', 'foo bar'.escapeHTML());
|
||||
assertEqual('foo <span>bar</span>', 'foo <span>bar</span>'.escapeHTML());
|
||||
assertEqual('foo ß bar', 'foo ß bar'.escapeHTML());
|
||||
testEscapeHTML: function() {
|
||||
this.assertEqual('foo bar', 'foo bar'.escapeHTML());
|
||||
this.assertEqual('foo <span>bar</span>', 'foo <span>bar</span>'.escapeHTML());
|
||||
this.assertEqual('foo ß bar', 'foo ß bar'.escapeHTML());
|
||||
|
||||
assertEqual('ウィメンズ2007\nクルーズコレクション',
|
||||
this.assertEqual('ウィメンズ2007\nクルーズコレクション',
|
||||
'ウィメンズ2007\nクルーズコレクション'.escapeHTML());
|
||||
|
||||
assertEqual('a<a href="blah">blub</a>b<span><div></div></span>cdef<strong>!!!!</strong>g',
|
||||
this.assertEqual('a<a href="blah">blub</a>b<span><div></div></span>cdef<strong>!!!!</strong>g',
|
||||
'a<a href="blah">blub</a>b<span><div></div></span>cdef<strong>!!!!</strong>g'.escapeHTML());
|
||||
|
||||
assertEqual(largeTextEscaped, largeTextUnescaped.escapeHTML());
|
||||
this.assertEqual(largeTextEscaped, largeTextUnescaped.escapeHTML());
|
||||
|
||||
assertEqual('1\n2', '1\n2'.escapeHTML());
|
||||
this.assertEqual('1\n2', '1\n2'.escapeHTML());
|
||||
|
||||
benchmark(function(){
|
||||
largeTextUnescaped.escapeHTML();
|
||||
},1000);
|
||||
}},
|
||||
this.benchmark(function() { largeTextUnescaped.escapeHTML() }, 1000);
|
||||
},
|
||||
|
||||
testUnescapeHTML: function() {with(this) {
|
||||
assertEqual('foo bar', 'foo bar'.unescapeHTML());
|
||||
assertEqual('foo <span>bar</span>', 'foo <span>bar</span>'.unescapeHTML());
|
||||
assertEqual('foo ß bar', 'foo ß bar'.unescapeHTML());
|
||||
testUnescapeHTML: function() {
|
||||
this.assertEqual('foo bar', 'foo bar'.unescapeHTML());
|
||||
this.assertEqual('foo <span>bar</span>', 'foo <span>bar</span>'.unescapeHTML());
|
||||
this.assertEqual('foo ß bar', 'foo ß bar'.unescapeHTML());
|
||||
|
||||
assertEqual('a<a href="blah">blub</a>b<span><div></div></span>cdef<strong>!!!!</strong>g',
|
||||
this.assertEqual('a<a href="blah">blub</a>b<span><div></div></span>cdef<strong>!!!!</strong>g',
|
||||
'a<a href="blah">blub</a>b<span><div></div></span>cdef<strong>!!!!</strong>g'.unescapeHTML());
|
||||
|
||||
assertEqual(largeTextUnescaped, largeTextEscaped.unescapeHTML());
|
||||
this.assertEqual(largeTextUnescaped, largeTextEscaped.unescapeHTML());
|
||||
|
||||
assertEqual('1\n2', '1\n2'.unescapeHTML());
|
||||
assertEqual('Pride & Prejudice', '<h1>Pride & Prejudice</h1>'.unescapeHTML());
|
||||
this.assertEqual('1\n2', '1\n2'.unescapeHTML());
|
||||
this.assertEqual('Pride & Prejudice', '<h1>Pride & Prejudice</h1>'.unescapeHTML());
|
||||
|
||||
benchmark(function(){
|
||||
largeTextEscaped.unescapeHTML();
|
||||
},1000);
|
||||
this.benchmark(function() { largeTextEscaped.unescapeHTML() }, 1000);
|
||||
|
||||
}},
|
||||
},
|
||||
|
||||
testTemplateEvaluation: function() {with(this) {
|
||||
testTemplateEvaluation: function() {
|
||||
var source = '<tr><td>#{name}</td><td>#{age}</td></tr>';
|
||||
var person = {name: 'Sam', age: 21};
|
||||
var template = new Template(source);
|
||||
|
||||
assertEqual('<tr><td>Sam</td><td>21</td></tr>',
|
||||
this.assertEqual('<tr><td>Sam</td><td>21</td></tr>',
|
||||
template.evaluate(person));
|
||||
assertEqual('<tr><td></td><td></td></tr>',
|
||||
this.assertEqual('<tr><td></td><td></td></tr>',
|
||||
template.evaluate({}));
|
||||
}},
|
||||
},
|
||||
|
||||
testTemplateEvaluationWithEmptyReplacement: function() {with(this) {
|
||||
testTemplateEvaluationWithEmptyReplacement: function() {
|
||||
var template = new Template('##{}');
|
||||
assertEqual('#', template.evaluate({}));
|
||||
assertEqual('#', template.evaluate({foo: 'bar'}));
|
||||
this.assertEqual('#', template.evaluate({}));
|
||||
this.assertEqual('#', template.evaluate({foo: 'bar'}));
|
||||
|
||||
template = new Template('#{}');
|
||||
assertEqual('', template.evaluate({}));
|
||||
}},
|
||||
this.assertEqual('', template.evaluate({}));
|
||||
},
|
||||
|
||||
testTemplateEvaluationWithFalses: function() {with(this) {
|
||||
testTemplateEvaluationWithFalses: function() {
|
||||
var source = '<tr><td>#{zero}</td><td>#{false_}</td><td>#{undef}</td><td>#{null_}</td><td>#{empty}</td></tr>';
|
||||
var falses = {zero:0, false_:false, undef:undefined, null_:null, empty:""};
|
||||
var template = new Template(source);
|
||||
|
||||
assertEqual('<tr><td>0</td><td>false</td><td></td><td></td><td></td></tr>',
|
||||
this.assertEqual('<tr><td>0</td><td>false</td><td></td><td></td><td></td></tr>',
|
||||
template.evaluate(falses));
|
||||
}},
|
||||
},
|
||||
|
||||
testTemplateEvaluationWithNested: function() {with(this) {
|
||||
testTemplateEvaluationWithNested: function() {
|
||||
var source = '#{name} #{manager.name} #{manager.age} #{manager.undef} #{manager.age.undef} #{colleagues.first.name}';
|
||||
var subject = { manager: { name: 'John', age: 29 }, name: 'Stephan', age: 22, colleagues: { first: { name: 'Mark' } } };
|
||||
assertEqual('Stephan', new Template('#{name}').evaluate(subject));
|
||||
assertEqual('John', new Template('#{manager.name}').evaluate(subject));
|
||||
assertEqual('29', new Template('#{manager.age}').evaluate(subject));
|
||||
assertEqual('', new Template('#{manager.undef}').evaluate(subject));
|
||||
assertEqual('', new Template('#{manager.age.undef}').evaluate(subject));
|
||||
assertEqual('Mark', new Template('#{colleagues.first.name}').evaluate(subject));
|
||||
assertEqual('Stephan John 29 Mark', new Template(source).evaluate(subject));
|
||||
}},
|
||||
var subject = { manager: { name: 'John', age: 29 }, name: 'Stephan', age: 22, colleagues: { first: { name: 'Mark' }} };
|
||||
this.assertEqual('Stephan', new Template('#{name}').evaluate(subject));
|
||||
this.assertEqual('John', new Template('#{manager.name}').evaluate(subject));
|
||||
this.assertEqual('29', new Template('#{manager.age}').evaluate(subject));
|
||||
this.assertEqual('', new Template('#{manager.undef}').evaluate(subject));
|
||||
this.assertEqual('', new Template('#{manager.age.undef}').evaluate(subject));
|
||||
this.assertEqual('Mark', new Template('#{colleagues.first.name}').evaluate(subject));
|
||||
this.assertEqual('Stephan John 29 Mark', new Template(source).evaluate(subject));
|
||||
},
|
||||
|
||||
testTemplateEvaluationWithIndexing: function() {with(this) {
|
||||
testTemplateEvaluationWithIndexing: function() {
|
||||
var source = '#{0} = #{[0]} - #{1} = #{[1]} - #{[2][0]} - #{[2].name} - #{first[0]} - #{[first][0]} - #{[\\]]} - #{first[\\]]}';
|
||||
var subject = [ 'zero', 'one', [ 'two-zero' ] ];
|
||||
subject[2].name = 'two-zero-name';
|
||||
subject.first = subject[2];
|
||||
subject[']'] = '\\';
|
||||
subject.first[']'] = 'first\\';
|
||||
assertEqual('zero', new Template('#{[0]}').evaluate(subject));
|
||||
assertEqual('one', new Template('#{[1]}').evaluate(subject));
|
||||
assertEqual('two-zero', new Template('#{[2][0]}').evaluate(subject));
|
||||
assertEqual('two-zero-name', new Template('#{[2].name}').evaluate(subject));
|
||||
assertEqual('two-zero', new Template('#{first[0]}').evaluate(subject));
|
||||
assertEqual('\\', new Template('#{[\\]]}').evaluate(subject));
|
||||
assertEqual('first\\', new Template('#{first[\\]]}').evaluate(subject));
|
||||
assertEqual('empty - empty2', new Template('#{[]} - #{m[]}').evaluate({ '': 'empty', m: {'': 'empty2'}}));
|
||||
assertEqual('zero = zero - one = one - two-zero - two-zero-name - two-zero - two-zero - \\ - first\\', new Template(source).evaluate(subject));
|
||||
}},
|
||||
this.assertEqual('zero', new Template('#{[0]}').evaluate(subject));
|
||||
this.assertEqual('one', new Template('#{[1]}').evaluate(subject));
|
||||
this.assertEqual('two-zero', new Template('#{[2][0]}').evaluate(subject));
|
||||
this.assertEqual('two-zero-name', new Template('#{[2].name}').evaluate(subject));
|
||||
this.assertEqual('two-zero', new Template('#{first[0]}').evaluate(subject));
|
||||
this.assertEqual('\\', new Template('#{[\\]]}').evaluate(subject));
|
||||
this.assertEqual('first\\', new Template('#{first[\\]]}').evaluate(subject));
|
||||
this.assertEqual('empty - empty2', new Template('#{[]} - #{m[]}').evaluate({ '': 'empty', m: {'': 'empty2'}}));
|
||||
this.assertEqual('zero = zero - one = one - two-zero - two-zero-name - two-zero - two-zero - \\ - first\\', new Template(source).evaluate(subject));
|
||||
},
|
||||
|
||||
testTemplateToTemplateReplacements: function() {with(this) {
|
||||
testTemplateToTemplateReplacements: function() {
|
||||
var source = 'My name is #{name}, my job is #{job}';
|
||||
var subject = {
|
||||
name: 'Stephan',
|
||||
getJob: function() { return 'Web developer'; },
|
||||
toTemplateReplacements: function() { return { name: this.name, job: this.getJob() } }
|
||||
};
|
||||
assertEqual('My name is Stephan, my job is Web developer', new Template(source).evaluate(subject));
|
||||
}},
|
||||
this.assertEqual('My name is Stephan, my job is Web developer', new Template(source).evaluate(subject));
|
||||
},
|
||||
|
||||
testTemplateEvaluationCombined: function() {with(this) {
|
||||
testTemplateEvaluationCombined: function() {
|
||||
var source = '#{name} is #{age} years old, managed by #{manager.name}, #{manager.age}.\n' +
|
||||
'Colleagues include #{colleagues[0].name} and #{colleagues[1].name}.';
|
||||
var subject = {
|
||||
|
@ -372,117 +368,117 @@
|
|||
manager: { name: 'John', age: 29 },
|
||||
colleagues: [ { name: 'Mark' }, { name: 'Indy' } ]
|
||||
};
|
||||
assertEqual('Stephan is 22 years old, managed by John, 29.\n' +
|
||||
this.assertEqual('Stephan is 22 years old, managed by John, 29.\n' +
|
||||
'Colleagues include Mark and Indy.',
|
||||
new Template(source).evaluate(subject));
|
||||
}},
|
||||
},
|
||||
|
||||
testInterpolate: function() {with(this) {
|
||||
testInterpolate: function() {
|
||||
var subject = { name: 'Stephan' };
|
||||
var pattern = /(^|.|\r|\n)(#\((.*?)\))/;
|
||||
assertEqual('#{name}: Stephan', '\\#{name}: #{name}'.interpolate(subject));
|
||||
assertEqual('#(name): Stephan', '\\#(name): #(name)'.interpolate(subject, pattern));
|
||||
}},
|
||||
this.assertEqual('#{name}: Stephan', '\\#{name}: #{name}'.interpolate(subject));
|
||||
this.assertEqual('#(name): Stephan', '\\#(name): #(name)'.interpolate(subject, pattern));
|
||||
},
|
||||
|
||||
testToQueryParams: function() {with(this) {
|
||||
testToQueryParams: function() {
|
||||
// only the query part
|
||||
var result = {a:undefined, b:'c'};
|
||||
assertHashEqual({}, ''.toQueryParams(), 'empty query');
|
||||
assertHashEqual({}, 'foo?'.toQueryParams(), 'empty query with URL');
|
||||
assertHashEqual(result, 'foo?a&b=c'.toQueryParams(), 'query with URL');
|
||||
assertHashEqual(result, 'foo?a&b=c#fragment'.toQueryParams(), 'query with URL and fragment');
|
||||
assertHashEqual(result, 'a;b=c'.toQueryParams(';'), 'custom delimiter');
|
||||
this.assertHashEqual({}, ''.toQueryParams(), 'empty query');
|
||||
this.assertHashEqual({}, 'foo?'.toQueryParams(), 'empty query with URL');
|
||||
this.assertHashEqual(result, 'foo?a&b=c'.toQueryParams(), 'query with URL');
|
||||
this.assertHashEqual(result, 'foo?a&b=c#fragment'.toQueryParams(), 'query with URL and fragment');
|
||||
this.assertHashEqual(result, 'a;b=c'.toQueryParams(';'), 'custom delimiter');
|
||||
|
||||
assertHashEqual({a:undefined}, 'a'.toQueryParams(), 'key without value');
|
||||
assertHashEqual({a:'b'}, 'a=b&=c'.toQueryParams(), 'empty key');
|
||||
assertHashEqual({a:'b', c:''}, 'a=b&c='.toQueryParams(), 'empty value');
|
||||
this.assertHashEqual({a:undefined}, 'a'.toQueryParams(), 'key without value');
|
||||
this.assertHashEqual({a:'b'}, 'a=b&=c'.toQueryParams(), 'empty key');
|
||||
this.assertHashEqual({a:'b', c:''}, 'a=b&c='.toQueryParams(), 'empty value');
|
||||
|
||||
assertHashEqual({'a b':'c', d:'e f', g:'h'},
|
||||
this.assertHashEqual({'a b':'c', d:'e f', g:'h'},
|
||||
'a%20b=c&d=e%20f&g=h'.toQueryParams(), 'proper decoding');
|
||||
assertHashEqual({a:'b=c=d'}, 'a=b=c=d'.toQueryParams(), 'multiple equal signs');
|
||||
assertHashEqual({a:'b', c:'d'}, '&a=b&&&c=d'.toQueryParams(), 'proper splitting');
|
||||
this.assertHashEqual({a:'b=c=d'}, 'a=b=c=d'.toQueryParams(), 'multiple equal signs');
|
||||
this.assertHashEqual({a:'b', c:'d'}, '&a=b&&&c=d'.toQueryParams(), 'proper splitting');
|
||||
|
||||
assertEnumEqual($w('r g b'), 'col=r&col=g&col=b'.toQueryParams()['col'],
|
||||
this.assertEnumEqual($w('r g b'), 'col=r&col=g&col=b'.toQueryParams()['col'],
|
||||
'collection without square brackets');
|
||||
var msg = 'empty values inside collection';
|
||||
assertEnumEqual(['r', '', 'b'], 'c=r&c=&c=b'.toQueryParams()['c'], msg);
|
||||
assertEnumEqual(['', 'blue'], 'c=&c=blue'.toQueryParams()['c'], msg);
|
||||
assertEnumEqual(['blue', ''], 'c=blue&c='.toQueryParams()['c'], msg);
|
||||
}},
|
||||
this.assertEnumEqual(['r', '', 'b'], 'c=r&c=&c=b'.toQueryParams()['c'], msg);
|
||||
this.assertEnumEqual(['', 'blue'], 'c=&c=blue'.toQueryParams()['c'], msg);
|
||||
this.assertEnumEqual(['blue', ''], 'c=blue&c='.toQueryParams()['c'], msg);
|
||||
},
|
||||
|
||||
testInspect: function() {with(this) {
|
||||
assertEqual('\'\'', ''.inspect());
|
||||
assertEqual('\'test\'', 'test'.inspect());
|
||||
assertEqual('\'test \\\'test\\\' "test"\'', 'test \'test\' "test"'.inspect());
|
||||
assertEqual('\"test \'test\' \\"test\\"\"', 'test \'test\' "test"'.inspect(true));
|
||||
assertEqual('\'\\b\\t\\n\\f\\r"\\\\\'', '\b\t\n\f\r"\\'.inspect());
|
||||
assertEqual('\"\\b\\t\\n\\f\\r\\"\\\\\"', '\b\t\n\f\r"\\'.inspect(true));
|
||||
assertEqual('\'\\b\\t\\n\\f\\r\'', '\x08\x09\x0a\x0c\x0d'.inspect());
|
||||
assertEqual('\'\\u001a\'', '\x1a'.inspect());
|
||||
}},
|
||||
testInspect: function() {
|
||||
this.assertEqual('\'\'', ''.inspect());
|
||||
this.assertEqual('\'test\'', 'test'.inspect());
|
||||
this.assertEqual('\'test \\\'test\\\' "test"\'', 'test \'test\' "test"'.inspect());
|
||||
this.assertEqual('\"test \'test\' \\"test\\"\"', 'test \'test\' "test"'.inspect(true));
|
||||
this.assertEqual('\'\\b\\t\\n\\f\\r"\\\\\'', '\b\t\n\f\r"\\'.inspect());
|
||||
this.assertEqual('\"\\b\\t\\n\\f\\r\\"\\\\\"', '\b\t\n\f\r"\\'.inspect(true));
|
||||
this.assertEqual('\'\\b\\t\\n\\f\\r\'', '\x08\x09\x0a\x0c\x0d'.inspect());
|
||||
this.assertEqual('\'\\u001a\'', '\x1a'.inspect());
|
||||
},
|
||||
|
||||
testInclude: function() {with(this) {
|
||||
assert('hello world'.include('h'));
|
||||
assert('hello world'.include('hello'));
|
||||
assert('hello world'.include('llo w'));
|
||||
assert('hello world'.include('world'));
|
||||
assert(!'hello world'.include('bye'));
|
||||
assert(!''.include('bye'));
|
||||
}},
|
||||
testInclude: function() {
|
||||
this.assert('hello world'.include('h'));
|
||||
this.assert('hello world'.include('hello'));
|
||||
this.assert('hello world'.include('llo w'));
|
||||
this.assert('hello world'.include('world'));
|
||||
this.assert(!'hello world'.include('bye'));
|
||||
this.assert(!''.include('bye'));
|
||||
},
|
||||
|
||||
testStartsWith: function() {with(this) {
|
||||
assert('hello world'.startsWith('h'));
|
||||
assert('hello world'.startsWith('hello'));
|
||||
assert(!'hello world'.startsWith('bye'));
|
||||
assert(!''.startsWith('bye'));
|
||||
assert(!'hell'.startsWith('hello'));
|
||||
}},
|
||||
testStartsWith: function() {
|
||||
this.assert('hello world'.startsWith('h'));
|
||||
this.assert('hello world'.startsWith('hello'));
|
||||
this.assert(!'hello world'.startsWith('bye'));
|
||||
this.assert(!''.startsWith('bye'));
|
||||
this.assert(!'hell'.startsWith('hello'));
|
||||
},
|
||||
|
||||
testEndsWith: function() {with(this) {
|
||||
assert('hello world'.endsWith('d'));
|
||||
assert('hello world'.endsWith(' world'));
|
||||
assert(!'hello world'.endsWith('planet'));
|
||||
assert(!''.endsWith('planet'));
|
||||
assert('hello world world'.endsWith(' world'));
|
||||
assert(!'z'.endsWith('az'));
|
||||
}},
|
||||
testEndsWith: function() {
|
||||
this.assert('hello world'.endsWith('d'));
|
||||
this.assert('hello world'.endsWith(' world'));
|
||||
this.assert(!'hello world'.endsWith('planet'));
|
||||
this.assert(!''.endsWith('planet'));
|
||||
this.assert('hello world world'.endsWith(' world'));
|
||||
this.assert(!'z'.endsWith('az'));
|
||||
},
|
||||
|
||||
testBlank: function() { with(this) {
|
||||
assert(''.blank());
|
||||
assert(' '.blank());
|
||||
assert('\t\r\n '.blank());
|
||||
assert(!'a'.blank());
|
||||
assert(!'\t y \n'.blank());
|
||||
}},
|
||||
testBlank: function() {
|
||||
this.assert(''.blank());
|
||||
this.assert(' '.blank());
|
||||
this.assert('\t\r\n '.blank());
|
||||
this.assert(!'a'.blank());
|
||||
this.assert(!'\t y \n'.blank());
|
||||
},
|
||||
|
||||
testEmpty: function() { with(this) {
|
||||
assert(''.empty());
|
||||
assert(!' '.empty());
|
||||
assert(!'\t\r\n '.empty());
|
||||
assert(!'a'.empty());
|
||||
assert(!'\t y \n'.empty());
|
||||
}},
|
||||
testEmpty: function() {
|
||||
this.assert(''.empty());
|
||||
this.assert(!' '.empty());
|
||||
this.assert(!'\t\r\n '.empty());
|
||||
this.assert(!'a'.empty());
|
||||
this.assert(!'\t y \n'.empty());
|
||||
},
|
||||
|
||||
testSucc: function() {with(this) {
|
||||
assertEqual('b', 'a'.succ());
|
||||
assertEqual('B', 'A'.succ());
|
||||
assertEqual('1', '0'.succ());
|
||||
assertEqual('abce', 'abcd'.succ());
|
||||
assertEqual('{', 'z'.succ());
|
||||
assertEqual(':', '9'.succ());
|
||||
}},
|
||||
testSucc: function() {
|
||||
this.assertEqual('b', 'a'.succ());
|
||||
this.assertEqual('B', 'A'.succ());
|
||||
this.assertEqual('1', '0'.succ());
|
||||
this.assertEqual('abce', 'abcd'.succ());
|
||||
this.assertEqual('{', 'z'.succ());
|
||||
this.assertEqual(':', '9'.succ());
|
||||
},
|
||||
|
||||
testTimes: function() {with(this) {
|
||||
testTimes: function() {
|
||||
|
||||
assertEqual('', ''.times(0));
|
||||
assertEqual('', ''.times(5));
|
||||
assertEqual('', 'a'.times(-1));
|
||||
assertEqual('', 'a'.times(0));
|
||||
assertEqual('a', 'a'.times(1));
|
||||
assertEqual('aa', 'a'.times(2));
|
||||
assertEqual('aaaaa', 'a'.times(5));
|
||||
assertEqual('foofoofoofoofoo', 'foo'.times(5));
|
||||
assertEqual('', 'foo'.times(-5));
|
||||
this.assertEqual('', ''.times(0));
|
||||
this.assertEqual('', ''.times(5));
|
||||
this.assertEqual('', 'a'.times(-1));
|
||||
this.assertEqual('', 'a'.times(0));
|
||||
this.assertEqual('a', 'a'.times(1));
|
||||
this.assertEqual('aa', 'a'.times(2));
|
||||
this.assertEqual('aaaaa', 'a'.times(5));
|
||||
this.assertEqual('foofoofoofoofoo', 'foo'.times(5));
|
||||
this.assertEqual('', 'foo'.times(-5));
|
||||
|
||||
/*window.String.prototype.oldTimes = function(count) {
|
||||
var result = '';
|
||||
|
@ -490,41 +486,41 @@
|
|||
return result;
|
||||
};
|
||||
|
||||
benchmark(function() {
|
||||
this.benchmark(function() {
|
||||
'foo'.times(15);
|
||||
}, 1000, 'new: ');
|
||||
|
||||
benchmark(function() {
|
||||
this.benchmark(function() {
|
||||
'foo'.oldTimes(15);
|
||||
}, 1000, 'previous: ');*/
|
||||
}},
|
||||
},
|
||||
|
||||
testToJSON: function() {with(this) {
|
||||
assertEqual('\"\"', ''.toJSON());
|
||||
assertEqual('\"test\"', 'test'.toJSON());
|
||||
}},
|
||||
testToJSON: function() {
|
||||
this.assertEqual('\"\"', ''.toJSON());
|
||||
this.assertEqual('\"test\"', 'test'.toJSON());
|
||||
},
|
||||
|
||||
testIsJSON: function() {with(this) {
|
||||
assert(!''.isJSON());
|
||||
assert(!' '.isJSON());
|
||||
assert('""'.isJSON());
|
||||
assert('"foo"'.isJSON());
|
||||
assert('{}'.isJSON());
|
||||
assert('[]'.isJSON());
|
||||
assert('null'.isJSON());
|
||||
assert('123'.isJSON());
|
||||
assert('true'.isJSON());
|
||||
assert('false'.isJSON());
|
||||
assert('"\\""'.isJSON());
|
||||
assert(!'\\"'.isJSON());
|
||||
assert(!'new'.isJSON());
|
||||
assert(!'\u0028\u0029'.isJSON());
|
||||
testIsJSON: function() {
|
||||
this.assert(!''.isJSON());
|
||||
this.assert(!' '.isJSON());
|
||||
this.assert('""'.isJSON());
|
||||
this.assert('"foo"'.isJSON());
|
||||
this.assert('{}'.isJSON());
|
||||
this.assert('[]'.isJSON());
|
||||
this.assert('null'.isJSON());
|
||||
this.assert('123'.isJSON());
|
||||
this.assert('true'.isJSON());
|
||||
this.assert('false'.isJSON());
|
||||
this.assert('"\\""'.isJSON());
|
||||
this.assert(!'\\"'.isJSON());
|
||||
this.assert(!'new'.isJSON());
|
||||
this.assert(!'\u0028\u0029'.isJSON());
|
||||
// we use '@' as a placeholder for characters authorized only inside brackets,
|
||||
// so this tests make sure it is not considered authorized elsewhere.
|
||||
assert(!'@'.isJSON());
|
||||
}},
|
||||
this.assert(!'@'.isJSON());
|
||||
},
|
||||
|
||||
testEvalJSON: function() {with(this) {
|
||||
testEvalJSON: function() {
|
||||
var valid = '{"test": \n\r"hello world!"}';
|
||||
var invalid = '{"test": "hello world!"';
|
||||
var dangerous = '{});attackTarget = "attack succeeded!";({}';
|
||||
|
@ -535,37 +531,37 @@
|
|||
var object = '{' + longString + ': ' + longString + '},';
|
||||
var huge = '[' + object.times(size) + '{"test": 123}]';
|
||||
|
||||
assertEqual('hello world!', valid.evalJSON().test);
|
||||
assertEqual('hello world!', valid.evalJSON(true).test);
|
||||
assertRaise('SyntaxError', function(){invalid.evalJSON();});
|
||||
assertRaise('SyntaxError', function(){invalid.evalJSON(true);});
|
||||
this.assertEqual('hello world!', valid.evalJSON().test);
|
||||
this.assertEqual('hello world!', valid.evalJSON(true).test);
|
||||
this.assertRaise('SyntaxError', function() { invalid.evalJSON() });
|
||||
this.assertRaise('SyntaxError', function() { invalid.evalJSON(true) });
|
||||
|
||||
attackTarget = "scared";
|
||||
attackTarget = "scared";
|
||||
dangerous.evalJSON();
|
||||
assertEqual("attack succeeded!", attackTarget);
|
||||
this.assertEqual("attack succeeded!", attackTarget);
|
||||
|
||||
attackTarget = "Not scared!";
|
||||
assertRaise('SyntaxError', function(){dangerous.evalJSON(true)});
|
||||
assertEqual("Not scared!", attackTarget);
|
||||
this.assertRaise('SyntaxError', function(){dangerous.evalJSON(true)});
|
||||
this.assertEqual("Not scared!", attackTarget);
|
||||
|
||||
assertEqual('hello world!', ('/*-secure- \r \n ' + valid + ' \n */').evalJSON().test);
|
||||
this.assertEqual('hello world!', ('/*-secure- \r \n ' + valid + ' \n */').evalJSON().test);
|
||||
var temp = Prototype.JSONFilter;
|
||||
Prototype.JSONFilter = /^\/\*([\s\S]*)\*\/$/; // test custom delimiters.
|
||||
assertEqual('hello world!', ('/*' + valid + '*/').evalJSON().test);
|
||||
this.assertEqual('hello world!', ('/*' + valid + '*/').evalJSON().test);
|
||||
Prototype.JSONFilter = temp;
|
||||
|
||||
assertMatch(123, huge.evalJSON(true).last().test);
|
||||
this.assertMatch(123, huge.evalJSON(true).last().test);
|
||||
|
||||
assertEqual('', '""'.evalJSON());
|
||||
assertEqual('foo', '"foo"'.evalJSON());
|
||||
assert('object', typeof '{}'.evalJSON());
|
||||
assert(Object.isArray('[]'.evalJSON()));
|
||||
assertNull('null'.evalJSON());
|
||||
assert(123, '123'.evalJSON());
|
||||
assertIdentical(true, 'true'.evalJSON());
|
||||
assertIdentical(false, 'false'.evalJSON());
|
||||
assertEqual('"', '"\\""'.evalJSON());
|
||||
}}
|
||||
this.assertEqual('', '""'.evalJSON());
|
||||
this.assertEqual('foo', '"foo"'.evalJSON());
|
||||
this.assert('object', typeof '{}'.evalJSON());
|
||||
this.assert(Object.isArray('[]'.evalJSON()));
|
||||
this.assertNull('null'.evalJSON());
|
||||
this.assert(123, '123'.evalJSON());
|
||||
this.assertIdentical(true, 'true'.evalJSON());
|
||||
this.assertIdentical(false, 'false'.evalJSON());
|
||||
this.assertEqual('"', '"\\""'.evalJSON());
|
||||
}
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
|
|
|
@ -56,144 +56,142 @@
|
|||
|
||||
new Test.Unit.Runner({
|
||||
|
||||
testIsRunningFromRake: function() { with(this) {
|
||||
testIsRunningFromRake: function() {
|
||||
if (window.location.toString().startsWith('http')) {
|
||||
assert(isRunningFromRake);
|
||||
info('These tests are running from rake.')
|
||||
this.assert(this.isRunningFromRake);
|
||||
this.info('These tests are running from rake.')
|
||||
} else {
|
||||
assert(!isRunningFromRake);
|
||||
info('These tests are *not* running from rake.')
|
||||
this.assert(!this.isRunningFromRake);
|
||||
this.info('These tests are *not* running from rake.')
|
||||
}
|
||||
}},
|
||||
},
|
||||
|
||||
testBuildMessage: function() {
|
||||
this.assertEqual("'foo' 'bar'", this.buildMessage('', '? ?', 'foo', 'bar'))
|
||||
},
|
||||
|
||||
testAssertEqual: function() { with(this) {
|
||||
assertEqual(0, 0);
|
||||
assertEqual(0, 0, "test");
|
||||
testAssertEqual: function() {
|
||||
this.assertEqual(0, 0);
|
||||
this.assertEqual(0, 0, "test");
|
||||
|
||||
assertEqual(0,'0');
|
||||
assertEqual(65.0, 65);
|
||||
this.assertEqual(0,'0');
|
||||
this.assertEqual(65.0, 65);
|
||||
|
||||
assertEqual("a", "a");
|
||||
assertEqual("a", "a", "test");
|
||||
this.assertEqual("a", "a");
|
||||
this.assertEqual("a", "a", "test");
|
||||
|
||||
assertNotEqual(0, 1);
|
||||
assertNotEqual("a","b");
|
||||
assertNotEqual({},{});
|
||||
assertNotEqual([],[]);
|
||||
assertNotEqual([],{});
|
||||
}},
|
||||
this.assertNotEqual(0, 1);
|
||||
this.assertNotEqual("a","b");
|
||||
this.assertNotEqual({},{});
|
||||
this.assertNotEqual([],[]);
|
||||
this.assertNotEqual([],{});
|
||||
},
|
||||
|
||||
testAssertEnumEqual: function() { with(this) {
|
||||
assertEnumEqual([], []);
|
||||
assertEnumEqual(['a', 'b'], ['a', 'b']);
|
||||
assertEnumEqual(['1', '2'], [1, 2]);
|
||||
assertEnumNotEqual(['1', '2'], [1, 2, 3]);
|
||||
}},
|
||||
testAssertEnumEqual: function() {
|
||||
this.assertEnumEqual([], []);
|
||||
this.assertEnumEqual(['a', 'b'], ['a', 'b']);
|
||||
this.assertEnumEqual(['1', '2'], [1, 2]);
|
||||
this.assertEnumNotEqual(['1', '2'], [1, 2, 3]);
|
||||
},
|
||||
|
||||
testAssertHashEqual: function() { with(this) {
|
||||
assertHashEqual({}, {});
|
||||
assertHashEqual({a:'b'}, {a:'b'});
|
||||
assertHashEqual({a:'b', c:'d'}, {c:'d', a:'b'});
|
||||
assertHashNotEqual({a:'b', c:'d'}, {c:'d', a:'boo!'});
|
||||
}},
|
||||
testAssertHashEqual: function() {
|
||||
this.assertHashEqual({}, {});
|
||||
this.assertHashEqual({a:'b'}, {a:'b'});
|
||||
this.assertHashEqual({a:'b', c:'d'}, {c:'d', a:'b'});
|
||||
this.assertHashNotEqual({a:'b', c:'d'}, {c:'d', a:'boo!'});
|
||||
},
|
||||
|
||||
testAssertRespondsTo: function() { with(this) {
|
||||
assertRespondsTo('isNice', testObj);
|
||||
assertRespondsTo('isBroken', testObj);
|
||||
}},
|
||||
testAssertRespondsTo: function() {
|
||||
this.assertRespondsTo('isNice', testObj);
|
||||
this.assertRespondsTo('isBroken', testObj);
|
||||
},
|
||||
|
||||
testAssertIdentical: function() { with(this) {
|
||||
assertIdentical(0, 0);
|
||||
assertIdentical(0, 0, "test");
|
||||
assertIdentical(1, 1);
|
||||
assertIdentical('a', 'a');
|
||||
assertIdentical('a', 'a', "test");
|
||||
assertIdentical('', '');
|
||||
assertIdentical(undefined, undefined);
|
||||
assertIdentical(null, null);
|
||||
assertIdentical(true, true);
|
||||
assertIdentical(false, false);
|
||||
testAssertIdentical: function() {
|
||||
this.assertIdentical(0, 0);
|
||||
this.assertIdentical(0, 0, "test");
|
||||
this.assertIdentical(1, 1);
|
||||
this.assertIdentical('a', 'a');
|
||||
this.assertIdentical('a', 'a', "test");
|
||||
this.assertIdentical('', '');
|
||||
this.assertIdentical(undefined, undefined);
|
||||
this.assertIdentical(null, null);
|
||||
this.assertIdentical(true, true);
|
||||
this.assertIdentical(false, false);
|
||||
|
||||
var obj = {a:'b'};
|
||||
assertIdentical(obj, obj);
|
||||
this.assertIdentical(obj, obj);
|
||||
|
||||
assertNotIdentical({1:2,3:4},{1:2,3:4});
|
||||
this.assertNotIdentical({1:2,3:4},{1:2,3:4});
|
||||
|
||||
assertIdentical(1, 1.0); // both are typeof == 'number'
|
||||
this.assertIdentical(1, 1.0); // both are typeof == 'number'
|
||||
|
||||
assertNotIdentical(1, '1');
|
||||
assertNotIdentical(1, '1.0');
|
||||
}},
|
||||
this.assertNotIdentical(1, '1');
|
||||
this.assertNotIdentical(1, '1.0');
|
||||
},
|
||||
|
||||
testAssertNullAndAssertUndefined: function() { with(this) {
|
||||
assertNull(null);
|
||||
assertNotNull(undefined);
|
||||
assertNotNull(0);
|
||||
assertNotNull('');
|
||||
assertNotUndefined(null);
|
||||
assertUndefined(undefined);
|
||||
assertNotUndefined(0);
|
||||
assertNotUndefined('');
|
||||
assertNullOrUndefined(null);
|
||||
assertNullOrUndefined(undefined);
|
||||
assertNotNullOrUndefined(0);
|
||||
assertNotNullOrUndefined('');
|
||||
}},
|
||||
testAssertNullAndAssertUndefined: function() {
|
||||
this.assertNull(null);
|
||||
this.assertNotNull(undefined);
|
||||
this.assertNotNull(0);
|
||||
this.assertNotNull('');
|
||||
this.assertNotUndefined(null);
|
||||
this.assertUndefined(undefined);
|
||||
this.assertNotUndefined(0);
|
||||
this.assertNotUndefined('');
|
||||
this.assertNullOrUndefined(null);
|
||||
this.assertNullOrUndefined(undefined);
|
||||
this.assertNotNullOrUndefined(0);
|
||||
this.assertNotNullOrUndefined('');
|
||||
},
|
||||
|
||||
testAssertMatch: function() { with(this) {
|
||||
assertMatch(/knowmad.jpg$/, 'http://script.aculo.us/images/knowmad.jpg');
|
||||
assertMatch(/Fuc/, 'Thomas Fuchs');
|
||||
assertMatch(/^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/, '$19.95');
|
||||
assertMatch(/(\d{3}\) ?)|(\d{3}[- \.])?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/, '704-343-9330');
|
||||
assertMatch(/^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))))$/, '2001-06-16');
|
||||
assertMatch(/^((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m\s*-\s*((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m$/i, '2:00PM-2:15PM');
|
||||
assertNoMatch(/zubar/, 'foo bar');
|
||||
}},
|
||||
testAssertMatch: function() {
|
||||
this.assertMatch(/knowmad.jpg$/, 'http://script.aculo.us/images/knowmad.jpg');
|
||||
this.assertMatch(/Fuc/, 'Thomas Fuchs');
|
||||
this.assertMatch(/^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/, '$19.95');
|
||||
this.assertMatch(/(\d{3}\) ?)|(\d{3}[- \.])?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/, '704-343-9330');
|
||||
this.assertMatch(/^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))))$/, '2001-06-16');
|
||||
this.assertMatch(/^((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m\s*-\s*((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m$/i, '2:00PM-2:15PM');
|
||||
this.assertNoMatch(/zubar/, 'foo bar');
|
||||
},
|
||||
|
||||
testAssertInstanceOf: function() { with(this) {
|
||||
assertInstanceOf(String, new String);
|
||||
assertInstanceOf(RegExp, /foo/);
|
||||
assertNotInstanceOf(String, {});
|
||||
}},
|
||||
testAssertInstanceOf: function() {
|
||||
this.assertInstanceOf(String, new String);
|
||||
this.assertInstanceOf(RegExp, /foo/);
|
||||
this.assertNotInstanceOf(String, {});
|
||||
},
|
||||
|
||||
testAssertVisible: function() { with(this) {
|
||||
assertVisible('testcss1');
|
||||
assertNotVisible('testcss1_span');
|
||||
//assertNotVisible('testcss2', "Due to a Safari bug, this test fails in Safari.");
|
||||
testAssertVisible: function() {
|
||||
this.assertVisible('testcss1');
|
||||
this.assertNotVisible('testcss1_span');
|
||||
//this.assertNotVisible('testcss2', "Due to a Safari bug, this test fails in Safari.");
|
||||
|
||||
Element.hide('testcss1');
|
||||
assertNotVisible('testcss1');
|
||||
assertNotVisible('testcss1_span');
|
||||
this.assertNotVisible('testcss1');
|
||||
this.assertNotVisible('testcss1_span');
|
||||
Element.show('testcss1');
|
||||
assertVisible('testcss1');
|
||||
assertNotVisible('testcss1_span');
|
||||
this.assertVisible('testcss1');
|
||||
this.assertNotVisible('testcss1_span');
|
||||
|
||||
Element.show('testcss1_span');
|
||||
assertVisible('testcss1_span');
|
||||
this.assertVisible('testcss1_span');
|
||||
Element.hide('testcss1');
|
||||
assertNotVisible('testcss1_span'); // hidden by parent
|
||||
}},
|
||||
this.assertNotVisible('testcss1_span'); // hidden by parent
|
||||
},
|
||||
|
||||
testAssertElementsMatch: function() { with(this) {
|
||||
assertElementsMatch($$('#tlist'), '#tlist');
|
||||
assertElementMatches($('tlist'), '#tlist');
|
||||
}}
|
||||
|
||||
testAssertElementsMatch: function() {
|
||||
this.assertElementsMatch($$('#tlist'), '#tlist');
|
||||
this.assertElementMatches($('tlist'), '#tlist');
|
||||
}
|
||||
});
|
||||
|
||||
new Test.Unit.Runner({
|
||||
testDummy: function() { with(this) {
|
||||
assert(true);
|
||||
}},
|
||||
testDummy: function() {
|
||||
this.assert(true);
|
||||
},
|
||||
|
||||
testMultipleTestRunner: function() { with(this) {
|
||||
assertEqual('passed', $('testlog_2').down('td', 1).innerHTML);
|
||||
}}
|
||||
|
||||
testMultipleTestRunner: function() {
|
||||
this.assertEqual('passed', $('testlog_2').down('td', 1).innerHTML);
|
||||
}
|
||||
}, {testLog: 'testlog_2'});
|
||||
// ]]>
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue