|
2 | 2 |
|
3 | 3 | # Unit testing for PPI::Token::Quote::Double
|
4 | 4 |
|
5 |
| -use strict; |
6 |
| -BEGIN { |
7 |
| - $| = 1; |
8 |
| - $^W = 1; |
9 |
| - no warnings 'once'; |
10 |
| - $PPI::XS_DISABLE = 1; |
11 |
| - $PPI::Lexer::X_TOKENIZER ||= $ENV{X_TOKENIZER}; |
12 |
| -} |
13 |
| -use Test::More tests => 20; |
14 |
| -use Test::NoWarnings; |
| 5 | +use lib 't/lib'; |
| 6 | +use PPI::Test::pragmas; |
| 7 | +use PPI::Test qw( :cmp ); |
| 8 | +use Test::More tests => 14; |
15 | 9 | use PPI;
|
16 | 10 |
|
17 | 11 |
|
18 | 12 | INTERPOLATIONS: {
|
19 |
| - # Get a set of objects |
20 |
| - my $Document = PPI::Document->new(\<<'END_PERL'); |
21 |
| -"no interpolations" |
22 |
| -"no \@interpolations" |
23 |
| -"has $interpolation" |
24 |
| -"has @interpolation" |
25 |
| -"has \\@interpolation" |
26 |
| -"" # False content to test double-negation scoping |
27 |
| -END_PERL |
28 |
| - isa_ok( $Document, 'PPI::Document' ); |
29 |
| - my $strings = $Document->find('Token::Quote::Double'); |
30 |
| - is( scalar @{$strings}, 6, 'Found the 6 test strings' ); |
31 |
| - is( $strings->[0]->interpolations, '', 'String 1: No interpolations' ); |
32 |
| - is( $strings->[1]->interpolations, '', 'String 2: No interpolations' ); |
33 |
| - is( $strings->[2]->interpolations, 1, 'String 3: Has interpolations' ); |
34 |
| - is( $strings->[3]->interpolations, 1, 'String 4: Has interpolations' ); |
35 |
| - is( $strings->[4]->interpolations, 1, 'String 5: Has interpolations' ); |
36 |
| - is( $strings->[5]->interpolations, '', 'String 6: No interpolations' ); |
| 13 | + for my $test ( |
| 14 | + { interpolations => '', code => '"no interpolations"' }, |
| 15 | + { interpolations => '', code => '"no \@interpolations"' }, |
| 16 | + { interpolations => 1, code => '"has $interpolation"' }, |
| 17 | + { interpolations => 1, code => '"has @interpolation"' }, |
| 18 | + { interpolations => 1, code => '"has \\\\@interpolation"' }, |
| 19 | + { |
| 20 | + interpolations => '', |
| 21 | + code => '"" # False content to test double-negation scoping', |
| 22 | + content => '""', |
| 23 | + STOP => 1, |
| 24 | + }, |
| 25 | + ) { |
| 26 | + my $code = delete $test->{code}; |
| 27 | + cmp_element( |
| 28 | + $code, |
| 29 | + { |
| 30 | + class => 'PPI::Token::Quote::Double', |
| 31 | + content => $code, |
| 32 | + %$test, |
| 33 | + } |
| 34 | + ); |
| 35 | + } |
37 | 36 | }
|
38 | 37 |
|
39 | 38 |
|
40 | 39 | SIMPLIFY: {
|
41 |
| - my $Document = PPI::Document->new(\<<'END_PERL'); |
42 |
| -"no special characters" |
43 |
| -"has \"double\" quotes" |
44 |
| -"has 'single' quotes" |
45 |
| -"has $interpolation" |
46 |
| -"has @interpolation" |
47 |
| -"" |
48 |
| -END_PERL |
49 |
| - isa_ok( $Document, 'PPI::Document' ); |
50 |
| - my $strings = $Document->find('Token::Quote::Double'); |
51 |
| - is( scalar @{$strings}, 6, 'Found the 6 test strings' ); |
52 |
| - is( $strings->[0]->simplify, q<'no special characters'>, 'String 1: No special characters' ); |
53 |
| - is( $strings->[1]->simplify, q<"has \"double\" quotes">, 'String 2: Double quotes' ); |
54 |
| - is( $strings->[2]->simplify, q<"has 'single' quotes">, 'String 3: Single quotes' ); |
55 |
| - is( $strings->[3]->simplify, q<"has $interpolation">, 'String 3: Has interpolation' ); |
56 |
| - is( $strings->[4]->simplify, q<"has @interpolation">, 'String 4: Has interpolation' ); |
57 |
| - is( $strings->[5]->simplify, q<''>, 'String 6: Empty string' ); |
| 40 | + for my $test ( |
| 41 | + { code => '"no special characters"', simplify => q<'no special characters'>, }, |
| 42 | + { code => '"has \"double\" quotes"', simplify => q<"has \"double\" quotes">, }, |
| 43 | + { code => '"has \'single\' quotes"', simplify => q<"has 'single' quotes">, }, |
| 44 | + { code => '"has $interpolation"', simplify => q<"has $interpolation">, }, |
| 45 | + { code => '"has @interpolation"', simplify => q<"has @interpolation">, }, |
| 46 | + { code => '""', simplify => q<''>, }, |
| 47 | + ) { |
| 48 | + my $code = delete $test->{code}; |
| 49 | + cmp_element( $code, { class => 'PPI::Token::Quote::Double', %$test } ); |
| 50 | + } |
58 | 51 | }
|
59 | 52 |
|
60 | 53 |
|
61 |
| -STRING: { |
62 |
| - my $Document = PPI::Document->new( \'print "foo";' ); |
63 |
| - isa_ok( $Document, 'PPI::Document' ); |
64 |
| - my $Double = $Document->find_first('Token::Quote::Double'); |
65 |
| - isa_ok( $Double, 'PPI::Token::Quote::Double' ); |
66 |
| - is( $Double->string, 'foo', '->string returns as expected' ); |
| 54 | +PARSING: { |
| 55 | + cmp_selement( |
| 56 | + 'print "foo";', |
| 57 | + [ |
| 58 | + { class => 'PPI::Token::Word', content => 'print' }, |
| 59 | + { class => 'PPI::Token::Quote::Double', content => '"foo"' }, |
| 60 | + { class => 'PPI::Token::Structure', content => ';' }, |
| 61 | + ] |
| 62 | + ); |
67 | 63 | }
|
0 commit comments