diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-10-04 20:28:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-04 20:28:51 -0400 |
commit | b81e5db17aa8b3088d6034ddf86b79c69410f012 (patch) | |
tree | 579e4c23d60d1b0d038156bc28a04f74ea87b2f0 /js/url_test.ts | |
parent | 9049213867d30f7df090a83b6baf3e0717a4d2d2 (diff) |
Merge deno_cli_snapshots into deno_cli (#3064)
Diffstat (limited to 'js/url_test.ts')
-rw-r--r-- | js/url_test.ts | 181 |
1 files changed, 0 insertions, 181 deletions
diff --git a/js/url_test.ts b/js/url_test.ts deleted file mode 100644 index 07a8028ce..000000000 --- a/js/url_test.ts +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { test, assert, assertEquals } from "./test_util.ts"; - -test(function urlParsing(): void { - const url = new URL( - "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat" - ); - assertEquals(url.hash, "#qat"); - assertEquals(url.host, "baz.qat:8000"); - assertEquals(url.hostname, "baz.qat"); - assertEquals( - url.href, - "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat" - ); - assertEquals(url.origin, "https://baz.qat:8000"); - assertEquals(url.password, "bar"); - assertEquals(url.pathname, "/qux/quux"); - assertEquals(url.port, "8000"); - assertEquals(url.protocol, "https:"); - assertEquals(url.search, "?foo=bar&baz=12"); - assertEquals(url.searchParams.getAll("foo"), ["bar"]); - assertEquals(url.searchParams.getAll("baz"), ["12"]); - assertEquals(url.username, "foo"); - assertEquals( - String(url), - "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat" - ); - assertEquals( - JSON.stringify({ key: url }), - `{"key":"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat"}` - ); -}); - -test(function urlModifications(): void { - const url = new URL( - "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat" - ); - url.hash = ""; - assertEquals( - url.href, - "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12" - ); - url.host = "qat.baz:8080"; - assertEquals( - url.href, - "https://foo:bar@qat.baz:8080/qux/quux?foo=bar&baz=12" - ); - url.hostname = "foo.bar"; - assertEquals( - url.href, - "https://foo:bar@foo.bar:8080/qux/quux?foo=bar&baz=12" - ); - url.password = "qux"; - assertEquals( - url.href, - "https://foo:qux@foo.bar:8080/qux/quux?foo=bar&baz=12" - ); - url.pathname = "/foo/bar%qat"; - assertEquals( - url.href, - "https://foo:qux@foo.bar:8080/foo/bar%qat?foo=bar&baz=12" - ); - url.port = ""; - assertEquals(url.href, "https://foo:qux@foo.bar/foo/bar%qat?foo=bar&baz=12"); - url.protocol = "http:"; - assertEquals(url.href, "http://foo:qux@foo.bar/foo/bar%qat?foo=bar&baz=12"); - url.search = "?foo=bar&foo=baz"; - assertEquals(url.href, "http://foo:qux@foo.bar/foo/bar%qat?foo=bar&foo=baz"); - assertEquals(url.searchParams.getAll("foo"), ["bar", "baz"]); - url.username = "foo@bar"; - assertEquals( - url.href, - "http://foo%40bar:qux@foo.bar/foo/bar%qat?foo=bar&foo=baz" - ); - url.searchParams.set("bar", "qat"); - assertEquals( - url.href, - "http://foo%40bar:qux@foo.bar/foo/bar%qat?foo=bar&foo=baz&bar=qat" - ); - url.searchParams.delete("foo"); - assertEquals(url.href, "http://foo%40bar:qux@foo.bar/foo/bar%qat?bar=qat"); - url.searchParams.append("foo", "bar"); - assertEquals( - url.href, - "http://foo%40bar:qux@foo.bar/foo/bar%qat?bar=qat&foo=bar" - ); -}); - -test(function urlModifyHref(): void { - const url = new URL("http://example.com/"); - url.href = "https://foo:bar@example.com:8080/baz/qat#qux"; - assertEquals(url.protocol, "https:"); - assertEquals(url.username, "foo"); - assertEquals(url.password, "bar"); - assertEquals(url.host, "example.com:8080"); - assertEquals(url.hostname, "example.com"); - assertEquals(url.pathname, "/baz/qat"); - assertEquals(url.hash, "#qux"); -}); - -test(function urlModifyPathname(): void { - const url = new URL("http://foo.bar/baz%qat/qux%quux"); - assertEquals(url.pathname, "/baz%qat/qux%quux"); - url.pathname = url.pathname; - assertEquals(url.pathname, "/baz%qat/qux%quux"); - url.pathname = "baz#qat qux"; - assertEquals(url.pathname, "/baz%23qat%20qux"); - url.pathname = url.pathname; - assertEquals(url.pathname, "/baz%23qat%20qux"); -}); - -test(function urlModifyHash(): void { - const url = new URL("http://foo.bar"); - url.hash = "%foo bar/qat%qux#bar"; - assertEquals(url.hash, "#%foo%20bar/qat%qux#bar"); - url.hash = url.hash; - assertEquals(url.hash, "#%foo%20bar/qat%qux#bar"); -}); - -test(function urlSearchParamsReuse(): void { - const url = new URL( - "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat" - ); - const sp = url.searchParams; - url.host = "baz.qat"; - assert(sp === url.searchParams, "Search params should be reused."); -}); - -test(function urlBaseURL(): void { - const base = new URL( - "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat" - ); - const url = new URL("/foo/bar?baz=foo#qux", base); - assertEquals(url.href, "https://foo:bar@baz.qat:8000/foo/bar?baz=foo#qux"); -}); - -test(function urlBaseString(): void { - const url = new URL( - "/foo/bar?baz=foo#qux", - "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat" - ); - assertEquals(url.href, "https://foo:bar@baz.qat:8000/foo/bar?baz=foo#qux"); -}); - -test(function urlRelativeWithBase(): void { - assertEquals(new URL("", "file:///a/a/a").href, "file:///a/a/a"); - assertEquals(new URL(".", "file:///a/a/a").href, "file:///a/a/"); - assertEquals(new URL("..", "file:///a/a/a").href, "file:///a/"); - assertEquals(new URL("b", "file:///a/a/a").href, "file:///a/a/b"); - assertEquals(new URL("b", "file:///a/a/a/").href, "file:///a/a/a/b"); - assertEquals(new URL("b/", "file:///a/a/a").href, "file:///a/a/b/"); - assertEquals(new URL("../b", "file:///a/a/a").href, "file:///a/b"); -}); - -test(function emptyBasePath(): void { - assertEquals(new URL("", "http://example.com").href, "http://example.com/"); -}); - -test(function deletingAllParamsRemovesQuestionMarkFromURL(): void { - const url = new URL("http://example.com/?param1¶m2"); - url.searchParams.delete("param1"); - url.searchParams.delete("param2"); - assertEquals(url.href, "http://example.com/"); - assertEquals(url.search, ""); -}); - -test(function removingNonExistentParamRemovesQuestionMarkFromURL(): void { - const url = new URL("http://example.com/?"); - assertEquals(url.href, "http://example.com/?"); - url.searchParams.delete("param1"); - assertEquals(url.href, "http://example.com/"); - assertEquals(url.search, ""); -}); - -test(function sortingNonExistentParamRemovesQuestionMarkFromURL(): void { - const url = new URL("http://example.com/?"); - assertEquals(url.href, "http://example.com/?"); - url.searchParams.sort(); - assertEquals(url.href, "http://example.com/"); - assertEquals(url.search, ""); -}); |