1# Before `make install' is performed this script should be runnable with 2# `make test'. After `make install' it should work as `perl test.pl' 3 4use 5.008001; 5 6use strict; 7use warnings; 8 9######################### We start with some black magic to print on failure. 10 11# Change 1..1 below to 1..last_test_to_print . 12# (It may become useful if the test is moved to ./t subdirectory.) 13 14my $loaded = 0; 15BEGIN { $| = 1; print "1..45\n"; } 16END {print "not ok 1\n" unless $loaded;} 17use Text::Balanced qw ( extract_delimited ); 18$loaded = 1; 19print "ok 1\n"; 20my $count=2; 21use vars qw( $DEBUG ); 22sub debug { print "\t>>>",@_ if $DEBUG } 23 24######################### End of black magic. 25 26## no critic (BuiltinFunctions::ProhibitStringyEval) 27 28my $cmd = "print"; 29my $neg = 0; 30my $str; 31while (defined($str = <DATA>)) 32{ 33 chomp $str; 34 if ($str =~ s/\A# USING://) { $neg = 0; $cmd = $str; next; } 35 elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; } 36 elsif (!$str || $str =~ /\A#/) { $neg = 0; next } 37 $str =~ s/\\n/\n/g; 38 debug "\tUsing: $cmd\n"; 39 debug "\t on: [$str]\n"; 40 41 my $var = eval "() = $cmd"; 42 debug "\t list got: [$var]\n"; 43 debug "\t list left: [$str]\n"; 44 print "not " if (substr($str,pos($str)||0,1) eq ';')==$neg; 45 print "ok ", $count++; 46 print " ($@)" if $@ && $DEBUG; 47 print "\n"; 48 49 pos $str = 0; 50 $var = eval $cmd; 51 $var = "<undef>" unless defined $var; 52 debug "\t scalar got: [$var]\n"; 53 debug "\t scalar left: [$str]\n"; 54 print "not " if ($str =~ '\A;')==$neg; 55 print "ok ", $count++; 56 print " ($@)" if $@ && $DEBUG; 57 print "\n"; 58} 59 60__DATA__ 61# USING: extract_delimited($str,'/#$',undef,'/#$'); 62/a/; 63/a///; 64#b#; 65#b###; 66$c$; 67$c$$$; 68 69# TEST EXTRACTION OF DELIMITED TEXT WITH ESCAPES 70# USING: extract_delimited($str,'/#$',undef,'\\'); 71/a/; 72/a\//; 73#b#; 74#b\##; 75$c$; 76$c\$$; 77 78# TEST EXTRACTION OF DELIMITED TEXT 79# USING: extract_delimited($str); 80'a'; 81"b"; 82`c`; 83'a\''; 84'a\\'; 85'\\a'; 86"a\\"; 87"\\a"; 88"b\'\"\'"; 89`c '\`abc\`'`; 90 91# TEST EXTRACTION OF DELIMITED TEXT 92# USING: extract_delimited($str,'/#$','-->'); 93-->/a/; 94-->#b#; 95-->$c$; 96 97# THIS SHOULD FAIL 98$c$; 99