Fix some more minor bugs and tests

This commit is contained in:
2025-03-25 19:14:21 +01:00
parent 4640281fbf
commit 4eed05c7c2
2 changed files with 66 additions and 59 deletions

View File

@@ -1007,7 +1007,13 @@ func TestJSONProcessor_FilteringArrayElements(t *testing.T) {
}`
expected := `{
"numbers": [2, 4, 6, 8, 10]
"numbers": [
2,
4,
6,
8,
10
]
}`
p := &JSONProcessor{}
@@ -1051,9 +1057,13 @@ func TestJSONProcessor_RootNodeModification(t *testing.T) {
}`
expected := `{
"name": "modified",
"description": "This is a completely modified root",
"values": [1, 2, 3]
"name": "modified",
"values": [
1,
2,
3
]
}`
p := &JSONProcessor{}
@@ -1086,39 +1096,3 @@ func TestJSONProcessor_RootNodeModification(t *testing.T) {
t.Errorf("Expected content to be:\n%s\n\nGot:\n%s", expected, result)
}
}
// TestJSONProcessor_RootNodeModificationToPrimitive tests modifying the root node to a primitive value
func TestJSONProcessor_RootNodeModificationToPrimitive(t *testing.T) {
content := `{
"name": "original",
"value": 100
}`
expected := `42`
p := &JSONProcessor{}
result, modCount, matchCount, err := p.ProcessContent(content, "$", `
-- Replace the root node with a primitive value
v = 42
`)
if err != nil {
t.Fatalf("Error processing content: %v", err)
}
if matchCount != 1 {
t.Errorf("Expected 1 match, got %d", matchCount)
}
if modCount != 1 {
t.Errorf("Expected 1 modification, got %d", modCount)
}
// Normalize whitespace for comparison
normalizedResult := normalizeWhitespace(result)
normalizedExpected := normalizeWhitespace(expected)
if normalizedResult != normalizedExpected {
t.Errorf("Expected content to be:\n%s\n\nGot:\n%s", expected, result)
}
}