Created
September 3, 2016 13:53
-
-
Save kana-sama/7238c5b3608a91bee48c014b8557e5da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package prompter_test | |
import ( | |
"fmt" | |
"reflect" | |
"testing" | |
"github.com/the-varlog/with/prompter" | |
) | |
type command int | |
const ( | |
push = iota | |
pull | |
) | |
type patch struct { | |
cmd command | |
args []string | |
out []string | |
} | |
var pushAndPullTests = struct { | |
initial []string | |
patches []patch | |
}{ | |
initial: []string{"first", "second"}, | |
patches: []patch{ | |
{cmd: push, args: []string{"third", "fourth"}, out: []string{"first", "second", "third", "fourth"}}, | |
{cmd: pull, out: []string{"first", "second", "third"}}, | |
{cmd: pull, out: []string{"first", "second"}}, | |
{cmd: push, args: []string{"fifth"}, out: []string{"first", "second", "fifth"}}, | |
{cmd: pull, out: []string{"first", "second"}}, | |
{cmd: pull, out: []string{"first"}}, | |
{cmd: pull, out: []string{}}, | |
{cmd: pull, out: []string{}}, | |
}, | |
} | |
func TestPushAndPull(t *testing.T) { | |
pr := prompter.New(pushAndPullTests.initial) | |
for _, patch := range pushAndPullTests.patches { | |
var method string | |
oldTokens := pr.Tokens() | |
switch patch.cmd { | |
case pull: | |
pr.Pull() | |
method = "Pull()" | |
case push: | |
pr.Push(patch.args) | |
method = fmt.Sprintf("Push(%v)", patch.args) | |
} | |
newTokens := pr.Tokens() | |
if !reflect.DeepEqual(newTokens, patch.out) { | |
t.Fatalf("prompter(%v).%s.Tokens() => %v, want %v", oldTokens, method, newTokens, patch.out) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment