.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / resolve-url / test / resolve-url.js
1 // Copyright 2014 Simon Lydell\r
2 // X11 (“MIT”) Licensed. (See LICENSE.)\r
3 \r
4 var test = require("tape")\r
5 \r
6 var resolveUrl = require("../")\r
7 \r
8 "use strict"\r
9 \r
10 test("resolveUrl", function(t) {\r
11 \r
12   t.plan(7)\r
13 \r
14   t.equal(typeof resolveUrl, "function", "is a function")\r
15 \r
16   t.equal(\r
17     resolveUrl("https://example.com/"),\r
18     "https://example.com/"\r
19   )\r
20 \r
21   var loc = "https://example.com/articles/resolving-urls/edit"\r
22 \r
23   t.equal(\r
24     resolveUrl(loc, "remove"),\r
25     "https://example.com/articles/resolving-urls/remove"\r
26   )\r
27 \r
28   t.equal(\r
29     resolveUrl(loc, "/static/scripts/app.js"),\r
30     "https://example.com/static/scripts/app.js"\r
31   )\r
32 \r
33   t.equal(\r
34     resolveUrl(loc, "/static/scripts/app.js", "../source-maps/app.js.map"),\r
35     "https://example.com/static/source-maps/app.js.map"\r
36   )\r
37 \r
38   t.equal(\r
39     resolveUrl(loc, "/static/scripts/app.js", "../source-maps/app.js.map", "../coffee/app.coffee"),\r
40     "https://example.com/static/coffee/app.coffee"\r
41   )\r
42 \r
43   t.equal(\r
44     resolveUrl(loc, "//cdn.example.com/jquery.js"),\r
45     "https://cdn.example.com/jquery.js"\r
46   )\r
47 \r
48 })\r
49 \r
50 test("edge cases", function(t) {\r
51 \r
52   t.plan(4)\r
53 \r
54   t["throws"](resolveUrl, /at least one argument/, "throws with no arguments")\r
55 \r
56   var accidentallyUndefined\r
57   var result\r
58   t.doesNotThrow(\r
59     function() { result = resolveUrl(accidentallyUndefined) },\r
60     "undefined is still an argument"\r
61   )\r
62   t.ok(result.match(/\/undefined$/), "undefined is stringified")\r
63 \r
64   t.equal(\r
65     resolveUrl("http://foo.org/test", undefined, {}, ["a/b"], null),\r
66     "http://foo.org/a/null",\r
67     "arguments are stringified"\r
68   )\r
69 \r
70 })\r