1#!/usr/bin/perl -w 2 3# Test slurpy parameters 4 5use strict; 6use warnings; 7 8use Test::More; 9use Test::Exception; 10 11{ 12 package Stuff; 13 use Method::Signatures; 14 use Test::More; 15 16 method slurpy(@that) { return \@that } 17 method slurpy_required(@that!) { return \@that } 18 method slurpy_last($this, @that) { return $this, \@that; } 19 20 ok !eval q[func slurpy_first(@that, $this) { return $this, \@that; }]; 21 like $@, qr{Slurpy parameter '\@that' must come at the end}; 22 TODO: { 23 local $TODO = "error message incorrect inside an eval"; 24 25 like $@, qr{Stuff::}; 26 like $@, qr{slurpy_first\(\)}; 27 } 28 29 ok !eval q[func slurpy_middle($this, @that, $other) { return $this, \@that, $other }]; 30 like $@, qr{slurpy parameter .* must come at the end}i; 31 TODO: { 32 local $TODO = "error message incorrect inside an eval"; 33 34 like $@, qr{Stuff::}; 35 like $@, qr{slurpy_middle\(\)}; 36 } 37 38 ok !eval q[func slurpy_positional(:@that) { return \@that; }]; 39 like $@, qr{slurpy parameter .* cannot be named. use a reference instead}i; 40 41 TODO: { 42 local $TODO = "error message incorrect inside an eval"; 43 44 like $@, qr{Stuff::}; 45 like $@, qr{slurpy_positional\(\)}; 46 } 47 48 ok !eval q[func slurpy_two($this, @that, @other) { return $this, \@that, \@other }]; 49 like $@, qr{can only have one slurpy parameter}; 50} 51 52 53note "Optional slurpy params accept 0 length list"; { 54 is_deeply [Stuff->slurpy()], [[]]; 55 is_deeply [Stuff->slurpy_last(23)], [23, []]; 56} 57 58note "Required slurpy params require an argument"; { 59 throws_ok { Stuff->slurpy_required() } 60 qr{slurpy_required\Q()\E, missing required argument \@that at \Q$0\E line @{[__LINE__ - 1]}}; 61} 62 63 64done_testing; 65