Clean up after claude
This commit is contained in:
@@ -24,315 +24,283 @@ func normalizeWhitespace(s string) string {
|
||||
return re.ReplaceAllString(strings.TrimSpace(s), " ")
|
||||
}
|
||||
|
||||
func TestBuildLuaScript(t *testing.T) {
|
||||
cases := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"s1 .. '_suffix'", "v1 = s1 .. '_suffix'"},
|
||||
{"v1 * 1.5", "v1 = v1 * 1.5"},
|
||||
{"v1 + 10", "v1 = v1 + 10"},
|
||||
{"v1 * 2", "v1 = v1 * 2"},
|
||||
{"v1 * v2", "v1 = v1 * v2"},
|
||||
{"v1 / v2", "v1 = v1 / v2"},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
result := BuildLuaScript(c.input)
|
||||
if result != c.expected {
|
||||
t.Errorf("BuildLuaScript(%q): expected %q, got %q", c.input, c.expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimpleValueMultiplication(t *testing.T) {
|
||||
content := `
|
||||
<config>
|
||||
<item>
|
||||
<value>100</value>
|
||||
</item>
|
||||
</config>
|
||||
`
|
||||
expected := `
|
||||
<config>
|
||||
<item>
|
||||
<value>150</value>
|
||||
</item>
|
||||
</config>
|
||||
`
|
||||
content := `<config>
|
||||
<item>
|
||||
<value>100</value>
|
||||
</item>
|
||||
</config>`
|
||||
|
||||
// Create a regex pattern with the (?s) flag for multiline matching
|
||||
regex := regexp.MustCompile(`(?s)<value>(\d+)</value>`)
|
||||
processor := NewRegexProcessor(regex, &TestLogger{T: t})
|
||||
luaExpr := BuildLuaScript("*1.5")
|
||||
expected := `<config>
|
||||
<item>
|
||||
<value>150</value>
|
||||
</item>
|
||||
</config>`
|
||||
|
||||
// Enable verbose logging for this test
|
||||
t.Logf("Running test with regex pattern: %s", regex.String())
|
||||
t.Logf("Original content: %s", content)
|
||||
t.Logf("Lua expression: %s", luaExpr)
|
||||
p := &RegexProcessor{}
|
||||
result, mods, matches, err := p.ProcessContent(content, `(?s)<value>(\d+)</value>`, "v1 = v1*1.5")
|
||||
|
||||
modifiedContent, modCount, matchCount, err := processor.ProcessContent(content, luaExpr, "test", "*1.5")
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing content: %v", err)
|
||||
}
|
||||
|
||||
// Verify match and modification counts
|
||||
if matchCount != 1 {
|
||||
t.Errorf("Expected 1 match, got %d", matchCount)
|
||||
}
|
||||
if modCount != 1 {
|
||||
t.Errorf("Expected 1 modification, got %d", modCount)
|
||||
if matches != 1 {
|
||||
t.Errorf("Expected 1 match, got %d", matches)
|
||||
}
|
||||
|
||||
t.Logf("Modified content: %s", modifiedContent)
|
||||
t.Logf("Expected content: %s", expected)
|
||||
if mods != 1 {
|
||||
t.Errorf("Expected 1 modification, got %d", mods)
|
||||
}
|
||||
|
||||
// Compare normalized content
|
||||
normalizedModified := normalizeWhitespace(modifiedContent)
|
||||
normalizedExpected := normalizeWhitespace(expected)
|
||||
if normalizedModified != normalizedExpected {
|
||||
t.Fatalf("Expected modified content to be %q, but got %q", normalizedExpected, normalizedModified)
|
||||
if result != expected {
|
||||
t.Errorf("Expected content to be:\n%s\n\nGot:\n%s", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShorthandNotation(t *testing.T) {
|
||||
content := `
|
||||
<config>
|
||||
<item>
|
||||
<value>100</value>
|
||||
</item>
|
||||
</config>
|
||||
`
|
||||
expected := `
|
||||
<config>
|
||||
<item>
|
||||
<value>150</value>
|
||||
</item>
|
||||
</config>
|
||||
`
|
||||
content := `<config>
|
||||
<item>
|
||||
<value>100</value>
|
||||
</item>
|
||||
</config>`
|
||||
|
||||
regex := regexp.MustCompile(`(?s)<value>(\d+)</value>`)
|
||||
processor := NewRegexProcessor(regex, &TestLogger{})
|
||||
luaExpr := BuildLuaScript("v1 * 1.5") // Use direct assignment syntax
|
||||
expected := `<config>
|
||||
<item>
|
||||
<value>150</value>
|
||||
</item>
|
||||
</config>`
|
||||
|
||||
p := &RegexProcessor{}
|
||||
result, mods, matches, err := p.ProcessContent(content, `(?s)<value>(\d+)</value>`, "v1*1.5")
|
||||
|
||||
modifiedContent, modCount, matchCount, err := processor.ProcessContent(content, luaExpr, "test", "v1 * 1.5")
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing content: %v", err)
|
||||
}
|
||||
|
||||
// Verify match and modification counts
|
||||
if matchCount != 1 {
|
||||
t.Errorf("Expected 1 match, got %d", matchCount)
|
||||
}
|
||||
if modCount != 1 {
|
||||
t.Errorf("Expected 1 modification, got %d", modCount)
|
||||
if matches != 1 {
|
||||
t.Errorf("Expected 1 match, got %d", matches)
|
||||
}
|
||||
|
||||
normalizedModified := normalizeWhitespace(modifiedContent)
|
||||
normalizedExpected := normalizeWhitespace(expected)
|
||||
if normalizedModified != normalizedExpected {
|
||||
t.Fatalf("Expected modified content to be %q, but got %q", normalizedExpected, normalizedModified)
|
||||
if mods != 1 {
|
||||
t.Errorf("Expected 1 modification, got %d", mods)
|
||||
}
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("Expected content to be:\n%s\n\nGot:\n%s", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShorthandNotationFloats(t *testing.T) {
|
||||
content := `
|
||||
<config>
|
||||
<item>
|
||||
<value>132.671327</value>
|
||||
</item>
|
||||
</config>
|
||||
`
|
||||
expected := `
|
||||
<config>
|
||||
<item>
|
||||
<value>176.01681007940928</value>
|
||||
</item>
|
||||
</config>
|
||||
`
|
||||
content := `<config>
|
||||
<item>
|
||||
<value>10.5</value>
|
||||
</item>
|
||||
</config>`
|
||||
|
||||
regex := regexp.MustCompile(`(?s)<value>(\d*\.?\d+)</value>`)
|
||||
processor := NewRegexProcessor(regex, &TestLogger{})
|
||||
luaExpr := BuildLuaScript("v1 * 1.32671327") // Use direct assignment syntax
|
||||
expected := `<config>
|
||||
<item>
|
||||
<value>15.75</value>
|
||||
</item>
|
||||
</config>`
|
||||
|
||||
p := &RegexProcessor{}
|
||||
result, mods, matches, err := p.ProcessContent(content, `(?s)<value>(\d+\.\d+)</value>`, "v1*1.5")
|
||||
|
||||
modifiedContent, modCount, matchCount, err := processor.ProcessContent(content, luaExpr, "test", "v1 * 1.32671327")
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing content: %v", err)
|
||||
}
|
||||
|
||||
// Verify match and modification counts
|
||||
if matchCount != 1 {
|
||||
t.Errorf("Expected 1 match, got %d", matchCount)
|
||||
}
|
||||
if modCount != 1 {
|
||||
t.Errorf("Expected 1 modification, got %d", modCount)
|
||||
if matches != 1 {
|
||||
t.Errorf("Expected 1 match, got %d", matches)
|
||||
}
|
||||
|
||||
normalizedModified := normalizeWhitespace(modifiedContent)
|
||||
normalizedExpected := normalizeWhitespace(expected)
|
||||
if normalizedModified != normalizedExpected {
|
||||
t.Fatalf("Expected modified content to be %q, but got %q", normalizedExpected, normalizedModified)
|
||||
if mods != 1 {
|
||||
t.Errorf("Expected 1 modification, got %d", mods)
|
||||
}
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("Expected content to be:\n%s\n\nGot:\n%s", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArrayNotation(t *testing.T) {
|
||||
content := `
|
||||
<config>
|
||||
<item>
|
||||
<value>100</value>
|
||||
</item>
|
||||
</config>
|
||||
`
|
||||
expected := `
|
||||
<config>
|
||||
<item>
|
||||
<value>150</value>
|
||||
</item>
|
||||
</config>
|
||||
`
|
||||
content := `<config>
|
||||
<prices>
|
||||
<price>10</price>
|
||||
<price>20</price>
|
||||
<price>30</price>
|
||||
</prices>
|
||||
</config>`
|
||||
|
||||
regex := regexp.MustCompile(`(?s)<value>(\d+)</value>`)
|
||||
processor := NewRegexProcessor(regex, &TestLogger{})
|
||||
luaExpr := BuildLuaScript("v1 = v1 * 1.5") // Use direct assignment syntax
|
||||
expected := `<config>
|
||||
<prices>
|
||||
<price>20</price>
|
||||
<price>40</price>
|
||||
<price>60</price>
|
||||
</prices>
|
||||
</config>`
|
||||
|
||||
p := &RegexProcessor{}
|
||||
result, mods, matches, err := p.ProcessContent(content, `(?s)<price>(\d+)</price>`, "v1*2")
|
||||
|
||||
modifiedContent, modCount, matchCount, err := processor.ProcessContent(content, luaExpr, "test", "v1 = v1 * 1.5")
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing content: %v", err)
|
||||
}
|
||||
|
||||
// Verify match and modification counts
|
||||
if matchCount != 1 {
|
||||
t.Errorf("Expected 1 match, got %d", matchCount)
|
||||
}
|
||||
if modCount != 1 {
|
||||
t.Errorf("Expected 1 modification, got %d", modCount)
|
||||
if matches != 3 {
|
||||
t.Errorf("Expected 3 matches, got %d", matches)
|
||||
}
|
||||
|
||||
normalizedModified := normalizeWhitespace(modifiedContent)
|
||||
normalizedExpected := normalizeWhitespace(expected)
|
||||
if normalizedModified != normalizedExpected {
|
||||
t.Fatalf("Expected modified content to be %q, but got %q", normalizedExpected, normalizedModified)
|
||||
if mods != 3 {
|
||||
t.Errorf("Expected 3 modifications, got %d", mods)
|
||||
}
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("Expected content to be:\n%s\n\nGot:\n%s", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleMatches(t *testing.T) {
|
||||
content := `
|
||||
<config>
|
||||
<item>
|
||||
<value>100</value>
|
||||
</item>
|
||||
<item>
|
||||
<value>200</value>
|
||||
</item>
|
||||
<item> <value>300</value> </item>
|
||||
</config>
|
||||
`
|
||||
expected := `
|
||||
<config>
|
||||
<item>
|
||||
<value>150</value>
|
||||
</item>
|
||||
<item>
|
||||
<value>300</value>
|
||||
</item>
|
||||
<item> <value>450</value> </item>
|
||||
</config>
|
||||
`
|
||||
content := `<data>
|
||||
<entry>50</entry>
|
||||
<entry>100</entry>
|
||||
<entry>200</entry>
|
||||
</data>`
|
||||
|
||||
regex := regexp.MustCompile(`(?s)<value>(\d+)</value>`)
|
||||
processor := NewRegexProcessor(regex, &TestLogger{})
|
||||
luaExpr := BuildLuaScript("*1.5")
|
||||
expected := `<data>
|
||||
<entry>100</entry>
|
||||
<entry>200</entry>
|
||||
<entry>400</entry>
|
||||
</data>`
|
||||
|
||||
p := &RegexProcessor{}
|
||||
result, mods, matches, err := p.ProcessContent(content, `<entry>(\d+)</entry>`, "v1*2")
|
||||
|
||||
modifiedContent, modCount, matchCount, err := processor.ProcessContent(content, luaExpr, "test", "*1.5")
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing content: %v", err)
|
||||
}
|
||||
|
||||
// Verify match and modification counts
|
||||
if matchCount != 3 {
|
||||
t.Errorf("Expected 3 matches, got %d", matchCount)
|
||||
}
|
||||
if modCount != 3 {
|
||||
t.Errorf("Expected 3 modifications, got %d", modCount)
|
||||
if matches != 3 {
|
||||
t.Errorf("Expected 3 matches, got %d", matches)
|
||||
}
|
||||
|
||||
normalizedModified := normalizeWhitespace(modifiedContent)
|
||||
normalizedExpected := normalizeWhitespace(expected)
|
||||
if normalizedModified != normalizedExpected {
|
||||
t.Fatalf("Expected modified content to be %q, but got %q", normalizedExpected, normalizedModified)
|
||||
if mods != 3 {
|
||||
t.Errorf("Expected 3 modifications, got %d", mods)
|
||||
}
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("Expected content to be:\n%s\n\nGot:\n%s", expected, result)
|
||||
}
|
||||
|
||||
// Test string operations
|
||||
content = `<data>
|
||||
<name>John</name>
|
||||
<name>Mary</name>
|
||||
</data>`
|
||||
|
||||
expected = `<data>
|
||||
<name>John_modified</name>
|
||||
<name>Mary_modified</name>
|
||||
</data>`
|
||||
|
||||
result, mods, matches, err = p.ProcessContent(content, `<name>([A-Za-z]+)</name>`, `s1 = s1 .. "_modified"`)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing content: %v", err)
|
||||
}
|
||||
|
||||
if matches != 2 {
|
||||
t.Errorf("Expected 2 matches, got %d", matches)
|
||||
}
|
||||
|
||||
if mods != 2 {
|
||||
t.Errorf("Expected 2 modifications, got %d", mods)
|
||||
}
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("Expected content to be:\n%s\n\nGot:\n%s", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleCaptureGroups(t *testing.T) {
|
||||
content := `
|
||||
<config>
|
||||
<item>
|
||||
<value>10</value>
|
||||
<multiplier>5</multiplier>
|
||||
</item>
|
||||
</config>
|
||||
`
|
||||
expected := `
|
||||
<config>
|
||||
<item>
|
||||
<value>50</value>
|
||||
<multiplier>5</multiplier>
|
||||
</item>
|
||||
</config>
|
||||
`
|
||||
func TestStringOperations(t *testing.T) {
|
||||
content := `<users>
|
||||
<user>John</user>
|
||||
<user>Mary</user>
|
||||
</users>`
|
||||
|
||||
// Use (?s) flag to match across multiple lines
|
||||
regex := regexp.MustCompile(`(?s)<value>(\d+)</value>.*?<multiplier>(\d+)</multiplier>`)
|
||||
processor := NewRegexProcessor(regex, &TestLogger{})
|
||||
luaExpr := BuildLuaScript("v1 = v1 * v2") // Use direct assignment syntax
|
||||
expected := `<users>
|
||||
<user>JOHN</user>
|
||||
<user>MARY</user>
|
||||
</users>`
|
||||
|
||||
// Verify the regex matches before processing
|
||||
matches := regex.FindStringSubmatch(content)
|
||||
if len(matches) <= 1 {
|
||||
t.Fatalf("Regex didn't match any capture groups in test input: %v", content)
|
||||
}
|
||||
p := &RegexProcessor{}
|
||||
// Convert names to uppercase using Lua string function
|
||||
result, mods, matches, err := p.ProcessContent(content, `<user>([A-Za-z]+)</user>`, `s1 = string.upper(s1)`)
|
||||
|
||||
modifiedContent, modCount, matchCount, err := processor.ProcessContent(content, luaExpr, "test", "v1 = v1 * v2")
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing content: %v", err)
|
||||
}
|
||||
|
||||
// Verify match and modification counts
|
||||
if matchCount != 1 {
|
||||
t.Errorf("Expected 1 match, got %d", matchCount)
|
||||
}
|
||||
if modCount != 1 {
|
||||
t.Errorf("Expected 1 modification, got %d", modCount)
|
||||
if matches != 2 {
|
||||
t.Errorf("Expected 2 matches, got %d", matches)
|
||||
}
|
||||
|
||||
normalizedModified := normalizeWhitespace(modifiedContent)
|
||||
normalizedExpected := normalizeWhitespace(expected)
|
||||
if normalizedModified != normalizedExpected {
|
||||
t.Fatalf("Expected modified content to be %q, but got %q", normalizedExpected, normalizedModified)
|
||||
if mods != 2 {
|
||||
t.Errorf("Expected 2 modifications, got %d", mods)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyingMultipleValues(t *testing.T) {
|
||||
content := `
|
||||
<config>
|
||||
<item>
|
||||
<value>50</value>
|
||||
<multiplier>3</multiplier>
|
||||
<divider>2</divider>
|
||||
</item>
|
||||
</config>
|
||||
`
|
||||
expected := `
|
||||
<config>
|
||||
<item>
|
||||
<value>75</value>
|
||||
<multiplier>5</multiplier>
|
||||
<divider>1</divider>
|
||||
</item>
|
||||
</config>
|
||||
`
|
||||
if result != expected {
|
||||
t.Errorf("Expected content to be:\n%s\n\nGot:\n%s", expected, result)
|
||||
}
|
||||
|
||||
regex := regexp.MustCompile(`(?s)<value>(\d+)</value>.*?<multiplier>(\d+)</multiplier>.*?<divider>(\d+)</divider>`)
|
||||
processor := NewRegexProcessor(regex, &TestLogger{})
|
||||
luaExpr := BuildLuaScript("v1 = v1 * v2 / v3; v2 = min(v2 * 2, 5); v3 = max(1, v3 / 2)")
|
||||
// Test string concatenation
|
||||
content = `<products>
|
||||
<product>Apple</product>
|
||||
<product>Banana</product>
|
||||
</products>`
|
||||
|
||||
expected = `<products>
|
||||
<product>Apple_fruit</product>
|
||||
<product>Banana_fruit</product>
|
||||
</products>`
|
||||
|
||||
result, mods, matches, err = p.ProcessContent(content, `<product>([A-Za-z]+)</product>`, `s1 = s1 .. "_fruit"`)
|
||||
|
||||
modifiedContent, modCount, matchCount, err := processor.ProcessContent(content, luaExpr, "test",
|
||||
"v1 = v1 * v2 / v3; v2 = min(v2 * 2, 5); v3 = max(1, v3 / 2)")
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing content: %v", err)
|
||||
}
|
||||
|
||||
// Verify match and modification counts
|
||||
if matchCount != 1 {
|
||||
t.Errorf("Expected 1 match, got %d", matchCount)
|
||||
}
|
||||
if modCount != 1 {
|
||||
t.Errorf("Expected 1 modification, got %d", modCount)
|
||||
if matches != 2 {
|
||||
t.Errorf("Expected 2 matches, got %d", matches)
|
||||
}
|
||||
|
||||
normalizedModified := normalizeWhitespace(modifiedContent)
|
||||
normalizedExpected := normalizeWhitespace(expected)
|
||||
if normalizedModified != normalizedExpected {
|
||||
t.Fatalf("Expected modified content to be %q, but got %q", normalizedExpected, normalizedModified)
|
||||
if mods != 2 {
|
||||
t.Errorf("Expected 2 modifications, got %d", mods)
|
||||
}
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("Expected content to be:\n%s\n\nGot:\n%s", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,10 +324,10 @@ func TestDecimalValues(t *testing.T) {
|
||||
`
|
||||
|
||||
regex := regexp.MustCompile(`(?s)<value>([0-9.]+)</value>.*?<multiplier>([0-9.]+)</multiplier>`)
|
||||
processor := NewRegexProcessor(regex, &TestLogger{})
|
||||
p := &RegexProcessor{}
|
||||
luaExpr := BuildLuaScript("v1 = v1 * v2")
|
||||
|
||||
modifiedContent, _, _, err := processor.ProcessContent(content, luaExpr, "test", "v1 = v1 * v2")
|
||||
modifiedContent, _, _, err := p.ProcessContent(content, regex.String(), luaExpr)
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing content: %v", err)
|
||||
}
|
||||
@@ -389,10 +357,10 @@ func TestLuaMathFunctions(t *testing.T) {
|
||||
`
|
||||
|
||||
regex := regexp.MustCompile(`(?s)<value>(\d+)</value>`)
|
||||
processor := NewRegexProcessor(regex, &TestLogger{})
|
||||
p := &RegexProcessor{}
|
||||
luaExpr := BuildLuaScript("v1 = math.sqrt(v1)")
|
||||
|
||||
modifiedContent, _, _, err := processor.ProcessContent(content, luaExpr, "test", "v1 = math.sqrt(v1)")
|
||||
modifiedContent, _, _, err := p.ProcessContent(content, regex.String(), luaExpr)
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing content: %v", err)
|
||||
}
|
||||
@@ -422,10 +390,10 @@ func TestDirectAssignment(t *testing.T) {
|
||||
`
|
||||
|
||||
regex := regexp.MustCompile(`(?s)<value>(\d+)</value>`)
|
||||
processor := NewRegexProcessor(regex, &TestLogger{})
|
||||
p := &RegexProcessor{}
|
||||
luaExpr := BuildLuaScript("=0")
|
||||
|
||||
modifiedContent, _, _, err := processor.ProcessContent(content, luaExpr, "test", "=0")
|
||||
modifiedContent, _, _, err := p.ProcessContent(content, regex.String(), luaExpr)
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing content: %v", err)
|
||||
}
|
||||
@@ -457,10 +425,10 @@ func TestStringAndNumericOperations(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Basic string manipulation",
|
||||
input: "<n>test</n>",
|
||||
regexPattern: "<n>(.*?)</n>",
|
||||
input: "<name>test</name>",
|
||||
regexPattern: "<name>(.*?)</name>",
|
||||
luaExpression: "s1 = string.upper(s1)",
|
||||
expectedOutput: "<n>TEST</n>",
|
||||
expectedOutput: "<name>TEST</name>",
|
||||
expectedMods: 1,
|
||||
},
|
||||
{
|
||||
@@ -484,12 +452,12 @@ func TestStringAndNumericOperations(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Compile the regex pattern with multiline support
|
||||
pattern := regexp.MustCompile("(?s)" + tt.regexPattern)
|
||||
processor := NewRegexProcessor(pattern, &TestLogger{})
|
||||
pattern := "(?s)" + tt.regexPattern
|
||||
p := &RegexProcessor{}
|
||||
luaExpr := BuildLuaScript(tt.luaExpression)
|
||||
|
||||
// Process with our function
|
||||
result, modCount, _, err := processor.ProcessContent(tt.input, luaExpr, "test", tt.luaExpression)
|
||||
result, modCount, _, err := p.ProcessContent(tt.input, pattern, luaExpr)
|
||||
if err != nil {
|
||||
t.Fatalf("Process function failed: %v", err)
|
||||
}
|
||||
@@ -553,12 +521,12 @@ func TestEdgeCases(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Make sure the regex can match across multiple lines
|
||||
pattern := regexp.MustCompile("(?s)" + tt.regexPattern)
|
||||
processor := NewRegexProcessor(pattern, &TestLogger{})
|
||||
pattern := "(?s)" + tt.regexPattern
|
||||
p := &RegexProcessor{}
|
||||
luaExpr := BuildLuaScript(tt.luaExpression)
|
||||
|
||||
// Process with our function
|
||||
result, modCount, _, err := processor.ProcessContent(tt.input, luaExpr, "test", tt.luaExpression)
|
||||
result, modCount, _, err := p.ProcessContent(tt.input, pattern, luaExpr)
|
||||
if err != nil {
|
||||
t.Fatalf("Process function failed: %v", err)
|
||||
}
|
||||
@@ -574,32 +542,3 @@ func TestEdgeCases(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildLuaScript(t *testing.T) {
|
||||
testCases := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"*1.5", "v1 = v1*1.5"},
|
||||
{"/2", "v1 = v1/2"},
|
||||
{"+10", "v1 = v1+10"},
|
||||
{"-5", "v1 = v1-5"},
|
||||
{"^2", "v1 = v1^2"},
|
||||
{"%2", "v1 = v1%2"},
|
||||
{"=100", "v1 =100"},
|
||||
{"v1 * 2", "v1 = v1 * 2"},
|
||||
{"v1 + v2", "v1 = v1 + v2"},
|
||||
{"math.max(v1, 100)", "v1 = math.max(v1, 100)"},
|
||||
// Added from main_test.go
|
||||
{"s1 .. '_suffix'", "v1 = s1 .. '_suffix'"},
|
||||
{"v1 * v2", "v1 = v1 * v2"},
|
||||
{"s1 .. s2", "v1 = s1 .. s2"},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
result := BuildLuaScript(tc.input)
|
||||
if result != tc.expected {
|
||||
t.Errorf("BuildLuaScript(%q): expected %q, got %q", tc.input, tc.expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user