Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
dbd736ae81 |
@@ -83,6 +83,7 @@ const (
|
||||
// The acceptable range is [16, 231] but here we remove some very dark colors
|
||||
// That make text unreadable on a dark terminal
|
||||
// See https://www.hackitu.de/termcolor256/
|
||||
// Wait - why are we hardcoding this? lol do for loops not exist in our universe?
|
||||
var colors = []int{22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 57, 62, 63, 64, 65, 67, 68, 69, 70, 71, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 148, 149, 150, 151, 152, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 184, 185, 186, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 226, 227, 228, 229, 230}
|
||||
var colorsIndex int = -1
|
||||
var shuffled bool
|
||||
|
49
home_test.go
Normal file
49
home_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestHomeDirectoryPatternExpansion(t *testing.T) {
|
||||
testDir := getTestSubDir(t)
|
||||
|
||||
// Ensure we're working within the project directory
|
||||
ensureInProjectDir(t, testDir)
|
||||
|
||||
// Change to test directory
|
||||
originalDir, _ := os.Getwd()
|
||||
defer os.Chdir(originalDir)
|
||||
os.Chdir(testDir)
|
||||
|
||||
// Get the actual home directory
|
||||
homeDir, err := os.UserHomeDir()
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Create a test directory in the home folder
|
||||
testHomeDir := filepath.Join(homeDir, "synclib_test")
|
||||
err = os.MkdirAll(testHomeDir, 0755)
|
||||
assert.NoError(t, err)
|
||||
defer os.RemoveAll(testHomeDir) // Cleanup
|
||||
|
||||
// Create a test file in the home directory
|
||||
testFile := filepath.Join(testHomeDir, "testhome.csv")
|
||||
err = os.WriteFile(testFile, []byte("test content"), 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Test the pattern with ~/ that should match the file
|
||||
pattern := "~/synclib_test/testhome.csv"
|
||||
links, err := ExpandPattern(pattern, testDir, "target.csv")
|
||||
|
||||
// This should work but currently fails due to the bug
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 1, len(links), "Pattern should match exactly 1 file")
|
||||
|
||||
if len(links) > 0 {
|
||||
assert.Contains(t, links[0].Source, "testhome.csv")
|
||||
assert.Equal(t, "target.csv", links[0].Target)
|
||||
}
|
||||
}
|
@@ -356,8 +356,14 @@ func loadFromReference(fromFile, currentFile, workdir string, visited map[string
|
||||
|
||||
// expandGlobs expands glob patterns in a single instruction
|
||||
func expandGlobs(instr LinkInstruction, filename, workdir string) ([]LinkInstruction, error) {
|
||||
LogSource("Expanding pattern source %s in YAML file %s", instr.Source, filename)
|
||||
newlinks, err := ExpandPattern(instr.Source, workdir, instr.Target)
|
||||
// Convert home directory (~) before expanding pattern
|
||||
convertedSource, err := ConvertHome(instr.Source)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting home directory in source %s: %w", instr.Source, err)
|
||||
}
|
||||
|
||||
LogSource("Expanding pattern source %s in YAML file %s", convertedSource, filename)
|
||||
newlinks, err := ExpandPattern(convertedSource, workdir, instr.Target)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -434,6 +440,11 @@ func parseYAMLFileRecursive(filename, workdir string, visited map[string]bool) (
|
||||
}
|
||||
|
||||
func ExpandPattern(source, workdir, target string) (links []LinkInstruction, err error) {
|
||||
// Convert home directory (~) before splitting pattern
|
||||
source, err = ConvertHome(source)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting home directory in source %s: %w", source, err)
|
||||
}
|
||||
static, pattern := doublestar.SplitPattern(source)
|
||||
if static == "" || static == "." {
|
||||
static = workdir
|
||||
|
Reference in New Issue
Block a user