Rework regex processor to be more betterer

This commit is contained in:
2025-03-24 21:29:03 +01:00
parent 56ac0c7101
commit 583b2169dc
2 changed files with 66 additions and 46 deletions

View File

@@ -181,7 +181,7 @@ func TestArrayNotation(t *testing.T) {
}
}
func TestMultipleMatches(t *testing.T) {
func TestMultipleNumericMatches(t *testing.T) {
content := `<data>
<entry>50</entry>
<entry>100</entry>
@@ -212,19 +212,21 @@ func TestMultipleMatches(t *testing.T) {
if result != expected {
t.Errorf("Expected content to be:\n%s\n\nGot:\n%s", expected, result)
}
}
// Test string operations
content = `<data>
func TestMultipleStringMatches(t *testing.T) {
content := `<data>
<name>John</name>
<name>Mary</name>
</data>`
expected = `<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"`)
p := &RegexProcessor{}
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)
@@ -243,7 +245,7 @@ func TestMultipleMatches(t *testing.T) {
}
}
func TestStringOperations(t *testing.T) {
func TestStringUpperCase(t *testing.T) {
content := `<users>
<user>John</user>
<user>Mary</user>
@@ -273,19 +275,21 @@ func TestStringOperations(t *testing.T) {
if result != expected {
t.Errorf("Expected content to be:\n%s\n\nGot:\n%s", expected, result)
}
}
// Test string concatenation
content = `<products>
func TestStringConcatenation(t *testing.T) {
content := `<products>
<product>Apple</product>
<product>Banana</product>
</products>`
expected = `<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"`)
p := &RegexProcessor{}
result, mods, matches, err := p.ProcessContent(content, `<product>([A-Za-z]+)</product>`, `s1 = s1 .. "_fruit"`)
if err != nil {
t.Fatalf("Error processing content: %v", err)