Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for subshell functions #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shdoc
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ match($0, /^([[:blank:]]*#[[:blank:]]+)@(stdin|stdout|stderr)[[:blank:]]+(.*[^[:
# - `function function_name () {`
# - `function_name () {`
# - `function_name {`
/^[[:blank:]]*(function[[:blank:]]+)?([a-zA-Z0-9_\-:-\\.]+)[[:blank:]]*(\([[:blank:]]*\))?[[:blank:]]*\{/ \
/^[[:blank:]]*(function[[:blank:]]+)?([a-zA-Z0-9_\-:-\\.]+)[[:blank:]]*(\([[:blank:]]*\))?[[:blank:]]*[({]/ \
{
process_function($0)
}
Expand All @@ -850,7 +850,7 @@ match($0, /^([[:blank:]]*#[[:blank:]]+)@(stdin|stdout|stderr)[[:blank:]]+(.*[^[:
}

# Handle lone opening bracket if previous line is a function declaration.
/^[[:blank:]]*\{/ \
/^[[:blank:]]*[({]/ \
&& function_declaration != "" {
debug("→ multi-line function declaration.")
# Process function declaration.
Expand Down
77 changes: 77 additions & 0 deletions tests/testcases/@function-declaration.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,35 @@ function g
function h()
{ echo "h"; }

# @description Subshell Function n°1
sa() (
echo "a"
)

# @description Subshell Function n°2
sb() ( echo "b" ; )

# @description Subshell Function n°3
:sc() ( echo "c"; )

# @description Subshell Function n°4
sd-method()
( echo "d"; )

# @description Subshell Function n°5
function se:function ( echo "e"; )

# @description Subshell Function n°6
function sf() ( echo "f"; )

# @description Subshell Function n°7
function sg
( echo "g"; )

# @description Subshell Function n°8
function sh()
( echo "h"; )

a
b
:c
Expand All @@ -43,6 +72,15 @@ e:function
f
g
h

sa
sb
:sc
sd-method
se:function
sf
sg
sh
EOF

tests:put expected <<EOF
Expand All @@ -65,6 +103,14 @@ with some more lines
* [f](#f)
* [g](#g)
* [h](#h)
* [sa](#sa)
* [sb](#sb)
* [:sc](#sc)
* [sd-method](#sd-method)
* [se:function](#sefunction)
* [sf](#sf)
* [sg](#sg)
* [sh](#sh)

### a

Expand Down Expand Up @@ -98,6 +144,37 @@ Function n°7

Function n°8

### sa

Subshell Function n°1

### sb

Subshell Function n°2

### :sc

Subshell Function n°3

### sd-method

Subshell Function n°4

### se:function

Subshell Function n°5

### sf

Subshell Function n°6

### sg

Subshell Function n°7

### sh

Subshell Function n°8
EOF

assert