|
@@ -369,35 +369,47 @@ Var
|
|
|
F : TPasImplForLoop;
|
|
|
E : TJSForStatement;
|
|
|
L : TJSStatementList;
|
|
|
- VS : TJSVariableStatement;
|
|
|
VD : TJSVarDeclaration;
|
|
|
A : TJSSimpleAssignStatement;
|
|
|
I : TJSUnaryPostPlusPlusExpression;
|
|
|
C : TJSRelationalExpressionLE;
|
|
|
+ VS: TJSVariableStatement;
|
|
|
|
|
|
begin
|
|
|
- // For I:=0 to 100 do a:=b;
|
|
|
+ // For I:=1 to 100 do a:=b;
|
|
|
F:=TPasImplForLoop.Create('',Nil);
|
|
|
F.Variable:=TPasVariable.Create('I',F);
|
|
|
- F.VariableName:='I';
|
|
|
+ F.VariableName:=CreateIdent('I');
|
|
|
F.StartExpr:=CreateLiteral(1);
|
|
|
F.EndExpr:=CreateLiteral(100);
|
|
|
F.Body:=CreateAssignStatement();
|
|
|
L:=TJSStatementList(Convert(F,TJSStatementList));
|
|
|
- VS:=TJSVariableStatement(AssertElement('Start with upper limit temp var',TJSVariableStatement,L.A));
|
|
|
- VD:=TJSVarDeclaration(AssertElement('Have variable',TJSVarDeclaration,VS.A));
|
|
|
- AssertEquals('Correct name for end value','i$endloopvalue',VD.Name);
|
|
|
- AssertLiteral('Correct end value',VD.Init,100);
|
|
|
- E:=TJSForStatement(AssertElement('Second in list is for statement',TJSForStatement,L.B));
|
|
|
- A:=TJSSimpleAssignStatement(AssertElement('Init statement is assign statement',TJSSimpleAssignStatement,E.Init));
|
|
|
- AssertLiteral('Init statement RHS is start value',A.Expr,1);
|
|
|
+ // Should be a list of two statements:
|
|
|
+ // i:=1;
|
|
|
+ // for(var $loopend=100; i<=$loopend; i++){ a:=b; }
|
|
|
+ A:=TJSSimpleAssignStatement(AssertElement('First in list is Init statement',TJSSimpleAssignStatement,L.A));
|
|
|
AssertIdentifier('Init statement LHS is loop variable',A.LHS,'i');
|
|
|
+ AssertLiteral('Init statement RHS is start value',A.Expr,1);
|
|
|
+
|
|
|
+ E:=TJSForStatement(AssertElement('Second in list is "for" statement',TJSForStatement,L.B));
|
|
|
+
|
|
|
+ // "var $loopend=100"
|
|
|
+ VS:=TJSVariableStatement(AssertElement('var '+LoopEndVar,TJSVariableStatement,E.Init));
|
|
|
+ VD:=TJSVarDeclaration(AssertElement('var '+LoopEndVar,TJSVarDeclaration,VS.A));
|
|
|
+ AssertEquals('Correct name for '+LoopEndVar,LoopEndVar,VD.Name);
|
|
|
+ AssertLiteral('Correct end value',VD.Init,100);
|
|
|
+
|
|
|
+ // i<=$loopend
|
|
|
+ C:=TJSRelationalExpressionLE(AssertElement('Condition is <= expression',TJSRelationalExpressionLE,E.Cond));
|
|
|
+ AssertIdentifier('Cond LHS is loop variable',C.A,'i');
|
|
|
+ AssertIdentifier('Cond RHS is '+LoopEndVar,C.B,LoopEndVar);
|
|
|
+
|
|
|
+ // i++
|
|
|
I:=TJSUnaryPostPlusPlusExpression(AssertElement('Increment is ++ statement',TJSUnaryPostPlusPlusExpression,E.Incr));
|
|
|
AssertIdentifier('++ on correct variable name',I.A,'i');
|
|
|
+
|
|
|
+ // body
|
|
|
AssertAssignStatement('Correct body',E.Body);
|
|
|
- C:=TJSRelationalExpressionLE(AssertElement('Condition is <= expression',TJSRelationalExpressionLE,E.Cond));
|
|
|
- AssertIdentifier('Cond LHS is loop variable',C.A,'i');
|
|
|
- AssertIdentifier('Cond RHS is end loop value variable',C.B,'i$endloopvalue');
|
|
|
end;
|
|
|
|
|
|
Procedure TTestStatementConverter.TestForLoopDown;
|
|
@@ -405,36 +417,49 @@ Var
|
|
|
F : TPasImplForLoop;
|
|
|
E : TJSForStatement;
|
|
|
L : TJSStatementList;
|
|
|
- VS : TJSVariableStatement;
|
|
|
VD : TJSVarDeclaration;
|
|
|
A : TJSSimpleAssignStatement;
|
|
|
I : TJSUnaryPostMinusMinusExpression;
|
|
|
C : TJSRelationalExpressionGE;
|
|
|
+ VS: TJSVariableStatement;
|
|
|
|
|
|
begin
|
|
|
- // For I:=0 to 100 do a:=b;
|
|
|
+ // For I:=100 downto 1 do a:=b;
|
|
|
F:=TPasImplForLoop.Create('',Nil);
|
|
|
F.Variable:=TPasVariable.Create('I',F);
|
|
|
- F.VariableName:='I';
|
|
|
+ F.VariableName:=CreateIdent('I');
|
|
|
F.StartExpr:=CreateLiteral(100);
|
|
|
F.EndExpr:=CreateLiteral(1);
|
|
|
F.LoopType:=ltDown;
|
|
|
F.Body:=CreateAssignStatement();
|
|
|
L:=TJSStatementList(Convert(F,TJSStatementList));
|
|
|
- VS:=TJSVariableStatement(AssertElement('Start with upper limit temp var',TJSVariableStatement,L.A));
|
|
|
- VD:=TJSVarDeclaration(AssertElement('Have variable',TJSVarDeclaration,VS.A));
|
|
|
- AssertEquals('Correct name for end value','i$endloopvalue',VD.Name);
|
|
|
- AssertLiteral('Correct end value',VD.Init,1);
|
|
|
- E:=TJSForStatement(AssertElement('Second in list is for statement',TJSForStatement,L.B));
|
|
|
- A:=TJSSimpleAssignStatement(AssertElement('Init statement is assign statement',TJSSimpleAssignStatement,E.Init));
|
|
|
- AssertLiteral('Init statement RHS is start value',A.Expr,100);
|
|
|
+
|
|
|
+ // Should be a list of two statements:
|
|
|
+ // i:=100;
|
|
|
+ // for(var $loopend=1; i>=$loopend; i--){ a:=b; }
|
|
|
+ A:=TJSSimpleAssignStatement(AssertElement('First in list is Init statement',TJSSimpleAssignStatement,L.A));
|
|
|
AssertIdentifier('Init statement LHS is loop variable',A.LHS,'i');
|
|
|
+ AssertLiteral('Init statement RHS is start value',A.Expr,100);
|
|
|
+
|
|
|
+ E:=TJSForStatement(AssertElement('Second in list is "for" statement',TJSForStatement,L.B));
|
|
|
+
|
|
|
+ // "var $loopend=1"
|
|
|
+ VS:=TJSVariableStatement(AssertElement('var '+LoopEndVar,TJSVariableStatement,E.Init));
|
|
|
+ VD:=TJSVarDeclaration(AssertElement('var '+LoopEndVar,TJSVarDeclaration,VS.A));
|
|
|
+ AssertEquals('Correct name for '+LoopEndVar,LoopEndVar,VD.Name);
|
|
|
+ AssertLiteral('Correct end value',VD.Init,1);
|
|
|
+
|
|
|
+ // i>=$loopend
|
|
|
+ C:=TJSRelationalExpressionGE(AssertElement('Condition is >= expression',TJSRelationalExpressionGE,E.Cond));
|
|
|
+ AssertIdentifier('Cond LHS is loop variable',C.A,'i');
|
|
|
+ AssertIdentifier('Cond RHS is '+LoopEndVar,C.B,LoopEndVar);
|
|
|
+
|
|
|
+ // i--
|
|
|
I:=TJSUnaryPostMinusMinusExpression(AssertElement('Increment is -- statement',TJSUnaryPostMinusMinusExpression,E.Incr));
|
|
|
- AssertIdentifier('++ on correct variable name',I.A,'i');
|
|
|
+ AssertIdentifier('-- on correct variable name',I.A,'i');
|
|
|
+
|
|
|
+ // body
|
|
|
AssertAssignStatement('Correct body',E.Body);
|
|
|
- C:=TJSRelationalExpressionGE(AssertElement('Condition is <= expression',TJSRelationalExpressionGE,E.Cond));
|
|
|
- AssertIdentifier('Cond LHS is loop variable',C.A,'i');
|
|
|
- AssertIdentifier('Cond RHS is end loop value variable',C.B,'i$endloopvalue');
|
|
|
end;
|
|
|
|
|
|
Procedure TTestStatementConverter.TestBeginEndBlockEmpty;
|