Changeset 21229
- Timestamp:
- 07/06/08 03:42:52 (5 months ago)
- Files:
-
- 1 modified
-
t/spec/S05-transliteration/trans.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
t/spec/S05-transliteration/trans.t
r21063 r21229 11 11 =end pod 12 12 13 plan 22;13 plan 40; 14 14 15 is("ABC".trans( ('A'=>'a'), ('B'=>'b'), ('C'=>'c') ),"abc", 16 "Each side can be individual characters"); 15 is("ABC".trans( ('A'=>'a'), ('B'=>'b'), ('C'=>'c') ), 16 "abc", 17 "Each side can be individual characters"); 17 18 18 is("XYZ".trans( ('XYZ' => 'xyz') ),"xyz", 19 "The two sides of the any pair can be strings interpreted as tr/// would multichar"); 19 is("XYZ".trans( ('XYZ' => 'xyz') ), 20 "xyz", 21 "The two sides of the any pair can be strings interpreted as tr/// would multichar"); 20 22 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"); 23 is("ABC".trans( ('A..C' => 'a..c') ), 24 "abc", 25 "The two sides of the any pair can be strings interpreted as tr/// would range"); 23 26 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"); 27 is("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"); 26 30 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"); 31 is("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"); 29 34 30 is("ABCDEF".trans( ('AB..E' => 'ab..e') ), "abcdeF", 31 "The two sides can consists of both chars and ranges"); 35 is("ABCDEF".trans( ('AB..E' => 'ab..e') ), 36 "abcdeF", 37 "The two sides can consists of both chars and ranges"); 32 38 33 is("ABCDEFGH".trans( ('A..CE..G' => 'a..ce..g') ),"abcDefgH", 34 "The two sides can consist of multiple ranges"); 39 is("ABCDEFGH".trans( ('A..CE..G' => 'a..ce..g') ), 40 "abcDefgH", 41 "The two sides can consist of multiple ranges"); 35 42 36 # These will need the way the hashes deal with pairs. 43 is("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" ); 37 46 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 stringified43 47 is("abcde".trans( ('a..e' => 'A'..'E') ), "ABCDE", 44 48 "Using string range on one side and array reference on the other"); 45 46 49 47 50 is("ABCDE".trans( (['A' .. 'E'] => "a..e") ), "abcde", 48 51 "Using array reference on one side and string range on the other"); 49 52 50 is(" <>&".trans( ([' ', '<', '>', '&'] => [' ', '<', '>', '&' ])), 51 " <>&","The array version can map one characters to one-or-more characters except spaces"); 53 is(" <>&".trans( ([' ', '<', '>', '&'] => 54 [' ', '<', '>', '&' ])), 55 " <>&","The array version can map one characters to one-or-more characters"); 52 56 53 57 is(" <>&".trans( ([' ', '<', '>', '&' ] => … … 59 63 [' ', 'AB', '<', '>', '&' ])), 60 64 "AB>&", 61 "The array version can map one characters to one-or-more characters, uses leftmost longest match"); 62 63 is(" <>&".trans( ([' ', '<', '&'] => 64 [' ', '<', '&' ])), 65 " <>&", 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 68 67 is("Whfg nabgure Crey unpxre".trans('a'..'z' => ['n'..'z','a'..'m'], 'A'..'Z' => ['N'..'Z','A'..'M']), 69 68 "Just another Perl hacker", … … 76 75 is("Whfg nabgure Crey unpxre".trans(' a .. z' => '_n .. za .. m', 'A .. Z' => 'N .. ZA .. M'), 77 76 "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 79 my $a = "abcdefghijklmnopqrstuvwxyz"; 80 81 my $b = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 82 83 is($a.trans('a..z' => 'A..Z'), $b); 84 85 is($b.trans('A..Z' => 'a..z'), $a); 86 87 is($a.trans('b..y' => 'B..Y'), 'aBCDEFGHIJKLMNOPQRSTUVWXYz'); 88 89 is("I\xcaJ".trans('I..J' => 'i..j'), "i\xcaj"); 90 91 is("\x12c\x190".trans("\x12c" => "\x190"), "\x190\x190"); 92 93 # should these be combined? 94 is($b.trans('A..H..Z' => 'a..h..z'), $a, 95 'ambiguous ranges combined'); 96 97 is($b.trans('..H..Z' => '__h..z'), 98 'ABCDEFGhijklmnopqrstuvwxyz', 99 'leading ranges interpreted as string'); 100 101 is($b.trans('A..H..' => 'a..h__'), 'abcdefghIJKLMNOPQRSTUVWXYZ', 102 'trailing ranges interpreted as string'); 103 104 is($b.trans('..A..H..' => '__a..h__'), 'abcdefghIJKLMNOPQRSTUVWXYZ', 105 'leading, trailing ranges interpreted as string'); 106 107 # complement, squeeze/squash, delete 108 109 is('bookkeeper'.trans(:s, 'a..z' => 'a..z'), 'bokeper', 110 ':s flag (squash)'); 111 112 is('bookkeeper'.trans(:d, 'ok' => ''), 'beeper', 113 ':d flag (delete)'); 114 115 is('ABC123DEF456GHI'.trans('A..Z' => 'x'), 'xxx123xxx456xxx', 116 'no flags'); 117 118 is('ABC123DEF456GHI'.trans(:c, 'A..Z' => 'x'),'ABCxxxDEFxxxGHI', 119 '... with :c'); 120 121 is('ABC111DEF222GHI'.trans(:s, '0..9' => 'x'),'ABCxDEFxGHI', 122 '... with :s'); 123 124 is('ABC111DEF222GHI'.trans(:c, :s, 'A..Z' => 'x'),'ABCxDEFxGHI', 125 '... with :s and :c'); 126 127 is('ABC111DEF222GHI'.trans(:c, :d, 'A..Z' => ''),'ABCDEFGHI', 128 '... with :d and :c'); 129 130 is('Good&Plenty'.trans('len' => 'x'), 'Good&Pxxxty', 131 'no flags'); 132 133 is('Good&Plenty'.trans(:s, 'len' => 'x',), 'Good&Pxty', 134 'squashing depends on replacement repeat, not searchlist repeat'); 135 136 is('Good&Plenty'.trans(:s, 'len' => 't'), 'Good&Ptty', 137 'squashing depends on replacement repeat, not searchlist repeat'); 79 138 80 139 #?rakudo skip 'tr///, feed operator not implemented'
