Skip to content

Commit

Permalink
Add Parameters:matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed Aug 14, 2019
1 parent 195a074 commit 884f62c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/libexec/grammar.sh
Expand Up @@ -68,6 +68,7 @@ mapping() {
Parameters ) parameters block "$2" ;;
Parameters:block ) parameters block "$2" ;;
Parameters:dynamic) parameters dynamic "$2" ;;
Parameters:matrix ) parameters matrix "$2" ;;
Include ) include "$2" ;;
%text ) text_begin raw "$2" ;;
%text:raw ) text_begin raw "$2" ;;
Expand Down
38 changes: 38 additions & 0 deletions lib/libexec/translator.sh
Expand Up @@ -278,6 +278,44 @@ parameters_dynamic() {
trans parameters_end "$parameter_count"
}

parameters_matrix() {
trans parameters_begin
code='' nest=0 arguments=''

while IFS= read -r line || [ "$line" ]; do
lineno=$(($lineno + 1))
trim line "$line"
case $line in (End | End\ * ) break; esac
case $line in (\#* | '') continue; esac

nest=$(($nest + 1))
parameters_matrix_code "for shellspex_matrix${nest} in $line"
arguments="$arguments\"\$shellspex_matrix${nest}\" "
until case $line in (*\\) false; esac; do
lineno=$(($lineno + 1))
IFS= read -r line
parameters_matrix_code "$line"
done
parameters_matrix_code "do"
done

trans parameters "$arguments"
code="${code}count=\$((\$count + 1))${LF}"

while [ $nest -gt 0 ]; do
parameters_matrix_code "done"
nest=$(($nest - 1))
done

eval "parameter_count=\$(count=0${LF}${code}echo \"\$count\")"
trans parameters_end "$parameter_count"
}

parameters_matrix_code() {
trans line "$1"
code="${code}${1}${LF}"
}

constant() {
if [ "$_block_no_stack" ]; then
syntax_error "Constant should be defined outside of Example Group/Example"
Expand Down
12 changes: 12 additions & 0 deletions spec/core/dsl/parameters_spec.sh
Expand Up @@ -37,4 +37,16 @@ Describe 'Parameters helper'
The output should eq "$1"
End
End

Describe 'matrix style'
Parameters:matrix
foo bar
1 2 3
End

It "example $1 $2"
When call echo "$1 $2"
The output should be present
End
End
End

0 comments on commit 884f62c

Please sign in to comment.