aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit_tests/utils_test.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_tests/utils_test.coffee')
-rw-r--r--tests/unit_tests/utils_test.coffee20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/unit_tests/utils_test.coffee b/tests/unit_tests/utils_test.coffee
new file mode 100644
index 00000000..6a44b460
--- /dev/null
+++ b/tests/unit_tests/utils_test.coffee
@@ -0,0 +1,20 @@
+require "./test_helper.js"
+extend(global, require "../../lib/utils.js")
+
+context "convertToUrl",
+ should "detect and clean up valid URLs", ->
+ assert.equal "http://www.google.com/", Utils.convertToUrl("http://www.google.com/")
+ assert.equal "http://www.google.com/", Utils.convertToUrl(" http://www.google.com/ ")
+ assert.equal "http://www.google.com", Utils.convertToUrl("www.google.com")
+ assert.equal "http://google.com", Utils.convertToUrl("google.com")
+ assert.equal "http://localhost", Utils.convertToUrl("localhost")
+ assert.equal "http://xyz.museum", Utils.convertToUrl("xyz.museum")
+ assert.equal "chrome://extensions", Utils.convertToUrl("chrome://extensions")
+ assert.equal "http://user:pass@ftp.xyz.com/test", Utils.convertToUrl("user:pass@ftp.xyz.com/test")
+ assert.equal "http://127.0.0.1", Utils.convertToUrl("127.0.0.1")
+ assert.equal "http://127.0.0.1:8080", Utils.convertToUrl("127.0.0.1:8080")
+ assert.equal "http://[::]:8080", Utils.convertToUrl("[::]:8080")
+
+ should "convert non-URL terms into search queries", ->
+ assert.equal "http://www.google.com/search?q=google", Utils.convertToUrl("google")
+ assert.equal "http://www.google.com/search?q=go%20ogle.com", Utils.convertToUrl("go ogle.com")