Skip to content

Commit

Permalink
Merge pull request #1552 from cucumber/update-perl-json-schema
Browse files Browse the repository at this point in the history
[gherkin-perl] Update to conform to JSON schema output specification
  • Loading branch information
ehuelsmann committed May 16, 2021
2 parents 7e1f06e + 5400fef commit ad565c6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 34 deletions.
2 changes: 2 additions & 0 deletions gherkin/CHANGELOG.md
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
@@ -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
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
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

0 comments on commit ad565c6

Please sign in to comment.