File Coverage

examples/i18n_de/features/step_definitions/calculator_steps.pl
Criterion Covered Total %
statement 214 214 100.0
branch n/a
condition n/a
subroutine 55 55 100.0
pod 0 1 0.0
total 269 270 99.6


line stmt bran cond sub pod time code
1             #!perl
2              
3 2     2   15 use strict;
  2         5  
  2         70  
4 2     2   8 use warnings;
  2         4  
  2         83  
5 2     2   10 use utf8; # Interpret funky German chars in regexes properly
  2         3  
  2         15  
6              
7 2     2   78 use Test::More;
  2         4  
  2         20  
8 2     2   566 use Test::BDD::Cucumber::StepFile;
  2         4  
  2         2250  
9              
10 2     2   31 use lib 'examples/calculator/lib/';
  2         3  
  2         13  
11              
12             Before sub {
13 2     2   1143 use_ok('Calculator');
  2     2   8  
  2     2   6  
  2     2   82  
  2     2   585  
  2     2   34  
  2     2   6  
  2     2   43  
  2     2   698  
  2     2   6  
  2     2   5  
  2     2   40  
  2     1   543  
  2     1   7  
  2     1   5  
  2     1   38  
  2     1   593  
  2     1   6  
  2     1   6  
  2     1   38  
  2     1   537  
  2     1   6  
  2     1   6  
  2     1   39  
  2     1   594  
  2     1   6  
  2     1   6  
  2     1   77  
  2     1   560  
  2     1   6  
  2     1   6  
  2     1   69  
  2     1   612  
  2     1   6  
  2     1   5  
  2     1   39  
  2     1   564  
  2     1   6  
  2     1   5  
  2     1   42  
  2     1   562  
  2     1   7  
  2     1   5  
  2     1   40  
  2     1   485  
  2     1   7  
  2     1   5  
  2     1   58  
  1         315  
  1         3  
  1         2  
  1         22  
  1         298  
  1         3  
  1         2  
  1         21  
  1         162  
  1         2  
  1         2  
  1         14  
  1         160  
  1         3  
  1         1  
  1         13  
  1         167  
  1         2  
  1         2  
  1         13  
  1         266  
  1         3  
  1         3  
  1         19  
  1         253  
  1         3  
  1         4  
  1         18  
  1         292  
  1         4  
  1         4  
  1         22  
  1         313  
  1         4  
  1         4  
  1         20  
  1         268  
  1         3  
  1         3  
  1         54  
  1         166  
  1         2  
  1         1  
  1         13  
  1         180  
  1         2  
  1         3  
  1         15  
  1         306  
  1         3  
  1         3  
  1         20  
  1         173  
  1         2  
  1         2  
  1         13  
  1         179  
  1         2  
  1         4  
  1         18  
  1         167  
  1         2  
  1         1  
  1         13  
  1         176  
  1         3  
  1         1  
  1         14  
  1         162  
  1         2  
  1         1  
  1         14  
  1         298  
  1         3  
  1         3  
  1         20  
  1         170  
  1         2  
  1         2  
  1         14  
  1         174  
  1         2  
  1         2  
  1         13  
  1         224  
  1         3  
  1         2  
  1         13  
  1         163  
  1         2  
  1         2  
  1         13  
  1         177  
  1         2  
  1         2  
  1         15  
  1         245  
  1         2  
  1         3  
  1         20  
  1         278  
  1         3  
  1         3  
  1         23  
  1         263  
  1         3  
  1         4  
  1         21  
  1         185  
  1         4  
  1         2  
  1         14  
  1         279  
  1         3  
  1         3  
  1         20  
  1         263  
  1         4  
  1         2  
  1         21  
  1         250  
  1         4  
  1         3  
  1         20  
  1         171  
  1         2  
  1         2  
  1         13  
  1         162  
  1         2  
  1         3  
  1         20  
  1         183  
  1         2  
  1         1  
  1         14  
  1         190  
  1         1  
  1         2  
  1         14  
  1         247  
  1         3  
  1         3  
  1         19  
14             };
15              
16             After sub {
17              
18             # a bit contrived, as garbage collection would clear it out
19             delete S->{'Calculator'};
20             ok( not exists S->{'Calculator'} );
21             };
22              
23             my %numbers_as_words = (
24             __THE_NUMBER_ONE__ => 1,
25             __THE_NUMBER_FOUR__ => 4,
26             __THE_NUMBER_FIVE__ => 5,
27             __THE_NUMBER_TEN__ => 10,
28             );
29              
30             sub map_word_to_number_i18n {
31 15     15 0 46 my $word = shift;
32              
33 15         72 ok($word);
34 15         9233 ok( exists $numbers_as_words{$word} );
35              
36 15         8109 return $numbers_as_words{$word};
37             }
38              
39             Transform qr/^(__THE_NUMBER_\w+__)$/, sub { map_word_to_number_i18n($1) };
40              
41             Transform qr/^table:number as word$/, sub {
42             my ( $c, $data ) = @_;
43              
44             for my $row ( @{$data} ) {
45             $row->{'number'} = map_word_to_number_i18n( $row->{'number as word'} );
46             }
47             };
48              
49             Gegebensei 'ein neues Objekt der Klasse Calculator', sub {
50             S->{'Calculator'} = Calculator->new();
51             };
52              
53             Wenn qr/^ich (.+) gedrückt habe/, sub {
54             S->{'Calculator'}->press($_) for split( /(,| und) /, C->matches->[0] );
55             };
56              
57             Wenn qr/^die Tasten (.+) gedrückt wurden/, sub {
58              
59             # Make this call the having pressed
60             my ($value) = @{ C->matches };
61             S->{'Calculator'}->key_in($value);
62             };
63              
64             Wenn 'ich erfolgreich folgende Rechnungen durchgeführt habe', sub {
65             my $calculator = S->{'Calculator'};
66              
67             for my $row ( @{ C->data } ) {
68             $calculator->key_in( $row->{'first'} );
69             $calculator->key_in( $row->{'operator'} );
70             $calculator->key_in( $row->{'second'} );
71             $calculator->press('=');
72              
73             is( $calculator->display, $row->{'result'},
74             $row->{'first'} . ' '
75             . $row->{'operator'} . ' '
76             . $row->{'second'} );
77             }
78             };
79              
80             Wenn 'ich folgende Zeichenfolge eingegeben habe', sub {
81             S->{'Calculator'}->key_in( C->data );
82             };
83              
84             Wenn 'ich folgende Zahlen addiert habe', sub {
85             for my $row ( @{ C->data } ) {
86             S->{'Calculator'}->key_in( $row->{number} );
87             S->{'Calculator'}->key_in('+');
88             }
89             };
90              
91             Dann qr/^ist auf der Anzeige (.+) zu sehen/, sub {
92             my ($value) = @{ C->matches };
93             is( S->{'Calculator'}->display, $value, "Calculator display as expected" );
94             };