fix(cli): respect stdin override in Scanln
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
905dfae6b1
commit
821f7d191d
2 changed files with 19 additions and 1 deletions
|
|
@ -132,7 +132,7 @@ func Label(word, value string) {
|
||||||
|
|
||||||
// Scanln reads from stdin.
|
// Scanln reads from stdin.
|
||||||
func Scanln(a ...any) (int, error) {
|
func Scanln(a ...any) (int, error) {
|
||||||
return fmt.Scanln(a...)
|
return fmt.Fscanln(newReader(), a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task prints a task header: "[label] message"
|
// Task prints a task header: "[label] message"
|
||||||
|
|
|
||||||
|
|
@ -141,3 +141,21 @@ func TestSection_GlyphTheme(t *testing.T) {
|
||||||
t.Fatalf("expected glyph theme to avoid unicode dashes, got %q", out)
|
t.Fatalf("expected glyph theme to avoid unicode dashes, got %q", out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestScanln_UsesOverrideStdin(t *testing.T) {
|
||||||
|
SetStdin(strings.NewReader("hello\n"))
|
||||||
|
defer SetStdin(nil)
|
||||||
|
|
||||||
|
var got string
|
||||||
|
n, err := Scanln(&got)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Scanln returned error: %v", err)
|
||||||
|
}
|
||||||
|
if n != 1 {
|
||||||
|
t.Fatalf("expected 1 scanned item, got %d", n)
|
||||||
|
}
|
||||||
|
if got != "hello" {
|
||||||
|
t.Fatalf("expected %q, got %q", "hello", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue