Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm committed Jul 21, 2021
1 parent 2ddd1fe commit 0b7cb8f
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions step_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package expandog_test

import (
"os"
"strings"
"testing"

"github.com/cucumber/godog"
"github.com/stretchr/testify/assert"

"github.com/nhatthm/expandog"
)

func TestExpandStep(t *testing.T) {
t.Parallel()

expanders := []interface{}{
// Raw replacer.
strings.NewReplacer("$TO", "Berlin"),
// Our expanders.
expandog.Pairs{
"HUSBAND": "John",
},
func() expandog.Pairs {
return expandog.Pairs{
"WIFE": "Jane",
}
},
func(s string) string {
return strings.ReplaceAll(s, "$FROM", "Paris")
},
expandog.Expander(func(s string) string {
return strings.ReplaceAll(s, "$TRANSPORT", "by bus")
}),
// Os.
expandog.EnvExpander,
}

// Set os env.
assert.NoError(t, os.Setenv("GREETINGS", "Hi Dave"))

defer func() {
_ = os.Unsetenv("GREETINGS") // nolint:errcheck
}()

step := &godog.Step{Text: "$GREETINGS, $HUSBAND & $WIFE are going from $FROM to $TO $TRANSPORT"}
expected := "Hi Dave, John & Jane are going from Paris to Berlin by bus"

expandog.ExpandStep(step, expanders...)

assert.Equal(t, expected, step.Text)
}

0 comments on commit 0b7cb8f

Please sign in to comment.