Skip to content

Commit

Permalink
feature added remaining text for positional args
Browse files Browse the repository at this point in the history
  • Loading branch information
ericjaystevens committed Aug 22, 2020
1 parent 5f81c69 commit 0f06415
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
38 changes: 33 additions & 5 deletions slashparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func getSimpleDef() []byte {
var SimpleDef = getSimpleDef()
var lotsOfArgsDef, _ = ioutil.ReadFile("./examples/helloWorld/lotsofargs.yaml")
var simpleDef2, _ = ioutil.ReadFile("./testData/simple2.yaml")
var doroDef, _ = ioutil.ReadFile("./testData/doro.yaml")

func TestNewSlashCommand(t *testing.T) {
tests := []newSlashCommandTests{
Expand Down Expand Up @@ -499,13 +500,40 @@ func TestGetSlashHelp(t *testing.T) {
assert.Equal(t, firstLine, "#### /Print Help")
}

type argumentTypesTests struct {
name string
commandString string
want string
argName string
slashDef []byte
}

func TestArgumentTypes(t *testing.T) {

newSlash, _ := NewSlashCommand(simpleDef2)
commandString := "/print reverse bunch of wisdom"
tests := []argumentTypesTests{
{
name: "single arg remaining text",
commandString: "/print reverse bunch of wisdom",
argName: "text",
want: "bunch of wisdom",
slashDef: simpleDef2,
},
{
name: "text arg then remaining text arg",
commandString: "/doro start 45 getting after it",
argName: "log",
want: "getting after it",
slashDef: doroDef,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {

got, _ := newSlash.getValues(commandString)
want := "bunch of wisdom"
newSlash, _ := NewSlashCommand(test.slashDef)
got, _ := newSlash.getValues(test.commandString)

assert.Equal(t, test.want, got[test.argName])
})

assert.Equal(t, want, got["text"])
}
}
18 changes: 18 additions & 0 deletions testData/doro.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: doro
description: Echos back what you type.
subcommands:
- name: start
description: start a pomodoro work session
arguments:
- name: time
argtype: text
description: how long your session should last
required: false
default: 25
position: 0
- name: log
argtype: remaining text
description: Actionable description of what you will be working on
required: false
position: 1

0 comments on commit 0f06415

Please sign in to comment.