[libtest-bdd-cucumber-perl] 35/52: Added temp var for langdef so the lines referring to it read a bit nicer. Reformatted changed functions with perltidy (tabs are gone now). Minor corrections to keyword regexes.

Intrigeri intrigeri at moszumanska.debian.org
Thu Jun 19 10:18:35 UTC 2014


This is an automated email from the git hooks/post-receive script.

intrigeri pushed a commit to annotated tag 0.19
in repository libtest-bdd-cucumber-perl.

commit 8f71cf553c8ea2503f8117e8e4f9f463825d70d3
Author: glauschwuffel <glauschwuffel at nomaden.org>
Date:   Sat May 31 07:47:20 2014 +0200

    Added temp var for langdef so the lines referring to it read a bit nicer. Reformatted changed functions with perltidy (tabs are gone now). Minor corrections to keyword regexes.
---
 lib/Test/BDD/Cucumber/Parser.pm | 204 +++++++++++++++++++++-------------------
 1 file changed, 108 insertions(+), 96 deletions(-)

diff --git a/lib/Test/BDD/Cucumber/Parser.pm b/lib/Test/BDD/Cucumber/Parser.pm
index d3b2d6e..d05d52c 100644
--- a/lib/Test/BDD/Cucumber/Parser.pm
+++ b/lib/Test/BDD/Cucumber/Parser.pm
@@ -128,113 +128,125 @@ sub _extract_feature_name {
 }
 
 sub _extract_conditions_of_satisfaction {
-	my ( $self, $feature, @lines ) = @_;
-
-	while ( my $line = shift( @lines ) ) {
-		next if $line->is_comment || $line->is_blank;
-
-		if ( $line->content =~ m/^((?:$self->{langdef}->{background}):|(?:$self->{langdef}->{scenario}):|@)/ ) {
-			unshift( @lines, $line );
-			last;
-		} else {
-			push( @{ $feature->satisfaction }, $line );
-		}
-	}
+    my ( $self, $feature, @lines ) = @_;
+
+    while ( my $line = shift(@lines) ) {
+        next if $line->is_comment || $line->is_blank;
+
+        my $langdef = $self->{langdef};
+        if ( $line->content =~ m/^((?:$langdef->{background}):|(?:$langdef->{scenario}):|@)/) {
+            unshift( @lines, $line );
+            last;
+        } else {
+            push( @{ $feature->satisfaction }, $line );
+        }
+    }
 
-	return $feature, $self->_remove_next_blanks( @lines );
+    return $feature, $self->_remove_next_blanks(@lines);
 }
 
 sub _extract_scenarios {
-	my ( $self, $feature, @lines ) = @_;
-	my $scenarios = 0;
-	my @scenario_tags;
-
-	while ( my $line = shift( @lines ) ) {
-		next if $line->is_comment || $line->is_blank;
-
-		if ( $line->content =~ m/^((?:$self->{langdef}->{background})|(?:$self->{langdef}->{scenario}))(?: Outline)?: ?(.+)?/ ) {
-			my ( $type, $name ) = ( $1, $2 );
-
-			# Only one background section, and it must be the first
-			if ( $scenarios++ && $type =~ m/^($self->{langdef}->{background})/ ) {
-				ouch 'parse_error', "Background not allowed after scenarios",
-					$line;
-			}
-
-			# Create the scenario
-			my $scenario = Test::BDD::Cucumber::Model::Scenario->new({
-				( $name ? ( name => $name ) : () ),
-				background => $type =~ m/^($self->{langdef}->{background})/ ? 1 : 0,
-				line       => $line,
-				tags       => [@{$feature->tags}, @scenario_tags]
-			});
-			@scenario_tags = ();
-
-			# Attempt to populate it
-			@lines = $self->_extract_steps( $feature, $scenario, @lines );
-
-			if ( $type =~ m/^($self->{langdef}->{background})/ ) {
-				$feature->background( $scenario );
-			} else {
-				push( @{ $feature->scenarios }, $scenario );
-			}
-
-		# Scenario-level tags
-		} elsif ( $line->content =~ m/^\s*\@\w/ ) {
-			my @tags = $line->content =~ m/\@([^\s]+)/g;
-			push( @scenario_tags, @tags );
-
-		} else {
-			ouch 'parse_error', "Malformed scenario line", $line;
-		}
-	}
+    my ( $self, $feature, @lines ) = @_;
+    my $scenarios = 0;
+    my @scenario_tags;
+
+    while ( my $line = shift(@lines) ) {
+        next if $line->is_comment || $line->is_blank;
+
+        my $langdef = $self->{langdef};
+        if ( $line->content =~ m/^((?:$langdef->{background})|(?:$langdef->{scenario}))(?: Outline)?: ?(.+)?/) {
+            my ( $type, $name ) = ( $1, $2 );
+
+            # Only one background section, and it must be the first
+            if ( $scenarios++ && $type =~ m/^($langdef->{background})/ ) {
+                ouch 'parse_error', "Background not allowed after scenarios",
+                  $line;
+            }
+
+            # Create the scenario
+            my $scenario = Test::BDD::Cucumber::Model::Scenario->new(
+                {
+                    ( $name ? ( name => $name ) : () ),
+                    background => $type =~ m/^($langdef->{background})/ ? 1 : 0,
+                    line => $line,
+                    tags => [ @{ $feature->tags }, @scenario_tags ]
+                }
+            );
+            @scenario_tags = ();
+
+            # Attempt to populate it
+            @lines = $self->_extract_steps( $feature, $scenario, @lines );
+
+            if ( $type =~ m/^($langdef->{background})/ ) {
+                $feature->background($scenario);
+            } else {
+                push( @{ $feature->scenarios }, $scenario );
+            }
+
+            # Scenario-level tags
+        } elsif ( $line->content =~ m/^\s*\@\w/ ) {
+            my @tags = $line->content =~ m/\@([^\s]+)/g;
+            push( @scenario_tags, @tags );
+
+        } else {
+            ouch 'parse_error', "Malformed scenario line", $line;
+        }
+    }
 
-	return $feature, $self->_remove_next_blanks( @lines );
+    return $feature, $self->_remove_next_blanks(@lines);
 }
 
 sub _extract_steps {
-	my ( $self, $feature, $scenario, @lines ) = @_;
-
-        my @givens = split( /\|/, $self->{langdef}->{given} );
-	my $last_verb = $givens[-1];
-
-	while ( my $line = shift( @lines ) ) {
-		next if $line->is_comment;
-		last if $line->is_blank;
-
-		# Conventional step?
-		if ( $line->content =~ m/^((?:$self->{langdef}->{given})|(?:$self->{langdef}->{and})|(?:$self->{langdef}->{when})|(?:$self->{langdef}->{then})|(?:$self->{langdef}->{but})) (.+)/ ) {
-			my ( $verb, $text ) = ( $1, $2 );
-			my $original_verb = $verb;
-			$verb = 'Given' if $verb =~ m/^($self->{langdef}->{given}$)/;
-			$verb = 'When' if  $verb =~ m/^($self->{langdef}->{when}$)/;
-			$verb = 'Then' if  $verb =~ m/^($self->{langdef}->{then}$)/;
-			$verb = $last_verb if $verb =~ m/^($self->{langdef}->{and}$)/ or $verb =~ m/^($self->{langdef}->{but}$)/;
+    my ( $self, $feature, $scenario, @lines ) = @_;
+
+    my $langdef   = $self->{langdef};
+    my @givens    = split( /\|/, $langdef->{given} );
+    my $last_verb = $givens[-1];
+
+    while ( my $line = shift(@lines) ) {
+        next if $line->is_comment;
+        last if $line->is_blank;
+
+        # Conventional step?
+        if ( $line->content =~
+m/^((?:$langdef->{given})|(?:$langdef->{and})|(?:$langdef->{when})|(?:$langdef->{then})|(?:$langdef->{but})) (.+)/
+          )
+        {
+            my ( $verb, $text ) = ( $1, $2 );
+            my $original_verb = $verb;
+            $verb = 'Given' if $verb =~ m/^($langdef->{given})$/;
+            $verb = 'When'  if $verb =~ m/^($langdef->{when})$/;
+            $verb = 'Then'  if $verb =~ m/^($langdef->{then})$/;
+            $verb = $last_verb
+              if $verb =~ m/^($langdef->{and})$/
+              or $verb =~ m/^($langdef->{but}$)/;
             $last_verb = $verb;
 
-			my $step = Test::BDD::Cucumber::Model::Step->new({
-				text => $text,
-				verb => $verb,
-				line => $line,
-				verb_original => $original_verb,
-			});
-
-			@lines = $self->_extract_step_data(
-				$feature, $scenario, $step, @lines );
-
-			push( @{ $scenario->steps }, $step );
-
-		# Outline data block...
-		} elsif ( $line->content =~ m/^($self->{langdef}->{examples}):$/ ) {
-			return $self->_extract_table( 6, $scenario,
-			    $self->_remove_next_blanks( @lines ));
-		} else {
-		    warn $line->content;
-			ouch 'parse_error', "Malformed step line", $line;
-		}
-	}
+            my $step = Test::BDD::Cucumber::Model::Step->new(
+                {
+                    text          => $text,
+                    verb          => $verb,
+                    line          => $line,
+                    verb_original => $original_verb,
+                }
+            );
+
+            @lines =
+              $self->_extract_step_data( $feature, $scenario, $step, @lines );
+
+            push( @{ $scenario->steps }, $step );
+
+            # Outline data block...
+        } elsif ( $line->content =~ m/^($langdef->{examples}):$/ ) {
+            return $self->_extract_table( 6, $scenario,
+                $self->_remove_next_blanks(@lines) );
+        } else {
+            warn $line->content;
+            ouch 'parse_error', "Malformed step line", $line;
+        }
+    }
 
-	return $self->_remove_next_blanks( @lines );
+    return $self->_remove_next_blanks(@lines);
 }
 
 sub _extract_step_data {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libtest-bdd-cucumber-perl.git



More information about the Pkg-perl-cvs-commits mailing list