mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 11:55:40 +02:00
Add test for c++20 three-way comparison expression
This commit is contained in:
parent
5622e59e5f
commit
5eb89637b2
2 changed files with 31 additions and 3 deletions
|
@ -111,6 +111,12 @@ public abstract class AST2TestBase extends SemanticTestBase {
|
||||||
public boolean isUseGNUExtensions() {
|
public boolean isUseGNUExtensions() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
STDCPP20 {
|
||||||
|
@Override
|
||||||
|
public boolean isUseGNUExtensions() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public abstract boolean isUseGNUExtensions();
|
public abstract boolean isUseGNUExtensions();
|
||||||
|
@ -122,6 +128,7 @@ public abstract class AST2TestBase extends SemanticTestBase {
|
||||||
|
|
||||||
private static final ScannerInfo GNU_SCANNER_INFO = new ScannerInfo(getGnuMap());
|
private static final ScannerInfo GNU_SCANNER_INFO = new ScannerInfo(getGnuMap());
|
||||||
private static final ScannerInfo SCANNER_INFO = new ScannerInfo(getStdMap());
|
private static final ScannerInfo SCANNER_INFO = new ScannerInfo(getStdMap());
|
||||||
|
private static final ScannerInfo STDCPP20_SCANNER_INFO = new ScannerInfo(getStdCpp20Map());
|
||||||
|
|
||||||
private static Map<String, String> getGnuMap() {
|
private static Map<String, String> getGnuMap() {
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
|
@ -147,6 +154,12 @@ public abstract class AST2TestBase extends SemanticTestBase {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Map<String, String> getStdCpp20Map() {
|
||||||
|
Map<String, String> map = getStdMap();
|
||||||
|
map.put("__cpp_impl_three_way_comparison", "201907L");
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
public AST2TestBase() {
|
public AST2TestBase() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -227,6 +240,8 @@ public abstract class AST2TestBase extends SemanticTestBase {
|
||||||
switch (scannerKind) {
|
switch (scannerKind) {
|
||||||
case GNU:
|
case GNU:
|
||||||
return GNU_SCANNER_INFO;
|
return GNU_SCANNER_INFO;
|
||||||
|
case STDCPP20:
|
||||||
|
return STDCPP20_SCANNER_INFO;
|
||||||
case STD:
|
case STD:
|
||||||
default:
|
default:
|
||||||
return SCANNER_INFO;
|
return SCANNER_INFO;
|
||||||
|
@ -294,16 +309,25 @@ public abstract class AST2TestBase extends SemanticTestBase {
|
||||||
assertEquals(x.getName().toString(), x2.getName().toString());
|
assertEquals(x.getName().toString(), x2.getName().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void validateSimpleBinaryExpressionC(String code, int operand) throws ParserException {
|
protected void validateSimpleBinaryExpression(String code, int operator, ParserLanguage language,
|
||||||
IASTBinaryExpression e = (IASTBinaryExpression) getExpressionFromStatementInCode(code, ParserLanguage.C);
|
ScannerKind scannerKind) throws ParserException {
|
||||||
|
IASTBinaryExpression e = (IASTBinaryExpression) getExpressionFromStatementInCode(code, language, scannerKind);
|
||||||
assertNotNull(e);
|
assertNotNull(e);
|
||||||
assertEquals(e.getOperator(), operand);
|
assertEquals(e.getOperator(), operator);
|
||||||
IASTIdExpression x = (IASTIdExpression) e.getOperand1();
|
IASTIdExpression x = (IASTIdExpression) e.getOperand1();
|
||||||
assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$
|
assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$
|
||||||
IASTIdExpression y = (IASTIdExpression) e.getOperand2();
|
IASTIdExpression y = (IASTIdExpression) e.getOperand2();
|
||||||
assertEquals(y.getName().toString(), "y"); //$NON-NLS-1$
|
assertEquals(y.getName().toString(), "y"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void validateSimpleBinaryExpressionC(String code, int operator) throws ParserException {
|
||||||
|
validateSimpleBinaryExpression(code, operator, ParserLanguage.C, ScannerKind.STD);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void validateSimpleBinaryExpressionCPP20(String code, int operator) throws ParserException {
|
||||||
|
validateSimpleBinaryExpression(code, operator, ParserLanguage.CPP, ScannerKind.STDCPP20);
|
||||||
|
}
|
||||||
|
|
||||||
protected IASTExpression getExpressionFromStatementInCode(String code, ParserLanguage language)
|
protected IASTExpression getExpressionFromStatementInCode(String code, ParserLanguage language)
|
||||||
throws ParserException {
|
throws ParserException {
|
||||||
return getExpressionFromStatementInCode(code, language, ScannerKind.STD);
|
return getExpressionFromStatementInCode(code, language, ScannerKind.STD);
|
||||||
|
|
|
@ -505,6 +505,10 @@ public class AST2Tests extends AST2TestBase {
|
||||||
validateConditionalExpressionC("x ? y : x"); //$NON-NLS-1$
|
validateConditionalExpressionC("x ? y : x"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCPP20Expressions() throws ParserException {
|
||||||
|
validateSimpleBinaryExpressionCPP20("x<=>y", IASTBinaryExpression.op_threewaycomparison); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
public void testMultipleDeclarators() throws Exception {
|
public void testMultipleDeclarators() throws Exception {
|
||||||
IASTTranslationUnit tu = parse("int r, s;", C); //$NON-NLS-1$
|
IASTTranslationUnit tu = parse("int r, s;", C); //$NON-NLS-1$
|
||||||
assertTrue(tu.isFrozen());
|
assertTrue(tu.isFrozen());
|
||||||
|
|
Loading…
Add table
Reference in a new issue