#!/usr/bin/env bash
#clear
#export PS4='\e[90m+${LINENO} in ${#BASH_SOURCE[@]}>${FUNCNAME[0]}:${BASH_SOURCE[@]##*/} \e[0m'
#set -x

level=$1
if [ -z "$level" ]; then
  level=1
fi
echo "starting: ${BASH_SOURCE[@]##*/} <LOG_LEVEL=$1>"

#echo "sourcing init"
source this
source test.suite

log.level $level

competionArray=(once config list file ite)
source oo

test.line() 
{
((TEST_COUNTER++))
console.log "


Test 0: line \"$*\"
===================================================================="
line.start "$@"
console.log "RETURN: $RETURN_VALUE  Result: $RESULT 
===================================================================="
}

test.case - "line test start" \
   line $*
expect 0 "*" "Test start"

source line

# ============================================================================
# Regression: [args...] must be stripped from paramList (commit 58048e1)
# Without the fix, this generates: declare: '[args...]=addDefaultValue': not a valid identifier
# ============================================================================
test.case $level "completion: [args...] stripped from paramList" \
  echo "branch command [args...]" '|' line.parse.paramList.new

# Feed a parameter list containing [args...] through the parser
PARSE_OUTPUT=$(echo "branch command [args...]" | line.parse.paramList.new 2>&1)
PARSE_RC=$?

# Check no "not a valid identifier" error
if echo "$PARSE_OUTPUT" | grep -q 'not a valid identifier'; then
  expect.fail "paramList parser should not produce 'not a valid identifier' for [args...]"
else
  expect.pass "no invalid identifier error from [args...]"
fi

# Check that [args...] does not appear as a PARAM_ variable in the output
if echo "$PARSE_OUTPUT" | grep -q 'PARAM_\['; then
  expect.fail "paramList should strip [args...], not create PARAM_[args...]"
else
  expect.pass "[args...] stripped from paramList output"
fi

# Check that valid params (branch, command) are still parsed
PARAM_COUNT=$(echo "$PARSE_OUTPUT" | grep -c 'PARAM_' || true)
if [ "$PARAM_COUNT" -ge 1 ]; then
  expect.pass "valid PARAM_ variables generated ($PARAM_COUNT found)"
else
  expect.fail "should generate at least 1 PARAM_ variable"
fi

### test.method

