Implement Set and SetAll (and Get)

This commit is contained in:
2025-03-25 15:32:45 +01:00
parent 08d5d707d0
commit 2b8d86ca87
3 changed files with 671 additions and 115 deletions

View File

@@ -158,12 +158,7 @@ func TestEvaluator(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
steps, err := ParseJSONPath(tt.path)
if err != nil {
t.Fatalf("Parse error: %v", err)
}
result := EvaluateJSONPath(testData, steps)
result := Get(testData, tt.path)
// Special handling for wildcard recursive test
if tt.name == "wildcard_recursive" {
@@ -187,18 +182,13 @@ func TestEvaluator(t *testing.T) {
t.Errorf("Expected %v, got %v", tt.expected, resultItem)
}
}
// if !reflect.DeepEqual(result, tt.expected) {
// t.Errorf("EvaluateJSONPath() = %v, want %v", result, tt.expected)
// }
})
}
}
func TestEdgeCases(t *testing.T) {
t.Run("empty_data", func(t *testing.T) {
steps, _ := ParseJSONPath("$.a.b")
result := EvaluateJSONPath(nil, steps)
result := Get(nil, "$.a.b")
if len(result) > 0 {
t.Errorf("Expected empty result, got %v", result)
}
@@ -215,9 +205,8 @@ func TestEdgeCases(t *testing.T) {
data := map[string]interface{}{
"42": "answer",
}
steps, _ := ParseJSONPath("$.42")
result := EvaluateJSONPath(data, steps)
if result[0] != "answer" {
result := Get(data, "$.42")
if len(result) == 0 || result[0] != "answer" {
t.Errorf("Expected 'answer', got %v", result)
}
})