@@ -24954,6 +24954,82 @@ TEST_F(FormatTest, DisableRegions) {
24954
24954
"// clang-format on");
24955
24955
}
24956
24956
24957
+ TEST_F(FormatTest, OneLineFormatOffRegex) {
24958
+ auto Style = getLLVMStyle();
24959
+ Style.OneLineFormatOffRegex = "// format off$";
24960
+
24961
+ verifyFormat("// format off\n"
24962
+ "int i ;\n"
24963
+ "int j;",
24964
+ " // format off\n"
24965
+ "int i ;\n"
24966
+ "int j ;",
24967
+ Style);
24968
+ verifyFormat("// format off?\n"
24969
+ "int i;",
24970
+ "// format off?\n"
24971
+ "int i ;",
24972
+ Style);
24973
+ verifyFormat("f(\"// format off\");", "f(\"// format off\") ;", Style);
24974
+
24975
+ verifyFormat("int i;\n"
24976
+ "// format off\n"
24977
+ "int j ;\n"
24978
+ "int k;",
24979
+ "int i ;\n"
24980
+ " // format off\n"
24981
+ "int j ;\n"
24982
+ "int k ;",
24983
+ Style);
24984
+
24985
+ verifyFormat("int i;\n"
24986
+ "int j ; // format off\n"
24987
+ "int k;",
24988
+ "int i ;\n"
24989
+ "int j ; // format off\n"
24990
+ "int k ;",
24991
+ Style);
24992
+
24993
+ verifyFormat("// clang-format off\n"
24994
+ "int i ;\n"
24995
+ "int j ; // format off\n"
24996
+ "int k ;\n"
24997
+ "// clang-format on\n"
24998
+ "f();",
24999
+ "// clang-format off\n"
25000
+ "int i ;\n"
25001
+ "int j ; // format off\n"
25002
+ "int k ;\n"
25003
+ "// clang-format on\n"
25004
+ "f() ;",
25005
+ Style);
25006
+
25007
+ Style.OneLineFormatOffRegex = "^/\\* format off \\*/";
25008
+ verifyFormat("int i;\n"
25009
+ " /* format off */ int j ;\n"
25010
+ "int k;",
25011
+ "int i ;\n"
25012
+ " /* format off */ int j ;\n"
25013
+ "int k ;",
25014
+ Style);
25015
+ verifyFormat("f(\"/* format off */\");", "f(\"/* format off */\") ;", Style);
25016
+
25017
+ Style.ColumnLimit = 50;
25018
+ Style.OneLineFormatOffRegex = "^LogErrorPrint$";
25019
+ verifyFormat("myproject::LogErrorPrint(logger, \"Don't split me!\");\n"
25020
+ "myproject::MyLogErrorPrinter(myLogger,\n"
25021
+ " \"Split me!\");",
25022
+ "myproject::LogErrorPrint(logger, \"Don't split me!\");\n"
25023
+ "myproject::MyLogErrorPrinter(myLogger, \"Split me!\");",
25024
+ Style);
25025
+
25026
+ Style.OneLineFormatOffRegex = "//(< clang-format off| NO_TRANSLATION)$";
25027
+ verifyNoChange(
25028
+ "int i ; //< clang-format off\n"
25029
+ "msg = sprintf(\"Long string with placeholders.\"); // NO_TRANSLATION",
25030
+ Style);
25031
+ }
25032
+
24957
25033
TEST_F(FormatTest, DoNotCrashOnInvalidInput) {
24958
25034
format("? ) =");
24959
25035
verifyNoCrash("#define a\\\n /**/}");
0 commit comments