Cross-Platform Crucible (#2)
Crucible groundwork for cross-platform compatibility. Reviewed-on: #2 Reviewed-by: xtul <mpiasecki720@protonmail.com> Co-authored-by: vickydotbat <vickydotbat@tutamail.com> Co-committed-by: vickydotbat <vickydotbat@tutamail.com>
This commit was merged in pull request #2.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package menu
|
||||
|
||||
import (
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var sample = []Item{
|
||||
{Label: "module build", Desc: "build the .mod", Args: []string{"module", "build"}},
|
||||
{Label: "topdata validate-topdata", Desc: "validate topdata", Args: []string{"topdata", "validate-topdata"}},
|
||||
}
|
||||
|
||||
func TestSelectReturnsChosenArgs(t *testing.T) {
|
||||
got, err := Select(io.Discard, strings.NewReader("1\n\n"), sample)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if want := []string{"module", "build"}; !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("got %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectAppendsExtraArgs(t *testing.T) {
|
||||
got, err := Select(io.Discard, strings.NewReader("2\n--dry-run foo\n"), sample)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
want := []string{"topdata", "validate-topdata", "--dry-run", "foo"}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("got %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectQuitReturnsNil(t *testing.T) {
|
||||
got, err := Select(io.Discard, strings.NewReader("q\n"), sample)
|
||||
if err != nil || got != nil {
|
||||
t.Fatalf("quit should return (nil,nil); got (%v,%v)", got, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectInvalidErrors(t *testing.T) {
|
||||
if _, err := Select(io.Discard, strings.NewReader("99\n"), sample); err == nil {
|
||||
t.Fatal("out-of-range selection should error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user