Skip to content

Instantly share code, notes, and snippets.

@ericf
Created August 26, 2010 06:27
Show Gist options
  • Select an option

  • Save ericf/550925 to your computer and use it in GitHub Desktop.

Select an option

Save ericf/550925 to your computer and use it in GitHub Desktop.
/**
* URLInfo Tests
*/
YUI.add('urlinfo-test', function(Y){
var suite = new Y.Test.Suite('URLInfo - Santize'),
re = /^(?:(https?:)\/\/)?(?:([^:@\s]+:?[^:@\s]+?)@)?([^:\/\s]+(?:\.[^:\/\s]{2,}){1,})(.*)/i;
function buildTestCase (name, allows, rejects) {
var config = {};
config.name = name;
config._should = {};
config._should.fail = {};
Y.each(allows, function(allow){
config[allow + ' - should allow'] = function(){
Y.assert(allow.match(re));
}
});
Y.each(rejects, function(reject){
var testName = reject + ' - should reject';
config._should.fail[testName] = true;
config[testName] = function(){
Y.assert(reject.match(re));
}
});
return new Y.Test.Case(config);
}
// *** Protocol TestCase *** //
suite.add(buildTestCase('protocol', [
// Allow
'http://example.com',
'https://example.com',
'hTTp://example.com',
'HttpS://example.com',
'example.com'
], [
// Reject
'asdf://example.com',
'//example.com',
'http:example.com'
]));
Y.Test.Runner.add(suite);
}, '@VERSION@', { requires: ['test'] });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment