Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

prototype: Remove usage of the statement from unit tests.

  • Loading branch information...
commit c01cb850c17a36d4a48c84ec77240061ccf37c7f 1 parent 87ce153
Tobie Langel tobie authored
2  CHANGELOG
View
@@ -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]
154 ext/update_helper/prototype_update_helper.html
View
@@ -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>
276 test/unit/ajax.html
View
@@ -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>
304 test/unit/array.html
View
@@ -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);
- }},
-
- testClear: function(){ with(this) {
- assertEnumEqual([], [].clear());
- assertEnumEqual([], [1].clear());
- 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());
+ this.assertEqual(3, $A(element.childNodes).length);
+ },
+
+ testClear: function(){
+ this.assertEnumEqual([], [].clear());
+ this.assertEnumEqual([], [1].clear());
+ this.assertEnumEqual([], [1,2].clear());
+ },
+
+ 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);
- }},
-
- testFirst: function(){ with(this) {
- assertUndefined([].first());
- assertEqual(1, [1].first());
- assertEqual(1, [1,2].first());
- }},
-
- testLast: function(){ with(this) {
- assertUndefined([].last());
- assertEqual(1, [1].last());
- 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());
- }},
-
- 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());
- }},
-
- 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));
- }},
+ this.assertNotIdentical(a, b);
+ },
+
+ testFirst: function(){
+ this.assertUndefined([].first());
+ this.assertEqual(1, [1].first());
+ this.assertEqual(1, [1,2].first());
+ },
+
+ testLast: function(){
+ this.assertUndefined([].last());
+ this.assertEqual(1, [1].last());
+ this.assertEqual(2, [1,2].last());
+ },
+
+ 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(){
+ 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(){
+ 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));
- }},
-
- testInspect: function(){ with(this) {
- assertEqual('[]',[].inspect());
- assertEqual('[1]',[1].inspect());
- assertEqual('[\'a\']',['a'].inspect());
- 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']));
+ 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(){
+ this.assertEqual('[]',[].inspect());
+ this.assertEqual('[1]',[1].inspect());
+ this.assertEqual('[\'a\']',['a'].inspect());
+ this.assertEqual('[\'a\', 1]',['a',1].inspect());
+ },
+
+ 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());
- }},
-
- testReverse: function(){ with(this) {
- assertEnumEqual([], [].reverse());
- assertEnumEqual([1], [1].reverse());
- assertEnumEqual([2,1], [1,2].reverse());
- assertEnumEqual([3,2,1], [1,2,3].reverse());
- }},
-
- testSize: function(){ with(this) {
- assertEqual(4, [0, 1, 2, 3].size());
- assertEqual(0, [].size());
- }},
+ 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(){
+ 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(){
+ 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));
- }},
-
- 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));
- }},
-
- 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'));
- }}
+ 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(){
+ 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(){
+ 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'));
+ }
});
// ]]>
568 test/unit/base.html
View
@@ -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());
+ }
});
// ]]>
1,378 test/unit/dom.html
View
@@ -447,587 +447,587 @@
var props = [];
this.properties.each(function(prop) {
if (eval(prop)) props[prop] = eval(prop);
- });
+ }, this);
return props;
}
};
new Test.Unit.Runner({
- testDollarFunction: function() { with(this) {
- assertUndefined($());
+ testDollarFunction: function() {
+ this.assertUndefined($());
- assertNull(document.getElementById('noWayThisIDExists'));
- assertNull($('noWayThisIDExists'));
+ this.assertNull(document.getElementById('noWayThisIDExists'));
+ this.assertNull($('noWayThisIDExists'));
- assertIdentical(document.getElementById('testdiv'), $('testdiv'));
- assertEnumEqual([ $('testdiv'), $('container') ], $('testdiv', 'container'));
- assertEnumEqual([ $('testdiv'), undefined, $('container') ],
+ this.assertIdentical(document.getElementById('testdiv'), $('testdiv'));
+ this.assertEnumEqual([ $('testdiv'), $('container') ], $('testdiv', 'container'));
+ this.assertEnumEqual([ $('testdiv'), undefined, $('container') ],
$('testdiv', 'noWayThisIDExists', 'container'));
var elt = $('testdiv');
- assertIdentical(elt, $(elt));
- assertRespondsTo('hide', elt);
- assertRespondsTo('childOf', elt);
- }},
+ this.assertIdentical(elt, $(elt));
+ this.assertRespondsTo('hide', elt);
+ this.assertRespondsTo('childOf', elt);
+ },
- testGetElementsByClassName: function() {with(this) {
+ testGetElementsByClassName: function() {
if (document.getElementsByClassName.toString().include('[native code]')) {
- info("browser uses native getElementsByClassName; skipping tests");
+ this.info("browser uses native getElementsByClassName; skipping tests");
return;
}
var div = $('class_names'), list = $('class_names_ul');
- assertElementsMatch(document.getElementsByClassName('A'), 'p.A', 'ul#class_names_ul.A', 'li.A.C');
+ this.assertElementsMatch(document.getElementsByClassName('A'), 'p.A', 'ul#class_names_ul.A', 'li.A.C');
if (Prototype.Browser.IE)
- assertUndefined(document.getElementById('unextended').show);
-
- assertElementsMatch(div.getElementsByClassName('B'), 'ul#class_names_ul.A.B', 'div.B.C.D');
- assertElementsMatch(div.getElementsByClassName('D C B'), 'div.B.C.D');
- assertElementsMatch(div.getElementsByClassName(' D\nC\tB '), 'div.B.C.D');
- assertElementsMatch(div.getElementsByClassName($w('D C B')));
- assertElementsMatch(list.getElementsByClassName('A'), 'li.A.C');
- assertElementsMatch(list.getElementsByClassName(' A '), 'li.A.C');
- assertElementsMatch(list.getElementsByClassName('C A'), 'li.A.C');
- assertElementsMatch(list.getElementsByClassName("C\nA "), 'li.A.C');
- assertElementsMatch(list.getElementsByClassName('B'));
- assertElementsMatch(list.getElementsByClassName('1'), 'li.1');
- assertElementsMatch(list.getElementsByClassName([1]), 'li.1');
- assertElementsMatch(list.getElementsByClassName(['1 junk']));
- assertElementsMatch(list.getElementsByClassName(''));
- assertElementsMatch(list.getElementsByClassName(' '));
- assertElementsMatch(list.getElementsByClassName(['']));
- assertElementsMatch(list.getElementsByClassName([' ', '']));
- assertElementsMatch(list.getElementsByClassName({}));
+ this.assertUndefined(document.getElementById('unextended').show);
+
+ this.assertElementsMatch(div.getElementsByClassName('B'), 'ul#class_names_ul.A.B', 'div.B.C.D');
+ this.assertElementsMatch(div.getElementsByClassName('D C B'), 'div.B.C.D');
+ this.assertElementsMatch(div.getElementsByClassName(' D\nC\tB '), 'div.B.C.D');
+ this.assertElementsMatch(div.getElementsByClassName($w('D C B')));
+ this.assertElementsMatch(list.getElementsByClassName('A'), 'li.A.C');