2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/op/sprintf2.t - Auxilliary tests for the sprintf opcode
11 % prove t/op/sprintf2.t
15 Executes sprintf tests.
21 .include 'test_more.pir'
27 minus_option__positive_length()
28 misc_w__minus_option()
29 string__positive_length()
30 string__negative_length()
32 float_length_and_prec()
33 float_neg_length_and_prec()
38 $P0 = new 'ResizablePMCArray'
41 $S0 = sprintf '<%*d>', $P0
42 is( $S0, '< 12>', 'positive length' )
46 $P0 = new 'ResizablePMCArray'
49 $S0 = sprintf '<%*d>', $P0
50 is( $S0, '<12 >', 'negative length' )
53 .sub minus_option__positive_length
54 $P0 = new 'ResizablePMCArray'
57 $S0 = sprintf '<%-*d>', $P0
58 is( $S0, '<12 >', 'minus option, positive length' )
61 .sub misc_w__minus_option
62 $P0 = new 'ResizablePMCArray'
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' )
77 .sub string__positive_length
78 $P0 = new 'ResizablePMCArray'
81 $S0 = sprintf '<%*s>', $P0
82 is( $S0, '< hi>', 'string, positive length' )
85 .sub string__negative_length
86 $P0 = new 'ResizablePMCArray'
89 $S0 = sprintf '<%*s>', $P0
90 is( $S0, '<hi >', 'string, negative length' )
93 .sub string__minus_flag
94 $P0 = new 'ResizablePMCArray'
97 $S0 = sprintf '<%-*s>', $P0
98 is( $S0, '<hi >', 'string, minus flag' )
101 .sub float_length_and_prec
102 $P0 = new 'ResizablePMCArray'
106 $S0 = sprintf '<%*.*f>', $P0
107 is( $S0, '< 123.46>', 'float length&prec' )
110 .sub float_neg_length_and_prec
111 $P0 = new 'ResizablePMCArray'
115 $S0 = sprintf '<%*.*f>', $P0
116 is( $S0, '<123.46 >', 'float -length&prec' )
125 # vim: expandtab shiftwidth=4 ft=pir: