Created
August 26, 2010 06:27
-
-
Save ericf/550925 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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