Skip to content

Commit

Permalink
[spec/assign] Add test cases to prepare for redo of assignment builtins.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Jul 15, 2019
1 parent 339d0d1 commit 8f07fbe
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
10 changes: 10 additions & 0 deletions doc/osh-data-model.md
Expand Up @@ -147,6 +147,16 @@ Respects the normal rules of argv.
$(1 + 2 * 3)
)

#### Associative Array Literals

(['k']=v)

Unlike bash, ([0]=v) is still an associative array literal.

It's not an indexed array literal. This matters when you take slices and
so forth?


#### "${a[@]}" is Evaluating (Splicing)

echo "${array[@]}"
Expand Down
3 changes: 2 additions & 1 deletion osh/runtime.asdl
Expand Up @@ -5,7 +5,8 @@ module runtime
-- The spids array is parallel to strs, the argv values. Note that each
-- entry in argv came from a single word, but a word can produce multiple
-- argv entries.
arg_vector = (string* strs, int* spids)
-- 'rhs' is for assignment builtins.
arg_vector = (string* strs, int* spids, value* rhs)

-- A parse-time word_part from syntax.asdl is evaluated to a runtime
-- part_value.
Expand Down
7 changes: 7 additions & 0 deletions osh/word_eval.py
Expand Up @@ -839,6 +839,9 @@ def _EvalWordPart(self, part, part_vals, quoted=False, is_subst=False):
if part.tag == word_part_e.ArrayLiteralPart:
raise AssertionError(
'Array literal should have been handled at word level')
elif part.tag == word_part_e.AssocArrayLiteral:
raise AssertionError(
'Assoc Array literal should have been handled at word level')

elif part.tag == word_part_e.LiteralPart:
# Split if it's in a substitution.
Expand Down Expand Up @@ -1170,6 +1173,10 @@ def EvalWordSequence2(self, words):
part_vals = []
self._EvalWordToParts(w, False, part_vals) # not double quoted

# TODO: Detect whether any parts are ArrayLiteralPart /
# AssocArrayLiteral. If so, then append directly to arg_vec.strs,
# spids, array_rhs, and skip the rest.

if 0:
log('')
log('part_vals after _EvalWordToParts:')
Expand Down
33 changes: 33 additions & 0 deletions spec/assign.test.sh
Expand Up @@ -485,3 +485,36 @@ argv.py "$ex2" "$ro2"
['a b c', 'a b c']
['a b c', 'a b c']
## END

#### assign and glob
cd $TMP
touch foo=a foo=b
foo=*
argv "$foo"
unset foo

export foo=*
argv "$foo"
unset foo

## STDOUT:
['*']
['*']
## END
## BUG dash STDOUT:
['*']
['b']
## END

#### declare and glob
cd $TMP
touch foo=a foo=b
typeset foo=*
argv "$foo"
unset foo
## STDOUT:
['*']
## END
## N-I dash STDOUT:
['']
## END
2 changes: 1 addition & 1 deletion test/spec.sh
Expand Up @@ -274,7 +274,7 @@ word-eval() {

# These cases apply to many shells.
assign() {
sh-spec spec/assign.test.sh --osh-failures-allowed 5 \
sh-spec spec/assign.test.sh --osh-failures-allowed 6 \
${REF_SHELLS[@]} $ZSH $OSH_LIST "$@"
}

Expand Down

0 comments on commit 8f07fbe

Please sign in to comment.