Skip to content

Commit

Permalink
better column-quantity checking without warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Sep 12, 2024
1 parent 971a915 commit 6c4255b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/PDL/Graphics/Simple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,8 @@ sub _translate_plot {

##############################
# Now check options
barf "plot style $ptn requires $pt->{args}[0] or $pt->{args}[1] columns; you gave ".(0+@args)
if @args != $pt->{args}[0] and @args != $pt->{args}[1];
barf "plot style $ptn requires ".join(" or ", @{$pt->{args}})." columns; you gave ".(0+@args)
if !grep @args == $_, @{$pt->{args}};

if ($ptn eq 'contours' and @args == 1) {
my $cntr_cnt = 9;
Expand Down
5 changes: 5 additions & 0 deletions t/simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ for my $bounds (5, {}, [1..3], [1,1]) {
eval { PDL::Graphics::Simple::_translate_plot(undef, undef, pdl(1), {yrange => $bounds}) };
like $@, qr/must be a 2-element ARRAY/;
}
{ my @w; local $SIG{__WARN__} = sub {push @w, @_};
eval { PDL::Graphics::Simple::_translate_plot(undef, undef, with=>'lines', pdl(1), pdl(1), pdl(1)) };
like $@, qr/requires 1 or 2 columns/;
eval { PDL::Graphics::Simple::_translate_plot(undef, undef, with=>'polylines', pdl(1)) };
like $@, qr/requires 2 columns/;
is "@w", "", "no warnings";
}

##############################
# Try the simple engine and convenience interfaces...
Expand Down

0 comments on commit 6c4255b

Please sign in to comment.