mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 01:45:33 +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() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
STDCPP20 {
|
||||
@Override
|
||||
public boolean isUseGNUExtensions() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
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 SCANNER_INFO = new ScannerInfo(getStdMap());
|
||||
private static final ScannerInfo STDCPP20_SCANNER_INFO = new ScannerInfo(getStdCpp20Map());
|
||||
|
||||
private static Map<String, String> getGnuMap() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
@ -147,6 +154,12 @@ public abstract class AST2TestBase extends SemanticTestBase {
|
|||
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() {
|
||||
super();
|
||||
}
|
||||
|
@ -227,6 +240,8 @@ public abstract class AST2TestBase extends SemanticTestBase {
|
|||
switch (scannerKind) {
|
||||
case GNU:
|
||||
return GNU_SCANNER_INFO;
|
||||
case STDCPP20:
|
||||
return STDCPP20_SCANNER_INFO;
|
||||
case STD:
|
||||
default:
|
||||
return SCANNER_INFO;
|
||||
|
@ -294,16 +309,25 @@ public abstract class AST2TestBase extends SemanticTestBase {
|
|||
assertEquals(x.getName().toString(), x2.getName().toString());
|
||||
}
|
||||
|
||||
protected void validateSimpleBinaryExpressionC(String code, int operand) throws ParserException {
|
||||
IASTBinaryExpression e = (IASTBinaryExpression) getExpressionFromStatementInCode(code, ParserLanguage.C);
|
||||
protected void validateSimpleBinaryExpression(String code, int operator, ParserLanguage language,
|
||||
ScannerKind scannerKind) throws ParserException {
|
||||
IASTBinaryExpression e = (IASTBinaryExpression) getExpressionFromStatementInCode(code, language, scannerKind);
|
||||
assertNotNull(e);
|
||||
assertEquals(e.getOperator(), operand);
|
||||
assertEquals(e.getOperator(), operator);
|
||||
IASTIdExpression x = (IASTIdExpression) e.getOperand1();
|
||||
assertEquals(x.getName().toString(), "x"); //$NON-NLS-1$
|
||||
IASTIdExpression y = (IASTIdExpression) e.getOperand2();
|
||||
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)
|
||||
throws ParserException {
|
||||
return getExpressionFromStatementInCode(code, language, ScannerKind.STD);
|
||||
|
|
|
@ -505,6 +505,10 @@ public class AST2Tests extends AST2TestBase {
|
|||
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 {
|
||||
IASTTranslationUnit tu = parse("int r, s;", C); //$NON-NLS-1$
|
||||
assertTrue(tu.isFrozen());
|
||||
|
|
Loading…
Add table
Reference in a new issue