Skip to content

Commit

Permalink
Merge pull request #13 from liamg/master
Browse files Browse the repository at this point in the history
fixed placeholder replacement
  • Loading branch information
dtaniwaki committed Aug 4, 2016
2 parents 806e72e + 3692d6c commit 3b84c6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/scripts/alias.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ loadArgumentsInAction = (args, action) ->

for val, i in argItems
if action.indexOf('$'+(i+1)) > -1 then action = action.replace('$'+(i+1), val) else action += " #{val}"

action = action.replace(/\$\d+/g, "")
action.trim()

Expand All @@ -34,7 +35,7 @@ module.exports = (robot) ->
sp = RegExp.$2
action = RegExp.$3

if action && action != 'alias'
if action && action.indexOf('alias') != 0
rest = ''
for k in Object.keys(table).sort().reverse()
v = table[k]
Expand Down
5 changes: 5 additions & 0 deletions test/alias_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe 'alias', ->

sharedExample = (done, src, dst)->
adapter.on "send", (envelope, strings)->
return if strings[0].indexOf('I made an alias') == 0
try
expect(strings).to.have.length(1)
expect(strings[0]).to.equal dst
Expand Down Expand Up @@ -90,6 +91,10 @@ describe 'alias', ->
it 'appends unused string', (done)->
sharedExample done, 'hubot params john hello hey', 'goo --name=john --message=hello hey'

context 'with placeholders in an alias action', ->
it 'does not replace placeholders', (done)->
sharedExample done, 'hubot alias command=something=$1 other=$2', 'alias command=something=$1 other=$2'

context 'with reverse order placeholders', ->
it 'replaces alias string', (done)->
sharedExample done, 'hubot reverse_params john hello hey', 'goo --name=hey --message=john hello'
Expand Down

0 comments on commit 3b84c6b

Please sign in to comment.