@@ -113,6 +113,58 @@ func TestJetbrainsCommand_DetectJetBrainsIDEs(t *testing.T) {
113113 }
114114}
115115
116+ func TestJetbrainsCommand_DetectJetBrainsIDEs_WithXDGConfigHome (t * testing.T ) {
117+ if runtime .GOOS != "linux" {
118+ // For testing purposes, we can't change runtime.GOOS, so skip on non-Linux
119+ t .Skip ("XDG_CONFIG_HOME test is only fully testable on Linux" )
120+ }
121+
122+ // Create temporary directory for XDG_CONFIG_HOME
123+ tempDir := t .TempDir ()
124+ xdgConfigHome := filepath .Join (tempDir , "config" )
125+
126+ // Create mock JetBrains configuration directory structure
127+ jetbrainsDir := filepath .Join (xdgConfigHome , "JetBrains" )
128+ ideaDir := filepath .Join (jetbrainsDir , "IntelliJIdea2023.3" )
129+ err := os .MkdirAll (ideaDir , 0755 )
130+ require .NoError (t , err )
131+
132+ // Create mock idea.properties file
133+ propertiesPath := filepath .Join (ideaDir , "idea.properties" )
134+ err = os .WriteFile (propertiesPath , []byte ("# Test properties\n " ), 0644 )
135+ require .NoError (t , err )
136+
137+ // Set XDG_CONFIG_HOME environment variable
138+ originalXDG := os .Getenv ("XDG_CONFIG_HOME" )
139+ defer func () {
140+ if originalXDG != "" {
141+ if err := os .Setenv ("XDG_CONFIG_HOME" , originalXDG ); err != nil {
142+ t .Logf ("Warning: failed to restore XDG_CONFIG_HOME: %v" , err )
143+ }
144+ } else {
145+ if err := os .Unsetenv ("XDG_CONFIG_HOME" ); err != nil {
146+ t .Logf ("Warning: failed to unset XDG_CONFIG_HOME: %v" , err )
147+ }
148+ }
149+ }()
150+ err = os .Setenv ("XDG_CONFIG_HOME" , xdgConfigHome )
151+ require .NoError (t , err )
152+
153+ // Test detection
154+ cmd := NewJetbrainsCommand ("" , "" )
155+ err = cmd .detectJetBrainsIDEs ()
156+ assert .NoError (t , err , "Detection should succeed when XDG_CONFIG_HOME is set" )
157+ assert .Len (t , cmd .detectedIDEs , 1 , "Should detect one IDE" )
158+
159+ if len (cmd .detectedIDEs ) > 0 {
160+ ide := cmd .detectedIDEs [0 ]
161+ assert .Equal (t , "IntelliJ IDEA" , ide .Name )
162+ assert .Equal (t , "2023.3" , ide .Version )
163+ assert .Equal (t , propertiesPath , ide .PropertiesPath )
164+ assert .Equal (t , ideaDir , ide .ConfigDir )
165+ }
166+ }
167+
116168func TestJetbrainsCommand_CreateBackup (t * testing.T ) {
117169 // Create temporary idea.properties file
118170 tempDir := t .TempDir ()
0 commit comments