Skip to content

Commit

Permalink
fix AlignParametersRule for table expressions chained with '][' (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgrassau committed Jul 31, 2023
1 parent c6f9ec1 commit 6590e88
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private Term(Token firstToken, boolean expandWithArithmeticOps) throws Unexpecte
} else {
while (token.getOpensLevel()) {
token = token.getNextSibling();
if (!token.isClosingParenthesisOrBracket() && !token.isIdentifier())
if (!token.isClosingParenthesisOrBracket() && !token.isIdentifier() && !token.textEquals("]["))
throw new UnexpectedSyntaxException(token, "Expected an identifier or a closing bracket, but found " + token.getTypeAndTextForErrorMessage() + "!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2641,4 +2641,97 @@ void testTableRowWithStrucAlignedWithComponents() {

testRule();
}

@Test
void testMoveChainedTableExpressionBehindCall() {
// expect the complete(!) chained table expression to be moved behind the call
buildSrc(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name(");
buildSrc(" lts_any_table ).");
buildSrc(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name(");
buildSrc(" lts_any_table[ 1 ] ).");
buildSrc(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name(");
buildSrc(" lts_any_table[ 1 ][ 2 ] ).");
buildSrc(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name(");
buildSrc(" lts_any_table[ 1 ][ 2 ][ 3 ] ).");

buildExp(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name( lts_any_table ).");
buildExp(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name( lts_any_table[ 1 ] ).");
buildExp(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name( lts_any_table[ 1 ][ 2 ] ).");
buildExp(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name( lts_any_table[ 1 ][ 2 ][ 3 ] ).");

testRule();
}

@Test
void testMoveChainedTableExpressionToNextLine() {
// where line length is exceeded, expect the complete chained table expressions to be moved to the next line
rule.configMaxLineLength.setValue(110);

buildSrc(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name( lts_any_table ).");
buildSrc(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name( lts_any_table[ 1 ] ).");
buildSrc(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name( lts_any_table[ 1 ][ 2 ] ).");
buildSrc(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name( lts_any_table[ 1 ][ 2 ][ 3 ] ).");

buildExp(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name( lts_any_table ).");
buildExp(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name( lts_any_table[ 1 ] ).");
buildExp(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name(");
buildExp(" lts_any_table[ 1 ][ 2 ] ).");
buildExp(" DATA(lv_some_value_with_a_long_name) = lo_any_instance->any_method_with_a_long_name(");
buildExp(" lts_any_table[ 1 ][ 2 ][ 3 ] ).");

testRule();
}

@Test
void testCondenseChainedTableExpression() {
// expect the chained table expressions to be condensed and moved behind the call

buildSrc(" any_method(");
buildSrc(" lt_any_table[");
buildSrc(" 1 ] ).");
buildSrc(" any_method(");
buildSrc(" lt_any_table[");
buildSrc(" 1 ][");
buildSrc(" 2 ] ).");
buildSrc(" any_method(");
buildSrc(" lt_any_table[");
buildSrc(" 1 ][");
buildSrc(" 2 ][");
buildSrc(" 3 ] ).");
buildSrc(" any_method(");
buildSrc(" par1 = lt_any_table[");
buildSrc(" 1 ]");
buildSrc(" param2 = lt_any_table[");
buildSrc(" 1 ][");
buildSrc(" 2 ]");
buildSrc(" parameter3 = lt_any_table[");
buildSrc(" 1 ][");
buildSrc(" 2 ][");
buildSrc(" 3 ] ).");

buildExp(" any_method( lt_any_table[ 1 ] ).");
buildExp(" any_method( lt_any_table[ 1 ][ 2 ] ).");
buildExp(" any_method( lt_any_table[ 1 ][ 2 ][ 3 ] ).");
buildExp(" any_method( par1 = lt_any_table[ 1 ]");
buildExp(" param2 = lt_any_table[ 1 ][ 2 ]");
buildExp(" parameter3 = lt_any_table[ 1 ][ 2 ][ 3 ] ).");

testRule();
}

@Test
void testVariousChainedTableExpressions() {
// expect chaining of table expressions with -comp and ->attribute to be identified as a single Term

buildSrc(" any_method(");
buildSrc(" par1 = lt_any_table[ 1 ]-comp");
buildSrc(" param2 = lt_any_table[ 1 ]-comp[ 2 ]");
buildSrc(" parameter3 = lt_any_table[ 1 ]-comp[ 2 ]->mt_attr[ 3 ] ).");

buildExp(" any_method( par1 = lt_any_table[ 1 ]-comp");
buildExp(" param2 = lt_any_table[ 1 ]-comp[ 2 ]");
buildExp(" parameter3 = lt_any_table[ 1 ]-comp[ 2 ]->mt_attr[ 3 ] ).");

testRule();
}
}

0 comments on commit 6590e88

Please sign in to comment.