返回 DeepSeek-Reasonix
open_workspace_windows_test.go
根目录 / desktop / open_workspace_windows_test.go
1 //go:build windows
2
3 package main
4
5 import (
6 "errors"
7 "os"
8 "path/filepath"
9 "testing"
10 )
11
12 func TestShellOpenCommandFolder(t *testing.T) {
13 dir := t.TempDir()
14 verb, target := shellOpenCommand(dir, true)
15 if verb != "explore" {
16 t.Fatalf("shellOpenCommand(folder %q) verb = %q, want explore", dir, verb)
17 }
18 if target != dir+string(os.PathSeparator) {
19 t.Fatalf("shellOpenCommand(folder %q) target = %q, want trailing separator", dir, target)
20 }
21 }
22
23 func TestShellOpenCommandFile(t *testing.T) {
24 file := filepath.Join(t.TempDir(), "notes.md")
25 if err := os.WriteFile(file, []byte("x"), 0o644); err != nil {
26 t.Fatal(err)
27 }
28 verb, target := shellOpenCommand(file, false)
29 if verb != "open" || target != file {
30 t.Fatalf("shellOpenCommand(file) = (%q, %q), want (open, %q)", verb, target, file)
31 }
32 }
33
34 func TestOpenWorkspacePathMissingPath(t *testing.T) {
35 missing := filepath.Join(t.TempDir(), "missing")
36 if err := openWorkspacePath(missing); !errors.Is(err, os.ErrNotExist) {
37 t.Fatalf("openWorkspacePath(missing) error = %v, want os.ErrNotExist", err)
38 }
39 }
40
41 func TestShellOpenCommandFolderWithTrailingSeparator(t *testing.T) {
42 dir := t.TempDir() + string(os.PathSeparator)
43 verb, target := shellOpenCommand(dir, true)
44 if verb != "explore" || target != dir {
45 t.Fatalf("shellOpenCommand(folder with separator) = (%q, %q), want (explore, %q)", verb, target, dir)
46 }
47 }
48
49 func TestShellOpenCommandFolderWithSiblingLnk(t *testing.T) {
50 // The reported regression: a folder whose base name also exists as a .lnk
51 // shortcut must open in Explorer, not launch the shortcut's target.
52 dir := t.TempDir()
53 folder := filepath.Join(dir, "app")
54 if err := os.Mkdir(folder, 0o755); err != nil {
55 t.Fatal(err)
56 }
57 if err := os.WriteFile(filepath.Join(dir, "app.lnk"), []byte("shortcut"), 0o644); err != nil {
58 t.Fatal(err)
59 }
60 verb, target := shellOpenCommand(folder, true)
61 if verb != "explore" {
62 t.Fatalf("shellOpenCommand(folder with sibling .lnk %q) verb = %q, want explore", folder, verb)
63 }
64 if target != folder+string(os.PathSeparator) {
65 t.Fatalf("shellOpenCommand(folder with sibling .lnk %q) target = %q, want trailing separator", folder, target)
66 }
67 }
68
68 lines GO