Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 0 additions & 120 deletions .opencode/rules/golang-cli.md

This file was deleted.

123 changes: 0 additions & 123 deletions .opencode/rules/golang-unit-testing.md

This file was deleted.

120 changes: 120 additions & 0 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"

"github.com/oussamaM1/treels/module"
)
Expand Down Expand Up @@ -125,6 +126,92 @@ func TestHumanReadableSize(t *testing.T) {
}
}

func TestResolveFileIconStyle(t *testing.T) {
tests := []struct {
name string
fileName string
wantIcon string
wantColor string
}{
{
name: "filename specific icon takes precedence",
fileName: "README.md",
wantIcon: module.ReadmeIcon,
wantColor: module.Cyan,
},
{
name: "known extension is case insensitive",
fileName: "main.GO",
wantIcon: module.GoLangIcon,
wantColor: module.LightBlue,
},
{
name: "multi-part config filename",
fileName: ".eslintrc.json",
wantIcon: module.ESLintIcon,
wantColor: module.Purple,
},
{
name: "unknown extension falls back to file icon",
fileName: "archive.unknown",
wantIcon: module.FileIcon,
wantColor: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := resolveFileIconStyle(tt.fileName)
if got.icon != tt.wantIcon || got.color != tt.wantColor {
t.Fatalf("resolveFileIconStyle(%q) = %+v, want icon %q and color %q", tt.fileName, got, tt.wantIcon, tt.wantColor)
}
})
}
}

func TestResolveFolderIconStyle(t *testing.T) {
tests := []struct {
name string
folderName string
wantIcon string
wantColor string
}{
{
name: "git folder",
folderName: ".git",
wantIcon: module.GitIcon,
wantColor: module.Orange,
},
{
name: "default folder",
folderName: "pkg",
wantIcon: module.FolderIcon,
wantColor: module.Pink,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := resolveFolderIconStyle(tt.folderName)
if got.icon != tt.wantIcon || got.color != tt.wantColor {
t.Fatalf("resolveFolderIconStyle(%q) = %+v, want icon %q and color %q", tt.folderName, got, tt.wantIcon, tt.wantColor)
}
})
}
}

func TestFormatFileWithOptions_HideIcon(t *testing.T) {
file := fakeFileInfo{name: "main.go"}

got := formatFileWithOptions("", file, module.Flags{HideIcon: true})
if strings.Contains(got, module.GoLangIcon) {
t.Fatalf("formatFileWithOptions() = %q, want no file icon", got)
}
if got != "main.go" {
t.Fatalf("formatFileWithOptions() = %q, want plain file name", got)
}
}

func TestReadDirectory_FilePath(t *testing.T) {
path := filepath.Join(t.TempDir(), "regular.txt")
mustWriteFile(t, path, "content")
Expand Down Expand Up @@ -174,3 +261,36 @@ func mustMkdir(t *testing.T, path string) {
t.Fatalf("Mkdir(%q) error = %v", path, err)
}
}

type fakeFileInfo struct {
name string
size int64
isDir bool
}

func (f fakeFileInfo) Name() string {
return f.name
}

func (f fakeFileInfo) Size() int64 {
return f.size
}

func (f fakeFileInfo) Mode() os.FileMode {
if f.isDir {
return os.ModeDir
}
return 0
}

func (f fakeFileInfo) ModTime() time.Time {
return time.Time{}
}

func (f fakeFileInfo) IsDir() bool {
return f.isDir
}

func (f fakeFileInfo) Sys() interface{} {
return nil
}
Loading
Loading