Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-05-30 21:25:21 -0400
committerSergey Prigogin2012-05-30 21:28:50 -0400
commit2776e06605754d52ce75effaf237edbbedddda73 (patch)
tree52ca1e5f8d856bbb5eb5006ea35689322baf1059 /core/org.eclipse.cdt.core.tests
parent3604f812ced75a313a8de08387e338a335771cd9 (diff)
downloadorg.eclipse.cdt-2776e06605754d52ce75effaf237edbbedddda73.tar.gz
org.eclipse.cdt-2776e06605754d52ce75effaf237edbbedddda73.tar.xz
org.eclipse.cdt-2776e06605754d52ce75effaf237edbbedddda73.zip
Bug 380498 - typedef is expanded during refactoring
Diffstat (limited to 'core/org.eclipse.cdt.core.tests')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java56
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java29
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java24
3 files changed, 101 insertions, 8 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java
index 4b1777864b..ed3edc18d6 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java
@@ -10,6 +10,7 @@
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
* Mike Kucera (IBM)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2;
@@ -628,6 +629,23 @@ public class AST2BaseTest extends BaseTestCase {
return selector.findImplicitName(offset, len);
}
+ public <T extends IASTNode> T assertNode(String context, String nodeText, Class<T> type, Class... cs) {
+ if (context == null) {
+ context = contents;
+ }
+ int offset = contents.indexOf(context);
+ assertTrue("Context \"" + context + "\" not found", offset >= 0);
+ int nodeOffset = context.indexOf(nodeText);
+ assertTrue("Node \"" + nodeText + "\" not found", nodeOffset >= 0);
+ IASTNodeSelector selector = tu.getNodeSelector(null);
+ IASTNode node = selector.findNode(offset + nodeOffset, nodeText.length());
+ return assertType(node, type, cs);
+ }
+
+ public <T extends IASTNode> T assertNode(String nodeText, Class<T> type, Class... cs) {
+ return assertNode(contents, nodeText, type, cs);
+ }
+
private String renderProblemID(int i) {
try {
for (Field field : IProblemBinding.class.getDeclaredFields()) {
@@ -652,17 +670,31 @@ public class AST2BaseTest extends BaseTestCase {
IBinding binding= binding(section, len);
assertTrue("ProblemBinding for name: " + section.substring(0, len),
!(binding instanceof IProblemBinding));
- assertInstance(binding, type);
+ return assertType(binding, type, cs);
+ }
+
+ public <T extends IBinding> T assertNonProblem(String section, Class<T> type, Class... cs) {
+ return assertNonProblem(section, section.length(), type, cs);
+ }
+
+ public <T extends IBinding> T assertNonProblem(String context, String name, Class<T> type, Class... cs) {
+ IBinding binding= binding(context, name);
+ assertTrue("ProblemBinding for name: " + name, !(binding instanceof IProblemBinding));
+ return assertType(binding, type, cs);
+ }
+
+ public <T, U extends T> U assertType(T obj, Class<U> type, Class... cs) {
+ assertInstance(obj, type);
for (Class c : cs) {
- assertInstance(binding, c);
+ assertInstance(obj, c);
}
- return type.cast(binding);
- }
-
+ return type.cast(obj);
+ }
+
private IBinding binding(String section, int len) {
IASTName name = findName(section, len);
final String selection = section.substring(0, len);
- assertNotNull("did not find \"" + selection + "\"", name);
+ assertNotNull("Did not find \"" + selection + "\"", name);
assertEquals(selection, name.getRawSignature());
IBinding binding = name.resolveBinding();
@@ -670,7 +702,17 @@ public class AST2BaseTest extends BaseTestCase {
return name.resolveBinding();
}
- }
+
+ private IBinding binding(String context, String name) {
+ IASTName astName = findName(context, name);
+ assertEquals(name, astName.getRawSignature());
+
+ IBinding binding = astName.resolveBinding();
+ assertNotNull("No binding for " + astName.getRawSignature(), binding);
+
+ return astName.resolveBinding();
+ }
+ }
final protected IASTTranslationUnit parseAndCheckBindings(String code, ParserLanguage lang) throws Exception {
return parseAndCheckBindings(code, lang, false);
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index c1bb59c155..a2773522dc 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -4705,6 +4705,33 @@ public class AST2CPPTests extends AST2BaseTest {
assertSame(i, col.getName(7).resolveBinding());
}
+ // template<typename T>
+ // class basic_string {
+ // basic_string& operator+=(const T* s);
+ // };
+ //
+ // template<typename T>
+ // basic_string<T> operator+(const T* cs, const basic_string<T>& s);
+ //
+ // template<typename T>
+ // basic_string<T> operator+(const basic_string<T>& s, const T* cs);
+ //
+ // typedef basic_string<char> string;
+ //
+ // void test(const string& s) {
+ // auto s1 = "" + s + "";
+ // auto s2 = s1 += "";
+ // }
+ public void testTypedefPreservation_380498() throws Exception {
+ BindingAssertionHelper ba= getAssertionHelper();
+ ICPPVariable s1 = ba.assertNonProblem("s1", ICPPVariable.class);
+ assertTrue(s1.getType() instanceof ITypedef);
+ assertEquals("string", ((ITypedef) s1.getType()).getName());
+ ICPPVariable s2 = ba.assertNonProblem("s2", ICPPVariable.class);
+ assertTrue(s2.getType() instanceof ITypedef);
+ assertEquals("string", ((ITypedef) s2.getType()).getName());
+ }
+
// int f() {
// return 5;
// }
@@ -4979,7 +5006,7 @@ public class AST2CPPTests extends AST2BaseTest {
// void f2() {
// f1(__null);
// }
- public void testBug240567() throws Exception {
+ public void testBug240567() throws Exception {
BindingAssertionHelper bh= getAssertionHelper();
bh.assertNonProblem("f1(__null", 2, ICPPFunction.class);
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
index e8479a2a0e..d76d3e9fbd 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
@@ -9,6 +9,7 @@
* Doug Schaefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2;
@@ -6081,6 +6082,29 @@ public class AST2Tests extends AST2BaseTest {
}
}
+ // typedef long unsigned int size_t;
+ //
+ // size_t a = 0;
+ // size_t x = a + 5;
+ // size_t y = 2 + a;
+ // size_t y = a * 2;
+ public void testTypeOfExpressionWithTypedef_380498() throws Exception {
+ final boolean[] isCpps= { false, true };
+ String code= getAboveComment();
+ for (boolean isCpp : isCpps) {
+ BindingAssertionHelper ba= new BindingAssertionHelper(code, isCpp);
+ IASTExpression exp = ba.assertNode("a + 5", IASTExpression.class);
+ assertTrue(exp.getExpressionType() instanceof ITypedef);
+ assertEquals("size_t", ((ITypedef) exp.getExpressionType()).getName());
+ exp = ba.assertNode("2 + a", IASTExpression.class);
+ assertTrue(exp.getExpressionType() instanceof ITypedef);
+ assertEquals("size_t", ((ITypedef) exp.getExpressionType()).getName());
+ exp = ba.assertNode("a * 2", IASTExpression.class);
+ assertTrue(exp.getExpressionType() instanceof ITypedef);
+ assertEquals("size_t", ((ITypedef) exp.getExpressionType()).getName());
+ }
+ }
+
// typedef int TInt;
// int a= TInt; //ref
public void testTypeAsExpressionIsProblem_261175() throws Exception {

Back to the top