166 lines
4.4 KiB
Go
166 lines
4.4 KiB
Go
package processor
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"cook/utils"
|
|
)
|
|
|
|
func TestRealAfflictionsXML(t *testing.T) {
|
|
// Read the real Afflictions.xml file
|
|
content, err := os.ReadFile("../testfiles/Afflictions.xml")
|
|
if err != nil {
|
|
t.Fatalf("Failed to read Afflictions.xml: %v", err)
|
|
}
|
|
|
|
original := string(content)
|
|
|
|
// Test 1: Double all maxstrength values using helper functions
|
|
command := utils.ModifyCommand{
|
|
Name: "double_maxstrength",
|
|
Lua: `
|
|
-- Double all maxstrength attributes in Affliction elements
|
|
local afflictions = findElements(root, "Affliction")
|
|
for _, affliction in ipairs(afflictions) do
|
|
modifyNumAttr(affliction, "maxstrength", function(val) return val * 2 end)
|
|
end
|
|
modified = true
|
|
`,
|
|
}
|
|
|
|
commands, err := ProcessXML(original, command, "Afflictions.xml")
|
|
if err != nil {
|
|
t.Fatalf("ProcessXML failed: %v", err)
|
|
}
|
|
|
|
if len(commands) == 0 {
|
|
t.Fatal("Expected modifications but got none")
|
|
}
|
|
|
|
t.Logf("Generated %d surgical modifications", len(commands))
|
|
|
|
// Apply modifications
|
|
result, count := utils.ExecuteModifications(commands, original)
|
|
|
|
t.Logf("Applied %d modifications", count)
|
|
|
|
// Verify specific changes
|
|
if !strings.Contains(result, `maxstrength="20"`) {
|
|
t.Errorf("Expected to find maxstrength=\"20\" (doubled from 10)")
|
|
}
|
|
if !strings.Contains(result, `maxstrength="480"`) {
|
|
t.Errorf("Expected to find maxstrength=\"480\" (doubled from 240)")
|
|
}
|
|
if !strings.Contains(result, `maxstrength="12"`) {
|
|
t.Errorf("Expected to find maxstrength=\"12\" (doubled from 6)")
|
|
}
|
|
|
|
// Verify formatting preserved (XML declaration should be there)
|
|
if !strings.Contains(result, `<?xml`) {
|
|
t.Errorf("XML declaration not preserved")
|
|
}
|
|
|
|
// Count lines to ensure structure preserved
|
|
origLines := len(strings.Split(original, "\n"))
|
|
resultLines := len(strings.Split(result, "\n"))
|
|
if origLines != resultLines {
|
|
t.Errorf("Line count changed: original %d, result %d", origLines, resultLines)
|
|
}
|
|
}
|
|
|
|
func TestRealAfflictionsAttributes(t *testing.T) {
|
|
// Read the real file
|
|
content, err := os.ReadFile("../testfiles/Afflictions.xml")
|
|
if err != nil {
|
|
t.Fatalf("Failed to read Afflictions.xml: %v", err)
|
|
}
|
|
|
|
original := string(content)
|
|
|
|
// Test 2: Modify resistance values using helper functions
|
|
command := utils.ModifyCommand{
|
|
Name: "increase_resistance",
|
|
Lua: `
|
|
-- Increase all minresistance and maxresistance by 50%
|
|
local effects = findElements(root, "Effect")
|
|
for _, effect in ipairs(effects) do
|
|
modifyNumAttr(effect, "minresistance", function(val) return val * 1.5 end)
|
|
modifyNumAttr(effect, "maxresistance", function(val) return val * 1.5 end)
|
|
end
|
|
modified = true
|
|
`,
|
|
}
|
|
|
|
commands, err := ProcessXML(original, command, "Afflictions.xml")
|
|
if err != nil {
|
|
t.Fatalf("ProcessXML failed: %v", err)
|
|
}
|
|
|
|
if len(commands) == 0 {
|
|
t.Fatal("Expected modifications but got none")
|
|
}
|
|
|
|
t.Logf("Generated %d surgical modifications", len(commands))
|
|
|
|
// Apply modifications
|
|
_, count := utils.ExecuteModifications(commands, original)
|
|
|
|
t.Logf("Applied %d modifications", count)
|
|
|
|
// Verify we made resistance modifications
|
|
if count < 10 {
|
|
t.Errorf("Expected at least 10 resistance modifications, got %d", count)
|
|
}
|
|
}
|
|
|
|
func TestRealAfflictionsNestedModifications(t *testing.T) {
|
|
// Read the real file
|
|
content, err := os.ReadFile("../testfiles/Afflictions.xml")
|
|
if err != nil {
|
|
t.Fatalf("Failed to read Afflictions.xml: %v", err)
|
|
}
|
|
|
|
original := string(content)
|
|
|
|
// Test 3: Modify nested Effect attributes using helper functions
|
|
command := utils.ModifyCommand{
|
|
Name: "modify_effects",
|
|
Lua: `
|
|
-- Double all amount values in ReduceAffliction elements
|
|
local reduces = findElements(root, "ReduceAffliction")
|
|
for _, reduce in ipairs(reduces) do
|
|
modifyNumAttr(reduce, "amount", function(val) return val * 2 end)
|
|
end
|
|
modified = true
|
|
`,
|
|
}
|
|
|
|
commands, err := ProcessXML(original, command, "Afflictions.xml")
|
|
if err != nil {
|
|
t.Fatalf("ProcessXML failed: %v", err)
|
|
}
|
|
|
|
if len(commands) == 0 {
|
|
t.Fatal("Expected modifications but got none")
|
|
}
|
|
|
|
t.Logf("Generated %d surgical modifications for nested elements", len(commands))
|
|
|
|
// Apply modifications
|
|
result, count := utils.ExecuteModifications(commands, original)
|
|
|
|
t.Logf("Applied %d modifications", count)
|
|
|
|
// Verify nested changes (0.001 * 2 = 0.002)
|
|
if !strings.Contains(result, `amount="0.002"`) {
|
|
t.Errorf("Expected to find amount=\"0.002\" (0.001 * 2)")
|
|
}
|
|
|
|
// Verify we modified the nested elements
|
|
if count < 8 {
|
|
t.Errorf("Expected at least 8 amount modifications, got %d", count)
|
|
}
|
|
}
|