From: <bl...@us...> - 2003-03-18 08:11:57
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv537/src/rftaparser Modified Files: ForStatementParserTest.cpp ForStatementParserTest.h Log Message: * fixed test bug for 'for (;;) * modified to match not structure (null expression instead of no node) Index: ForStatementParserTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ForStatementParserTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ForStatementParserTest.cpp 20 Dec 2002 16:52:11 -0000 1.1 --- ForStatementParserTest.cpp 18 Mar 2003 08:11:55 -0000 1.2 *************** *** 60,63 **** --- 60,65 ---- ForStatementParserTest::testForNoArgs() { + checkFor( "", "", "" ); + /* std::string iterationExpr( ";;" ); std::string source( "for (" + iterationExpr + ") ;" ); *************** *** 82,91 **** propertyStart, propertyEnd - propertyStart ); ! // it should not have a declaration property ! CPPUNIT_ASSERT( !forAST->hasProperty( ASTNodeProperties::declarationProperty ) ); ! // it should not hace a condition property ! CPPUNIT_ASSERT( !forAST->hasProperty( ASTNodeProperties::conditionProperty ) ); ! // it should not hace a next-step property ! CPPUNIT_ASSERT( !forAST->hasProperty( ASTNodeProperties::nextStepProperty ) ); } --- 84,92 ---- propertyStart, propertyEnd - propertyStart ); ! ASTNodePtr forIterationsNode = forAST->getProperty( ASTNodeProperties::iterationProperty ); ! CPPUNIT_ASSERT( forIterationsNode->hasProperty( ASTNodeProperties::declarationProperty ) ); ! CPPUNIT_ASSERT( forIterationsNode->hasProperty( ASTNodeProperties::conditionProperty ) ); ! CPPUNIT_ASSERT( forIterationsNode->hasProperty( ASTNodeProperties::nextStepProperty ) ); ! */ } *************** *** 93,98 **** ForStatementParserTest::testSimpleFor() { ! std::string decl ( "i=0;" ); ! std::string cond ( "i<10;" ); std::string next ( "i++" ); --- 94,99 ---- ForStatementParserTest::testSimpleFor() { ! std::string decl ( "i=0" ); ! std::string cond ( "i<10" ); std::string next ( "i++" ); *************** *** 103,109 **** ForStatementParserTest::testDeclaringFor() { ! std::string iterationExpr( "int index = 0 ; index < 10 ; index++ " ); ! std::string decl ( "int index = 0 ;" ); ! std::string cond ( "index < 10 ;" ); std::string next ( "index++" ); --- 104,109 ---- ForStatementParserTest::testDeclaringFor() { ! std::string decl ( "int index = 0" ); ! std::string cond ( "index < 10" ); std::string next ( "index++" ); *************** *** 112,125 **** void ! ForStatementParserTest::checkFor( ! std::string decl, ! std::string cond, ! std::string next ! ) { ! std::string iterationExpr( decl+cond+next ); std::string source( "for (" + iterationExpr + ") ;" ); int startIndex = 0; int endIndex = source.length(); SourceASTNodePtr sourceAST = RFTA_ASSERT_KEYWORD_PARSER_PASS( ForStatementParser, --- 112,128 ---- void ! ForStatementParserTest::checkFor( std::string decl, ! std::string cond, ! std::string next ) { ! std::string iterationExpr( decl + ";" + cond + ";" + next ); std::string source( "for (" + iterationExpr + ") ;" ); int startIndex = 0; int endIndex = source.length(); + int iterationsStartIndex = std::string( "for (" ).length(); + int iterationsEndIndex = iterationsStartIndex + iterationExpr.length(); + int declarationStartIndex = iterationsStartIndex; + int conditionStartIndex = declarationStartIndex + decl.length() +1; + int iterationStartIndex = conditionStartIndex + cond.length() + 1; SourceASTNodePtr sourceAST = RFTA_ASSERT_KEYWORD_PARSER_PASS( ForStatementParser, *************** *** 133,173 **** endIndex-startIndex ); - int propertyStart = startIndex + std::string("for (").length(); - int propertyEnd = propertyStart + iterationExpr.length(); RFTA_ASSERT_NODE_PROPERTY_HAS( forAST, ASTNodeProperties::iterationProperty, ASTNodeTypes::forIterationExpression, ! propertyStart, ! propertyEnd - propertyStart ); ! if ( forAST->hasProperty( ASTNodeProperties::iterationProperty ) ) ! { ! ASTNodePtr iterationProp = forAST->getProperty( ASTNodeProperties::iterationProperty ); ! int declStart = propertyStart; ! int declLen = decl.length(); ! int condStart = declStart+declLen; ! int condLen = cond.length(); ! int nextStart = condStart+condLen; ! int nextLen = next.length(); ! // check for declaration property: ! RFTA_ASSERT_NODE_PROPERTY_HAS( iterationProp, ! ASTNodeProperties::declarationProperty, ! ASTNodeTypes::declarationOrExpression, ! declStart, ! declLen ); ! // check for condition property: ! RFTA_ASSERT_NODE_PROPERTY_HAS( iterationProp, ! ASTNodeProperties::conditionProperty, ! ASTNodeTypes::unparsedConditionExpression, ! condStart, ! condLen ); ! // check for condition property: ! RFTA_ASSERT_NODE_PROPERTY_HAS( iterationProp, ! ASTNodeProperties::nextStepProperty, ! ASTNodeTypes::declarationOrExpression, ! nextStart, ! nextLen ); ! } } } // namespace Refactoring --- 136,181 ---- endIndex-startIndex ); RFTA_ASSERT_NODE_PROPERTY_HAS( forAST, ASTNodeProperties::iterationProperty, ASTNodeTypes::forIterationExpression, ! iterationsStartIndex, ! iterationsEndIndex - iterationsStartIndex ); ! ASTNodePtr iterationProp = forAST->getProperty( ASTNodeProperties::iterationProperty ); ! RFTA_ASSERT_NODE_PROPERTY_HAS( iterationProp, ! ASTNodeProperties::declarationProperty, ! getExpectedNodeTypeFor( decl ), ! declarationStartIndex, ! decl.length() ); ! RFTA_ASSERT_NODE_PROPERTY_HAS( iterationProp, ! ASTNodeProperties::conditionProperty, ! getExpectedConditionNodeTypeFor( cond ), ! conditionStartIndex, ! cond.length() ); ! RFTA_ASSERT_NODE_PROPERTY_HAS( iterationProp, ! ASTNodeProperties::nextStepProperty, ! getExpectedNodeTypeFor( decl ), ! iterationStartIndex, ! next.length() ); ! } ! ! ! ASTNodeType ! ForStatementParserTest::getExpectedNodeTypeFor( const std::string &expression ) ! { ! if ( expression.empty() ) ! return ASTNodeTypes::nullExpression; ! return ASTNodeTypes::declarationOrExpression; } + + + ASTNodeType + ForStatementParserTest::getExpectedConditionNodeTypeFor( const std::string &expression ) + { + if ( expression.empty() ) + return ASTNodeTypes::nullExpression; + return ASTNodeTypes::unparsedConditionExpression; + } + } // namespace Refactoring Index: ForStatementParserTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ForStatementParserTest.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ForStatementParserTest.h 20 Dec 2002 16:52:11 -0000 1.1 --- ForStatementParserTest.h 18 Mar 2003 08:11:55 -0000 1.2 *************** *** 8,11 **** --- 8,12 ---- #include "ParserTesting.h" + #include <rfta/parser/ASTNodes.h> *************** *** 46,49 **** --- 47,54 ---- void ForStatementParserTest::checkFor( std::string decl, std::string cond, std::string next ); + + ASTNodeType getExpectedNodeTypeFor( const std::string &expression ); + + ASTNodeType getExpectedConditionNodeTypeFor( const std::string &expression ); private: |