tests-always-included / mo

Mustache templates in pure bash
Other
563 stars 67 forks source link

Feature: Key and Index Accessors Inside Loops #57

Closed Swivelgames closed 1 year ago

Swivelgames commented 1 year ago

Implements #56

Swivelgames commented 1 year ago

Tested using fidian/multishell-small

bash-3 - Runs error-free: **YES** - Test Failures: _**YES**_ Assoc test fails simply due to `declare -A` is test file. But `mo` runs without errors. ``` # run-script-againt-shells bash-3 ./run-tests ``` ``` bash-3.1.23: FAIL ... tests/assoc-array ... FAIL (status code 1) ... tests/function-args ... FAIL (status code 1) # EXISTING TEST ... Pass: 27 Fail: 2 ``` ``` bash-3.2.57: FAIL ... tests/assoc-array ... FAIL (status code 1) ... Pass: 28 Fail: 1 ```
bash-4 - Runs error-free: **YES** - Test Failures: _**NO**_ Different versions output assoc arrays in different order ``` bash-4.0.44: pass bash-4.1.17: pass bash-4.2.53: pass bash-4.3.48: pass bash-4.4.23: pass ```
bash-5 - Runs error-free: **YES** - Test Failures: _**NO**_ Different versions output assoc arrays in different order ``` bash-5.0.18: pass bash-5.1.8: pass ```
fidian commented 1 year ago

Sorry for not making this more clear earlier when I asked you to combine the logic. Could you make two changes?

  1. The example in README.md uses @. No label. Would you change this to @key?
  2. Would you remove @index or change it's implementation? If we were to follow Handlebars, then @index would be a 0-based numeric value when iterating across objects. That might be more work to properly support and I would rather get @key implemented because you've expressed a need for this functionality.
Swivelgames commented 1 year ago

@fidian Ah! My apologies. I had originally implemented @index to only output if it was a 0-based number, but I don't have an immediate need for it, so we can certainly reimplement this if someone ever has a major need for it.

As for the README, I must have totally overlooked that. Good catch :sweat_smile:

Swivelgames commented 1 year ago

Done!

fidian commented 1 year ago

Excellent, thanks!