Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Units: add a test case for FunctionParameters subparser #2846

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Units/simple-function-parameters.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--fields=+lK
6 changes: 6 additions & 0 deletions Units/simple-function-parameters.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
foo input.pl /^fun foo($x, $y, $z = 5) {$/;" fun language:FunctionParameters
bar input.pl /^method bar($label, $n) {$/;" method language:FunctionParameters
create_point input.pl /^fun create_point(:$x, :$y, :$color) {$/;" fun language:FunctionParameters
Derived input.pl /^package Derived {$/;" package language:Perl
Derived input.pl /^package Derived {$/;" class language:Moose
go_big input.pl /^ has 'go_big' => ($/;" attribute language:Moose class:Derived
40 changes: 40 additions & 0 deletions Units/simple-function-parameters.d/input.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Taken from https://metacpan.org/pod/Function::Parameters
use Function::Parameters;

# plain function
fun foo($x, $y, $z = 5) {
return $x + $y + $z;
}
print foo(1, 2), "\n"; # 8

# method with implicit $self
method bar($label, $n) {
return "$label: " . ($n * $self->scale);
}

# named arguments: order doesn't matter in the call
fun create_point(:$x, :$y, :$color) {
print "creating a $color point at ($x, $y)\n";
}
create_point(
color => "red",
x => 10,
y => 5,
);

package Derived {
use Function::Parameters qw(:std :modifiers);
use Moo;

extends 'Base';

has 'go_big' => (
is => 'ro',
);

# "around" method with implicit $orig and $self
around size() {
return $self->$orig() * 2 if $self->go_big;
return $self->$orig();
}
}