aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/ui/term/cursor_test.go
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
commitdd84b9d64fb98746a230cd24233ff50a562c39c9 (patch)
treeb583261ef00b3afe72ec4d6dacb31e57779a6faf /cli/internal/ui/term/cursor_test.go
parent0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff)
downloadHydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz
HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip
Diffstat (limited to 'cli/internal/ui/term/cursor_test.go')
-rw-r--r--cli/internal/ui/term/cursor_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/cli/internal/ui/term/cursor_test.go b/cli/internal/ui/term/cursor_test.go
new file mode 100644
index 0000000..270ebe8
--- /dev/null
+++ b/cli/internal/ui/term/cursor_test.go
@@ -0,0 +1,43 @@
+//go:build !windows
+// +build !windows
+
+// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+// SPDX-License-Identifier: Apache-2.0
+package cursor
+
+import (
+ "io"
+ "strings"
+ "testing"
+
+ "github.com/AlecAivazis/survey/v2/terminal"
+ "github.com/stretchr/testify/require"
+)
+
+func TestEraseLine(t *testing.T) {
+ testCases := map[string]struct {
+ inWriter func(writer io.Writer) terminal.FileWriter
+ shouldErase bool
+ }{
+ "should erase a line if the writer is a file": {
+ inWriter: func(writer io.Writer) terminal.FileWriter {
+ return &fakeFileWriter{w: writer}
+ },
+ shouldErase: true,
+ },
+ }
+
+ for name, tc := range testCases {
+ t.Run(name, func(t *testing.T) {
+ // GIVEN
+ buf := new(strings.Builder)
+
+ // WHEN
+ EraseLine(tc.inWriter(buf))
+
+ // THEN
+ isErased := buf.String() != ""
+ require.Equal(t, tc.shouldErase, isErased)
+ })
+ }
+}