diff --git a/lib/Hyperlink-Redirect/Helpers.rakumod b/lib/Hyperlink-Redirect/Helpers.rakumod index a835b8f..f393233 100644 --- a/lib/Hyperlink-Redirect/Helpers.rakumod +++ b/lib/Hyperlink-Redirect/Helpers.rakumod @@ -3,7 +3,7 @@ use Libarchive::Filter :gzip; my $starts-with-protocol = rx:i/ ^https? '://'/; -sub fix-protocol($url) is export { +sub fix-protocol(Str $url) is export { return "http://" ~ $url unless $url ~~ $starts-with-protocol; return $url; diff --git a/t/01-basic.rakutest b/t/01-basic.rakutest new file mode 100644 index 0000000..8a98458 --- /dev/null +++ b/t/01-basic.rakutest @@ -0,0 +1,17 @@ +use v6.d; +use Humming-Bird::Core; +use Test; +# Local libs +use lib 'lib'; +use Hyperlink-Redirect; +use Hyperlink-Redirect::Helpers; + +plan 2; + +ok fix-protocol("seriousbusiness.international") eq "http://seriousbusiness.international", \ +"fix-protocol fixes bare domains correctly"\ +or diag "\nfix-protocol should return the same string with 'http://' prefixed if protocol isn't specified"; + +ok fix-protocol("https://www.seriousbusiness.international") eq "https://www.seriousbusiness.international",\ +"fix-protocol does not mangle correctly formatted domains"\ +or diag "\nThe URL should remain unchanged when the protocol is specified"; \ No newline at end of file