26 | | # [ 'format', [arguments], "expected output", 'description' ] |
27 | | my @tests = ( |
28 | | [ '<%*d>', [4,12], "< 12>\n", 'positive length' ], |
29 | | [ '<%*d>', [-4,12], "<12 >\n", 'negative length' ], |
30 | | [ '<%-*d>', [4,12], "<12 >\n", 'minus option, positive length' ], |
31 | | [ '|%c|%0c|%-1c|%1c|%-6c|%6c|%*c|%*c|', [65,65,65,65,65,65,3,65,-4,65], |
32 | | "|A|A|A|A|A | A| A|A |\n", 'misc w/ minus option' ], |
33 | | [ '<%*s>', [4,'"hi"'], "< hi>\n", 'string, positive length' ], |
34 | | [ '<%*s>', [-4,'"hi"'], "<hi >\n", 'string, negative length' ], |
35 | | [ '<%-*s>', [4,'"hi"'], "<hi >\n", 'string, minus flag' ], |
36 | | [ '<%*.*f>', [7,2,123.456], "< 123.46>\n", 'float length&prec' ], |
37 | | [ '<%*.*f>', [-7,2,123.456], "<123.46 >\n", 'float -length&prec' ], |
38 | | ); |
| 25 | positive_length() |
| 26 | negative_length() |
| 27 | minus_option__positive_length() |
| 28 | misc_w__minus_option() |
| 29 | string__positive_length() |
| 30 | string__negative_length() |
| 31 | string__minus_flag() |
| 32 | float_length_and_prec() |
| 33 | float_neg_length_and_prec() |
| 34 | |
| 35 | .end |
| 36 | |
| 37 | .sub positive_length |
| 38 | $P0 = new 'ResizablePMCArray' |
| 39 | push $P0,4 |
| 40 | push $P0,12 |
| 41 | $S0 = sprintf '<%*d>', $P0 |
| 42 | is( $S0, '< 12>', 'positive length' ) |
| 43 | .end |
| 44 | |
| 45 | .sub negative_length |
| 46 | $P0 = new 'ResizablePMCArray' |
| 47 | push $P0,-4 |
| 48 | push $P0,12 |
| 49 | $S0 = sprintf '<%*d>', $P0 |
| 50 | is( $S0, '<12 >', 'negative length' ) |
| 51 | .end |
| 52 | |
| 53 | .sub minus_option__positive_length |
| 54 | $P0 = new 'ResizablePMCArray' |
| 55 | push $P0,4 |
| 56 | push $P0,12 |
| 57 | $S0 = sprintf '<%-*d>', $P0 |
| 58 | is( $S0, '<12 >', 'minus option, positive length' ) |
| 59 | .end |
| 60 | |
| 61 | .sub misc_w__minus_option |
| 62 | $P0 = new 'ResizablePMCArray' |
| 63 | push $P0,65 |
| 64 | push $P0,65 |
| 65 | push $P0,65 |
| 66 | push $P0,65 |
| 67 | push $P0,65 |
| 68 | push $P0,65 |
| 69 | push $P0,3 |
| 70 | push $P0,65 |
| 71 | push $P0,-4 |
| 72 | push $P0,65 |
| 73 | $S0 = sprintf '|%c|%0c|%-1c|%1c|%-6c|%6c|%*c|%*c|', $P0 |
| 74 | is( $S0, '|A|A|A|A|A | A| A|A |', 'misc w/ minus option' ) |
| 75 | .end |
| 76 | |
| 77 | .sub string__positive_length |
| 78 | $P0 = new 'ResizablePMCArray' |
| 79 | push $P0,4 |
| 80 | push $P0,"hi" |
| 81 | $S0 = sprintf '<%*s>', $P0 |
| 82 | is( $S0, '< hi>', 'string, positive length' ) |
| 83 | .end |
| 84 | |
| 85 | .sub string__negative_length |
| 86 | $P0 = new 'ResizablePMCArray' |
| 87 | push $P0,-4 |
| 88 | push $P0,"hi" |
| 89 | $S0 = sprintf '<%*s>', $P0 |
| 90 | is( $S0, '<hi >', 'string, negative length' ) |
| 91 | .end |
| 92 | |
| 93 | .sub string__minus_flag |
| 94 | $P0 = new 'ResizablePMCArray' |
| 95 | push $P0,4 |
| 96 | push $P0,"hi" |
| 97 | $S0 = sprintf '<%-*s>', $P0 |
| 98 | is( $S0, '<hi >', 'string, minus flag' ) |
| 99 | .end |
| 100 | |
| 101 | .sub float_length_and_prec |
| 102 | $P0 = new 'ResizablePMCArray' |
| 103 | push $P0,7 |
| 104 | push $P0,2 |
| 105 | push $P0,123.456 |
| 106 | $S0 = sprintf '<%*.*f>', $P0 |
| 107 | is( $S0, '< 123.46>', 'float length&prec' ) |
| 108 | .end |
| 109 | |
| 110 | .sub float_neg_length_and_prec |
| 111 | $P0 = new 'ResizablePMCArray' |
| 112 | push $P0,-7 |
| 113 | push $P0,2 |
| 114 | push $P0,123.456 |
| 115 | $S0 = sprintf '<%*.*f>', $P0 |
| 116 | is( $S0, '<123.46 >', 'float -length&prec' ) |
| 117 | .end |
| 118 | |
| 119 | |
| 120 | |