mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-01 10:09:47 +01:00
codetools: added example testexpreval
git-svn-id: trunk@22807 -
This commit is contained in:
parent
a39ba22e7d
commit
58f1799eae
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -494,6 +494,8 @@ components/codetools/examples/scanexamples/unusedunits1.pas svneol=native#text/p
|
||||
components/codetools/examples/scanexamples/wrongforwarddefinitions.pas svneol=native#text/plain
|
||||
components/codetools/examples/setincludepath.lpi svneol=native#text/plain
|
||||
components/codetools/examples/setincludepath.pas svneol=native#text/plain
|
||||
components/codetools/examples/testexpreval.lpi svneol=native#text/plain
|
||||
components/codetools/examples/testexpreval.pas svneol=native#text/plain
|
||||
components/codetools/examples/testscompleteblock/beginwithoutindent1.inc svneol=native#text/plain
|
||||
components/codetools/examples/testscompleteblock/beginwithoutindent1_result1.inc svneol=native#text/plain
|
||||
components/codetools/examples/testscompleteblock/beginwithoutindent1_result2.inc svneol=native#text/plain
|
||||
|
||||
52
components/codetools/examples/testexpreval.lpi
Normal file
52
components/codetools/examples/testexpreval.lpi
Normal file
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="7"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<LRSInOutputDirectory Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<TargetFileExt Value=""/>
|
||||
<Title Value="testexpreval"/>
|
||||
</General>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="2">
|
||||
<Item1>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="CodeTools"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="1">
|
||||
<Unit0>
|
||||
<Filename Value="testexpreval.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="TestExprEval"/>
|
||||
</Unit0>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="8"/>
|
||||
<SearchPaths>
|
||||
<OtherUnitFiles Value="scanexamples/"/>
|
||||
</SearchPaths>
|
||||
<Other>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</CONFIG>
|
||||
71
components/codetools/examples/testexpreval.pas
Normal file
71
components/codetools/examples/testexpreval.pas
Normal file
@ -0,0 +1,71 @@
|
||||
{
|
||||
***************************************************************************
|
||||
* *
|
||||
* This source is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This code is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* General Public License for more details. *
|
||||
* *
|
||||
* A copy of the GNU General Public License is available on the World *
|
||||
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
||||
* obtain it by writing to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
* *
|
||||
***************************************************************************
|
||||
|
||||
Author: Mattias Gaertner
|
||||
|
||||
Abstract:
|
||||
Demonstrating, how to add a method to a class and extending the uses section.
|
||||
}
|
||||
program TestExprEval;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileProcs, ExprEval;
|
||||
|
||||
var
|
||||
e: TExpressionEvaluator;
|
||||
|
||||
procedure Test(Expr, ExpectedResult: string);
|
||||
var
|
||||
OldResult, NewResult: String;
|
||||
begin
|
||||
DebugLn(['Test Expression="',expr,'"']);
|
||||
OldResult:=e.Eval(Expr);
|
||||
NewResult:=e.Eval2(Expr);
|
||||
DebugLn(['Test eval2 OldResult="',OldResult,'" NewResult="',NewResult,'"']);
|
||||
if NewResult<>ExpectedResult then
|
||||
DebugLn(['FATAL: Expression="',expr,'" ExpectedResult="',ExpectedResult,'" <> NewResult="',NewResult,'"']);
|
||||
end;
|
||||
|
||||
begin
|
||||
e:=TExpressionEvaluator.Create;
|
||||
e.Variables['A']:='123';
|
||||
//Test('defined A','1');
|
||||
//Test('defined(A)','1');
|
||||
//Test('undefined(A)','0');
|
||||
//Test('not undefined(A)','1');
|
||||
//Test('not defined A','0');
|
||||
//Test('A or B','123');
|
||||
//Test('defined(B)','0');
|
||||
//Test('B or A','1');
|
||||
//Test('defined(B) or defined(A)','1');
|
||||
//Test('defined(B) or not defined(A)','0');
|
||||
//Test('not defined(B) or not defined(A)','1');
|
||||
//Test('not defined(B) or defined(A)','1');
|
||||
//Test('1 << 2','4');
|
||||
//Test('4 >> 1','2');
|
||||
//Test('4 = ''4''','1');
|
||||
//Test('(1+1)=2','1');
|
||||
//Test('(1+(2+4))=7','1');
|
||||
Test('(1+2*3)=7','1');
|
||||
e.Free;
|
||||
end.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user