--------------------------------------------------------------------------- Non-TTY fallback tests ---------------------------------------------------------------------------
(t *testing.T)
| 740 | // --------------------------------------------------------------------------- |
| 741 | |
| 742 | func 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 | |
| 773 | func TestPromptNonInteractiveSelect_ByValue(t *testing.T) { |
| 774 | opts := []struct{ label, value string }{ |
nothing calls this directly
no test coverage detected