Skip to content

Commit

Permalink
Document the fact that we don't implement ,, with an arg.
Browse files Browse the repository at this point in the history
The arg could be a constant string or a glob.  The semantics are quite
weird.
  • Loading branch information
Andy Chu committed Sep 29, 2018
1 parent 19da39c commit 07752d9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
12 changes: 11 additions & 1 deletion core/libstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,28 @@ def DoUnarySuffixOp(s, op, arg):

elif op.op_id in (Id.VOp1_Percent, Id.VOp1_DPercent): # const suffix
if s.endswith(arg):
# Mutate it so we preserve the flags.
return s[:-len(arg)]
else:
return s

elif op.op_id == Id.VOp1_Comma: # Only lowercase the first letter
if arg != '':
raise NotImplementedError("%s can't have an argument" % op.op_id)
return s[0].lower() + s[1:]

elif op.op_id == Id.VOp1_DComma:
if arg != '':
raise NotImplementedError("%s can't have an argument" % op.op_id)
return s.lower()

elif op.op_id == Id.VOp1_Caret: # Only uppercase the first letter
if arg != '':
raise NotImplementedError("%s can't have an argument" % op.op_id)
return s[0].upper() + s[1:]

elif op.op_id == Id.VOp1_DCaret:
if arg != '':
raise NotImplementedError("%s can't have an argument" % op.op_id)
return s.upper()

else: # e.g. ^ ^^ , ,,
Expand Down Expand Up @@ -251,6 +258,9 @@ def DoUnarySuffixOp(s, op, arg):
else:
return s

else:
raise NotImplementedError("Can't use %s with pattern" % op.op_id)


def _AllMatchPositions(s, regex):
"""Returns a list of all (start, end) match positions of the regex against s.
Expand Down
23 changes: 23 additions & 0 deletions spec/var-op-other.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,26 @@ ABC DEF
## N-I dash status: 2
## N-I mksh/zsh status: 1

#### Lower Case with constant string (VERY WEIRD)
x='AAA ABC DEF'
echo ${x,A}
echo ${x,,A} # replaces every A only?
## STDOUT:
aAA ABC DEF
aaa aBC DEF
## END
## N-I dash/mksh/zsh stdout-json: ""
## N-I dash status: 2
## N-I mksh/zsh status: 1

#### Lower Case glob
x='ABC DEF'
echo ${x,[d-f]}
echo ${x,,[d-f]} # This seems buggy, it doesn't include F?
## STDOUT:
ABC DEF
ABC deF
## END
## N-I dash/mksh/zsh stdout-json: ""
## N-I dash status: 2
## N-I mksh/zsh status: 1
2 changes: 1 addition & 1 deletion test/spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ var-op-test() {
}

var-op-other() {
sh-spec spec/var-op-other.test.sh \
sh-spec spec/var-op-other.test.sh --osh-failures-allowed 2 \
${REF_SHELLS[@]} $ZSH $OSH_LIST "$@"
}

Expand Down

0 comments on commit 07752d9

Please sign in to comment.