From 5c9c76a3d928ed7f00d7fc6c2dd06939688c446d Mon Sep 17 00:00:00 2001 From: satish puppala Date: Thu, 4 Jan 2018 20:39:11 +0530 Subject: [PATCH 1/2] fixes #1246 forced string literal to column-1 --- src/indent.cpp | 14 +++++ tests/input/staging/UNI-2020.cs | 63 +++++++++++++-------- tests/output/cs/10090-string_multi.cs | 2 +- tests/output/staging/10015-misc-failures.cs | 2 +- tests/output/staging/10074-UNI-2020.cs | 63 +++++++++++++-------- 5 files changed, 92 insertions(+), 52 deletions(-) diff --git a/src/indent.cpp b/src/indent.cpp index 282f7f07fd..aafd35e364 100644 --- a/src/indent.cpp +++ b/src/indent.cpp @@ -646,6 +646,20 @@ void indent_text(void) pc = chunk_get_head(); while (pc != nullptr) { + // forces string literal to column-1 [Fix for 1246] + if ( (pc->type == CT_STRING || pc->type == CT_STRING_MULTI) + && !(cpd.lang_flags & LANG_OC)) + { + string str = pc->text(); + if ((str[0] == '@') && (chunk_get_prev(pc)->type == CT_NEWLINE)) + { + indent_column_set(1); + reindent_line(pc, indent_column); + pc = chunk_get_next(pc); + did_newline = false; + } + } + if (pc->type == CT_NEWLINE) { LOG_FMT(LINDLINE, "%s(%d): orig_line is %zu, NEWLINE\n", diff --git a/tests/input/staging/UNI-2020.cs b/tests/input/staging/UNI-2020.cs index 7ac6c2ba6e..37d9ef23d6 100644 --- a/tests/input/staging/UNI-2020.cs +++ b/tests/input/staging/UNI-2020.cs @@ -1,32 +1,45 @@ -// This has to do with the @" that opens a literal string getting aligned when we don't want it to. -// Test code: +// As discussed with unity updating the test case -void Func() { - OtherFunc( -@"multi -line"); -} + var a = @"asdasda"; + + var d = +@"asdasda"; -// ...becomes: + var d = + @"asdasda"; -void Func() -{ - OtherFunc( - @"multi -line"); -} + var b = @" +line1 +line2"; -// (This also happens with var x = \n@"" and probably a few other scenarios.) -// There's no way to keep it from indenting the first line of the string literal. We want to leave it at column 1 because it's being used for a "here doc" that doesn't want leading spaces from indentation. It's weird looking for just the first line to be indented. -// This likely requires a new Uncrustify feature to support. -// Workaround: start the @" on the previous line and permit the string to have an extra empty first line, like this: + var c = Very(Long(Nested(Function( +@"line1 +line2")))); -void Func() -{ - OtherFunc(@" -multi -line"); -} +var c = Very(Long(Nested(Function( + @"line1 +line2")))); + + var c = Function( + hey, + you, +@"line1 +line2", fubar, + hmm); -// That might be ok for many cases, especially here-docs that are for script source. +var c = Function( + hey, + you, + @"line1 +line2", fubar, + hmm); + + var c = Function( + hey, + you, +@"line1 +line2", + fubar, + hmm); +} diff --git a/tests/output/cs/10090-string_multi.cs b/tests/output/cs/10090-string_multi.cs index 7d006dcea5..2f4160aa23 100644 --- a/tests/output/cs/10090-string_multi.cs +++ b/tests/output/cs/10090-string_multi.cs @@ -7,7 +7,7 @@ public void F() var y = @" abc" + "def"; var z = "" + - @" +@" "; } } diff --git a/tests/output/staging/10015-misc-failures.cs b/tests/output/staging/10015-misc-failures.cs index a4a3e2db7a..5cae3bd69f 100644 --- a/tests/output/staging/10015-misc-failures.cs +++ b/tests/output/staging/10015-misc-failures.cs @@ -1,7 +1,7 @@ void Func() { OtherFunc( - @"multi +@"multi line"); } diff --git a/tests/output/staging/10074-UNI-2020.cs b/tests/output/staging/10074-UNI-2020.cs index 7ac6c2ba6e..14da47885f 100644 --- a/tests/output/staging/10074-UNI-2020.cs +++ b/tests/output/staging/10074-UNI-2020.cs @@ -1,32 +1,45 @@ -// This has to do with the @" that opens a literal string getting aligned when we don't want it to. -// Test code: +// As discussed with unity updating the test case -void Func() { - OtherFunc( -@"multi -line"); -} + var a = @"asdasda"; -// ...becomes: + var d = +@"asdasda"; -void Func() -{ - OtherFunc( - @"multi -line"); -} + var d = +@"asdasda"; -// (This also happens with var x = \n@"" and probably a few other scenarios.) -// There's no way to keep it from indenting the first line of the string literal. We want to leave it at column 1 because it's being used for a "here doc" that doesn't want leading spaces from indentation. It's weird looking for just the first line to be indented. -// This likely requires a new Uncrustify feature to support. -// Workaround: start the @" on the previous line and permit the string to have an extra empty first line, like this: + var b = @" +line1 +line2"; -void Func() -{ - OtherFunc(@" -multi -line"); -} + var c = Very(Long(Nested(Function( +@"line1 +line2")))); -// That might be ok for many cases, especially here-docs that are for script source. + var c = Very(Long(Nested(Function( +@"line1 +line2")))); + + var c = Function( + hey, + you, +@"line1 +line2", fubar, + hmm); + + var c = Function( + hey, + you, +@"line1 +line2", fubar, + hmm); + + var c = Function( + hey, + you, +@"line1 +line2", + fubar, + hmm); +} From d47bddb964a6cca78cfe2b40f4905430be80141f Mon Sep 17 00:00:00 2001 From: satish puppala Date: Thu, 4 Jan 2018 20:47:22 +0530 Subject: [PATCH 2/2] testcase moved to regression --- tests/regression.test | 1 + tests/staging.test | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/regression.test b/tests/regression.test index 0eb103a16c..0d90dee070 100644 --- a/tests/regression.test +++ b/tests/regression.test @@ -62,6 +62,7 @@ 10071 staging/Uncrustify.Cpp.cfg staging/UNI-1983.cpp 10072 staging/Uncrustify.CSharp.cfg staging/UNI-2007.cs 10073 staging/Uncrustify.CSharp.cfg staging/UNI-2008.cs +10074 staging/Uncrustify.CSharp.cfg staging/UNI-2020.cs 10075 staging/UNI-2021.cfg staging/UNI-2021.cs 10076 staging/UNI-1343.cfg staging/UNI-1343.cs 10077 staging/Uncrustify.CSharp.cfg staging/UNI-1919.cs diff --git a/tests/staging.test b/tests/staging.test index 5a95bda2a9..a191e2c58d 100644 --- a/tests/staging.test +++ b/tests/staging.test @@ -18,7 +18,6 @@ 10061 staging/Uncrustify.CSharp.cfg staging/UNI-1355.cs 10064 staging/Uncrustify.CSharp.cfg staging/UNI-1443.cs 10068 staging/Uncrustify.CSharp.cfg staging/UNI-1979.cs -10074 staging/Uncrustify.CSharp.cfg staging/UNI-2020.cs 10076 staging/Uncrustify.CSharp.cfg staging/UNI-1343.cs 60004 staging/Uncrustify.CSharp.cfg staging/UNI-2684.cs 60005 staging/Uncrustify.CSharp.cfg staging/UNI-2685.cs