Hi,
Test haven't passed, so I fixed problem (was in currency negative format).
Changes:
1.Use clocale under UNIX so various locales can be tested
2.Don't hardcode DecimalSeparator, now it's as it is.
3.Fix test unexpected halt on NegCurrFormat in [0, 4] when there's no minus
sign but brackets.
thanks
zeljko
Index: tests/test/tstrreal4.pp
===================================================================
--- tests/test/tstrreal4.pp (revision 15946)
+++ tests/test/tstrreal4.pp (working copy)
@@ -1,34 +1,35 @@
program tstrreal4;
{ test for issue #13722 by Zeljan Rikalo}
-uses SysUtils;
+uses
+ {$IFDEF UNIX}
+ clocale,
+ {$ENDIF}
+ SysUtils;
procedure test;
var
s: string;
r: double;
+ DS: Char;
begin
- {$IFDEF FPC}
- CurrencyFormat := 1;
- NegCurrFormat := 0;
- {$ENDIF}
- DecimalSeparator := '.';
+ DS := DecimalSeparator;
r := 0.001;
s := FloatToStrF(r, ffGeneral, 12, 2);
{must print 0.001 }
writeln(s);
- if (s <> '0.001') then
+ if (s <> '0'+DS+'001') then
halt(1);
s := FloatToStrF(r, ffFixed, 12, 2);
{must print 0.00 }
writeln(s);
- if (s <> '0.00') then
+ if (s <> '0'+DS+'00') then
halt(1);
s := FloatToStrF(r, ffNumber, 12, 2);
{must print 0.00 }
writeln(s);
- if (s <> '0.00') then
+ if (s <> '0'+DS+'00') then
halt(1);
r := -0.00001;
@@ -37,7 +38,7 @@
{must print -0.00001 }
writeln(s);
{$IFDEF FPC}
- if (s <> '-0.00001') then
+ if (s <> '-0'+DS+'00001') then
{$ELSE}
if (s <> '-1E-05') then // is this DCC bug ?
{$ENDIF}
@@ -46,25 +47,26 @@
s := FloatToStrF(r, ffExponent, 12, 2);
{must print -1.00000000000E-05 }
writeln(s);
- if (s <> '-1.00000000000E-05') then
+ if (s <> '-1'+DS+'00000000000E-05') then
halt(1);
s := FloatToStrF(r, ffFixed, 12, 2);
{must print 0.00 }
writeln(s);
- if (s <> '0.00') then
+ if (s <> '0'+DS+'00') then
halt(1);
s := FloatToStrF(r, ffNumber, 12, 2);
{must print 0.00 }
writeln(s);
- if (s <> '0.00') then
+ if (s <> '0'+DS+'00') then
halt(1);
s := FloatToStrF(r, ffCurrency, 12, 2);
{must print without leading zero }
writeln(s);
- if (length(s) > 0) and (Pos('-', s) > 0) then
+ if (length(s) > 0) and
+ ((Pos('-', s) > 0) or ((Pos('(', s) > 0) and (Pos(')', s) > 0))) then
halt(1);
r := -0.00000;
@@ -78,25 +80,26 @@
s := FloatToStrF(r, ffExponent, 12, 2);
{must print 0.00 }
writeln(s);
- if (s <> '0.00000000000E+00') then
+ if (s <> '0'+DS+'00000000000E+00') then
halt(1);
s := FloatToStrF(r, ffFixed, 12, 2);
{must print 0.00 }
writeln(s);
- if (s <> '0.00') then
+ if (s <> '0'+DS+'00') then
halt(1);
s := FloatToStrF(r, ffNumber, 12, 2);
{must print 0.00 }
writeln(s);
- if (s <> '0.00') then
+ if (s <> '0'+DS+'00') then
halt(1);
s := FloatToStrF(r, ffCurrency, 12, 2);
{must print without leading zero }
writeln(s);
- if (length(s) > 0) and (Pos('-', s) > 0) then
+ if (length(s) > 0) and
+ ((Pos('-', s) > 0) or ((Pos('(', s) > 0) and (Pos(')', s) > 0))) then
halt(1);
// Now check if we remove leading negative sign by mistake
@@ -106,7 +109,7 @@
{must print -0.00001 }
writeln(s);
{$IFDEF FPC}
- if (s <> '-0.00001') then
+ if (s <> '-0'+DS+'00001') then
{$ELSE}
if (s <> '-1E-5') then // is this DCC bug ?
{$ENDIF}
@@ -116,7 +119,7 @@
{must print -0.00001 }
writeln(s);
{$IFDEF FPC}
- if (s <> '-1.00000000000E-0005') then
+ if (s <> '-1'+DS+'00000000000E-0005') then
{$ELSE}
if (s <> '-1.00000000000E-5') then
{$ENDIF}
@@ -125,19 +128,20 @@
s := FloatToStrF(r, ffFixed, 12, 5);
{must print 0.00 }
writeln(s);
- if (s <> '-0.00001') then
+ if (s <> '-0'+DS+'00001') then
halt(1);
s := FloatToStrF(r, ffNumber, 12, 5);
{must print 0.00 }
writeln(s);
- if (s <> '-0.00001') then
+ if (s <> '-0'+DS+'00001') then
halt(1);
s := FloatToStrF(r, ffCurrency, 12, 5);
- {must print without leading zero }
+ {here we check for various currency negative formats}
writeln(s);
- if (length(s) > 0) and (Pos('-', s) = 0) then
+ if (length(s) > 0) and
+ (Pos('-', s) = 0) and (Pos('(', s) = 0) and (Pos(')', s) = 0) then
halt(1);
writeln('Tests for FloatToStrF(): SUCCESS');
end;
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel