diff options
author | zhvv117 <[email protected]> | 2025-01-31 12:58:25 +0300 |
---|---|---|
committer | zhvv117 <[email protected]> | 2025-01-31 13:24:51 +0300 |
commit | 757ce306e6a07bfb3a3c4d729c75cd7512af2e45 (patch) | |
tree | cc372ebce924cddb5da846cb9e8a2d48a8b45223 | |
parent | f12d0f878911d1506ff75f19bb550d498b9ec242 (diff) |
Fix comment line count calculation
commit_hash:b18a35e909cfd6662088765125b0d6f3dcf83c15
-rw-r--r-- | yql/essentials/sql/v1/format/sql_format.cpp | 4 | ||||
-rw-r--r-- | yql/essentials/sql/v1/format/sql_format_ut.h | 20 |
2 files changed, 19 insertions, 5 deletions
diff --git a/yql/essentials/sql/v1/format/sql_format.cpp b/yql/essentials/sql/v1/format/sql_format.cpp index 3b180827a65..19619bf6e89 100644 --- a/yql/essentials/sql/v1/format/sql_format.cpp +++ b/yql/essentials/sql/v1/format/sql_format.cpp @@ -496,6 +496,10 @@ private: ++CommentLines; } + if (!text.StartsWith("--")) { + CommentLines += CountIf(text, [](auto c) { return c == '\n'; }); + } + Out(text); if (text.StartsWith("--") && !text.EndsWith("\n")) { diff --git a/yql/essentials/sql/v1/format/sql_format_ut.h b/yql/essentials/sql/v1/format/sql_format_ut.h index 0960fec3b69..b22bf1cb21c 100644 --- a/yql/essentials/sql/v1/format/sql_format_ut.h +++ b/yql/essentials/sql/v1/format/sql_format_ut.h @@ -1,10 +1,10 @@ Y_UNIT_TEST(Pragma) { TCases cases = { - {"pragma user = user;","PRAGMA user = user;\n"}, - {"pragma user = default;","PRAGMA user = default;\n"}, - {"pragma user.user = user;","PRAGMA user.user = user;\n"}, - {"pragma user.user(user);","PRAGMA user.user(user);\n"}, - {"pragma user.user(user, user);","PRAGMA user.user(user, user);\n"}, + {"pragma user = user;", "PRAGMA user = user;\n"}, + {"pragma user = default;", "PRAGMA user = default;\n"}, + {"pragma user.user = user;", "PRAGMA user.user = user;\n"}, + {"pragma user.user(user);", "PRAGMA user.user(user);\n"}, + {"pragma user.user(user, user);", "PRAGMA user.user(user, user);\n"}, }; TSetup setup; @@ -1512,6 +1512,16 @@ Y_UNIT_TEST(Union) { setup.Run(cases); } +Y_UNIT_TEST(Comment) { + TCases cases = { + {"/*\nmulti\nline\ncomment\n*/\npragma foo = \"true\";\npragma bar = \"1\"", + "/*\nmulti\nline\ncomment\n*/\nPRAGMA foo = 'true';\nPRAGMA bar = '1';\n"}, + }; + + TSetup setup; + setup.Run(cases); +} + Y_UNIT_TEST(CommentAfterLastSelect) { TCases cases = { {"SELECT 1--comment\n", |