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

[gherkin-perl] Update to conform to JSON schema output specification #1552

Merged
merged 4 commits into from
May 16, 2021
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 gherkin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
### Removed

### Fixed
* [Perl] Updated to pass acceptance tests.
([#1552](https://github.com/cucumber/common/pull/1552) [ehuelsmann])

## [19.0.0] - 2021-05-15

Expand Down
2 changes: 1 addition & 1 deletion gherkin/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LANGUAGES ?= go javascript ruby java python dotnet
LANGUAGES ?= go javascript ruby java perl python dotnet
include default.mk

post-release: print-documentation-instructions
Expand Down
22 changes: 5 additions & 17 deletions gherkin/perl/lib/Gherkin/AstBuilder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ sub get_cells {
return \@cells;
}

sub get_description { return $_[1]->get_single('Description') }
sub get_description { return ($_[1]->get_single('Description') || '') }
sub get_steps { return $_[1]->get_items('Step') }

sub reject_nones {
Expand All @@ -175,19 +175,7 @@ sub reject_nones {
for my $key ( keys %$values ) {
my $value = $values->{$key};
if (defined $value) {
if (ref $value) {
if (reftype $value eq 'ARRAY') {
$defined_only->{$key} = $value
if (scalar(@$value) > 0);
}
else {
$defined_only->{$key} = $value;
}
}
elsif (not ref $value) {
$defined_only->{$key} = $value
unless "$value" eq '';
}
$defined_only->{$key} = $value;
}
}

Expand Down Expand Up @@ -228,10 +216,10 @@ sub transform_node {
{
location => $self->get_location($separator_token),
content => $content,
mediaType => $media_type,
mediaType => ($media_type eq '' ) ? undef : $media_type,
delimiter => $delimiter
}
);
);
} elsif ( $node->rule_type eq 'DataTable' ) {
my $rows = $self->get_table_rows($node);
return $self->reject_nones(
Expand Down Expand Up @@ -326,7 +314,7 @@ sub transform_node {
name => $examples_line->matched_text,
description => $description,
tableHeader => $examples_table->{'tableHeader'} || undef,
tableBody => $examples_table->{'tableBody'} || undef
tableBody => $examples_table->{'tableBody'} || []
}
);
} elsif ( $node->rule_type eq 'ExamplesTable' ) {
Expand Down
25 changes: 9 additions & 16 deletions gherkin/perl/lib/Gherkin/Pickles/Compiler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,7 @@ sub reject_nones {
for my $key ( keys %$values ) {
my $value = $values->{$key};
if (defined $value) {
if (ref $value) {
if (reftype $value eq 'ARRAY') {
$defined_only->{$key} = $value
if (scalar(@$value) > 0);
}
else {
$defined_only->{$key} = $value;
}
}
elsif (not ref $value) {
$defined_only->{$key} = $value
unless "$value" eq '';
}
$defined_only->{$key} = $value;
}
}

Expand All @@ -78,9 +66,14 @@ sub _compile_scenario {
$scenario, $language, $id_generator, $pickle_sink )
= @_;

for my $examples ( @{ $scenario->{'examples'} ||
[ { tableHeader => {},
tableBody => [ { cells => [] } ]} ] } ) {
my @examples = @{ $scenario->{'examples'} };
if (scalar @examples == 0) {
# Create an empty example in order to iterate once below
push @examples, { tableHeader => {},
tableBody => [ { cells => [] } ]};
}

for my $examples (@examples) {
my $variable_cells = $examples->{'tableHeader'}->{'cells'};

for my $values ( @{ $examples->{'tableBody'} || [] } ) {
Expand Down