| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package command
- import (
- "bytes"
- "testing"
- )
- func TestArgOrStdin(t *testing.T) {
- tests := []struct {
- args []string
- stdin string
- i int
- w string
- we error
- }{
- {
- args: []string{
- "a",
- },
- stdin: "b",
- i: 0,
- w: "a",
- we: nil,
- },
- {
- args: []string{
- "a",
- },
- stdin: "b",
- i: 1,
- w: "b",
- we: nil,
- },
- {
- args: []string{
- "a",
- },
- stdin: "",
- i: 1,
- w: "",
- we: ErrNoAvailSrc,
- },
- }
- for i, tt := range tests {
- var b bytes.Buffer
- b.Write([]byte(tt.stdin))
- g, ge := argOrStdin(tt.args, &b, tt.i)
- if g != tt.w {
- t.Errorf("#%d: expect %v, not %v", i, tt.w, g)
- }
- if ge != tt.we {
- t.Errorf("#%d: expect %v, not %v", i, tt.we, ge)
- }
- }
- }
|