1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Added SelectionParse failed test.

This commit is contained in:
John Camelon 2004-05-11 20:21:55 +00:00
parent b988081c1f
commit 9af8c9f02e
4 changed files with 111 additions and 53 deletions

View file

@ -0,0 +1,38 @@
/**********************************************************************
* Copyright (c) 2002-2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.core.parser.failedTests;
import java.io.StringWriter;
import java.io.Writer;
import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.tests.SelectionParseBaseTest;
/**
* @author johnc
*
*/
public class SelectionParseFailedTest extends SelectionParseBaseTest {
public void testBug61800() throws Exception
{
Writer writer = new StringWriter();
writer.write( "class ABCDEF {\n"); //$NON-NLS-1$
writer.write( " static int stInt; };\n"); //$NON-NLS-1$
writer.write( "int ABCDEF::stInt = 5;\n"); //$NON-NLS-1$
String code = writer.toString();
int startIndex = code.indexOf( "::stInt") + 2; //$NON-NLS-1$
IASTNode node = parse( code, startIndex, startIndex+ 5, false );
// IASTNode node = parse( code, startIndex, startIndex+ 5 );
// assertTrue( node instanceof IASTField );
// assertEquals( ((IASTField)node).getName(), "stInt" ); //$NON-NLS-1$
}
}

View file

@ -0,0 +1,69 @@
/**********************************************************************
* Copyright (c) 2002-2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.NullLogService;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.ast.IASTNode;
/**
* @author johnc
*
*/
public class SelectionParseBaseTest extends CompleteParseBaseTest {
protected IASTNode parse(String code, int offset1, int offset2) throws Exception {
return parse( code, offset1, offset2, true );
}
/**
* @param code
* @param offset1
* @param offset2
* @param b
* @return
*/
protected IASTNode parse(String code, int offset1, int offset2, boolean expectedToPass) throws Exception {
callback = new FullParseCallback();
IParser parser = null;
parser =
ParserFactory.createParser(
ParserFactory.createScanner(
new StringReader(code),
"completion-test", //$NON-NLS-1$
new ScannerInfo(),
ParserMode.SELECTION_PARSE,
ParserLanguage.CPP,
callback,
new NullLogService(), null),
callback,
ParserMode.SELECTION_PARSE,
ParserLanguage.CPP,
ParserUtil.getParserLogService());
IParser.ISelectionParseResult result =parser.parse( offset1, offset2 );
if( expectedToPass )
{
assertNotNull( result );
String filename = result.getFilename();
assertTrue( !filename.equals( "")); //$NON-NLS-1$
return (IASTNode) result.getOffsetableNamedElement();
}
return null;
}
}

View file

@ -10,18 +10,11 @@
***********************************************************************/
package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.NullLogService;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTField;
import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
@ -32,14 +25,8 @@ import org.eclipse.cdt.core.parser.ast.IASTVariable;
/**
* @author jcamelon
*/
public class SelectionParseTest extends CompleteParseBaseTest {
public class SelectionParseTest extends SelectionParseBaseTest {
protected IASTNode parse(String code, int offset1, int offset2 )
throws Exception {
return parse( code, offset1, offset2, true );
}
public void testBaseCase_VariableReference() throws Exception
{
String code = "void f() { int x; x=3; }"; //$NON-NLS-1$
@ -68,44 +55,6 @@ public class SelectionParseTest extends CompleteParseBaseTest {
assertNull( parse( code, offset1, offset2, false ));
}
/**
* @param code
* @param offset1
* @param offset2
* @param b
* @return
*/
protected IASTNode parse(String code, int offset1, int offset2, boolean expectedToPass ) throws Exception {
callback = new FullParseCallback();
IParser parser = null;
parser =
ParserFactory.createParser(
ParserFactory.createScanner(
new StringReader(code),
"completion-test", //$NON-NLS-1$
new ScannerInfo(),
ParserMode.SELECTION_PARSE,
ParserLanguage.CPP,
callback,
new NullLogService(), null),
callback,
ParserMode.SELECTION_PARSE,
ParserLanguage.CPP,
ParserUtil.getParserLogService());
IParser.ISelectionParseResult result =parser.parse( offset1, offset2 );
if( expectedToPass )
{
assertNotNull( result );
String filename = result.getFilename();
assertTrue( !filename.equals( "")); //$NON-NLS-1$
return (IASTNode) result.getOffsetableNamedElement();
}
return null;
}
public void testBaseCase_FunctionDeclaration() throws Exception
{
String code = "int x(); x( );"; //$NON-NLS-1$

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.core.model.tests.WorkingCopyTests;
import org.eclipse.cdt.core.parser.failedTests.ASTFailedTests;
import org.eclipse.cdt.core.parser.failedTests.FailedCompleteParseASTTest;
import org.eclipse.cdt.core.parser.failedTests.STLFailedTests;
import org.eclipse.cdt.core.parser.failedTests.SelectionParseFailedTest;
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
import org.eclipse.cdt.core.search.tests.SearchTestSuite;
@ -67,6 +68,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
suite.addTestSuite(ASTFailedTests.class);
suite.addTestSuite(STLFailedTests.class);
suite.addTestSuite(FailedCompleteParseASTTest.class);
suite.addTestSuite(SelectionParseFailedTest.class);
return suite;
}