Skip to content

Commit f5a547d

Browse files
committed
convert t/ppi_token_quote_double.t to using PPI::Test helpers
1 parent 65db67c commit f5a547d

File tree

1 file changed

+47
-51
lines changed

1 file changed

+47
-51
lines changed

t/ppi_token_quote_double.t

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,62 @@
22

33
# Unit testing for PPI::Token::Quote::Double
44

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;
159
use PPI;
1610

1711

1812
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+
}
3736
}
3837

3938

4039
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+
}
5851
}
5952

6053

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+
);
6763
}

0 commit comments

Comments
 (0)