Changeset 21229

Show
Ignore:
Timestamp:
07/06/08 03:42:52 (5 months ago)
Author:
cjfields
Message:

add complement, deletion, squash tests

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • t/spec/S05-transliteration/trans.t

    r21063 r21229  
    1111=end pod 
    1212 
    13 plan 22; 
     13plan 40; 
    1414 
    15 is("ABC".trans( ('A'=>'a'), ('B'=>'b'), ('C'=>'c') ),"abc", 
    16         "Each side can be individual characters"); 
     15is("ABC".trans( ('A'=>'a'), ('B'=>'b'), ('C'=>'c') ), 
     16    "abc", 
     17    "Each side can be individual characters"); 
    1718 
    18 is("XYZ".trans( ('XYZ' => 'xyz') ),"xyz", 
    19            "The two sides of the any pair can be strings interpreted as tr/// would multichar"); 
     19is("XYZ".trans( ('XYZ' => 'xyz') ), 
     20    "xyz", 
     21    "The two sides of the any pair can be strings interpreted as tr/// would multichar"); 
    2022 
    21 is("ABC".trans( ('A..C' => 'a..c') ),"abc", 
    22            "The two sides of the any pair can be strings interpreted as tr/// would range"); 
     23is("ABC".trans( ('A..C' => 'a..c') ), 
     24    "abc", 
     25    "The two sides of the any pair can be strings interpreted as tr/// would range"); 
    2326 
    24 is("ABC-DEF".trans(("- AB..Z" => "_ a..z")),"abc_def", 
    25            "If the first character is a dash it isn't part of a range"); 
     27is("ABC-DEF".trans(("- AB..Z" => "_ a..z")), 
     28    "abc_def", 
     29    "If the first character is a dash it isn't part of a range"); 
    2630 
    27 is("ABC-DEF".trans(("A..YZ-" => "a..z_")),"abc_def", 
    28            "If the last character is a dash it isn't part of a range"); 
     31is("ABC-DEF".trans(("A..YZ-" => "a..z_")), 
     32    "abc_def", 
     33    "If the last character is a dash it isn't part of a range"); 
    2934 
    30 is("ABCDEF".trans( ('AB..E' => 'ab..e') ), "abcdeF", 
    31                   "The two sides can consists of both chars and ranges"); 
     35is("ABCDEF".trans( ('AB..E' => 'ab..e') ), 
     36    "abcdeF", 
     37    "The two sides can consists of both chars and ranges"); 
    3238 
    33 is("ABCDEFGH".trans( ('A..CE..G' => 'a..ce..g') ),"abcDefgH", 
    34                   "The two sides can consist of multiple ranges"); 
     39is("ABCDEFGH".trans( ('A..CE..G' => 'a..ce..g') ), 
     40    "abcDefgH", 
     41    "The two sides can consist of multiple ranges"); 
    3542 
    36 # These will need the way the hashes deal with pairs. 
     43is("ABCXYZ".trans( (['A'..'C'] => ['a'..'c']), (<X Y Z> => <x y z>) ), 
     44    "abcxyz", 
     45    "The two sides of each pair may also be array references" ); 
    3746 
    38 # This works by accident. 
    39 is("ABCXYZ".trans( (['A'..'C'] => ['a'..'c']), (<X Y Z> => <x y z>) ),"abcxyz", 
    40            "The two sides of each pair may also be array references" ); 
    41  
    42 # We're probally unable to "fix" these two as long as the left hand of => gets stringified 
    4347is("abcde".trans( ('a..e' => 'A'..'E') ), "ABCDE", 
    4448           "Using string range on one side and array reference on the other"); 
    45  
    4649 
    4750is("ABCDE".trans( (['A' .. 'E'] => "a..e") ), "abcde", 
    4851           "Using array reference on one side and string range on the other"); 
    4952 
    50 is("&nbsp;&lt;&gt;&amp;".trans( (['&nbsp;', '&lt;', '&gt;', '&amp;'] => [' ',      '<',    '>',    '&'     ])), 
    51     " <>&","The array version can map one characters to one-or-more characters except spaces"); 
     53is("&nbsp;&lt;&gt;&amp;".trans( (['&nbsp;', '&lt;', '&gt;', '&amp;'] => 
     54    [' ',      '<',    '>',    '&'     ])), 
     55    " <>&","The array version can map one characters to one-or-more characters"); 
    5256 
    5357is(" <>&".trans( ([' ',      '<',    '>',    '&'    ] =>  
     
    5963                                 [' ',      'AB',         '<',    '>',    '&'    ])), 
    6064                                "AB>&", 
    61     "The array version can map one characters to one-or-more characters, uses leftmost longest match"); 
    62  
    63 is("&nbsp;&lt;&gt;&amp;".trans( (['&nbsp;', '&lt;', '&amp;'] => 
    64                                  [' ',      '<',    '&'    ])), 
    65                                 " <&gt;&", 
    66     "The array version can map one characters to one-or-more characters, uses leftmost longest match"); 
    67  
     65    "The array version can map one characters to one-or-more characters, using leftmost longest match"); 
     66     
    6867is("Whfg nabgure Crey unpxre".trans('a'..'z' => ['n'..'z','a'..'m'], 'A'..'Z' => ['N'..'Z','A'..'M']), 
    6968    "Just another Perl hacker", 
     
    7675is("Whfg nabgure Crey unpxre".trans(' a .. z' => '_n .. za .. m', 'A .. Z' => 'N .. ZA .. M'), 
    7776    "Just_another_Perl_hacker", 
    78     "Spaces in interpreted ranges are skipped, all others important"); 
     77    "Spaces in interpreted ranges are skipped, all others are important"); 
     78 
     79my $a = "abcdefghijklmnopqrstuvwxyz"; 
     80 
     81my $b = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
     82 
     83is($a.trans('a..z' => 'A..Z'), $b); 
     84 
     85is($b.trans('A..Z' => 'a..z'), $a); 
     86 
     87is($a.trans('b..y' => 'B..Y'), 'aBCDEFGHIJKLMNOPQRSTUVWXYz'); 
     88 
     89is("I\xcaJ".trans('I..J' => 'i..j'), "i\xcaj"); 
     90 
     91is("\x12c\x190".trans("\x12c" => "\x190"), "\x190\x190"); 
     92 
     93# should these be combined? 
     94is($b.trans('A..H..Z' => 'a..h..z'), $a, 
     95    'ambiguous ranges combined'); 
     96 
     97is($b.trans('..H..Z' => '__h..z'), 
     98    'ABCDEFGhijklmnopqrstuvwxyz', 
     99    'leading ranges interpreted as string'); 
     100 
     101is($b.trans('A..H..' => 'a..h__'), 'abcdefghIJKLMNOPQRSTUVWXYZ', 
     102    'trailing ranges interpreted as string'); 
     103 
     104is($b.trans('..A..H..' => '__a..h__'), 'abcdefghIJKLMNOPQRSTUVWXYZ', 
     105    'leading, trailing ranges interpreted as string'); 
     106     
     107# complement, squeeze/squash, delete 
     108 
     109is('bookkeeper'.trans(:s, 'a..z' => 'a..z'), 'bokeper', 
     110    ':s flag (squash)'); 
     111 
     112is('bookkeeper'.trans(:d, 'ok' => ''), 'beeper', 
     113    ':d flag (delete)'); 
     114     
     115is('ABC123DEF456GHI'.trans('A..Z' => 'x'), 'xxx123xxx456xxx', 
     116    'no flags'); 
     117 
     118is('ABC123DEF456GHI'.trans(:c, 'A..Z' => 'x'),'ABCxxxDEFxxxGHI', 
     119    '... with :c'); 
     120 
     121is('ABC111DEF222GHI'.trans(:s, '0..9' => 'x'),'ABCxDEFxGHI', 
     122    '... with :s'); 
     123 
     124is('ABC111DEF222GHI'.trans(:c, :s, 'A..Z' => 'x'),'ABCxDEFxGHI', 
     125    '... with :s and :c'); 
     126 
     127is('ABC111DEF222GHI'.trans(:c, :d, 'A..Z' => ''),'ABCDEFGHI', 
     128    '... with :d and :c'); 
     129 
     130is('Good&Plenty'.trans('len' => 'x'), 'Good&Pxxxty', 
     131    'no flags');  
     132 
     133is('Good&Plenty'.trans(:s, 'len' => 'x',), 'Good&Pxty', 
     134    'squashing depends on replacement repeat, not searchlist repeat'); 
     135 
     136is('Good&Plenty'.trans(:s, 'len' => 't'), 'Good&Ptty', 
     137    'squashing depends on replacement repeat, not searchlist repeat'); 
    79138 
    80139#?rakudo skip 'tr///, feed operator not implemented'