rootmarkers_test.go 987 B

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