From 1bd1dff6d449ab221e191679fd8ec516b7cc1d4e Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Mon, 8 Apr 2019 19:30:35 +0200 Subject: Initial commit --- t/02-actions.t.t | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 t/02-actions.t.t (limited to 't/02-actions.t.t') diff --git a/t/02-actions.t.t b/t/02-actions.t.t new file mode 100644 index 0000000..8eae227 --- /dev/null +++ b/t/02-actions.t.t @@ -0,0 +1,77 @@ +#! /usr/bin/env perl6 + +use v6.d; + +use URL::Grammar; +use URL::Grammar::Actions; + +use Test; + +plan 2; + +subtest "https://www.tyil.nl", { + plan 8; + + my %match = URL::Grammar.parse("https://www.tyil.nl", actions => URL::Grammar::Actions.new).made; + + is %match, "https", "Scheme is 'https'"; + is %match, "www.tyil.nl", "Hostname is 'www.tyil.nl'"; + + nok %match, "URL contains no username"; + nok %match, "URL contains no password"; + nok %match, "URL contains no port"; + nok %match, "URL contains no path"; + nok %match, "URL contains no query"; + nok %match, "URL contains no fragment"; +}; + +subtest "https://tyil:donthackme\@www.tyil.nl:8443/a/path/part?foo=bar&perl=6#module", { + plan 8; + + my %match = URL::Grammar.parse( + "https://tyil:donthackme\@www.tyil.nl:8443/a/path/part?foo=bar&perl=6#module", + actions => URL::Grammar::Actions.new, + ).made; + + is %match, "https", "Scheme is 'https'"; + is %match, "tyil", "Username is 'tyil'"; + is %match, "donthackme", "Password is 'donthackme'"; + is %match, "www.tyil.nl", "Hostname is 'www.tyil.nl'"; + is %match, 8443, "Port is 8443"; + is %match, "module", "Fragment is 'module'"; + + subtest "path", { + plan 4; + + my @path = %match.list; + + is @path.elems, 3, "Path consists of 3 parts"; + is @path[0], "a", "Part 0 is 'a'"; + is @path[1], "path", "Part 1 is 'path'"; + is @path[2], "part", "Part 2 is 'part'"; + } + + subtest "query", { + plan 3; + + my %query = %match.hash; + + is %query.elems, 2, "Query consists of 2 parts"; + + subtest "foo", { + plan 2; + + ok %query:exists, "Query has a key 'foo'"; + is %query, "bar", "Value for 'foo' is 'bar'"; + } + + subtest "perl", { + plan 2; + + ok %query:exists, "Query has a key 'perl'"; + is %query, "6", "Value for 'perl' is '6'"; + } + } +} + +# vim: ft=perl6 noet -- cgit v1.1