* Case else without semicolon in front (bug ID 31284)

git-svn-id: trunk@35362 -
This commit is contained in:
michael 2017-01-29 16:36:06 +00:00
parent a51efe50b7
commit f55215f53a
2 changed files with 32 additions and 1 deletions

View File

@ -3938,9 +3938,14 @@ begin
CloseBlock;
CloseStatement(false);
end;
// Case ... else without semicolon in front.
end else if (CurBlock is TPasImplCaseStatement) then
begin
UngetToken;
CloseStatement(False);
exit;
end else if (CurBlock is TPasImplWhileDo) then
begin
//if .. then while .. do smt else ..
CloseBlock;
UngetToken;
end else if (CurBlock is TPasImplForLoop) then

View File

@ -96,6 +96,7 @@ Type
Procedure TestCaseElseBlock2Assignments;
Procedure TestCaseIfCaseElse;
Procedure TestCaseIfElse;
Procedure TestCaseElseNoSemicolon;
Procedure TestRaise;
Procedure TestRaiseEmpty;
Procedure TestRaiseAt;
@ -1206,6 +1207,31 @@ begin
AssertNotNull('If statement has else block',TPasImplIfElse(S.Elements[0]).ElseBranch);
end;
procedure TTestStatementParser.TestCaseElseNoSemicolon;
Var
C : TPasImplCaseOf;
S : TPasImplCaseStatement;
B : TPasImplbeginBlock;
begin
DeclareVar('integer');
TestStatement(['case a of','1 : dosomething;','2 : dosomethingmore','else','a:=1;','end;']);
C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf;
AssertNotNull('Have case expression',C.CaseExpr);
AssertExpression('Case expression',C.CaseExpr,pekIdent,'a');
AssertEquals('case label count',3,C.Elements.Count);
S:=TPasImplCaseStatement(C.Elements[0]);
AssertEquals('case 1',1,S.Expressions.Count);
AssertExpression('Case With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'1');
S:=TPasImplCaseStatement(C.Elements[1]);
AssertEquals('case 2',1,S.Expressions.Count);
AssertExpression('Case With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'2');
AssertEquals('third is else',TPasImplCaseElse,TObject(C.Elements[2]).ClassType);
AssertNotNull('Have else branch',C.ElseBranch);
AssertEquals('Correct else branch class',TPasImplCaseElse,C.ElseBranch.ClassType);
AssertEquals('1 statements in else branch ',1,TPasImplCaseElse(C.ElseBranch).Elements.Count);
end;
procedure TTestStatementParser.TestRaise;
Var