1
+ /*
2
+ * This file is a part of BSL Language Server.
3
+ *
4
+ * Copyright (c) 2018-2025
5
+ * Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors
6
+ *
7
+ * SPDX-License-Identifier: LGPL-3.0-or-later
8
+ *
9
+ * BSL Language Server is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU Lesser General Public
11
+ * License as published by the Free Software Foundation; either
12
+ * version 3.0 of the License, or (at your option) any later version.
13
+ *
14
+ * BSL Language Server is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ * Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with BSL Language Server.
21
+ */
22
+ package com .github ._1c_syntax .bsl .languageserver .utils .expressiontree ;
23
+
24
+ import com .github ._1c_syntax .bsl .languageserver .context .ServerContext ;
25
+ import com .github ._1c_syntax .bsl .languageserver .util .TestUtils ;
26
+ import org .junit .jupiter .api .Test ;
27
+
28
+ import static org .assertj .core .api .Assertions .assertThat ;
29
+ import static org .assertj .core .api .Assertions .assertThatNoException ;
30
+
31
+ class ExpressionTreeBuildingVisitorTest {
32
+
33
+ @ Test
34
+ void testEmptyParenthesesHandling () {
35
+ // Create test code with empty parentheses
36
+ var code = """
37
+ Процедура ТестПроцедура()
38
+ Если () Тогда
39
+ Возврат;
40
+ КонецЕсли;
41
+ КонецПроцедуры
42
+ """ ;
43
+
44
+ var documentContext = TestUtils .getDocumentContext (code );
45
+ var serverContext = new ServerContext ();
46
+ serverContext .populateContext (documentContext );
47
+
48
+ // Assert that no exception is thrown when processing the if statement with empty parentheses
49
+ assertThatNoException ().isThrownBy (() -> {
50
+ var ast = documentContext .getAst ();
51
+ var ifStatements = ast .getDescendants ()
52
+ .stream ()
53
+ .filter (node -> node .getClass ().getSimpleName ().equals ("IfStatementContext" ))
54
+ .findFirst ();
55
+
56
+ // If the statement should exist
57
+ assertThat (ifStatements ).isPresent ();
58
+
59
+ var visitor = new ExpressionTreeBuildingVisitor ();
60
+ var ifStatement = ifStatements .get ();
61
+
62
+ // Find the expression node within the if statement
63
+ var expressions = ifStatement .getDescendants ()
64
+ .stream ()
65
+ .filter (node -> node .getClass ().getSimpleName ().equals ("ExpressionContext" ))
66
+ .findFirst ();
67
+
68
+ assertThat (expressions ).isPresent ();
69
+
70
+ // Try to build expression tree from empty parentheses
71
+ visitor .visitExpression ((com .github ._1c_syntax .bsl .parser .BSLParser .ExpressionContext ) expressions .get ());
72
+
73
+ // Result should be null since there's no expression
74
+ assertThat (visitor .getExpressionTree ()).isNull ();
75
+ });
76
+ }
77
+ }
0 commit comments