aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2013-01-07 16:36:17 +0000
committerNico Weber <nicolasweber@gmx.de>2013-01-07 16:36:17 +0000
commita9ccdd1b8ef31d1942193ffa6bc32781055cf493 (patch)
treefd44c3585b70f7659e1a85d595914b4166e04760 /unittests/Format/FormatTest.cpp
parentd0af4b46741560cf2e52d819e1f3a2506a1e7a3c (diff)
Formatter: Add tests for try/catch. Let 'throw' start an expression.
Before: throw a *b; Now: throw a * b; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171754 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r--unittests/Format/FormatTest.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 17e98741fd..d4490dddfc 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -377,6 +377,46 @@ TEST_F(FormatTest, FormatsNamespaces) {
"}");
}
+TEST_F(FormatTest, FormatTryCatch) {
+ verifyFormat("try {\n"
+ " throw a * b;\n"
+ "}\n"
+ "catch (int a) {\n"
+ " // Do nothing.\n"
+ "}\n"
+ "catch (...) {\n"
+ " exit(42);\n"
+ "}");
+
+ // Function-level try statements.
+ verifyFormat("int f() try {\n"
+ " return 4;\n"
+ "}\n"
+ "catch (...) {\n"
+ " return 5;\n"
+ "}");
+ verifyFormat("class A {\n"
+ " int a;\n"
+ " A() try : a(0) {\n"
+ " }\n"
+ " catch (...) {\n"
+ " throw;\n"
+ " }\n"
+ "};\n");
+}
+
+TEST_F(FormatTest, FormatObjCTryCatch) {
+ verifyFormat("@try {\n"
+ " f();\n"
+ "}\n"
+ "@catch (NSException e) {\n"
+ " @throw;\n"
+ "}\n"
+ "@finally {\n"
+ " exit(42);\n"
+ "}");
+}
+
TEST_F(FormatTest, StaticInitializers) {
verifyFormat("static SomeClass SC = { 1, 'a' };");