aboutsummaryrefslogtreecommitdiff
path: root/t/03-instantiation.t
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2019-04-08 19:30:35 +0200
committerPatrick Spek <p.spek@tyil.nl>2019-04-08 19:30:35 +0200
commit1bd1dff6d449ab221e191679fd8ec516b7cc1d4e (patch)
treedbb9afa885183300b40e7cd9c29dc892aa4635c3 /t/03-instantiation.t
Initial commit
Diffstat (limited to 't/03-instantiation.t')
-rw-r--r--t/03-instantiation.t94
1 files changed, 94 insertions, 0 deletions
diff --git a/t/03-instantiation.t b/t/03-instantiation.t
new file mode 100644
index 0000000..15b7efa
--- /dev/null
+++ b/t/03-instantiation.t
@@ -0,0 +1,94 @@
+#! /usr/bin/env perl6
+
+use v6.d;
+
+use Test;
+use URL;
+
+plan 2;
+
+subtest "Object oriented", {
+ plan 2;
+
+ subtest "https://www.tyil.nl", {
+ plan 8;
+
+ my $url = URL.new(
+ scheme => "https",
+ hostname => "www.tyil.nl",
+ );
+
+ is $url.username, Str, "Username is empty";
+ is $url.password, Str, "Password is emtpy";
+ is $url.port, Int, "Port is empty";
+ is $url.path, [], "Path is empty";
+ is $url.query, {}, "Query is empty";
+ is $url.fragment, Str, "Fragment is empty";
+
+ is $url.scheme, "https", "Scheme is 'https'";
+ is $url.hostname, "www.tyil.nl", "Host is 'www.tyil.nl'";
+ }
+
+ subtest "https://tyil:donthackme\@www.tyil.nl:8443/a/path/part?foo=bar&perl=6#module", {
+ plan 8;
+
+ my $url = URL.new(
+ scheme => "https",
+ username => "tyil",
+ password => "donthackme",
+ hostname => "www.tyil.nl",
+ port => 8443,
+ path => ["a", "path", "part"],
+ query => { foo => "bar", perl => "6" },
+ fragment => "module",
+ );
+
+ is $url.scheme, "https", "Scheme is https";
+ is $url.username, "tyil", "Username is 'tyil'";
+ is $url.password, "donthackme", "Password is 'donthackme'";
+ is $url.hostname, "www.tyil.nl", "Host is www.tyil.nl";
+ is $url.port, 8443, "Port is 8443";
+ is $url.fragment, "module", "Fragment is 'module'";
+
+ subtest "path", {
+ plan 4;
+
+ my @path = $url.path;
+
+ is @path.elems, 3, "URL path part contains 3 elements";
+ is @path[0], "a", "URL path part 0 is 'a'";
+ is @path[1], "path", "URL path part 1 is 'path'";
+ is @path[2], "part", "URL path part 2 is 'part'";
+ }
+
+ subtest "query", {
+ plan 3;
+
+ my %query = $url.query;
+
+ is %query.elems, 2, "URL query part contains 2 elements";
+ is %query<foo>, "bar", "foo query is bar";
+ is %query<perl>, "6", "perl query is 6";
+ }
+ }
+}
+
+subtest "Grammar", {
+ subtest "https://www.tyil.nl", {
+ plan 8;
+
+ my $url = URL.new("https://www.tyil.nl");
+
+ is $url.username, Str, "Username is empty";
+ is $url.password, Str, "Password is emtpy";
+ is $url.port, Int, "Port is empty";
+ is $url.path, [], "Path is empty";
+ is $url.query, {}, "Query is empty";
+ is $url.fragment, Str, "Fragment is empty";
+
+ is $url.scheme, "https", "Scheme is 'https'";
+ is $url.hostname, "www.tyil.nl", "Host is 'www.tyil.nl'";
+ }
+}
+
+# vim: ft=perl6 noet