From c0b5b9755057bfdca4f050b8030f9812523807f1 Mon Sep 17 00:00:00 2001 From: Mike O'Regan Date: Wed, 5 Mar 2014 19:16:03 -0600 Subject: [PATCH] convert t/ppi_token_quote_double.t to using PPI::Test helpers --- t/ppi_token_quote_double.t | 98 ++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 51 deletions(-) diff --git a/t/ppi_token_quote_double.t b/t/ppi_token_quote_double.t index b83e9226..713027c3 100644 --- a/t/ppi_token_quote_double.t +++ b/t/ppi_token_quote_double.t @@ -2,66 +2,62 @@ # Unit testing for PPI::Token::Quote::Double -use strict; -BEGIN { - $| = 1; - $^W = 1; - no warnings 'once'; - $PPI::XS_DISABLE = 1; - $PPI::Lexer::X_TOKENIZER ||= $ENV{X_TOKENIZER}; -} -use Test::More tests => 20; -use Test::NoWarnings; +use lib 't/lib'; +use PPI::Test::pragmas; +use PPI::Test qw( :cmp ); +use Test::More tests => 14; use PPI; INTERPOLATIONS: { - # Get a set of objects - my $Document = PPI::Document->new(\<<'END_PERL'); -"no interpolations" -"no \@interpolations" -"has $interpolation" -"has @interpolation" -"has \\@interpolation" -"" # False content to test double-negation scoping -END_PERL - isa_ok( $Document, 'PPI::Document' ); - my $strings = $Document->find('Token::Quote::Double'); - is( scalar @{$strings}, 6, 'Found the 6 test strings' ); - is( $strings->[0]->interpolations, '', 'String 1: No interpolations' ); - is( $strings->[1]->interpolations, '', 'String 2: No interpolations' ); - is( $strings->[2]->interpolations, 1, 'String 3: Has interpolations' ); - is( $strings->[3]->interpolations, 1, 'String 4: Has interpolations' ); - is( $strings->[4]->interpolations, 1, 'String 5: Has interpolations' ); - is( $strings->[5]->interpolations, '', 'String 6: No interpolations' ); + for my $test ( + { interpolations => '', code => '"no interpolations"' }, + { interpolations => '', code => '"no \@interpolations"' }, + { interpolations => 1, code => '"has $interpolation"' }, + { interpolations => 1, code => '"has @interpolation"' }, + { interpolations => 1, code => '"has \\\\@interpolation"' }, + { + interpolations => '', + code => '"" # False content to test double-negation scoping', + content => '""', + STOP => 1, + }, + ) { + my $code = delete $test->{code}; + cmp_element( + $code, + { + class => 'PPI::Token::Quote::Double', + content => $code, + %$test, + } + ); + } } SIMPLIFY: { - my $Document = PPI::Document->new(\<<'END_PERL'); -"no special characters" -"has \"double\" quotes" -"has 'single' quotes" -"has $interpolation" -"has @interpolation" -"" -END_PERL - isa_ok( $Document, 'PPI::Document' ); - my $strings = $Document->find('Token::Quote::Double'); - is( scalar @{$strings}, 6, 'Found the 6 test strings' ); - is( $strings->[0]->simplify, q<'no special characters'>, 'String 1: No special characters' ); - is( $strings->[1]->simplify, q<"has \"double\" quotes">, 'String 2: Double quotes' ); - is( $strings->[2]->simplify, q<"has 'single' quotes">, 'String 3: Single quotes' ); - is( $strings->[3]->simplify, q<"has $interpolation">, 'String 3: Has interpolation' ); - is( $strings->[4]->simplify, q<"has @interpolation">, 'String 4: Has interpolation' ); - is( $strings->[5]->simplify, q<''>, 'String 6: Empty string' ); + for my $test ( + { code => '"no special characters"', simplify => q<'no special characters'>, }, + { code => '"has \"double\" quotes"', simplify => q<"has \"double\" quotes">, }, + { code => '"has \'single\' quotes"', simplify => q<"has 'single' quotes">, }, + { code => '"has $interpolation"', simplify => q<"has $interpolation">, }, + { code => '"has @interpolation"', simplify => q<"has @interpolation">, }, + { code => '""', simplify => q<''>, }, + ) { + my $code = delete $test->{code}; + cmp_element( $code, { class => 'PPI::Token::Quote::Double', %$test } ); + } } -STRING: { - my $Document = PPI::Document->new( \'print "foo";' ); - isa_ok( $Document, 'PPI::Document' ); - my $Double = $Document->find_first('Token::Quote::Double'); - isa_ok( $Double, 'PPI::Token::Quote::Double' ); - is( $Double->string, 'foo', '->string returns as expected' ); +PARSING: { + cmp_selement( + 'print "foo";', + [ + { class => 'PPI::Token::Word', content => 'print' }, + { class => 'PPI::Token::Quote::Double', content => '"foo"' }, + { class => 'PPI::Token::Structure', content => ';' }, + ] + ); }