From 97ee572be74b447567387c031bb5d49478f7130c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Sun, 12 Jan 2020 11:42:57 +0100 Subject: [PATCH] formatting of if expressions --- CodeCompletion/CodeFormatter.cs | 17 +++++++++++++++++ TestSuite/formatter_tests/input/ifexpr1.pas | 3 +++ TestSuite/formatter_tests/input/ifexpr2.pas | 3 +++ TestSuite/formatter_tests/should/ifexpr1.pas | 3 +++ TestSuite/formatter_tests/should/ifexpr2.pas | 3 +++ 5 files changed, 29 insertions(+) create mode 100644 TestSuite/formatter_tests/input/ifexpr1.pas create mode 100644 TestSuite/formatter_tests/input/ifexpr2.pas create mode 100644 TestSuite/formatter_tests/should/ifexpr1.pas create mode 100644 TestSuite/formatter_tests/should/ifexpr2.pas diff --git a/CodeCompletion/CodeFormatter.cs b/CodeCompletion/CodeFormatter.cs index e235176da..615285f27 100644 --- a/CodeCompletion/CodeFormatter.cs +++ b/CodeCompletion/CodeFormatter.cs @@ -3387,6 +3387,23 @@ namespace CodeFormatters visit_node(diap.left); visit_node(diap.right); } + + public override void visit(if_expr_new _if_expr_new) + { + sb.Append("if"); //sb.Append(" "); + SetKeywordOffset("if"); + read_from_beg_pos = true; + visit_node(_if_expr_new.condition); + if (!in_one_row(_if_expr_new.condition)) + add_newline_after = true; + add_space_before = true; + visit_node(_if_expr_new.if_true); + if (_if_expr_new.if_false != null) + { + add_space_before = true; + visit_node(_if_expr_new.if_false); + } + } #endregion } } \ No newline at end of file diff --git a/TestSuite/formatter_tests/input/ifexpr1.pas b/TestSuite/formatter_tests/input/ifexpr1.pas new file mode 100644 index 000000000..2967b744f --- /dev/null +++ b/TestSuite/formatter_tests/input/ifexpr1.pas @@ -0,0 +1,3 @@ +begin +var b:=if i<2 then (2+4)*4 else 3+5; +end. \ No newline at end of file diff --git a/TestSuite/formatter_tests/input/ifexpr2.pas b/TestSuite/formatter_tests/input/ifexpr2.pas new file mode 100644 index 000000000..23b1b2994 --- /dev/null +++ b/TestSuite/formatter_tests/input/ifexpr2.pas @@ -0,0 +1,3 @@ +begin + var b := if a<2 then 2+3 else if a>3 then 2+5 else 3+4; +end. \ No newline at end of file diff --git a/TestSuite/formatter_tests/should/ifexpr1.pas b/TestSuite/formatter_tests/should/ifexpr1.pas new file mode 100644 index 000000000..0cd8a42be --- /dev/null +++ b/TestSuite/formatter_tests/should/ifexpr1.pas @@ -0,0 +1,3 @@ +begin + var b := if i < 2 then (2 + 4) * 4 else 3 + 5; +end. \ No newline at end of file diff --git a/TestSuite/formatter_tests/should/ifexpr2.pas b/TestSuite/formatter_tests/should/ifexpr2.pas new file mode 100644 index 000000000..86e6ad4aa --- /dev/null +++ b/TestSuite/formatter_tests/should/ifexpr2.pas @@ -0,0 +1,3 @@ +begin + var b := if a < 2 then 2 + 3 else if a > 3 then 2 + 5 else 3 + 4; +end. \ No newline at end of file