57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package clipboard
|
|
|
|
import (
|
|
"net/url"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestFormatClipboardContent(t *testing.T) {
|
|
for _, test := range []struct {
|
|
name string
|
|
snapshot Snapshot
|
|
want string
|
|
}{
|
|
{"empty", Snapshot{}, "The clipboard is empty"},
|
|
{"text", Snapshot{HasText: true, Text: "hello"}, "Text in clipboard hello"},
|
|
{"empty text", Snapshot{HasText: true}, "Text in clipboard "},
|
|
{"image overrides text", Snapshot{HasText: true, Text: "hello", Image: true}, "The clipboard contains a image"},
|
|
} {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
if got := Format(test.snapshot); got != test.want {
|
|
t.Fatalf("got %q, want %q", got, test.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFormatURIObjects(t *testing.T) {
|
|
root := t.TempDir()
|
|
folder := filepath.Join(root, "a folder")
|
|
file := filepath.Join(root, "a file")
|
|
link := filepath.Join(root, "link")
|
|
if err := os.Mkdir(folder, 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(file, []byte("x"), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Symlink(file, link); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
uri := func(localPath string) string { return (&url.URL{Scheme: "file", Path: localPath}).String() }
|
|
snapshot := Snapshot{URIs: []string{uri(folder), uri(file), uri(link)}}
|
|
want := "3 Objects in clipboard a folder Folder a file File link File Link"
|
|
if got := Format(snapshot); got != want {
|
|
t.Fatalf("got %q, want %q", got, want)
|
|
}
|
|
if got := Format(Snapshot{URIs: []string{"", uri(file)}}); got != "1 Object in clipboard a file File" {
|
|
t.Fatalf("single URI = %q", got)
|
|
}
|
|
}
|