1package lsp
2
3import (
4 "os"
5 "path/filepath"
6 "testing"
7
8 "github.com/stretchr/testify/require"
9)
10
11func TestHasRootMarkers(t *testing.T) {
12 t.Parallel()
13
14 // Create a temporary directory for testing
15 tmpDir := t.TempDir()
16
17 // Test with empty root markers (should return true)
18 require.True(t, HasRootMarkers(tmpDir, []string{}))
19
20 // Test with non-existent markers
21 require.False(t, HasRootMarkers(tmpDir, []string{"go.mod", "package.json"}))
22
23 // Create a go.mod file
24 goModPath := filepath.Join(tmpDir, "go.mod")
25 err := os.WriteFile(goModPath, []byte("module test"), 0o644)
26 require.NoError(t, err)
27
28 // Test with existing marker
29 require.True(t, HasRootMarkers(tmpDir, []string{"go.mod", "package.json"}))
30
31 // Test with only non-existent markers
32 require.False(t, HasRootMarkers(tmpDir, []string{"package.json", "Cargo.toml"}))
33
34 // Test with glob patterns
35 require.True(t, HasRootMarkers(tmpDir, []string{"*.mod"}))
36 require.False(t, HasRootMarkers(tmpDir, []string{"*.json"}))
37}