You've already forked lazarus-ccr
fpspreadsheet: Reactivate the expression parser test cases which were commented (and forgotten) some time ago. Activate missing argument tests. Add some "exotic" formulas. All passed.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4186 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1259,14 +1259,6 @@ begin
|
||||
ParserError(SErrUnexpectedEndOfExpression);
|
||||
end;
|
||||
|
||||
{ If the result types differ, they are converted to a common type if possible. }
|
||||
{
|
||||
procedure TsExpressionParser.CheckNodes(var ALeft, ARight: TsExprNode);
|
||||
begin
|
||||
ALeft := MatchNodes(ALeft, ARight);
|
||||
ARight := MatchNodes(ARight, ALeft);
|
||||
end;
|
||||
}
|
||||
procedure TsExpressionParser.CheckResultType(const Res: TsExpressionResult;
|
||||
AType: TsResultType); inline;
|
||||
begin
|
||||
@ -1280,24 +1272,7 @@ begin
|
||||
FHashList.Clear;
|
||||
FreeAndNil(FExprNode);
|
||||
end;
|
||||
(*
|
||||
function TsExpressionParser.ConvertNode(ToDo: TsExprNode;
|
||||
ToType: TsResultType): TsExprNode;
|
||||
begin
|
||||
Result := ToDo;
|
||||
case ToDo.NodeType of
|
||||
rtInteger :
|
||||
case ToType of
|
||||
rtFloat : Result := TsIntToFloatExprNode.Create(self, Result);
|
||||
rtDateTime : Result := TsIntToDateTimeExprNode.Create(self, Result);
|
||||
end;
|
||||
rtFloat :
|
||||
case ToType of
|
||||
rtDateTime : Result := TsFloatToDateTimeExprNode.Create(self, Result);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
*)
|
||||
|
||||
{ Prepares copy mode: The formula is contained in ASourceCell and will be
|
||||
modified such as seen from ADestCell. }
|
||||
procedure TsExpressionParser.PrepareCopyMode(ASourceCell, ADestCell: PCell);
|
||||
@ -1487,7 +1462,6 @@ begin
|
||||
GetToken;
|
||||
CheckEOF;
|
||||
Right := Level3;
|
||||
//CheckNodes(Result, right);
|
||||
case tt of
|
||||
ttLessthan : C := TsLessExprNode;
|
||||
ttLessthanEqual : C := TsLessEqualExprNode;
|
||||
@ -1519,7 +1493,6 @@ begin
|
||||
GetToken;
|
||||
CheckEOF;
|
||||
right := Level4;
|
||||
//CheckNodes(Result, right);
|
||||
case tt of
|
||||
ttPlus : Result := TsAddExprNode.Create(self, Result, right);
|
||||
ttMinus : Result := TsSubtractExprNode.Create(self, Result, right);
|
||||
@ -1545,7 +1518,6 @@ begin
|
||||
tt := TokenType;
|
||||
GetToken;
|
||||
right := Level5;
|
||||
//CheckNodes(Result, right);
|
||||
case tt of
|
||||
ttMul : Result := TsMultiplyExprNode.Create(self, Result, right);
|
||||
ttDiv : Result := TsDivideExprNode.Create(self, Result, right);
|
||||
@ -1570,7 +1542,6 @@ begin
|
||||
tt := TokenType;
|
||||
GetToken;
|
||||
right := Level6;
|
||||
//CheckNodes(Result, right);
|
||||
Result := TsPowerExprNode.Create(self, Result, right);
|
||||
end;
|
||||
except
|
||||
@ -1581,13 +1552,10 @@ end;
|
||||
|
||||
function TsExpressionParser.Level6: TsExprNode;
|
||||
var
|
||||
//isPlus, isMinus: Boolean;
|
||||
signs: String;
|
||||
i: Integer;
|
||||
begin
|
||||
{$ifdef debugexpr} Writeln('Level 6 ',TokenName(TokenType),': ',CurrentToken);{$endif debugexpr}
|
||||
// isPlus := false;
|
||||
// isMinus := false;
|
||||
signs := '';
|
||||
while (TokenType in [ttPlus, ttMinus]) do
|
||||
begin
|
||||
@ -1595,10 +1563,6 @@ begin
|
||||
ttPlus : signs := signs + '+';
|
||||
ttMinus : signs := signs + '-';
|
||||
end;
|
||||
{
|
||||
isPlus := (TokenType = ttPlus);
|
||||
isMinus := (TokenType = ttMinus);
|
||||
}
|
||||
GetToken;
|
||||
end;
|
||||
Result := Level7;
|
||||
@ -1610,23 +1574,11 @@ begin
|
||||
end;
|
||||
dec(i);
|
||||
end;
|
||||
{
|
||||
if isPlus then
|
||||
Result := TsUPlusExprNode.Create(self, Result);
|
||||
if isMinus then
|
||||
Result := TsUMinusExprNode.Create(self, Result);
|
||||
}
|
||||
|
||||
while TokenType = ttPercent do begin
|
||||
Result := TsPercentExprNode.Create(self, Result);
|
||||
GetToken;
|
||||
end;
|
||||
{
|
||||
if TokenType = ttPercent then begin
|
||||
Result := TsPercentExprNode.Create(self, Result);
|
||||
GetToken;
|
||||
end;
|
||||
}
|
||||
end;
|
||||
|
||||
function TsExpressionParser.Level7: TsExprNode;
|
||||
@ -1653,53 +1605,7 @@ begin
|
||||
end
|
||||
else
|
||||
Result := Primitive;
|
||||
{
|
||||
if TokenType = ttPower then
|
||||
begin
|
||||
try
|
||||
CheckEOF;
|
||||
GetToken;
|
||||
Right := Level1; //Primitive;
|
||||
CheckNodes(Result, right);
|
||||
Result := TsPowerExprNode.Create(self, Result, Right);
|
||||
//GetToken;
|
||||
except
|
||||
Result.Free;
|
||||
raise;
|
||||
end;
|
||||
end; }
|
||||
{
|
||||
if TokenType = ttPercent then begin
|
||||
Result := TsPercentExprNode.Create(self, Result);
|
||||
GetToken;
|
||||
end;
|
||||
}
|
||||
end;
|
||||
(*
|
||||
{ Checks types of todo and match. If ToDO can be converted to it matches
|
||||
the type of match, then a node is inserted.
|
||||
For binary operations, this function is called for both operands. }
|
||||
function TsExpressionParser.MatchNodes(ToDo, Match: TsExprNode): TsExprNode;
|
||||
var
|
||||
TT, MT : TsResultType;
|
||||
begin
|
||||
Result := ToDo;
|
||||
TT := ToDo.NodeType;
|
||||
MT := Match.NodeType;
|
||||
if TT <> MT then
|
||||
begin
|
||||
if TT = rtInteger then
|
||||
begin
|
||||
if (MT in [rtFloat, rtDateTime]) then
|
||||
Result := ConvertNode(ToDo, MT);
|
||||
end
|
||||
else if (TT = rtFloat) then
|
||||
begin
|
||||
if (MT = rtDateTime) then
|
||||
Result := ConvertNode(ToDo, rtDateTime);
|
||||
end;
|
||||
end;
|
||||
end; *)
|
||||
|
||||
procedure TsExpressionParser.ParserError(Msg: String);
|
||||
begin
|
||||
@ -2057,14 +1963,7 @@ begin
|
||||
CreateNodeFromRPN(FExprNode, index);
|
||||
if Assigned(FExprNode) then FExprNode.Check;
|
||||
end;
|
||||
(*
|
||||
{ Signals that the parser is in SharedFormulaMode, i.e. there is an active cell
|
||||
to which all relative addresses have to be adapted. }
|
||||
function TsExpressionParser.SharedFormulaMode: Boolean;
|
||||
begin
|
||||
Result := (ActiveCell <> nil) and (ActiveCell^.SharedFormulaBase <> nil);
|
||||
end;
|
||||
*)
|
||||
|
||||
function TsExpressionParser.TokenType: TsTokenType;
|
||||
begin
|
||||
Result := FScanner.TokenType;
|
||||
@ -2236,10 +2135,6 @@ begin
|
||||
if ID.ExcelCode = AExcelCode then exit;
|
||||
dec(Result);
|
||||
end;
|
||||
{
|
||||
while (Result >= 0) and (GetI(Result).ExcelCode = AExcelCode) do
|
||||
dec(Result);
|
||||
}
|
||||
end;
|
||||
|
||||
procedure TsExprIdentifierDefs.SetI(AIndex: Integer;
|
||||
@ -2816,16 +2711,7 @@ function TsUPlusExprNode.AsString: String;
|
||||
begin
|
||||
Result := '+' + TrimLeft(Operand.AsString);
|
||||
end;
|
||||
{
|
||||
procedure TsUPlusExprNode.Check;
|
||||
const
|
||||
AllowedTokens = [rtInteger, rtFloat, rtCell, rtEmpty, rtError];
|
||||
begin
|
||||
inherited;
|
||||
if not (Operand.NodeType in AllowedTokens) then
|
||||
RaiseParserError(SErrNoUPlus, [ResultTypeName(Operand.NodeType), Operand.AsString])
|
||||
end;
|
||||
}
|
||||
|
||||
procedure TsUPlusExprNode.GetNodeValue(out Result: TsExpressionResult);
|
||||
var
|
||||
cell: PCell;
|
||||
@ -2875,16 +2761,7 @@ function TsUMinusExprNode.AsString: String;
|
||||
begin
|
||||
Result := '-' + TrimLeft(Operand.AsString);
|
||||
end;
|
||||
{
|
||||
procedure TsUMinusExprNode.Check;
|
||||
const
|
||||
AllowedTokens = [rtInteger, rtFloat, rtCell, rtEmpty, rtError];
|
||||
begin
|
||||
inherited;
|
||||
if not (Operand.NodeType in AllowedTokens) then
|
||||
RaiseParserError(SErrNoNegation, [ResultTypeName(Operand.NodeType), Operand.AsString])
|
||||
end;
|
||||
}
|
||||
|
||||
procedure TsUMinusExprNode.GetNodeValue(out Result: TsExpressionResult);
|
||||
var
|
||||
cell: PCell;
|
||||
|
@ -212,7 +212,13 @@ begin
|
||||
exit;
|
||||
end;
|
||||
|
||||
if Length(Args) = 2 then begin
|
||||
if (Length(Args) = 2) then
|
||||
begin
|
||||
if (Args[1].ResultType = rtMissingArg) then
|
||||
begin
|
||||
Result := ErrorResult(errOverflow); // #NUM! as tested by Excel
|
||||
exit;
|
||||
end;
|
||||
base := ArgToFloat(Args[1]);
|
||||
if base < 0 then begin
|
||||
Result := ErrorResult(errOverflow); // #NUM!
|
||||
@ -698,19 +704,19 @@ var
|
||||
begin
|
||||
s := ArgToString(Args[0]);
|
||||
if s = '' then
|
||||
Result.ResultType := rtEmpty
|
||||
Result := EmptyResult
|
||||
else
|
||||
if Length(Args) > 2 then
|
||||
Result := ErrorResult(errArgError)
|
||||
else
|
||||
begin
|
||||
if Length(Args) = 1 then
|
||||
count := 1
|
||||
else
|
||||
if Args[1].ResultType in [rtInteger, rtFloat] then
|
||||
count := ArgToInt(Args[1])
|
||||
if Args[1].ResultType = rtMissingArg then
|
||||
count := 1
|
||||
else
|
||||
begin
|
||||
Result := ErrorResult(errWrongType);
|
||||
exit;
|
||||
end;
|
||||
count := ArgToInt(Args[1]);
|
||||
Result := StringResult(UTF8LeftStr(s, count));
|
||||
end;
|
||||
end;
|
||||
@ -780,18 +786,19 @@ var
|
||||
begin
|
||||
s := ArgToString(Args[0]);
|
||||
if s = '' then
|
||||
Result.ResultType := rtEmpty
|
||||
else begin
|
||||
Result := EmptyResult
|
||||
else
|
||||
if Length(Args) > 2 then
|
||||
Result := ErrorResult(errArgError)
|
||||
else
|
||||
begin
|
||||
if Length(Args) = 1 then
|
||||
count := 1
|
||||
else
|
||||
if Args[1].ResultType in [rtInteger, rtFloat] then
|
||||
count := ArgToInt(Args[1])
|
||||
if Args[1].ResultType = rtMissingArg then
|
||||
count := 1
|
||||
else
|
||||
begin
|
||||
Result := ErrorResult(errWrongType);
|
||||
exit;
|
||||
end;
|
||||
count := ArgToInt(Args[1]);
|
||||
Result := StringResult(UTF8RightStr(s, count));
|
||||
end;
|
||||
end;
|
||||
|
@ -4347,25 +4347,25 @@ begin
|
||||
if FWorksheet.IsMergeBase(ACell) then
|
||||
begin
|
||||
FWorksheet.FindMergedRange(ACell, r1, c1, r2, c2);
|
||||
rowsSpannedStr := Format('table:number-rows-spanned="%d"', [r2 - r1 + 1]);
|
||||
colsSpannedStr := Format('table:number-columns-spanned="%d"', [c2 - c1 + 1]);
|
||||
spannedStr := colsSpannedStr + ' ' + rowsSpannedStr;
|
||||
rowsSpannedStr := Format(' table:number-rows-spanned="%d"', [r2 - r1 + 1]);
|
||||
colsSpannedStr := Format(' table:number-columns-spanned="%d"', [c2 - c1 + 1]);
|
||||
spannedStr := colsSpannedStr + rowsSpannedStr;
|
||||
end else
|
||||
spannedStr := '';
|
||||
|
||||
fmt := FWorkbook.GetCellFormat(ACell^.FormatIndex);
|
||||
if fmt.UsedFormattingFields <> [] then
|
||||
AppendToStream(AStream, Format(
|
||||
'<table:table-cell table:style-name="ce%d" %s>', [ACell^.FormatIndex, spannedStr]),
|
||||
'<table:table-cell table:style-name="ce%d"%s>', [ACell^.FormatIndex, spannedStr]),
|
||||
comment,
|
||||
'</table:table-cell>')
|
||||
else
|
||||
if comment <> '' then
|
||||
AppendToStream(AStream,
|
||||
'<table:table-cell ' + spannedStr + '>' + comment + '</table:table-cell>')
|
||||
'<table:table-cell' + spannedStr + '>' + comment + '</table:table-cell>')
|
||||
else
|
||||
AppendToStream(AStream,
|
||||
'<table:table-cell ' + spannedStr + '/>');
|
||||
'<table:table-cell' + spannedStr + '/>');
|
||||
end;
|
||||
|
||||
{@@ ----------------------------------------------------------------------------
|
||||
@ -5086,9 +5086,9 @@ begin
|
||||
if FWorksheet.IsMergeBase(ACell) then
|
||||
begin
|
||||
FWorksheet.FindMergedRange(ACell, r1, c1, r2, c2);
|
||||
rowsSpannedStr := Format('table:number-rows-spanned="%d"', [r2 - r1 + 1]);
|
||||
colsSpannedStr := Format('table:number-columns-spanned="%d"', [c2 - c1 + 1]);
|
||||
spannedStr := colsSpannedStr + ' ' + rowsSpannedStr;
|
||||
rowsSpannedStr := Format(' table:number-rows-spanned="%d"', [r2 - r1 + 1]);
|
||||
colsSpannedStr := Format(' table:number-columns-spanned="%d"', [c2 - c1 + 1]);
|
||||
spannedStr := colsSpannedStr + rowsSpannedStr;
|
||||
end else
|
||||
spannedStr := '';
|
||||
|
||||
@ -5111,39 +5111,39 @@ begin
|
||||
cctNumber:
|
||||
begin
|
||||
valuetype := 'float';
|
||||
value := 'office:value="' + Format('%g', [ACell^.NumberValue], FPointSeparatorSettings) + '"';
|
||||
value := ' office:value="' + Format('%g', [ACell^.NumberValue], FPointSeparatorSettings) + '"';
|
||||
end;
|
||||
cctDateTime:
|
||||
if trunc(ACell^.DateTimeValue) = 0 then
|
||||
begin
|
||||
valuetype := 'time';
|
||||
value := 'office:time-value="' + FormatDateTime(ISO8601FormatTimeOnly, ACell^.DateTimeValue) + '"';
|
||||
value := ' office:time-value="' + FormatDateTime(ISO8601FormatTimeOnly, ACell^.DateTimeValue) + '"';
|
||||
end
|
||||
else
|
||||
begin
|
||||
valuetype := 'date';
|
||||
if frac(ACell^.DateTimeValue) = 0.0 then
|
||||
value := 'office:date-value="' + FormatDateTime(ISO8601FormatDateOnly, ACell^.DateTimeValue) + '"'
|
||||
value := ' office:date-value="' + FormatDateTime(ISO8601FormatDateOnly, ACell^.DateTimeValue) + '"'
|
||||
else
|
||||
value := 'office:date-value="' + FormatDateTime(ISO8601FormatExtended, ACell^.DateTimeValue) + '"';
|
||||
value := ' office:date-value="' + FormatDateTime(ISO8601FormatExtended, ACell^.DateTimeValue) + '"';
|
||||
end;
|
||||
cctUTF8String:
|
||||
begin
|
||||
valuetype := 'string';
|
||||
value := 'office:string-value="' + ACell^.UTF8StringValue +'"';
|
||||
value := ' office:string-value="' + ACell^.UTF8StringValue +'"';
|
||||
valueStr := '<text:p>' + ACell^.UTF8StringValue + '</text:p>';
|
||||
end;
|
||||
cctBool:
|
||||
begin
|
||||
valuetype := 'boolean';
|
||||
value := 'office:boolean-value="' + BoolToStr(ACell^.BoolValue, 'true', 'false') + '"';
|
||||
value := ' office:boolean-value="' + BoolToStr(ACell^.BoolValue, 'true', 'false') + '"';
|
||||
end;
|
||||
cctError:
|
||||
begin
|
||||
// Strange: but in case of an error, Open/LibreOffice always writes a
|
||||
// float value 0 to the cell
|
||||
valuetype := 'float';
|
||||
value := 'office:value="0"';
|
||||
value := ' office:value="0"';
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -5154,7 +5154,7 @@ begin
|
||||
data type. Seems to work... }
|
||||
if FWorksheet.GetCalcState(ACell) = csCalculated then
|
||||
AppendToStream(AStream, Format(
|
||||
'<table:table-cell table:formula="=%s" office:value-type="%s" %s %s %s>' +
|
||||
'<table:table-cell table:formula="=%s" office:value-type="%s"%s%s%s>' +
|
||||
comment +
|
||||
valueStr +
|
||||
'</table:table-cell>', [
|
||||
@ -5163,7 +5163,7 @@ begin
|
||||
else
|
||||
begin
|
||||
AppendToStream(AStream, Format(
|
||||
'<table:table-cell table:formula="=%s" %s %s', [
|
||||
'<table:table-cell table:formula="=%s"%s%s', [
|
||||
formula, lStyle, spannedStr]));
|
||||
if comment <> '' then
|
||||
AppendToStream(AStream, '>' + comment + '</table:table-cell>')
|
||||
@ -5198,7 +5198,7 @@ begin
|
||||
// Style
|
||||
fmt := FWorkbook.GetCellFormat(ACell^.FormatIndex);
|
||||
if fmt.UsedFormattingFields <> [] then
|
||||
lStyle := ' table:style-name="ce' + IntToStr(ACell^.FormatIndex) + '" '
|
||||
lStyle := ' table:style-name="ce' + IntToStr(ACell^.FormatIndex) + '"'
|
||||
else
|
||||
lStyle := '';
|
||||
|
||||
@ -5209,9 +5209,9 @@ begin
|
||||
if FWorksheet.IsMergeBase(ACell) then
|
||||
begin
|
||||
FWorksheet.FindMergedRange(ACell, r1, c1, r2, c2);
|
||||
rowsSpannedStr := Format('table:number-rows-spanned="%d"', [r2 - r1 + 1]);
|
||||
colsSpannedStr := Format('table:number-columns-spanned="%d"', [c2 - c1 + 1]);
|
||||
spannedStr := colsSpannedStr + ' ' + rowsSpannedStr;
|
||||
rowsSpannedStr := Format(' table:number-rows-spanned="%d"', [r2 - r1 + 1]);
|
||||
colsSpannedStr := Format(' table:number-columns-spanned="%d"', [c2 - c1 + 1]);
|
||||
spannedStr := colsSpannedStr + rowsSpannedStr;
|
||||
end else
|
||||
spannedStr := '';
|
||||
|
||||
@ -5253,7 +5253,7 @@ begin
|
||||
|
||||
// Write it ...
|
||||
AppendToStream(AStream, Format(
|
||||
'<table:table-cell office:value-type="string" %s %s>' +
|
||||
'<table:table-cell office:value-type="string"%s%s>' +
|
||||
comment +
|
||||
textp +
|
||||
'</table:table-cell>', [
|
||||
@ -5298,7 +5298,7 @@ begin
|
||||
if (nfkCurrency in nfSection.Kind) then
|
||||
valtype := 'currency'
|
||||
end;
|
||||
lStyle := ' table:style-name="ce' + IntToStr(ACell^.FormatIndex) + '" ';
|
||||
lStyle := ' table:style-name="ce' + IntToStr(ACell^.FormatIndex) + '"';
|
||||
end else
|
||||
lStyle := '';
|
||||
|
||||
@ -5309,9 +5309,9 @@ begin
|
||||
if FWorksheet.IsMergeBase(ACell) then
|
||||
begin
|
||||
FWorksheet.FindMergedRange(ACell, r1, c1, r2, c2);
|
||||
rowsSpannedStr := Format('table:number-rows-spanned="%d"', [r2 - r1 + 1]);
|
||||
colsSpannedStr := Format('table:number-columns-spanned="%d"', [c2 - c1 + 1]);
|
||||
spannedStr := colsSpannedStr + ' ' + rowsSpannedStr;
|
||||
rowsSpannedStr := Format(' table:number-rows-spanned="%d"', [r2 - r1 + 1]);
|
||||
colsSpannedStr := Format(' table:number-columns-spanned="%d"', [c2 - c1 + 1]);
|
||||
spannedStr := colsSpannedStr + rowsSpannedStr;
|
||||
end else
|
||||
spannedStr := '';
|
||||
|
||||
@ -5330,7 +5330,7 @@ begin
|
||||
FWorkbook.AddErrorMsg(rsODSHyperlinksOfTextCellsOnly, [GetCellString(ARow, ACol)]);
|
||||
|
||||
AppendToStream(AStream, Format(
|
||||
'<table:table-cell office:value-type="%s" office:value="%s" %s %s >' +
|
||||
'<table:table-cell office:value-type="%s" office:value="%s"%s%s >' +
|
||||
comment +
|
||||
'<text:p>%s</text:p>' +
|
||||
'</table:table-cell>', [
|
||||
|
@ -1518,7 +1518,9 @@ begin
|
||||
(Pos('<', AppoSt) = 1) or
|
||||
(Pos('>', AppoSt) = 1) or
|
||||
(Pos('"', AppoSt) = 1) or
|
||||
(Pos(''', AppoSt) = 1) then begin
|
||||
(Pos(''', AppoSt) = 1) or
|
||||
(Pos('%', AppoSt) = 1) // %
|
||||
then begin
|
||||
//'&' is the first char of a special chat, it must not be converted
|
||||
WrkStr:=WrkStr + AText[Idx];
|
||||
end else begin
|
||||
@ -1529,6 +1531,7 @@ begin
|
||||
'>': WrkStr:=WrkStr + '>';
|
||||
'"': WrkStr:=WrkStr + '"';
|
||||
'''':WrkStr:=WrkStr + ''';
|
||||
'%': WrkStr:=WrkStr + '%';
|
||||
{
|
||||
#10: WrkStr := WrkStr + ' ';
|
||||
#13: WrkStr := WrkStr + ' ';
|
||||
|
@ -9,6 +9,8 @@
|
||||
MyWorksheet.WriteNumber (1, 12, 1); // M2
|
||||
MyWorksheet.WriteNumber (1, 13, 2); // N2
|
||||
|
||||
// Create an error in H2
|
||||
MyWorksheet.WriteFormula (1, 7, '1/0');
|
||||
{------------------------------------------------------------------------------}
|
||||
{ Basic operations }
|
||||
{------------------------------------------------------------------------------}
|
||||
@ -52,7 +54,7 @@
|
||||
{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! DO NOT CHANGE THIS FORMULA - ITS RESULT (-9) IS HARD-CODED IN OTHER TESTS !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
|
||||
(*
|
||||
|
||||
// Add cell values - relative addresses
|
||||
inc(Row);
|
||||
formula := 'B1+B2';
|
||||
@ -317,6 +319,23 @@
|
||||
SetLength(sollValues, Row+1);
|
||||
sollValues[Row] := FloatResult(4 * power(2, 0.5));
|
||||
|
||||
// Exotic sample from OpenOffice test files
|
||||
inc(Row);
|
||||
formula := '50%^200%';
|
||||
MyWorksheet.WriteUTF8Text(Row, 0, formula);
|
||||
if UseRPNFormula then
|
||||
MyWorksheet.WriteRPNFormula(Row, 1, CreateRPNFormula(
|
||||
RPNNumber(50.0,
|
||||
RPNFunc(fekPercent,
|
||||
RPNNumber(200.0,
|
||||
RPNFunc(fekPercent,
|
||||
RPNFunc(fekPower, nil)))))))
|
||||
else
|
||||
MyWorksheet.WriteFormula(Row, 1, formula);
|
||||
MyWorksheet.WriteNumber(Row, 2, power(0.5, 2));
|
||||
SetLength(sollValues, Row+1);
|
||||
sollValues[Row] := FloatResult(power(0.5, 2));
|
||||
|
||||
// Power function
|
||||
if AFormat <> sfExcel2 then begin
|
||||
// Power of constant
|
||||
@ -428,6 +447,21 @@
|
||||
SetLength(sollValues, Row+1);
|
||||
sollValues[Row] := FloatResult(+cellB2);
|
||||
|
||||
// Exotic case from OpenOffice test files
|
||||
inc(Row);
|
||||
formula := '+-B2';
|
||||
MyWorksheet.WriteUTF8Text(Row, 0, formula);
|
||||
if UseRPNFormula then
|
||||
MyWorksheet.WriteRPNFormula(Row, 1, CreateRPNFormula(
|
||||
RPNCellvalue('B2',
|
||||
RPNFunc(fekUMinus,
|
||||
RPNFunc(fekUPlus, nil)))))
|
||||
else
|
||||
MyWorksheet.WriteFormula(Row, 1, formula);
|
||||
MyWorksheet.WriteNumber(Row, 2, -cellB2);
|
||||
SetLength(sollValues, Row+1);
|
||||
sollValues[Row] := FloatResult(-cellB2);
|
||||
|
||||
// String result
|
||||
inc(Row);
|
||||
formula := '"Hallo"';
|
||||
@ -1364,11 +1398,9 @@
|
||||
SetLength(sollValues, Row+1);
|
||||
sollValues[Row] := FloatResult(logn(2, number));
|
||||
|
||||
{ removed until new formula system supports missing arguments...
|
||||
|
||||
// LOG - valid result (2 arguments, base missing)
|
||||
// LOG - error result (2 arguments, base missing)
|
||||
inc(Row);
|
||||
formula := 'LOG(0.1, )';
|
||||
formula := 'LOG(0.1,)';
|
||||
MyWorksheet.WriteUTF8Text(Row, 0, formula);
|
||||
if UseRPNFormula then
|
||||
MyWorksheet.WriteRPNFormula(Row, 1, CreateRPNFormula(
|
||||
@ -1383,7 +1415,6 @@
|
||||
sollValues[Row] := FloatResult(0)
|
||||
else
|
||||
sollValues[Row] := ErrorResult(errOverflow);
|
||||
}
|
||||
|
||||
// LOG - valid result (1 argument)
|
||||
inc(Row);
|
||||
@ -3001,7 +3032,7 @@
|
||||
SetLength(sollValues, Row+1);
|
||||
sollValues[Row] := StringResult('Ha');
|
||||
Myworksheet.WriteUTF8Text(Row, 2, sollValues[Row].ResString);
|
||||
*)
|
||||
|
||||
// LEFT (2 parameters, utf8)
|
||||
inc(Row);
|
||||
formula := 'LEFT("Ändern",3)';
|
||||
@ -3017,7 +3048,6 @@
|
||||
sollValues[Row] := StringResult('Änd');
|
||||
Myworksheet.WriteUTF8Text(Row, 2, sollValues[Row].ResString);
|
||||
|
||||
{ -- at the momement no missing arguments support
|
||||
// LEFT (2 parameters, 1 of them missing)
|
||||
inc(Row);
|
||||
formula := 'LEFT("Hallo world",)';
|
||||
@ -3032,7 +3062,7 @@
|
||||
SetLength(sollValues, Row+1);
|
||||
sollValues[Row] := StringResult('H');
|
||||
Myworksheet.WriteUTF8Text(Row, 2, sollValues[Row].ResString);
|
||||
}
|
||||
|
||||
// LEFT (1 parameter)
|
||||
inc(Row);
|
||||
formula := 'LEFT("Hallo world")';
|
||||
@ -3169,10 +3199,9 @@
|
||||
sollValues[Row] := StringResult('ld');
|
||||
Myworksheet.WriteUTF8Text(Row, 2, sollValues[Row].ResString);
|
||||
|
||||
{ --- no missing parameter support now
|
||||
// RIGHT (2 parameters, one of them missing)
|
||||
inc(Row);
|
||||
formula := 'RIGHT("Hallo world", )';
|
||||
formula := 'RIGHT("Hallo world",)';
|
||||
MyWorksheet.WriteUTF8Text(Row, 0, formula);
|
||||
if UseRPNFormula then
|
||||
MyWorksheet.WriteRPNFormula(Row, 1, CreateRPNFormula(
|
||||
@ -3184,7 +3213,6 @@
|
||||
SetLength(sollValues, Row+1);
|
||||
sollValues[Row] := StringResult('d');
|
||||
Myworksheet.WriteUTF8Text(Row, 2, sollValues[Row].ResString);
|
||||
}
|
||||
|
||||
// RIGHT (1 parameter)
|
||||
inc(Row);
|
||||
@ -3444,8 +3472,37 @@
|
||||
SetLength(sollValues, Row+1);
|
||||
sollValues[Row] := CreateNumberArg(MyWorkbook.GetWorksheetCount);
|
||||
*)
|
||||
// IsBlank
|
||||
|
||||
// ERROR.TYPE
|
||||
(* ---- fails for ODS ---> to be checked
|
||||
inc(Row);
|
||||
formula := 'ERROR.TYPE(A1)';
|
||||
MyWorksheet.WriteUTF8Text(Row, 0, formula);
|
||||
if UseRPNFormula then
|
||||
MyWorksheet.WriteRPNFormula(Row, 1, CreateRPNFormula(
|
||||
RPNCellRef('A1',
|
||||
RPNFUNC('ERROR.TYPE', nil))))
|
||||
else
|
||||
MyWorksheet.WriteFormula(Row, 1, formula);
|
||||
SetLength(sollvalues, Row+1);
|
||||
sollValues[Row] := ErrorResult(errArgError);
|
||||
MyWorksheet.WriteUTF8Text(Row, 2, '#N/A');
|
||||
|
||||
inc(Row);
|
||||
formula := 'ERROR.TYPE(H2)'; // this cells contains "1/0" --> #DIV/0!
|
||||
MyWorksheet.WriteUTF8Text(Row, 0, formula);
|
||||
if UseRPNFormula then
|
||||
MyWorksheet.WriteRPNFormula(Row, 1, CreateRPNFormula(
|
||||
RPNCellRef('H2',
|
||||
RPNFUNC('ERROR.TYPE', nil))))
|
||||
else
|
||||
MyWorksheet.WriteFormula(Row, 1, formula);
|
||||
SetLength(sollvalues, Row+1);
|
||||
sollValues[Row] := IntegerResult(ord(errDivideByZero));
|
||||
MyWorksheet.WriteUTF8Text(Row, 2, IntToStr(ord(errDivideByZero)));
|
||||
*)
|
||||
|
||||
// IsBlank
|
||||
inc(Row);
|
||||
formula := 'ISBLANK(A1)';
|
||||
MyWorksheet.WriteUTF8Text(Row, 0, formula);
|
||||
@ -3489,7 +3546,6 @@
|
||||
// IsErr
|
||||
inc(Row);
|
||||
formula := 'ISERR(H2)';
|
||||
MyWorksheet.WriteFormula(1, 7, '1/0'); // Create an error in H2
|
||||
MyWorksheet.WriteUTF8Text(Row, 0, formula);
|
||||
if UseRPNFormula then
|
||||
myWorksheet.WriteRPNFormula(Row, 1, CreateRPNFormula(
|
||||
|
Reference in New Issue
Block a user