mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Improved assert[Non]ProblemOnFirstIdentifier methods.
This commit is contained in:
parent
c31f99c76e
commit
936b844596
2 changed files with 20 additions and 7 deletions
|
@ -8334,7 +8334,7 @@ public class AST2CPPTests extends AST2TestBase {
|
||||||
public void testLambdaWithCapture_446225() throws Exception {
|
public void testLambdaWithCapture_446225() throws Exception {
|
||||||
BindingAssertionHelper bh = getAssertionHelper();
|
BindingAssertionHelper bh = getAssertionHelper();
|
||||||
ICPPVariable foo1= bh.assertNonProblemOnFirstIdentifier("foo =", ICPPVariable.class);
|
ICPPVariable foo1= bh.assertNonProblemOnFirstIdentifier("foo =", ICPPVariable.class);
|
||||||
ICPPVariable foo2= bh.assertNonProblemOnFirstIdentifier("foo]", ICPPVariable.class);
|
ICPPVariable foo2= bh.assertNonProblemOnFirstIdentifier("[foo]", ICPPVariable.class);
|
||||||
assertTrue(foo1 == foo2);
|
assertTrue(foo1 == foo2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -550,15 +550,26 @@ public class AST2TestBase extends BaseTestCase {
|
||||||
return (T) binding;
|
return (T) binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getIdentifierLength(String str) {
|
private int getIdentifierOffset(String str) {
|
||||||
|
for (int i = 0; i < str.length(); ++i) {
|
||||||
|
if (Character.isJavaIdentifierPart(str.charAt(i)))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
fail("Didn't find identifier in \"" + str + "\"");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getIdentifierLength(String str, int offset) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < str.length() && Character.isJavaIdentifierPart(str.charAt(i)); ++i) {
|
for (i = offset; i < str.length() && Character.isJavaIdentifierPart(str.charAt(i)); ++i) {
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IProblemBinding assertProblemOnFirstIdentifier(String section) {
|
public IProblemBinding assertProblemOnFirstIdentifier(String section) {
|
||||||
return assertProblem(section, getIdentifierLength(section));
|
int offset = getIdentifierOffset(section);
|
||||||
|
String identifier = section.substring(offset, getIdentifierLength(section, offset));
|
||||||
|
return assertProblem(section, identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IProblemBinding assertProblemOnFirstIdentifier(String section, int problemId) {
|
public IProblemBinding assertProblemOnFirstIdentifier(String section, int problemId) {
|
||||||
|
@ -568,7 +579,9 @@ public class AST2TestBase extends BaseTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends IBinding> T assertNonProblemOnFirstIdentifier(String section, Class... cs) {
|
public <T extends IBinding> T assertNonProblemOnFirstIdentifier(String section, Class... cs) {
|
||||||
return assertNonProblem(section, getIdentifierLength(section), cs);
|
int offset = getIdentifierOffset(section);
|
||||||
|
String identifier = section.substring(offset, getIdentifierLength(section, offset));
|
||||||
|
return assertNonProblem(section, identifier, cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertNoName(String section, int len) {
|
public void assertNoName(String section, int len) {
|
||||||
|
@ -586,7 +599,7 @@ public class AST2TestBase extends BaseTestCase {
|
||||||
public IASTImplicitName assertImplicitName(String section, int len, Class<?> bindingClass) {
|
public IASTImplicitName assertImplicitName(String section, int len, Class<?> bindingClass) {
|
||||||
IASTName name = findImplicitName(section, len);
|
IASTName name = findImplicitName(section, len);
|
||||||
final String selection = section.substring(0, len);
|
final String selection = section.substring(0, len);
|
||||||
assertNotNull("did not find \"" + selection + "\"", name);
|
assertNotNull("Did not find \"" + selection + "\"", name);
|
||||||
|
|
||||||
assertInstance(name, IASTImplicitName.class);
|
assertInstance(name, IASTImplicitName.class);
|
||||||
IASTImplicitNameOwner owner = (IASTImplicitNameOwner) name.getParent();
|
IASTImplicitNameOwner owner = (IASTImplicitNameOwner) name.getParent();
|
||||||
|
|
Loading…
Add table
Reference in a new issue