use 5.010; # need regex extensions use warnings; use strict; use Test::More 'no_plan' # safer to use done_testing() ; use Test::NoWarnings; # test datasets #################################################### use constant TEST_VECTOR_SET_1 => ( "each contain one or more single character", [ qw(a a) ], [ qw(ab a b) ], [ qw(abc a b c) ], [ qw(aba b) ], [ qw(abb a) ], [ qw(aab b) ], [ qw(cpcdeqe p d q) ], [ qw(pcdcq p d q) ], [ qw(cpdqc p d q) ], [ qw(aapdq p d q) ], [ qw(apadq p d q) ], [ qw(apdaq p d q) ], [ qw(apdqa p d q) ], [ qw(paadq p d q) ], [ qw(padaq p d q) ], [ qw(padqa p d q) ], [ qw(pdaaq p d q) ], [ qw(pdaqa p d q) ], [ qw(pdqaa p d q) ], "expected results from LanX pm#1201799", [ qw(aaaab b) ], [ qw(aaaba b) ], [ qw(aabaa b) ], [ qw(abaaa b) ], [ qw(abbbb a) ], [ qw(baaaa b) ], [ qw(babbb a) ], [ qw(bbabb a) ], [ qw(bbbab a) ], [ qw(bbbba a) ], "none of these contain any single character", [ 'aa' ], [ 'aaa' ], [ 'aabb' ], [ 'aaabbb' ], [ 'abcabc' ], [ 'abcxcbax' ], [ 'xabccbax' ], [ 'abcxxcba' ], [ 'abacbc' ], ); # functions under test ############################################# sub rx_1 { my ($string, ) = @_; local our %seen; my $singleton = qr{ # captures a singleton (.) # capture/test this char (?(?{ $seen{$^N}++ }) (*FAIL)) # fail if seen before (?(?= .*? \g{-1}) (*FAIL)) # fail if seen later in string }xms; # extract all singletons. return [ $string =~ m{ (?= $singleton) }xmsg ]; } # testing, testing... ############################################## FUNT: for my $ar_funt ( # function # name comment [ 'rx_1', '1st try - not "pure"', ], ) { my ($func_name, $func_note) = @$ar_funt; *singletons = do { no strict 'refs'; *$func_name; }; defined $func_note ? note "\n $func_name() -- $func_note \n\n" : note "\n $func_name() \n\n" ; VECTOR: for my $ar_vector (TEST_VECTOR_SET_1) { if (not ref $ar_vector) { # comment string if not vector ref. note $ar_vector; next VECTOR; } my ($string, @expected) = @$ar_vector; is_deeply singletons($string), \@expected, qq{'$string' -> (@expected)}, ; } # end for VECTOR } # end for FUNT note "\n done testing functions \n\n"; done_testing(); exit; # utility functions ################################################ # none