mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-07 12:07:58 +02:00
* New "tval1" test to verify that Val with constants works properly
This commit is contained in:
parent
6597f02ebc
commit
d8079ea239
32
tests/test/cg/tval1.pp
Normal file
32
tests/test/cg/tval1.pp
Normal file
@ -0,0 +1,32 @@
|
||||
{ %OPT=-O3 }
|
||||
|
||||
{$mode objfpc}
|
||||
|
||||
program tval1;
|
||||
|
||||
function TryStrToInt(const s: string; out i: Longint): boolean; inline;
|
||||
var
|
||||
Error : word;
|
||||
begin
|
||||
Val(s, i, Error);
|
||||
TryStrToInt:=(Error=0)
|
||||
end;
|
||||
|
||||
procedure DoTest;
|
||||
var
|
||||
Output: Longint;
|
||||
begin
|
||||
if TryStrToInt('Invalid', Output) then
|
||||
Halt(1);
|
||||
|
||||
if not TryStrToInt('2', Output) then
|
||||
Halt(2);
|
||||
|
||||
if Output <> 2 then
|
||||
Halt(3);
|
||||
end;
|
||||
|
||||
begin
|
||||
DoTest(); { This is so "Output" is a local variable rather than global }
|
||||
WriteLn('ok');
|
||||
end.
|
Loading…
Reference in New Issue
Block a user