Skip to content

Commit

Permalink
Add tests for OnExit function for interactive printers
Browse files Browse the repository at this point in the history
  • Loading branch information
lammel committed May 15, 2023
1 parent e9bb62c commit 7a928e2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions interactive_confirm_printer_test.go
@@ -1,6 +1,7 @@
package pterm_test

import (
"reflect"
"testing"

"atomicgo.dev/keyboard"
Expand Down Expand Up @@ -126,3 +127,14 @@ func TestInteractiveConfirmPrinter_WithTextStyle(t *testing.T) {
p := pterm.DefaultInteractiveConfirm.WithTextStyle(style)
testza.AssertEqual(t, p.TextStyle, style)
}

func TestInteractiveConfirmPrinter_OnExit(t *testing.T) {
// OnExit function defaults to nil
pd := pterm.InteractiveConfirmPrinter{}
testza.AssertNil(t, pd.OnExitFunc)

// Verify OnExit is set
exitfunc := func() {}
p := pterm.DefaultInteractiveConfirm.OnExit(exitfunc)
testza.AssertEqual(t, reflect.ValueOf(p.OnExitFunc).Pointer(), reflect.ValueOf(exitfunc).Pointer())
}
12 changes: 12 additions & 0 deletions interactive_multiselect_printer_test.go
@@ -1,6 +1,7 @@
package pterm_test

import (
"reflect"
"testing"

"atomicgo.dev/keyboard"
Expand Down Expand Up @@ -66,3 +67,14 @@ func TestInteractiveMultiselectPrinter_WithCheckmark(t *testing.T) {
p := pterm.DefaultInteractiveMultiselect.WithCheckmark(&pterm.Checkmark{Checked: "+", Unchecked: "-"}).WithOptions([]string{"a", "b", "c"})
testza.AssertEqual(t, p.Checkmark, &pterm.Checkmark{Checked: "+", Unchecked: "-"})
}

func TestInteractiveMultiselectPrinter_OnExit(t *testing.T) {
// OnExit function defaults to nil
pd := pterm.InteractiveMultiselectPrinter{}
testza.AssertNil(t, pd.OnExitFunc)

// Verify OnExit is set
exitfunc := func() {}
p := pterm.DefaultInteractiveMultiselect.OnExit(exitfunc)
testza.AssertEqual(t, reflect.ValueOf(p.OnExitFunc).Pointer(), reflect.ValueOf(exitfunc).Pointer())
}
12 changes: 12 additions & 0 deletions interactive_select_printer_test.go
@@ -1,6 +1,7 @@
package pterm_test

import (
"reflect"
"testing"

"atomicgo.dev/keyboard"
Expand Down Expand Up @@ -49,3 +50,14 @@ func TestInteractiveSelectPrinter_WithMaxHeight(t *testing.T) {
p := pterm.DefaultInteractiveSelect.WithMaxHeight(1337)
testza.AssertEqual(t, p.MaxHeight, 1337)
}

func TestInteractiveSelectPrinter_OnExit(t *testing.T) {
// OnExit function defaults to nil
pd := pterm.InteractiveSelectPrinter{}
testza.AssertNil(t, pd.OnExitFunc)

// Verify OnExit is set
exitfunc := func() {}
p := pterm.DefaultInteractiveSelect.OnExit(exitfunc)
testza.AssertEqual(t, reflect.ValueOf(p.OnExitFunc).Pointer(), reflect.ValueOf(exitfunc).Pointer())
}
12 changes: 12 additions & 0 deletions interactive_textinput_printer_test.go
@@ -1,6 +1,7 @@
package pterm_test

import (
"reflect"
"testing"

"atomicgo.dev/keyboard"
Expand Down Expand Up @@ -41,3 +42,14 @@ func TestInteractiveTextInputPrinter_WithMask(t *testing.T) {
result, _ := pterm.DefaultInteractiveTextInput.WithMask("*").Show()
testza.AssertEqual(t, result, "abc")
}

func TestInteractiveTextInputPrinter_OnExit(t *testing.T) {
// OnExit function defaults to nil
pd := pterm.InteractiveTextInputPrinter{}
testza.AssertNil(t, pd.OnExitFunc)

// Verify OnExit is set
exitfunc := func() {}
p := pterm.DefaultInteractiveTextInput.OnExit(exitfunc)
testza.AssertEqual(t, reflect.ValueOf(p.OnExitFunc).Pointer(), reflect.ValueOf(exitfunc).Pointer())
}

0 comments on commit 7a928e2

Please sign in to comment.