Skip to content

Commit 340abd2

Browse files
committed
- include formatter unit tests for pipe operator
1 parent a167880 commit 340abd2

File tree

6 files changed

+109
-0
lines changed

6 files changed

+109
-0
lines changed

php/php.editor/src/org/netbeans/modules/php/editor/indent/FormatVisitor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ public void visit(CompositionExpression node) {
10981098

10991099
formatTokens.add(new FormatToken(FormatToken.Kind.WHITESPACE_AROUND_KEY_VALUE_OP, ts.offset() + ts.token().length()));
11001100
formatTokens.add(new FormatToken(FormatToken.Kind.TEXT, ts.offset(), ts.token().text().toString()));
1101+
//todo implement a minimum space arround pipe operator (|>trim())
11011102
scan(node.getRight());
11021103
}
11031104

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
21+
$var = "Example " |> strtoupper(...) |> trim(...);
22+
23+
24+
$var2 = "Example2 " |> strtoupper(...) |> str_shuffle(...) |>trim(...);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
$var = "Example " |> strtoupper(...) |> trim(...);
23+
24+
$var2 = "Example2 " |> strtoupper(...) |> str_shuffle(...) |>trim(...);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
21+
$var = "Example"
22+
|> strtoupper(...)
23+
|> str_shuffle(...)
24+
|>trim(...);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
$var = "Example"
23+
|> strtoupper(...)
24+
|> str_shuffle(...)
25+
|>trim(...);

php/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/PHPFormatterTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,4 +1298,15 @@ public void testFinalFieldsAnonClass_02() throws Exception {
12981298
HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults());
12991299
reformatFileContents("testfiles/formatting/php84/finalFieldsAnonClass_02.php", options);
13001300
}
1301+
1302+
//PHP 8.5 pipe operator
1303+
public void testPipeOperatorInlineExpression_01() throws Exception {
1304+
HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults());
1305+
reformatFileContents("testfiles/formatting/php85/pipeOperatorInlineExpression_01.php", options);
1306+
}
1307+
1308+
public void testPipeOperatorMultilineExpression_01() throws Exception {
1309+
HashMap<String, Object> options = new HashMap<>(FmtOptions.getDefaults());
1310+
reformatFileContents("testfiles/formatting/php85/pipeOperatorMultilineExpression_01.php", options);
1311+
}
13011312
}

0 commit comments

Comments
 (0)