Browse Source

Always accept empty string as meaning zero is TryRomanToInt, fixes intermittent errors in tromantoint test

git-svn-id: trunk@40537 -
pierre 6 years ago
parent
commit
f8563772c5
2 changed files with 17 additions and 3 deletions
  1. 6 1
      packages/rtl-objpas/src/inc/strutils.pp
  2. 11 2
      tests/test/units/strutils/tromantoint.pp

+ 6 - 1
packages/rtl-objpas/src/inc/strutils.pp

@@ -2427,7 +2427,12 @@ begin
       Result := True;
     Exit;
   end;
-  if (Len = 0) then Exit;
+  if (Len = 0) then
+  begin
+    Result:=true;
+    N:=0;
+    Exit;
+  end;
   i := 1;
   N := 0;
   Terminated := False;

+ 11 - 2
tests/test/units/strutils/tromantoint.pp

@@ -14,10 +14,16 @@ procedure RomanToIntTest(const testRoman: string;
   var
     test: integer;
   begin
-    test := RomanToInt(testRoman);
+    try
+      test := RomanToInt(testRoman);
+    except
+      { make sure that if an exception is generated,
+        the error is raised }
+      test:=expectation-1;
+    end;
     if test <> expectation then
     begin
-      writeln('Testing strUtils/RomanToInt: Test with ', testRoman, ' failed.');
+      writeln('Testing strUtils/RomanToInt: Test with "', testRoman, '" failed.');
       writeln('Returned number: ', test);
       writeln('Expected number: ', expectation);
       exitCode := 1;
@@ -30,6 +36,9 @@ var
   testInteger: integer;
 
 begin
+  { Check that empty string is accepted as zero vvalue }
+  RomanToIntTest('',0);
+
   for i := 1 to 2000 do
   begin
     testInteger := i;