Add support for !num inside of named capture groups
This commit is contained in:
@@ -581,6 +581,39 @@ func TestNamedCaptureGroups(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamedCaptureGroupsNum(t *testing.T) {
|
||||
content := `<config>
|
||||
<item>
|
||||
<value>100</value>
|
||||
</item>
|
||||
</config>`
|
||||
|
||||
expected := `<config>
|
||||
<item>
|
||||
<value>200</value>
|
||||
</item>
|
||||
</config>`
|
||||
|
||||
p := &RegexProcessor{}
|
||||
result, mods, matches, err := p.ProcessContent(content, `(?s)<value>(?<amount>!num)</value>`, "amount = amount * 2")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error processing content: %v", err)
|
||||
}
|
||||
|
||||
if matches != 1 {
|
||||
t.Errorf("Expected 1 match, got %d", matches)
|
||||
}
|
||||
|
||||
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 TestMultipleNamedCaptureGroups(t *testing.T) {
|
||||
content := `<product>
|
||||
<name>Widget</name>
|
||||
|
Reference in New Issue
Block a user