Repository: reubeno/brush
Pull request #405 (2025-03-12 16:27:13)

fix: allow newline in empty array assignment
Closes: #404

github-actions[bot]: # Performance Benchmark Report
| Benchmark name                         | Baseline (μs) |  Test/PR (μs) |    Delta (μs) | Delta %         |
| -------------------------------------- | ------------- | ------------- | ------------- | --------------- |
| `clone_shell_object                  ` | `   18.27 μs` | `   17.73 μs` | `   -0.54 μs` | `🟢 -2.95%    ` |
| `eval_arithmetic                     ` | `    0.17 μs` | `    0.17 μs` | `    0.00 μs` | `⚪  Unchanged` |
| `expand_one_string                   ` | `    1.84 μs` | `    1.82 μs` | `   -0.02 μs` | `⚪  Unchanged` |
| `for_loop                            ` | `   22.49 μs` | `   22.20 μs` | `   -0.29 μs` | `🟢 -1.31%    ` |
| `function_call                       ` | `    2.42 μs` | `    2.46 μs` | `    0.05 μs` | `⚪  Unchanged` |
| `instantiate_shell                   ` | `   57.76 μs` | `   57.41 μs` | `   -0.35 μs` | `🟢 -0.61%    ` |
| `instantiate_shell_with_init_scripts ` | `24374.08 μs` | `23793.45 μs` | ` -580.63 μs` | `⚪  Unchanged` |
| `parse_bash_completion               ` | ` 1664.88 μs` | ` 1658.71 μs` | `   -6.17 μs` | `⚪  Unchanged` |
| `parse_sample_script                 ` | `    1.73 μs` | `    1.74 μs` | `    0.01 μs` | `🟠 +0.81%    ` |
| `run_echo_builtin_command            ` | `   15.49 μs` | `   15.20 μs` | `   -0.29 μs` | `⚪  Unchanged` |
| `run_one_external_command            ` | ` 2195.69 μs` | ` 2163.47 μs` | `  -32.23 μs` | `🟢 -1.47%    ` |
| `tokenize_sample_script              ` | `    2.93 μs` | `    2.79 μs` | `   -0.14 μs` | `🟢 -4.81%    ` |

# Code Coverage Report: Only Changed Files listed

| Package | Base Coverage | New Coverage | Difference |
| ------- | ------------- | ------------ | ---------- |
| brush-core/src/options.rs | 🟢 93.48% | 🟢 92.39% | 🔴 -1.09% |
| **Overall Coverage** | **🟢 76.1%** | **🟢 76.09%** | **🔴 -0.01%** |

_Minimum allowed coverage is_ `70%`_, this run produced_ `76.09%`

# Test Summary: bash-completion test suite
| Outcome            | Count                   | Percentage |
| ------------------ | ----------------------: | ---------: |
| ✅ Pass            | 1343            | <span style='color:green'>63.95</span> |
| ❗️ Error           | 221           | <span style='color:red'>10.52</span> |
| ❌ Fail            | 160            | <span style='color:red'>7.62</span> |
| ⏩ Skip            | 361            | 17.19 |
| ❎ Expected Fail   | 14   | 0.67 |
| ✔️ Unexpected Pass | 1 | <span style='color:red'>0.05</span> |
| 📊 Total           | 2100           | 100.00 |

<!-- Sticky Pull Request Comment -->
reubeno: Thanks for the updates; I'll merge when the test run passes. 

Patch:
diff --git a/brush-parser/src/parser.rs b/brush-parser/src/parser.rs
index 2fce40b..f71f9e0 100644
--- a/brush-parser/src/parser.rs
+++ b/brush-parser/src/parser.rs
@@ -765,7 +765,7 @@ peg::parser! {
             }
 
         rule array_elements() -> Vec<&'input String> =
-            e:array_element()*
+             linebreak() e:array_element()* { e }
 
         rule array_element() -> &'input String =
             linebreak() [Token::Word(e, _)] linebreak() { e }


Test patch:
diff --git a/brush-shell/tests/cases/arrays.yaml b/brush-shell/tests/cases/arrays.yaml
index e503438..61536dd 100644
--- a/brush-shell/tests/cases/arrays.yaml
+++ b/brush-shell/tests/cases/arrays.yaml
@@ -320,3 +320,8 @@ cases:
       echo "\"\${myarray[*]}\": ${myarray[*]}"
       echo "\${myarray[@]}:" ${myarray[@]}
       echo "\${myarray[*]}:" ${myarray[*]}
+
+  - name: "Empty array with newline"
+    stdin: |
+      declare -a myarray=(
+      )