/
sprintf2.t
124 lines (100 loc) · 2.32 KB
/
sprintf2.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!./parrot
# Copyright (C) 2001-2010, Parrot Foundation.
=head1 NAME
t/op/sprintf2.t - Auxiliary tests for the sprintf opcode
=head1 SYNOPSIS
% prove t/op/sprintf2.t
=head1 DESCRIPTION
Executes sprintf tests.
=cut
.sub main :main
.include 'test_more.pir'
plan(9)
positive_length()
negative_length()
minus_option__positive_length()
misc_w__minus_option()
string__positive_length()
string__negative_length()
string__minus_flag()
float_length_and_prec()
float_neg_length_and_prec()
.end
.sub positive_length
$P0 = new 'ResizablePMCArray'
push $P0,4
push $P0,12
$S0 = sprintf '<%*d>', $P0
is( $S0, '< 12>', 'positive length' )
.end
.sub negative_length
$P0 = new 'ResizablePMCArray'
push $P0,-4
push $P0,12
$S0 = sprintf '<%*d>', $P0
is( $S0, '<12 >', 'negative length' )
.end
.sub minus_option__positive_length
$P0 = new 'ResizablePMCArray'
push $P0,4
push $P0,12
$S0 = sprintf '<%-*d>', $P0
is( $S0, '<12 >', 'minus option, positive length' )
.end
.sub misc_w__minus_option
$P0 = new 'ResizablePMCArray'
push $P0,65
push $P0,65
push $P0,65
push $P0,65
push $P0,65
push $P0,65
push $P0,3
push $P0,65
push $P0,-4
push $P0,65
$S0 = sprintf '|%c|%0c|%-1c|%1c|%-6c|%6c|%*c|%*c|', $P0
is( $S0, '|A|A|A|A|A | A| A|A |', 'misc w/ minus option' )
.end
.sub string__positive_length
$P0 = new 'ResizablePMCArray'
push $P0,4
push $P0,"hi"
$S0 = sprintf '<%*s>', $P0
is( $S0, '< hi>', 'string, positive length' )
.end
.sub string__negative_length
$P0 = new 'ResizablePMCArray'
push $P0,-4
push $P0,"hi"
$S0 = sprintf '<%*s>', $P0
is( $S0, '<hi >', 'string, negative length' )
.end
.sub string__minus_flag
$P0 = new 'ResizablePMCArray'
push $P0,4
push $P0,"hi"
$S0 = sprintf '<%-*s>', $P0
is( $S0, '<hi >', 'string, minus flag' )
.end
.sub float_length_and_prec
$P0 = new 'ResizablePMCArray'
push $P0,7
push $P0,2
push $P0,123.456
$S0 = sprintf '<%*.*f>', $P0
is( $S0, '< 123.46>', 'float length&prec' )
.end
.sub float_neg_length_and_prec
$P0 = new 'ResizablePMCArray'
push $P0,-7
push $P0,2
push $P0,123.456
$S0 = sprintf '<%*.*f>', $P0
is( $S0, '<123.46 >', 'float -length&prec' )
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: