Skip to content

Commit 30a0f0f

Browse files
committed
14 more tests for %e, %f, %g.
1 parent 8e3a39e commit 30a0f0f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

t/jvm/06-sprintf.t

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ sub is($actual, $expected, $description) {
2424
}
2525
}
2626

27-
plan(135);
27+
plan(149);
2828

2929
is(nqp::sprintf('Walter Bishop', []), 'Walter Bishop', 'no directives' );
3030

@@ -147,6 +147,11 @@ is(nqp::sprintf('%020.2E', [3.1415]), '00000000000003.14E+0', '020.2 %E');
147147
is(nqp::sprintf('%020.2e', [-3.1415]), '-0000000000003.14e+0', 'negative 020.2 %e');
148148
is(nqp::sprintf('%020.2E', [-3.1415]), '-0000000000003.14E+0', 'negative 020.2 %E');
149149
is(nqp::sprintf('%e', [2.718281828459]), nqp::sprintf('%.6e', [2.718281828459]), '%e defaults to .6');
150+
is(nqp::sprintf('<%7.3e>', [3.1415e20]), '<3.142e+20>', '%e handles big numbers');
151+
is(nqp::sprintf('<%7.3e>', [-3.1415e20]), '<-3.142e+20>', '%e handles big negative numbers');
152+
is(nqp::sprintf('<%7.3e>', [3.1415e-20]), '<3.142e-20>', '%e handles small numbers');
153+
is(nqp::sprintf('<%7.3e>', [-3.1415e-20]), '<-3.142e-20>', '%e handles small negative numbers');
154+
is(nqp::sprintf('<%7.3e>', [3e20]), '<3.000e+20>', '%e fills up to precision');
150155

151156
is(nqp::sprintf('%5.2f', [3.1415]), ' 3.14', '5.2 %f');
152157
is(nqp::sprintf('%5.2F', [3.1415]), ' 3.14', '5.2 %F');
@@ -161,6 +166,11 @@ is(nqp::sprintf('%020.2F', [-3.1415]), '-0000000000000003.14', 'negative 020.
161166
is(nqp::sprintf('%f', [2.718281828459]), nqp::sprintf('%.6f', [2.718281828459]), '%f defaults to .6');
162167
is(nqp::sprintf('<%7.3f>', [0]), '< 0.000>', '%f fills up to precision');
163168
is(nqp::sprintf('<%7.3f>', [0.1]), '< 0.100>', '%f fills up to precision');
169+
is(nqp::sprintf('<%7.3f>', [3.1]), '< 3.100>', '%f fills up to precision');
170+
is(nqp::sprintf('<%7.3f>', [3.1415e20]), '<314150000000000000000.000>', '%f handles big numbers');
171+
is(nqp::sprintf('<%7.3f>', [-3.1415e20]), '<-314150000000000000000.000>', '%f handles big negative numbers');
172+
is(nqp::sprintf('<%7.3f>', [3.1415e-2]), '< 0.031>', '%f handles small numbers');
173+
is(nqp::sprintf('<%7.3f>', [-3.1415e-2]), '< -0.031>', '%f handles small negative numbers');
164174

165175
is(nqp::sprintf('%5.2g', [3.1415]), ' 3.14', '5.2 %g');
166176
is(nqp::sprintf('%5.2G', [3.1415]), ' 3.14', '5.2 %G');
@@ -173,6 +183,8 @@ is(nqp::sprintf('%020.2G', [3.1415]), '00000000000000003.14', '020.2 %G');
173183
is(nqp::sprintf('%020.2g', [-3.1415]), '-0000000000000003.14', 'negative 020.2 %g');
174184
is(nqp::sprintf('%020.2G', [-3.1415]), '-0000000000000003.14', 'negative 020.2 %G');
175185
is(nqp::sprintf('%g', [2.718281828459]), nqp::sprintf('%.6f', [2.718281828459]), '%g defaults to .6');
186+
is(nqp::sprintf('<%7.3g>', [0]), '< 0.000>', '%g fills up to precision');
187+
is(nqp::sprintf('<%7.3g>', [0.1]), '< 0.100>', '%g fills up to precision');
176188

177189
is(nqp::sprintf('%5.2g', [3.1415e20]), '3.14e+20', '5.2 %g');
178190
is(nqp::sprintf('%5.2G', [3.1415e20]), '3.14e+20', '5.2 %G');
@@ -184,3 +196,5 @@ is(nqp::sprintf('%020.2g', [3.1415e20]), '0000000000003.14e+20', '020.2 %g')
184196
is(nqp::sprintf('%020.2G', [3.1415e20]), '0000000000003.14e+20', '020.2 %G');
185197
is(nqp::sprintf('%020.2g', [-3.1415e20]), '-000000000003.14e+20', 'negative 020.2 %g');
186198
is(nqp::sprintf('%020.2G', [-3.1415e20]), '-000000000003.14e+20', 'negative 020.2 %G');
199+
is(nqp::sprintf('<%7.3g>', [3e20]), '< 3.000e+20>', '%g fills up to precision');
200+
is(nqp::sprintf('<%7.3g>', [3.1e20]), '< 3.100e+20>', '%g fills up to precision');

0 commit comments

Comments
 (0)