diff --git a/cpanfile b/cpanfile index 249ff52..2a20261 100644 --- a/cpanfile +++ b/cpanfile @@ -31,6 +31,7 @@ requires "JSON::MaybeXS"; requires "JSON::MaybeXS"; requires "JSON::MaybeXS"; requires "lib"; +requires "lib::relative"; requires "List::Util"; requires "List::Util"; requires "LWP::Simple"; diff --git a/t/core-plugin.t b/t/core-plugin.t index 64f6ce4..e69efa2 100644 --- a/t/core-plugin.t +++ b/t/core-plugin.t @@ -4,36 +4,10 @@ use strict; use warnings; use utf8; use Test::More; -use Test::Differences qw/ eq_or_diff /; -use Capture::Tiny qw/capture/; -use lib '.'; -my $sub = require plugins::core; +use lib::relative './lib', '../lib', '..'; +use t::simple_plugin; -sub make_said -{ - my ($body, $who, $server, $channel) = @_; - - my @args = split /\s+/, $body; - my $said = { - body => $body, - recommended_args => \@args, - }; -} - -sub check -{ - local $Test::Builder::Level = $Test::Builder::Level + 1; - my ( $body, $want, $res, $blurb ) = @_; - - my $said = make_said($body); - my ($out, $err, @result) = capture { - $sub->( $said ); - }; - - return eq_or_diff( $err, "", "no errors" ) - && eq_or_diff(\@result, $res, "Result is correct") - && eq_or_diff( $out, $want, $blurb ); -} +load_plugin("core"); check("", "usage: core Module::Here", ["handled"], "usage help"); check("CGI", "CGI Added to perl core as of 5.004 and deprecated in 5.019007", ["handled"], "deprecated"); diff --git a/t/lib/t/common.pm b/t/lib/t/common.pm new file mode 100644 index 0000000..a334f7a --- /dev/null +++ b/t/lib/t/common.pm @@ -0,0 +1,35 @@ +package t::common; + +use strict; +use warnings; +use utf8; +use parent 'Exporter'; + +our @EXPORT=qw/load_plugin make_said/; + +# This doesn't let us test multiple plugins at a time, which might be needed for the compose plugin +# This can be fixed later +our $plugin; + +sub load_plugin { + my $name = shift; + + my $fullname = "plugins/$name.pm"; + + $plugin = require $fullname; +} + +sub make_said +{ + my ($body, $who, $server, $channel) = @_; + + # TODO make this fill out a lot more of the said object + + my @args = split /\s+/, $body; + my $said = { + body => $body, + recommended_args => \@args, + }; +} + +1; diff --git a/t/lib/t/simple_plugin.pm b/t/lib/t/simple_plugin.pm new file mode 100644 index 0000000..f9f0368 --- /dev/null +++ b/t/lib/t/simple_plugin.pm @@ -0,0 +1,29 @@ +package t::simple_plugin; + +use strict; +use warnings; +use utf8; +use parent 'Exporter'; +use t::common; + +our @EXPORT=qw/load_plugin make_said check/; + +use Test::Differences qw/ eq_or_diff /; +use Capture::Tiny qw/capture/; + +sub check +{ + local $Test::Builder::Level = $Test::Builder::Level + 1; + my ( $body, $want, $res, $blurb ) = @_; + + my $said = make_said($body); + my ($out, $err, @result) = capture { + $t::common::plugin->( $said ); + }; + + return eq_or_diff( $err, "", "no errors" ) + && eq_or_diff(\@result, $res, "Result is correct") + && eq_or_diff( $out, $want, $blurb ); +} + +1; diff --git a/t/quote-plugin.t b/t/quote-plugin.t new file mode 100644 index 0000000..788c9cc --- /dev/null +++ b/t/quote-plugin.t @@ -0,0 +1,20 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; +use Test::More; +use lib::relative './lib', '../lib', '..'; +use t::simple_plugin; + +load_plugin("quote"); + +check("", "", [], "do nothing"); +check('d TESTING HERE', q{"TESTING HERE"}, [1], 'quote d simple'); +check('c TESTING HERE', q{TESTING HERE}, [1], 'quote d simple'); +check(qq{d "TESTING \nHERE"}, q{"\\x22TESTING \\x0aHERE\\x22"}, [1], 'quote d complex'); +check(qq{c "TESTING \nHERE"}, q{\\x22TESTING \\x0aHERE\\x22}, [1], 'quote c complex'); +check(qq{e "TESTING \nHERE"}, q{\\x22TESTING\\x20\\x0aHERE\\x22}, [1], 'quote e complex'); +check(qq{f "TESTING \nHERE"}, q{"\\x22TESTING\\x20\\x0aHERE\\x22"}, [1], 'quote f complex'); +check('h TESTING HERE', q{54455354494e472048455245}, [1], 'quote h'); +done_testing(); diff --git a/t/unicode-plugin.t b/t/unicode-plugin.t index d6e4ecd..f255137 100644 --- a/t/unicode-plugin.t +++ b/t/unicode-plugin.t @@ -3,34 +3,28 @@ use strict; use warnings; use utf8; -use Test::More tests => 4; -use Test::Differences qw/ eq_or_diff /; -use lib '.'; -use plugins::unicode; +use Test::More; +use lib::relative './lib', '../lib', '..'; +use t::simple_plugin; +use Encode qw/encode/; -sub check -{ - local $Test::Builder::Level = $Test::Builder::Level + 1; - my ( $body, $want, $blurb ) = @_; - my ( $err, $out ) = unip( map speng($_), split " ", $body ); - - return eq_or_diff( $err, [], "no errors" ) - && eq_or_diff( $out, $want, $blurb ); -} +load_plugin("unicode"); # TEST*2 check( "perl", - [ - "U+0070 (70): LATIN SMALL LETTER P [p]", - "U+0065 (65): LATIN SMALL LETTER E [e]", - "U+0072 (72): LATIN SMALL LETTER R [r]", - "U+006C (6c): LATIN SMALL LETTER L [l]", - ], + "U+0070 (70): LATIN SMALL LETTER P [p] ". + "U+0065 (65): LATIN SMALL LETTER E [e] ". + "U+0072 (72): LATIN SMALL LETTER R [r] ". + "U+006C (6c): LATIN SMALL LETTER L [l]\n", + [1], "ascii" ); # TEST*2 -check( "💟", [ "U+1F49F (f0 9f 92 9f): HEART DECORATION [💟]", ], - "emoji", ); +check( + "💟", + encode("utf8", "U+1F49F (f0 9f 92 9f): HEART DECORATION [💟]\n"), + [1], + "emoji" );