MCPcopy Create free account
hub / github.com/github/gh-aw / TestPromptNonInteractiveSelect_ByNumber

Function TestPromptNonInteractiveSelect_ByNumber

pkg/cli/interactive_test.go:742–771  ·  view source on GitHub ↗

--------------------------------------------------------------------------- Non-TTY fallback tests ---------------------------------------------------------------------------

(t *testing.T)

Source from the content-addressed store, hash-verified

740// ---------------------------------------------------------------------------
741
742func TestPromptNonInteractiveSelect_ByNumber(t *testing.T) {
743 opts := []struct{ label, value string }{
744 {"Option A", "a"},
745 {"Option B", "b"},
746 {"Option C", "c"},
747 }
748
749 for _, tt := range []struct {
750 input string
751 wantVal string
752 wantErr bool
753 }{
754 {"1", "a", false},
755 {"2", "b", false},
756 {"3", "c", false},
757 {"0", "", true},
758 {"4", "", true},
759 } {
760 t.Run("input="+tt.input, func(t *testing.T) {
761 scanner := newScannerFromString(tt.input)
762 got, err := promptNonInteractiveSelect(scanner, "Pick one", opts)
763 if (err != nil) != tt.wantErr {
764 t.Fatalf("promptNonInteractiveSelect(%q) error=%v, wantErr=%v", tt.input, err, tt.wantErr)
765 }
766 if err == nil && got != tt.wantVal {
767 t.Errorf("promptNonInteractiveSelect(%q) = %q, want %q", tt.input, got, tt.wantVal)
768 }
769 })
770 }
771}
772
773func TestPromptNonInteractiveSelect_ByValue(t *testing.T) {
774 opts := []struct{ label, value string }{

Callers

nothing calls this directly

Calls 4

newScannerFromStringFunction · 0.85
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected