From b44737421a1f4af094218c3c07c594d0dce67476 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Wed, 28 Jul 2021 14:49:37 +0100 Subject: [PATCH] Test improvements. --- file_test.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/file_test.go b/file_test.go index 0e5d28d..25f565c 100644 --- a/file_test.go +++ b/file_test.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "path/filepath" "testing" "time" @@ -44,7 +45,6 @@ func ExampleSelectFileSave() { {"Web files", []string{"*.html", "*.js", "*.css"}}, {"Image files", []string{"*.png", "*.gif", "*.ico", "*.jpg", "*.webp"}}, }) - // Output: } func ExampleSelectFile_directory() { @@ -202,3 +202,30 @@ func TestSelectFileMutiple_script(t *testing.T) { } }) } + +func TestSelectFileSave_script(t *testing.T) { + t.Run("Cancel", func(t *testing.T) { + zenity.Info(fmt.Sprintf("In the file save dialog, cancel.")) + str, err := zenity.SelectFileSave() + if skip, err := skip(err); skip { + t.Skip("skipping:", err) + } + if str != "" || err != zenity.ErrCanceled { + t.Errorf("SelectFileSave() = %q, %v; want %q, %v", str, err, "", zenity.ErrCanceled) + } + }) + t.Run("Name", func(t *testing.T) { + zenity.Info(fmt.Sprintf("In the file save dialog, press OK.")) + str, err := zenity.SelectFileSave( + zenity.ConfirmOverwrite(), + zenity.Filename("Χρτο.go"), + zenity.FileFilter{"Go files", []string{"*.go"}}, + ) + if skip, err := skip(err); skip { + t.Skip("skipping:", err) + } + if _, name := filepath.Split(str); name != "Χρτο.go" || err != nil { + t.Errorf("SelectFileSave() = %q, %v; want %q, nil", str, err, "Χρτο.go") + } + }) +}