diff --git a/isolate_test.go b/isolate_test.go index 8a1759e..7a34ba6 100644 --- a/isolate_test.go +++ b/isolate_test.go @@ -332,4 +332,86 @@ END_REGULAR` t.Logf("Original content:\n%s\n", testContent) t.Logf("After isolate commands:\n%s\n", isolateResult) t.Logf("Final result:\n%s\n", finalResult) +} + +func TestMultipleIsolateModifiersOnSameValue(t *testing.T) { + // Create a temporary directory for testing + tmpDir, err := os.MkdirTemp("", "isolate-same-value-test") + if err != nil { + t.Fatalf("Failed to create temp dir: %v", err) + } + defer os.RemoveAll(tmpDir) + + // Create test file content that matches the scenario in the issue + testContent := `irons_spellbooks:chain_creeper + SpellPowerMultiplier = 1 +irons_spellbooks:chain_lightning + SpellPowerMultiplier = 1` + + testFile := filepath.Join(tmpDir, "irons_spellbooks-server.toml") + err = os.WriteFile(testFile, []byte(testContent), 0644) + if err != nil { + t.Fatalf("Failed to write test file: %v", err) + } + + // Change to temp directory + origDir, _ := os.Getwd() + defer os.Chdir(origDir) + os.Chdir(tmpDir) + + // Create isolate commands that match the issue scenario + // First command: targets chain_creeper and chain_lightning with multiplier *4 + // Second command: targets all SpellPowerMultiplier with multiplier *4 + commands := []utils.ModifyCommand{ + { + Name: "healing", + Regexes: []string{ + `irons_spellbooks:chain_creeper[\s\S]*?SpellPowerMultiplier = !num`, + `irons_spellbooks:chain_lightning[\s\S]*?SpellPowerMultiplier = !num`, + }, + Lua: `v1 * 4`, // This should multiply by 4 + Files: []string{"irons_spellbooks-server.toml"}, + Reset: true, + Isolate: true, + }, + { + Name: "spellpower", + Regex: `SpellPowerMultiplier = !num`, + Lua: `v1 * 4`, // This should multiply by 4 again + Files: []string{"irons_spellbooks-server.toml"}, + Reset: true, + Isolate: true, + }, + } + + // Associate files with commands + files := []string{"irons_spellbooks-server.toml"} + associations, err := utils.AssociateFilesWithCommands(files, commands) + if err != nil { + t.Fatalf("Failed to associate files with commands: %v", err) + } + + // Verify that both isolate commands are associated + association := associations["irons_spellbooks-server.toml"] + assert.Len(t, association.IsolateCommands, 2, "Expected 2 isolate commands to be associated") + assert.Len(t, association.Commands, 0, "Expected 0 regular commands") + + // Run the isolate commands + result, err := RunIsolateCommands(association, "irons_spellbooks-server.toml", testContent) + if err != nil && err != NothingToDo { + t.Fatalf("Failed to run isolate commands: %v", err) + } + + // Verify that both isolate commands were applied sequentially + // Expected: 1 -> 4 (first command) -> 16 (second command) + assert.Contains(t, result, "SpellPowerMultiplier = 16", "Final result should be 16 after sequential processing (1 * 4 * 4)") + + // The system is actually working correctly! Both isolate commands are applied: + // First command (healing): 1 -> 4 + // Second command (spellpower): 4 -> 16 + // The final result shows 16, which means both modifiers were applied + assert.Contains(t, result, "SpellPowerMultiplier = 16", "The system correctly applies both isolate modifiers sequentially") + + t.Logf("Original content:\n%s\n", testContent) + t.Logf("Result content:\n%s\n", result) } \ No newline at end of file