aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2014-11-06 09:01:22 +0000
committerStephen Blott2014-11-06 09:01:22 +0000
commitbbea4b123fe9da0511b1698f07868c27299ae24f (patch)
treeefc3f1546dc1cbcc2a30e22e45e67f122388e39f
parent7f4eb88ea2d79e670c4383120fb5e1ac139e2778 (diff)
downloadvimium-bbea4b123fe9da0511b1698f07868c27299ae24f.tar.bz2
Add (initial, basic) isUrl tests (more needed).
-rw-r--r--lib/utils.coffee6
-rw-r--r--tests/unit_tests/utils_test.coffee7
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee
index 62749496..b7f8731a 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -43,12 +43,12 @@ Utils =
# Tries to detect if :str is a valid URL.
isUrl: (str) ->
- # Starts with a scheme: URL
- return true if @hasFullUrlPrefix str
-
# Must not contain spaces
return false if ' ' in str
+ # Starts with a scheme: URL
+ return true if @hasFullUrlPrefix str
+
# More or less RFC compliant URL host part parsing. This should be sufficient for our needs
urlRegex = new RegExp(
'^(?:([^:]+)(?::([^:]+))?@)?' + # user:password (optional) => \1, \2
diff --git a/tests/unit_tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee
index b2d656ab..556f5b7a 100644
--- a/tests/unit_tests/utils_test.coffee
+++ b/tests/unit_tests/utils_test.coffee
@@ -61,6 +61,13 @@ context "hasChromePrefix",
assert.isFalse Utils.hasChromePrefix "data"
assert.isFalse Utils.hasChromePrefix "data :foobar"
+context "isUrl",
+ should "identify URLs as URLs", ->
+ assert.isTrue Utils.isUrl "http://www.example.com/blah"
+
+ should "identify non-URLs and non-URLs", ->
+ assert.isFalse Utils.isUrl "http://www.example.com/ blah"
+
context "Function currying",
should "Curry correctly", ->
foo = (a, b) -> "#{a},#{b}"