Skip to content

Commit

Permalink
More tests for c++17 fold expression
Browse files Browse the repository at this point in the history
  • Loading branch information
i-garrison authored and jonahgraham committed Feb 14, 2023
1 parent dc8313b commit 04c2da4
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import static org.eclipse.cdt.core.parser.ParserLanguage.CPP;

import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTProblemExpression;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFoldExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPTestBase;

Expand Down Expand Up @@ -79,6 +81,16 @@ public void testFoldExpression2() throws Exception {
helper.assertVariableValue("val42", 1);
}

// template<typename... SP>
// template<typename... TP>
// void fold_multi(SP... sp, TP... tp) {
// ((... + tp) + ... + sp);
// (sp + ... + tp);
// }
public void testFoldExpressionNested() throws Exception {
parseAndCheckBindings();
}

// template <typename CharT>
// struct ostream {
// template <typename T>
Expand Down Expand Up @@ -122,4 +134,56 @@ public void testFoldExpressionRecognition2() throws Exception {
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tdef.getDeclaration();
IASTProblemStatement p1 = getStatement(fdef, 0);
}

// template<typename... T>
// void sum(T... vals) {
// (++vals + ...);
// ((2*vals) + ...);
// }
public void testFoldExpressionRecognitionSuccess() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit tu = parse(code, CPP, ScannerKind.STD, false);
ICPPASTTemplateDeclaration tdef = getDeclaration(tu, 0);
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tdef.getDeclaration();
ICPPASTFoldExpression e1 = getExpressionOfStatement(fdef, 0);
ICPPASTFoldExpression e2 = getExpressionOfStatement(fdef, 1);
}

// template<typename... T>
// void sum(T... vals) {
// (... + ... + ...);
// (... + ... + vals);
// (... + vals + ...);
// (... + vals + vals);
// (vals + ... + ...);
// (vals + vals + ...);
// (1 + vals + ...);
// (1 * vals + ...);
// (1 * ... + vals);
// (... + 1 + vals);
// (... + 1 * vals);
// (vals + ... + 1 * 2);
// (1 * 2 + ... + vals);
// }
public void testFoldExpressionErrors() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit tu = parse(code, CPP, ScannerKind.STD, false);
ICPPASTTemplateDeclaration tdef = getDeclaration(tu, 0);
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tdef.getDeclaration();
for (int i = 0; i < 13; ++i) {
IASTProblemExpression e = getExpressionOfStatement(fdef, i);
}
}

// template<typename... T>
// void f(T... vals) {
// (... <=> vals);
// }
public void testFoldExpressionDisallowedOpToken() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit tu = parse(code, CPP, ScannerKind.STDCPP20, false);
ICPPASTTemplateDeclaration tdef = getDeclaration(tu, 0);
IASTFunctionDefinition fdef = (IASTFunctionDefinition) tdef.getDeclaration();
IASTProblemExpression e1 = getExpressionOfStatement(fdef, 0);
}
}

0 comments on commit 04c2da4

Please sign in to comment.