mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 20:35:38 +02:00
Testcase for bug 168924, parsing simple expression like '(a)+1'
This commit is contained in:
parent
3499064a9a
commit
bcd4d2426d
3 changed files with 43 additions and 4 deletions
|
@ -14,11 +14,10 @@
|
|||
*/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
|
@ -50,6 +49,9 @@ import org.eclipse.cdt.core.parser.NullLogService;
|
|||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.ANSICParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
||||
|
@ -71,7 +73,7 @@ import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfigurat
|
|||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class AST2BaseTest extends TestCase {
|
||||
public class AST2BaseTest extends BaseTestCase {
|
||||
|
||||
private static final IParserLogService NULL_LOG = new NullLogService();
|
||||
|
||||
|
@ -375,4 +377,9 @@ public class AST2BaseTest extends TestCase {
|
|||
}
|
||||
public int size() { return nameList.size(); }
|
||||
}
|
||||
|
||||
protected StringBuffer[] getContents(int sections) throws IOException {
|
||||
return TestSourceReader.getContentsForTest(
|
||||
CTestPlugin.getDefault().getBundle(), "parser", getClass(), getName(), sections);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,11 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
|
@ -94,6 +97,10 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
|||
*/
|
||||
public class AST2Tests extends AST2BaseTest {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(AST2Tests.class);
|
||||
}
|
||||
|
||||
public void testBug75189() throws Exception {
|
||||
parseAndCheckBindings( "struct A{};typedef int (*F) (A*);" ); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -3476,4 +3483,29 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
parse(buffer.toString(), ParserLanguage.C, true, false);
|
||||
}
|
||||
|
||||
// void func(int a) {
|
||||
// int z=0;
|
||||
// z= (a)+z;
|
||||
// z= (a)-z;
|
||||
// z= (a)*z;
|
||||
// z= (a)&z;
|
||||
// z= (a)|z;
|
||||
// z= (a)/z;
|
||||
// z= (a)%z;
|
||||
// }
|
||||
public void _testBracketAroundIdentifier_168924() throws IOException, ParserException {
|
||||
StringBuffer buf= getContents(1)[0];
|
||||
IASTTranslationUnit tu= parse(buf.toString(), ParserLanguage.C, true, true);
|
||||
IASTFunctionDefinition func= (IASTFunctionDefinition) tu.getDeclarations()[0];
|
||||
IASTParameterDeclaration[] params= ((IASTStandardFunctionDeclarator) func.getDeclarator()).getParameters();
|
||||
IBinding binding= params[0].getDeclarator().getName().resolveBinding();
|
||||
assertEquals(7, tu.getReferences(binding).length);
|
||||
|
||||
tu= parse(buf.toString(), ParserLanguage.CPP, true, true);
|
||||
func= (IASTFunctionDefinition) tu.getDeclarations()[0];
|
||||
params= ((IASTStandardFunctionDeclarator) func.getDeclarator()).getParameters();
|
||||
binding= params[0].getDeclarator().getName().resolveBinding();
|
||||
assertEquals(7, tu.getReferences(binding).length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class DOMParserTestSuite extends TestCase {
|
|||
|
||||
public static Test suite() {
|
||||
TestSuite suite= new TestSuite(ParserTestSuite.class.getName());
|
||||
suite.addTestSuite( AST2Tests.class );
|
||||
suite.addTest( AST2Tests.suite() );
|
||||
suite.addTestSuite( GCCTests.class );
|
||||
suite.addTestSuite( AST2CPPTests.class );
|
||||
suite.addTestSuite( AST2TemplateTests.class );
|
||||
|
|
Loading…
Add table
Reference in a new issue