|
@@ -506,6 +506,7 @@ type
|
|
procedure DoEchoBoolean(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
procedure DoEchoBoolean(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
procedure DoEchoDate(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
procedure DoEchoDate(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
procedure DoEchoFloat(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
procedure DoEchoFloat(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
|
|
+ procedure DoEchoCurrency(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
procedure DoEchoInteger(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
procedure DoEchoInteger(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
procedure DoEchoString(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
procedure DoEchoString(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
procedure DoGetDate(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
procedure DoGetDate(var Result: TFPExpressionResult; Const Args: TExprParameterArray);
|
|
@@ -518,6 +519,7 @@ type
|
|
Procedure AssertOperand(N : TFPExprNode; OperandClass : TClass);
|
|
Procedure AssertOperand(N : TFPExprNode; OperandClass : TClass);
|
|
Procedure AssertResultType(RT : TResultType);
|
|
Procedure AssertResultType(RT : TResultType);
|
|
Procedure AssertResult(F : TExprFloat);
|
|
Procedure AssertResult(F : TExprFloat);
|
|
|
|
+ Procedure AssertCurrencyResult(C : Currency);
|
|
Procedure AssertResult(I : Int64);
|
|
Procedure AssertResult(I : Int64);
|
|
Procedure AssertResult(S : String);
|
|
Procedure AssertResult(S : String);
|
|
Procedure AssertResult(B : Boolean);
|
|
Procedure AssertResult(B : Boolean);
|
|
@@ -730,9 +732,10 @@ type
|
|
FTest33 : TFPExprIdentifierDef;
|
|
FTest33 : TFPExprIdentifierDef;
|
|
procedure DoGetBooleanVar(var Res: TFPExpressionResult; ConstRef AName: ShortString);
|
|
procedure DoGetBooleanVar(var Res: TFPExpressionResult; ConstRef AName: ShortString);
|
|
procedure DoGetBooleanVarWrong(var Res: TFPExpressionResult; ConstRef AName: ShortString);
|
|
procedure DoGetBooleanVarWrong(var Res: TFPExpressionResult; ConstRef AName: ShortString);
|
|
- procedure DoTestVariable33;
|
|
|
|
procedure TestAccess(Skip: TResultType);
|
|
procedure TestAccess(Skip: TResultType);
|
|
|
|
+ procedure TestAccess(Skip: TResultTypes);
|
|
Protected
|
|
Protected
|
|
|
|
+ procedure DoTestVariable33;
|
|
procedure AddVariabletwice;
|
|
procedure AddVariabletwice;
|
|
procedure UnknownVariable;
|
|
procedure UnknownVariable;
|
|
Procedure ReadWrongType;
|
|
Procedure ReadWrongType;
|
|
@@ -775,6 +778,8 @@ type
|
|
procedure TestVariable32;
|
|
procedure TestVariable32;
|
|
procedure TestVariable33;
|
|
procedure TestVariable33;
|
|
procedure TestVariable34;
|
|
procedure TestVariable34;
|
|
|
|
+ procedure TestVariable35;
|
|
|
|
+ procedure TestVariable36;
|
|
end;
|
|
end;
|
|
|
|
|
|
{ TTestParserFunctions }
|
|
{ TTestParserFunctions }
|
|
@@ -814,6 +819,10 @@ type
|
|
procedure TestFunction27;
|
|
procedure TestFunction27;
|
|
procedure TestFunction28;
|
|
procedure TestFunction28;
|
|
procedure TestFunction29;
|
|
procedure TestFunction29;
|
|
|
|
+ procedure TestFunction30;
|
|
|
|
+ procedure TestFunction31;
|
|
|
|
+ procedure TestFunction32;
|
|
|
|
+ procedure TestFunction33;
|
|
end;
|
|
end;
|
|
|
|
|
|
{ TAggregateNode }
|
|
{ TAggregateNode }
|
|
@@ -851,6 +860,7 @@ type
|
|
Procedure TestCountAggregate;
|
|
Procedure TestCountAggregate;
|
|
Procedure TestSumAggregate;
|
|
Procedure TestSumAggregate;
|
|
Procedure TestSumAggregate2;
|
|
Procedure TestSumAggregate2;
|
|
|
|
+ Procedure TestSumAggregate3;
|
|
Procedure TestAvgAggregate;
|
|
Procedure TestAvgAggregate;
|
|
Procedure TestAvgAggregate2;
|
|
Procedure TestAvgAggregate2;
|
|
Procedure TestAvgAggregate3;
|
|
Procedure TestAvgAggregate3;
|
|
@@ -871,6 +881,7 @@ type
|
|
procedure TestVariable4;
|
|
procedure TestVariable4;
|
|
procedure TestVariable5;
|
|
procedure TestVariable5;
|
|
procedure TestVariable6;
|
|
procedure TestVariable6;
|
|
|
|
+ procedure TestVariable7;
|
|
procedure TestFunction1;
|
|
procedure TestFunction1;
|
|
procedure TestFunction2;
|
|
procedure TestFunction2;
|
|
end;
|
|
end;
|
|
@@ -895,6 +906,7 @@ type
|
|
procedure AssertDateTimeExpression(Const AExpression : String; Const AResult : TDateTime);
|
|
procedure AssertDateTimeExpression(Const AExpression : String; Const AResult : TDateTime);
|
|
procedure AssertAggregateExpression(Const AExpression : String; AResult : Int64; AUpdateCount : integer);
|
|
procedure AssertAggregateExpression(Const AExpression : String; AResult : Int64; AUpdateCount : integer);
|
|
procedure AssertAggregateExpression(Const AExpression : String; AResult : TExprFloat; AUpdateCount : integer);
|
|
procedure AssertAggregateExpression(Const AExpression : String; AResult : TExprFloat; AUpdateCount : integer);
|
|
|
|
+ procedure AssertAggregateCurrExpression(Const AExpression : String; AResult : Currency; AUpdateCount : integer);
|
|
Published
|
|
Published
|
|
procedure TestRegister;
|
|
procedure TestRegister;
|
|
Procedure TestVariablepi;
|
|
Procedure TestVariablepi;
|
|
@@ -962,6 +974,8 @@ type
|
|
Procedure TestFunctionstrtodatetime;
|
|
Procedure TestFunctionstrtodatetime;
|
|
Procedure TestFunctionstrtodatetimedef;
|
|
Procedure TestFunctionstrtodatetimedef;
|
|
Procedure TestFunctionAggregateSum;
|
|
Procedure TestFunctionAggregateSum;
|
|
|
|
+ Procedure TestFunctionAggregateSumFloat;
|
|
|
|
+ Procedure TestFunctionAggregateSumCurrency;
|
|
Procedure TestFunctionAggregateCount;
|
|
Procedure TestFunctionAggregateCount;
|
|
Procedure TestFunctionAggregateAvg;
|
|
Procedure TestFunctionAggregateAvg;
|
|
Procedure TestFunctionAggregateMin;
|
|
Procedure TestFunctionAggregateMin;
|
|
@@ -1004,6 +1018,7 @@ begin
|
|
Case Result.ResultType of
|
|
Case Result.ResultType of
|
|
rtInteger : Result.ResInteger:=FVarValue;
|
|
rtInteger : Result.ResInteger:=FVarValue;
|
|
rtFloat : Result.ResFloat:=FVarValue / 2;
|
|
rtFloat : Result.ResFloat:=FVarValue / 2;
|
|
|
|
+ rtCurrency : Result.ResCurrency:=FVarValue / 2;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -1163,6 +1178,40 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestParserAggregate.TestSumAggregate3;
|
|
|
|
+Var
|
|
|
|
+ C : TAggregateSum;
|
|
|
|
+ V : TFPExprVariable;
|
|
|
|
+ I : Integer;
|
|
|
|
+ R : TFPExpressionResult;
|
|
|
|
+ A : TExprArgumentArray;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ FFunction.ResultType:=rtCurrency;
|
|
|
|
+ FFunction.ParameterTypes:='F';
|
|
|
|
+ FFunction.Name:='SUM';
|
|
|
|
+ FFunction2.ResultType:=rtCurrency;
|
|
|
|
+ C:=Nil;
|
|
|
|
+ V:=TFPExprVariable.CreateIdentifier(FFunction2);
|
|
|
|
+ try
|
|
|
|
+ SetLength(A,1);
|
|
|
|
+ A[0]:=V;
|
|
|
|
+ C:=TAggregateSum.CreateFunction(FFunction,A);
|
|
|
|
+ C.Check;
|
|
|
|
+ C.InitAggregate;
|
|
|
|
+ For I:=1 to 10 do
|
|
|
|
+ begin
|
|
|
|
+ FVarValue:=I;
|
|
|
|
+ C.UpdateAggregate;
|
|
|
|
+ end;
|
|
|
|
+ C.GetNodeValue(R);
|
|
|
|
+ AssertEquals('Correct type',rtCurrency,R.ResultType);
|
|
|
|
+ AssertEquals('Correct value',55/2,R.ResCurrency,0.1);
|
|
|
|
+ finally
|
|
|
|
+ C.Free;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TTestParserAggregate.TestAvgAggregate;
|
|
procedure TTestParserAggregate.TestAvgAggregate;
|
|
|
|
|
|
Var
|
|
Var
|
|
@@ -1237,7 +1286,6 @@ procedure TTestParserAggregate.TestAvgAggregate3;
|
|
Var
|
|
Var
|
|
C : TAggregateAvg;
|
|
C : TAggregateAvg;
|
|
V : TFPExprVariable;
|
|
V : TFPExprVariable;
|
|
- I : Integer;
|
|
|
|
R : TFPExpressionResult;
|
|
R : TFPExpressionResult;
|
|
A : TExprArgumentArray;
|
|
A : TExprArgumentArray;
|
|
|
|
|
|
@@ -1565,6 +1613,7 @@ begin
|
|
AssertEquals('Correct result',2.34,FN.ConstValue.ResFloat);
|
|
AssertEquals('Correct result',2.34,FN.ConstValue.ResFloat);
|
|
AssertEquals('Correct result',2.34,FN.NodeValue.ResFloat);
|
|
AssertEquals('Correct result',2.34,FN.NodeValue.ResFloat);
|
|
Val(FN.AsString,F,C);
|
|
Val(FN.AsString,F,C);
|
|
|
|
+ AssertEquals('Correct conversion',0,C);
|
|
AssertEquals('AsString ok',2.34,F,0.001);
|
|
AssertEquals('AsString ok',2.34,F,0.001);
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -2828,6 +2877,12 @@ begin
|
|
AssertEquals('Correct float result',F,FP.Evaluate.ResFloat);
|
|
AssertEquals('Correct float result',F,FP.Evaluate.ResFloat);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestExpressionParser.AssertCurrencyResult(C: Currency);
|
|
|
|
+begin
|
|
|
|
+ AssertEquals('Correct currency result',C,FP.ExprNode.NodeValue.ResCurrency);
|
|
|
|
+ AssertEquals('Correct currency result',C,FP.Evaluate.ResCurrency);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TTestExpressionParser.AssertResult(I: Int64);
|
|
procedure TTestExpressionParser.AssertResult(I: Int64);
|
|
begin
|
|
begin
|
|
AssertEquals('Correct integer result',I,FP.ExprNode.NodeValue.ResInteger);
|
|
AssertEquals('Correct integer result',I,FP.ExprNode.NodeValue.ResInteger);
|
|
@@ -4439,6 +4494,7 @@ begin
|
|
rtString : res.ResString:=FP.Identifiers[0].AsString;
|
|
rtString : res.ResString:=FP.Identifiers[0].AsString;
|
|
rtInteger : Res.ResInteger:=FP.Identifiers[0].AsInteger;
|
|
rtInteger : Res.ResInteger:=FP.Identifiers[0].AsInteger;
|
|
rtFloat : Res.ResFloat:=FP.Identifiers[0].AsFloat;
|
|
rtFloat : Res.ResFloat:=FP.Identifiers[0].AsFloat;
|
|
|
|
+ rtCurrency : Res.ResCurrency:=FP.Identifiers[0].AsCurrency;
|
|
rtDateTime : Res.ResDateTime:=FP.Identifiers[0].AsDateTime;
|
|
rtDateTime : Res.ResDateTime:=FP.Identifiers[0].AsDateTime;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -4455,6 +4511,7 @@ begin
|
|
rtString : FP.Identifiers[0].AsString:=res.ResString;
|
|
rtString : FP.Identifiers[0].AsString:=res.ResString;
|
|
rtInteger : FP.Identifiers[0].AsInteger:=Res.ResInteger;
|
|
rtInteger : FP.Identifiers[0].AsInteger:=Res.ResInteger;
|
|
rtFloat : FP.Identifiers[0].AsFloat:=Res.ResFloat;
|
|
rtFloat : FP.Identifiers[0].AsFloat:=Res.ResFloat;
|
|
|
|
+ rtCurrency : FP.Identifiers[0].AsCurrency:=Res.ResCurrency;
|
|
rtDateTime : FP.Identifiers[0].AsDateTime:=Res.ResDateTime;
|
|
rtDateTime : FP.Identifiers[0].AsDateTime:=Res.ResDateTime;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -4540,14 +4597,12 @@ Var
|
|
begin
|
|
begin
|
|
D:=Now;
|
|
D:=Now;
|
|
I:=FP.Identifiers.AddDateTimeVariable('a',D);
|
|
I:=FP.Identifiers.AddDateTimeVariable('a',D);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
AssertException('Cannot add same name twice',EExprParser,@AddVariabletwice);
|
|
AssertException('Cannot add same name twice',EExprParser,@AddVariabletwice);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TTestParserVariables.TestVariable8;
|
|
procedure TTestParserVariables.TestVariable8;
|
|
|
|
|
|
-Var
|
|
|
|
- I : TFPExprIdentifierDef;
|
|
|
|
-
|
|
|
|
begin
|
|
begin
|
|
FP.Identifiers.AddIntegerVariable('a',123);
|
|
FP.Identifiers.AddIntegerVariable('a',123);
|
|
FP.Identifiers.AddIntegerVariable('b',123);
|
|
FP.Identifiers.AddIntegerVariable('b',123);
|
|
@@ -4564,6 +4619,7 @@ Var
|
|
|
|
|
|
begin
|
|
begin
|
|
I:=FP.Identifiers.AddIntegerVariable('a',123);
|
|
I:=FP.Identifiers.AddIntegerVariable('a',123);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
FP.Expression:='a';
|
|
FP.Expression:='a';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPExprVariable, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPExprVariable, FP.ExprNode);
|
|
@@ -4578,6 +4634,7 @@ Var
|
|
|
|
|
|
begin
|
|
begin
|
|
I:=FP.Identifiers.AddStringVariable('a','a123');
|
|
I:=FP.Identifiers.AddStringVariable('a','a123');
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
FP.Expression:='a';
|
|
FP.Expression:='a';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPExprVariable, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPExprVariable, FP.ExprNode);
|
|
@@ -4592,6 +4649,7 @@ Var
|
|
|
|
|
|
begin
|
|
begin
|
|
I:=FP.Identifiers.AddFloatVariable('a',1.23);
|
|
I:=FP.Identifiers.AddFloatVariable('a',1.23);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
FP.Expression:='a';
|
|
FP.Expression:='a';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPExprVariable, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPExprVariable, FP.ExprNode);
|
|
@@ -4599,6 +4657,21 @@ begin
|
|
AssertResult(1.23);
|
|
AssertResult(1.23);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestParserVariables.TestVariable36;
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ I : TFPExprIdentifierDef;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ I:=FP.Identifiers.AddCurrencyVariable('a',1.23);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
|
|
+ FP.Expression:='a';
|
|
|
|
+ AssertNotNull('Have result node',FP.ExprNode);
|
|
|
|
+ AssertNodeType('Constant expression',TFPExprVariable, FP.ExprNode);
|
|
|
|
+ AssertResultType(rtCurrency);
|
|
|
|
+ AssertCurrencyResult(1.23);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TTestParserVariables.TestVariable12;
|
|
procedure TTestParserVariables.TestVariable12;
|
|
|
|
|
|
Var
|
|
Var
|
|
@@ -4606,6 +4679,7 @@ Var
|
|
|
|
|
|
begin
|
|
begin
|
|
I:=FP.Identifiers.AddBooleanVariable('a',True);
|
|
I:=FP.Identifiers.AddBooleanVariable('a',True);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
FP.Expression:='a';
|
|
FP.Expression:='a';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPExprVariable, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPExprVariable, FP.ExprNode);
|
|
@@ -4622,6 +4696,7 @@ Var
|
|
begin
|
|
begin
|
|
D:=Date;
|
|
D:=Date;
|
|
I:=FP.Identifiers.AddDateTimeVariable('a',D);
|
|
I:=FP.Identifiers.AddDateTimeVariable('a',D);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
FP.Expression:='a';
|
|
FP.Expression:='a';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPExprVariable, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPExprVariable, FP.ExprNode);
|
|
@@ -4648,6 +4723,7 @@ Var
|
|
|
|
|
|
begin
|
|
begin
|
|
I:=FP.Identifiers.AddIntegerVariable('a',1);
|
|
I:=FP.Identifiers.AddIntegerVariable('a',1);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
FP.BuildHashList;
|
|
FP.BuildHashList;
|
|
S:=FP.IdentifierByName('A');
|
|
S:=FP.IdentifierByName('A');
|
|
AssertSame('Identifier found',I,S);
|
|
AssertSame('Identifier found',I,S);
|
|
@@ -4660,6 +4736,7 @@ Var
|
|
|
|
|
|
begin
|
|
begin
|
|
I:=FP.Identifiers.AddIntegerVariable('a',1);
|
|
I:=FP.Identifiers.AddIntegerVariable('a',1);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
FP.BuildHashList;
|
|
FP.BuildHashList;
|
|
S:=FP.IdentifierByName('B');
|
|
S:=FP.IdentifierByName('B');
|
|
AssertNull('Identifier not found',S);
|
|
AssertNull('Identifier not found',S);
|
|
@@ -4668,10 +4745,11 @@ end;
|
|
procedure TTestParserVariables.TestVariable17;
|
|
procedure TTestParserVariables.TestVariable17;
|
|
|
|
|
|
Var
|
|
Var
|
|
- I,S : TFPExprIdentifierDef;
|
|
|
|
|
|
+ I : TFPExprIdentifierDef;
|
|
|
|
|
|
begin
|
|
begin
|
|
I:=FP.Identifiers.AddIntegerVariable('a',1);
|
|
I:=FP.Identifiers.AddIntegerVariable('a',1);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
FP.BuildHashList;
|
|
FP.BuildHashList;
|
|
AssertException('Identifier not found',EExprParser,@unknownvariable);
|
|
AssertException('Identifier not found',EExprParser,@unknownvariable);
|
|
end;
|
|
end;
|
|
@@ -4683,6 +4761,7 @@ Var
|
|
|
|
|
|
begin
|
|
begin
|
|
I:=FP.Identifiers.AddIntegerVariable('a',1);
|
|
I:=FP.Identifiers.AddIntegerVariable('a',1);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
S:=FP.Identifiers.FindIdentifier('B');
|
|
S:=FP.Identifiers.FindIdentifier('B');
|
|
AssertNull('Identifier not found',S);
|
|
AssertNull('Identifier not found',S);
|
|
end;
|
|
end;
|
|
@@ -4711,18 +4790,24 @@ end;
|
|
|
|
|
|
procedure TTestParserVariables.TestAccess(Skip : TResultType);
|
|
procedure TTestParserVariables.TestAccess(Skip : TResultType);
|
|
|
|
|
|
|
|
+begin
|
|
|
|
+ TestAccess([Skip]);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TTestParserVariables.TestAccess(Skip : TResultTypes);
|
|
|
|
+
|
|
Var
|
|
Var
|
|
rt : TResultType;
|
|
rt : TResultType;
|
|
|
|
|
|
begin
|
|
begin
|
|
For rt:=Low(TResultType) to High(TResultType) do
|
|
For rt:=Low(TResultType) to High(TResultType) do
|
|
- if rt<>skip then
|
|
|
|
|
|
+ if Not (rt in skip) then
|
|
begin
|
|
begin
|
|
FasWrongType:=rt;
|
|
FasWrongType:=rt;
|
|
AssertException('Acces as '+ResultTypeName(rt),EExprParser,@ReadWrongtype);
|
|
AssertException('Acces as '+ResultTypeName(rt),EExprParser,@ReadWrongtype);
|
|
end;
|
|
end;
|
|
For rt:=Low(TResultType) to High(TResultType) do
|
|
For rt:=Low(TResultType) to High(TResultType) do
|
|
- if rt<>skip then
|
|
|
|
|
|
+ if Not (rt in skip) then
|
|
begin
|
|
begin
|
|
FasWrongType:=rt;
|
|
FasWrongType:=rt;
|
|
AssertException('Acces as '+ResultTypeName(rt),EExprParser,@WriteWrongtype);
|
|
AssertException('Acces as '+ResultTypeName(rt),EExprParser,@WriteWrongtype);
|
|
@@ -4732,13 +4817,20 @@ end;
|
|
procedure TTestParserVariables.TestVariable21;
|
|
procedure TTestParserVariables.TestVariable21;
|
|
begin
|
|
begin
|
|
FP.IDentifiers.AddIntegerVariable('a',1);
|
|
FP.IDentifiers.AddIntegerVariable('a',1);
|
|
- TestAccess(rtInteger);
|
|
|
|
|
|
+ TestAccess([rtInteger]);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TTestParserVariables.TestVariable22;
|
|
procedure TTestParserVariables.TestVariable22;
|
|
begin
|
|
begin
|
|
FP.IDentifiers.AddFloatVariable('a',1.0);
|
|
FP.IDentifiers.AddFloatVariable('a',1.0);
|
|
- TestAccess(rtFloat);
|
|
|
|
|
|
+ TestAccess([rtFloat]);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TTestParserVariables.TestVariable35;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ FP.IDentifiers.AddCurrencyVariable('a',1.0);
|
|
|
|
+ TestAccess([rtCurrency]);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TTestParserVariables.TestVariable23;
|
|
procedure TTestParserVariables.TestVariable23;
|
|
@@ -4886,6 +4978,7 @@ Var
|
|
|
|
|
|
begin
|
|
begin
|
|
B:=FTest33.AsBoolean;
|
|
B:=FTest33.AsBoolean;
|
|
|
|
+ AssertTrue(B in [true,False])
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TTestParserVariables.TestVariable33;
|
|
procedure TTestParserVariables.TestVariable33;
|
|
@@ -4947,6 +5040,12 @@ begin
|
|
Result.resFloat:=Args[0].resFloat;
|
|
Result.resFloat:=Args[0].resFloat;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+Procedure EchoCurrency(Var Result : TFPExpressionResult; Const Args : TExprParameterArray);
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ Result.resCurrency:=Args[0].resCurrency;
|
|
|
|
+end;
|
|
|
|
+
|
|
Procedure EchoString(Var Result : TFPExpressionResult; Const Args : TExprParameterArray);
|
|
Procedure EchoString(Var Result : TFPExpressionResult; Const Args : TExprParameterArray);
|
|
|
|
|
|
begin
|
|
begin
|
|
@@ -4977,6 +5076,12 @@ begin
|
|
Result.resFloat:=Args[0].resFloat;
|
|
Result.resFloat:=Args[0].resFloat;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+Procedure TTestExpressionParser.DoEchoCurrency(Var Result : TFPExpressionResult; Const Args : TExprParameterArray);
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ Result.resCurrency:=Args[0].resCurrency;
|
|
|
|
+end;
|
|
|
|
+
|
|
Procedure TTestExpressionParser.DoEchoString(Var Result : TFPExpressionResult; Const Args : TExprParameterArray);
|
|
Procedure TTestExpressionParser.DoEchoString(Var Result : TFPExpressionResult; Const Args : TExprParameterArray);
|
|
|
|
|
|
begin
|
|
begin
|
|
@@ -5011,6 +5116,7 @@ begin
|
|
rtString : res.ResString:=FP.Identifiers[0].AsString;
|
|
rtString : res.ResString:=FP.Identifiers[0].AsString;
|
|
rtInteger : Res.ResInteger:=FP.Identifiers[0].AsInteger;
|
|
rtInteger : Res.ResInteger:=FP.Identifiers[0].AsInteger;
|
|
rtFloat : Res.ResFloat:=FP.Identifiers[0].AsFloat;
|
|
rtFloat : Res.ResFloat:=FP.Identifiers[0].AsFloat;
|
|
|
|
+ rtCurrency : Res.ResCurrency:=FP.Identifiers[0].AsCurrency;
|
|
rtDateTime : Res.ResDateTime:=FP.Identifiers[0].AsDateTime;
|
|
rtDateTime : Res.ResDateTime:=FP.Identifiers[0].AsDateTime;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -5027,6 +5133,7 @@ begin
|
|
rtString : FP.Identifiers[0].AsString:=res.ResString;
|
|
rtString : FP.Identifiers[0].AsString:=res.ResString;
|
|
rtInteger : FP.Identifiers[0].AsInteger:=Res.ResInteger;
|
|
rtInteger : FP.Identifiers[0].AsInteger:=Res.ResInteger;
|
|
rtFloat : FP.Identifiers[0].AsFloat:=Res.ResFloat;
|
|
rtFloat : FP.Identifiers[0].AsFloat:=Res.ResFloat;
|
|
|
|
+ rtCurrency : FP.Identifiers[0].AsCurrency:=Res.ResCurrency;
|
|
rtDateTime : FP.Identifiers[0].AsDateTime:=Res.ResDateTime;
|
|
rtDateTime : FP.Identifiers[0].AsDateTime:=Res.ResDateTime;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -5119,6 +5226,24 @@ begin
|
|
AssertException('No write access',EExprParser,@TryWrite);
|
|
AssertException('No write access',EExprParser,@TryWrite);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestParserFunctions.TestFunction30;
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ I : TFPExprIdentifierDef;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ I:=FP.Identifiers.AddFunction('EchoCurrency','C','C',@EchoCurrency);
|
|
|
|
+ AssertEquals('List is dirty',True,FP.Dirty);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
|
|
+ AssertEquals('One variable added',1,FP.Identifiers.Count);
|
|
|
|
+ AssertSame('Result equals variable added',I,FP.Identifiers[0]);
|
|
|
|
+ AssertEquals('Function has correct resulttype',rtCurrency,I.ResultType);
|
|
|
|
+ AssertSame('Function has correct address',Pointer(@EchoCurrency),Pointer(I.OnGetFunctionValueCallBack));
|
|
|
|
+ FaccessAs:=rtCurrency;
|
|
|
|
+ AssertException('No read access',EExprParser,@TryRead);
|
|
|
|
+ AssertException('No write access',EExprParser,@TryWrite);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TTestParserFunctions.TestFunction6;
|
|
procedure TTestParserFunctions.TestFunction6;
|
|
|
|
|
|
Var
|
|
Var
|
|
@@ -5197,6 +5322,21 @@ begin
|
|
// AssertSame('Function has correct address',Pointer(@EchoFloat),Pointer(I.OnGetFunctionValueCallBack));
|
|
// AssertSame('Function has correct address',Pointer(@EchoFloat),Pointer(I.OnGetFunctionValueCallBack));
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestParserFunctions.TestFunction31;
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ I : TFPExprIdentifierDef;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ I:=FP.Identifiers.AddFunction('EchoCurrency','C','C',@DoEchoCurrency);
|
|
|
|
+ AssertEquals('List is dirty',True,FP.Dirty);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
|
|
+ AssertEquals('One variable added',1,FP.Identifiers.Count);
|
|
|
|
+ AssertSame('Result equals variable added',I,FP.Identifiers[0]);
|
|
|
|
+ AssertEquals('Function has correct resulttype',rtCurrency,I.ResultType);
|
|
|
|
+// AssertSame('Function has correct address',Pointer(@EchoFloat),Pointer(I.OnGetFunctionValueCallBack));
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TTestParserFunctions.TestFunction11;
|
|
procedure TTestParserFunctions.TestFunction11;
|
|
|
|
|
|
Var
|
|
Var
|
|
@@ -5221,6 +5361,7 @@ Var
|
|
begin
|
|
begin
|
|
D:=Date;
|
|
D:=Date;
|
|
I:=FP.Identifiers.AddFunction('Date','D','',@GetDate);
|
|
I:=FP.Identifiers.AddFunction('Date','D','',@GetDate);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
FP.Expression:='Date';
|
|
FP.Expression:='Date';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
@@ -5237,7 +5378,9 @@ Var
|
|
begin
|
|
begin
|
|
D:=Date;
|
|
D:=Date;
|
|
I:=FP.Identifiers.AddDateTimeVariable('a',D);
|
|
I:=FP.Identifiers.AddDateTimeVariable('a',D);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
I:=FP.Identifiers.AddFunction('EchoDate','D','D',@EchoDate);
|
|
I:=FP.Identifiers.AddFunction('EchoDate','D','D',@EchoDate);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
FP.Expression:='EchoDate(a)';
|
|
FP.Expression:='EchoDate(a)';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
@@ -5248,11 +5391,10 @@ end;
|
|
procedure TTestParserFunctions.TestFunction14;
|
|
procedure TTestParserFunctions.TestFunction14;
|
|
Var
|
|
Var
|
|
I : TFPExprIdentifierDef;
|
|
I : TFPExprIdentifierDef;
|
|
- D : TDateTime;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
- D:=Date;
|
|
|
|
I:=FP.Identifiers.AddFunction('EchoInteger','I','I',@EchoInteger);
|
|
I:=FP.Identifiers.AddFunction('EchoInteger','I','I',@EchoInteger);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
FP.Expression:='EchoInteger(13)';
|
|
FP.Expression:='EchoInteger(13)';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
@@ -5263,11 +5405,10 @@ end;
|
|
procedure TTestParserFunctions.TestFunction15;
|
|
procedure TTestParserFunctions.TestFunction15;
|
|
Var
|
|
Var
|
|
I : TFPExprIdentifierDef;
|
|
I : TFPExprIdentifierDef;
|
|
- D : TDateTime;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
- D:=Date;
|
|
|
|
I:=FP.Identifiers.AddFunction('EchoBoolean','B','B',@EchoBoolean);
|
|
I:=FP.Identifiers.AddFunction('EchoBoolean','B','B',@EchoBoolean);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
FP.Expression:='EchoBoolean(True)';
|
|
FP.Expression:='EchoBoolean(True)';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
@@ -5278,11 +5419,10 @@ end;
|
|
procedure TTestParserFunctions.TestFunction16;
|
|
procedure TTestParserFunctions.TestFunction16;
|
|
Var
|
|
Var
|
|
I : TFPExprIdentifierDef;
|
|
I : TFPExprIdentifierDef;
|
|
- D : TDateTime;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
- D:=Date;
|
|
|
|
I:=FP.Identifiers.AddFunction('EchoFloat','F','F',@EchoFloat);
|
|
I:=FP.Identifiers.AddFunction('EchoFloat','F','F',@EchoFloat);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
FP.Expression:='EchoFloat(1.234)';
|
|
FP.Expression:='EchoFloat(1.234)';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
@@ -5290,14 +5430,47 @@ begin
|
|
AssertResult(1.234);
|
|
AssertResult(1.234);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestParserFunctions.TestFunction32;
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ I : TFPExprIdentifierDef;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ // Note there will be an implicit conversion float-> currency as the const will be a float
|
|
|
|
+ I:=FP.Identifiers.AddFunction('EchoCurrency','C','C',@EchoCurrency);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
|
|
+ FP.Expression:='EchoCurrency(1.234)';
|
|
|
|
+ AssertNotNull('Have result node',FP.ExprNode);
|
|
|
|
+ AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
|
|
+ AssertResultType(rtCurrency);
|
|
|
|
+ AssertCurrencyResult(1.234);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TTestParserFunctions.TestFunction33;
|
|
|
|
+Var
|
|
|
|
+ I : TFPExprIdentifierDef;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ // Note there will be no conversion
|
|
|
|
+ I:=FP.Identifiers.AddCurrencyVariable('a',1.234);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
|
|
+ I:=FP.Identifiers.AddFunction('EchoCurrency','C','C',@EchoCurrency);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
|
|
+ FP.Expression:='EchoCurrency(a)';
|
|
|
|
+ AssertNotNull('Have result node',FP.ExprNode);
|
|
|
|
+ AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
|
|
+ AssertResultType(rtCurrency);
|
|
|
|
+ AssertCurrencyResult(1.234);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TTestParserFunctions.TestFunction17;
|
|
procedure TTestParserFunctions.TestFunction17;
|
|
|
|
+
|
|
Var
|
|
Var
|
|
I : TFPExprIdentifierDef;
|
|
I : TFPExprIdentifierDef;
|
|
- D : TDateTime;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
- D:=Date;
|
|
|
|
I:=FP.Identifiers.AddFunction('EchoString','S','S',@EchoString);
|
|
I:=FP.Identifiers.AddFunction('EchoString','S','S',@EchoString);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
FP.Expression:='EchoString(''Aloha'')';
|
|
FP.Expression:='EchoString(''Aloha'')';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionCallBack, FP.ExprNode);
|
|
@@ -5315,7 +5488,9 @@ Var
|
|
begin
|
|
begin
|
|
D:=Date;
|
|
D:=Date;
|
|
I:=FP.Identifiers.AddDateTimeVariable('a',D);
|
|
I:=FP.Identifiers.AddDateTimeVariable('a',D);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
I:=FP.Identifiers.AddFunction('EchoDate','D','D',@DoEchoDate);
|
|
I:=FP.Identifiers.AddFunction('EchoDate','D','D',@DoEchoDate);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
FP.Expression:='EchoDate(a)';
|
|
FP.Expression:='EchoDate(a)';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionEventHandler, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionEventHandler, FP.ExprNode);
|
|
@@ -5326,11 +5501,10 @@ end;
|
|
procedure TTestParserFunctions.TestFunction19;
|
|
procedure TTestParserFunctions.TestFunction19;
|
|
Var
|
|
Var
|
|
I : TFPExprIdentifierDef;
|
|
I : TFPExprIdentifierDef;
|
|
- D : TDateTime;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
- D:=Date;
|
|
|
|
I:=FP.Identifiers.AddFunction('EchoInteger','I','I',@DoEchoInteger);
|
|
I:=FP.Identifiers.AddFunction('EchoInteger','I','I',@DoEchoInteger);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
FP.Expression:='EchoInteger(13)';
|
|
FP.Expression:='EchoInteger(13)';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionEventHandler, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionEventHandler, FP.ExprNode);
|
|
@@ -5341,11 +5515,10 @@ end;
|
|
procedure TTestParserFunctions.TestFunction20;
|
|
procedure TTestParserFunctions.TestFunction20;
|
|
Var
|
|
Var
|
|
I : TFPExprIdentifierDef;
|
|
I : TFPExprIdentifierDef;
|
|
- D : TDateTime;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
- D:=Date;
|
|
|
|
I:=FP.Identifiers.AddFunction('EchoBoolean','B','B',@DoEchoBoolean);
|
|
I:=FP.Identifiers.AddFunction('EchoBoolean','B','B',@DoEchoBoolean);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
FP.Expression:='EchoBoolean(True)';
|
|
FP.Expression:='EchoBoolean(True)';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionEventHandler, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionEventHandler, FP.ExprNode);
|
|
@@ -5356,11 +5529,10 @@ end;
|
|
procedure TTestParserFunctions.TestFunction21;
|
|
procedure TTestParserFunctions.TestFunction21;
|
|
Var
|
|
Var
|
|
I : TFPExprIdentifierDef;
|
|
I : TFPExprIdentifierDef;
|
|
- D : TDateTime;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
- D:=Date;
|
|
|
|
I:=FP.Identifiers.AddFunction('EchoFloat','F','F',@DoEchoFloat);
|
|
I:=FP.Identifiers.AddFunction('EchoFloat','F','F',@DoEchoFloat);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
FP.Expression:='EchoFloat(1.234)';
|
|
FP.Expression:='EchoFloat(1.234)';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionEventHandler, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionEventHandler, FP.ExprNode);
|
|
@@ -5371,11 +5543,10 @@ end;
|
|
procedure TTestParserFunctions.TestFunction22;
|
|
procedure TTestParserFunctions.TestFunction22;
|
|
Var
|
|
Var
|
|
I : TFPExprIdentifierDef;
|
|
I : TFPExprIdentifierDef;
|
|
- D : TDateTime;
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
- D:=Date;
|
|
|
|
I:=FP.Identifiers.AddFunction('EchoString','S','S',@DoEchoString);
|
|
I:=FP.Identifiers.AddFunction('EchoString','S','S',@DoEchoString);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
FP.Expression:='EchoString(''Aloha'')';
|
|
FP.Expression:='EchoString(''Aloha'')';
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNotNull('Have result node',FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionEventHandler, FP.ExprNode);
|
|
AssertNodeType('Constant expression',TFPFunctionEventHandler, FP.ExprNode);
|
|
@@ -5392,6 +5563,7 @@ Var
|
|
begin
|
|
begin
|
|
D:=Date;
|
|
D:=Date;
|
|
I:=FP.Identifiers.AddFunction('Date','D','',@DoGetDate);
|
|
I:=FP.Identifiers.AddFunction('Date','D','',@DoGetDate);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
AssertEquals('List is dirty',True,FP.Dirty);
|
|
AssertEquals('List is dirty',True,FP.Dirty);
|
|
AssertNotNull('Addvariable returns result',I);
|
|
AssertNotNull('Addvariable returns result',I);
|
|
AssertEquals('One variable added',1,FP.Identifiers.Count);
|
|
AssertEquals('One variable added',1,FP.Identifiers.Count);
|
|
@@ -5411,8 +5583,8 @@ Var
|
|
|
|
|
|
begin
|
|
begin
|
|
I:=FP.Identifiers.AddFunction('AddInteger','I','II',@DoAddInteger);
|
|
I:=FP.Identifiers.AddFunction('AddInteger','I','II',@DoAddInteger);
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
AssertEquals('List is dirty',True,FP.Dirty);
|
|
AssertEquals('List is dirty',True,FP.Dirty);
|
|
- AssertNotNull('Addvariable returns result',I);
|
|
|
|
AssertEquals('One variable added',1,FP.Identifiers.Count);
|
|
AssertEquals('One variable added',1,FP.Identifiers.Count);
|
|
AssertSame('Result equals variable added',I,FP.Identifiers[0]);
|
|
AssertSame('Result equals variable added',I,FP.Identifiers[0]);
|
|
AssertEquals('Function has correct resulttype',rtInteger,I.ResultType);
|
|
AssertEquals('Function has correct resulttype',rtInteger,I.ResultType);
|
|
@@ -5431,7 +5603,7 @@ Var
|
|
begin
|
|
begin
|
|
I:=FP.Identifiers.AddFunction('Delete','S','SII',@DoDeleteString);
|
|
I:=FP.Identifiers.AddFunction('Delete','S','SII',@DoDeleteString);
|
|
AssertEquals('List is dirty',True,FP.Dirty);
|
|
AssertEquals('List is dirty',True,FP.Dirty);
|
|
- AssertNotNull('Addvariable returns result',I);
|
|
|
|
|
|
+ AssertNotNull('Have identifier',I);
|
|
AssertEquals('One variable added',1,FP.Identifiers.Count);
|
|
AssertEquals('One variable added',1,FP.Identifiers.Count);
|
|
AssertSame('Result equals variable added',I,FP.Identifiers[0]);
|
|
AssertSame('Result equals variable added',I,FP.Identifiers[0]);
|
|
AssertEquals('Function has correct resulttype',rtString,I.ResultType);
|
|
AssertEquals('Function has correct resulttype',rtString,I.ResultType);
|
|
@@ -5507,6 +5679,7 @@ Var
|
|
begin
|
|
begin
|
|
// Test type mismatch
|
|
// Test type mismatch
|
|
I:=FP.Identifiers.AddFunction('AddInteger','I','II',@DoAddInteger);
|
|
I:=FP.Identifiers.AddFunction('AddInteger','I','II',@DoAddInteger);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
TestParser('AddInteger(3 and 2,''s'')');
|
|
TestParser('AddInteger(3 and 2,''s'')');
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -5589,6 +5762,21 @@ begin
|
|
AssertEquals('Variable has correct value',FloatToStr(1.23),I.Value);
|
|
AssertEquals('Variable has correct value',FloatToStr(1.23),I.Value);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestBuiltinsManager.TestVariable7;
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ I : TFPBuiltinExprIdentifierDef;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ I:=FM.AddCurrencyVariable(bcUser,'a',1.23);
|
|
|
|
+ AssertNotNull('Addvariable returns result',I);
|
|
|
|
+ AssertEquals('One variable added',1,FM.IdentifierCount);
|
|
|
|
+ AssertSame('Result equals variable added',I,FM.Identifiers[0]);
|
|
|
|
+ AssertEquals('Variable has correct category',ord(bcUser),Ord(I.Category));
|
|
|
|
+ AssertEquals('Variable has correct resulttype',rtCurrency,I.ResultType);
|
|
|
|
+ AssertEquals('Variable has correct value',CurrToStr(1.23),I.Value);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TTestBuiltinsManager.TestVariable5;
|
|
procedure TTestBuiltinsManager.TestVariable5;
|
|
|
|
|
|
Var
|
|
Var
|
|
@@ -5786,6 +5974,21 @@ begin
|
|
AssertResult(AResult);
|
|
AssertResult(AResult);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestBuiltins.AssertAggregateCurrExpression(Const AExpression : String; AResult : Currency; AUpdateCount : integer);
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ FP.BuiltIns:=AllBuiltIns;
|
|
|
|
+ SetExpression(AExpression);
|
|
|
|
+ AssertEquals('Has aggregate',True,FP.ExprNode.HasAggregate);
|
|
|
|
+ FP.InitAggregate;
|
|
|
|
+ While AUpdateCount>0 do
|
|
|
|
+ begin
|
|
|
|
+ FP.UpdateAggregate;
|
|
|
|
+ Dec(AUpdateCount);
|
|
|
|
+ end;
|
|
|
|
+ AssertCurrencyResult(AResult);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TTestBuiltins.TestRegister;
|
|
procedure TTestBuiltins.TestRegister;
|
|
|
|
|
|
begin
|
|
begin
|
|
@@ -6314,9 +6517,21 @@ end;
|
|
procedure TTestBuiltins.TestFunctionAggregateSum;
|
|
procedure TTestBuiltins.TestFunctionAggregateSum;
|
|
begin
|
|
begin
|
|
FP.Identifiers.AddIntegerVariable('S',2);
|
|
FP.Identifiers.AddIntegerVariable('S',2);
|
|
|
|
+ AssertAggregateExpression('sum(S)',10,5);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TTestBuiltins.TestFunctionAggregateSumFloat;
|
|
|
|
+begin
|
|
|
|
+ FP.Identifiers.AddFloatVariable('S',2.0);
|
|
AssertAggregateExpression('sum(S)',10.0,5);
|
|
AssertAggregateExpression('sum(S)',10.0,5);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TTestBuiltins.TestFunctionAggregateSumCurrency;
|
|
|
|
+begin
|
|
|
|
+ FP.Identifiers.AddCurrencyVariable('S',2.0);
|
|
|
|
+ AssertAggregateCurrExpression('sum(S)',Currency(10.0),5);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TTestBuiltins.TestFunctionAggregateCount;
|
|
procedure TTestBuiltins.TestFunctionAggregateCount;
|
|
begin
|
|
begin
|
|
AssertAggregateExpression('count',5,5);
|
|
AssertAggregateExpression('count',5,5);
|
|
@@ -6796,7 +7011,7 @@ end;
|
|
|
|
|
|
initialization
|
|
initialization
|
|
|
|
|
|
- RegisterTests([TTestExpressionScanner, TTestDestroyNode,
|
|
|
|
|
|
+ RegisterTests('ExprPars',[TTestExpressionScanner, TTestDestroyNode,
|
|
TTestConstExprNode,TTestNegateExprNode,
|
|
TTestConstExprNode,TTestNegateExprNode,
|
|
TTestBinaryAndNode,TTestBinaryOrNode,TTestBinaryXOrNode,
|
|
TTestBinaryAndNode,TTestBinaryOrNode,TTestBinaryXOrNode,
|
|
TTestNotNode,TTestEqualNode,TTestUnEqualNode,
|
|
TTestNotNode,TTestEqualNode,TTestUnEqualNode,
|