Improve error handling across the board
This commit is contained in:
@@ -93,6 +93,7 @@ func TestEvaluator(t *testing.T) {
|
||||
name string
|
||||
path string
|
||||
expected []JSONNode
|
||||
error bool
|
||||
}{
|
||||
{
|
||||
name: "simple_property_access",
|
||||
@@ -146,18 +147,26 @@ func TestEvaluator(t *testing.T) {
|
||||
name: "invalid_index",
|
||||
path: "$.store.book[5]",
|
||||
expected: []JSONNode{},
|
||||
error: true,
|
||||
},
|
||||
{
|
||||
name: "nonexistent_property",
|
||||
path: "$.store.nonexistent",
|
||||
expected: []JSONNode{},
|
||||
error: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Use GetWithPaths directly
|
||||
result := Get(testData, tt.path)
|
||||
result, err := Get(testData, tt.path)
|
||||
if err != nil {
|
||||
if !tt.error {
|
||||
t.Errorf("Get() returned error: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Special handling for wildcard recursive test
|
||||
if tt.name == "wildcard_recursive" {
|
||||
@@ -201,7 +210,11 @@ func TestEvaluator(t *testing.T) {
|
||||
|
||||
func TestEdgeCases(t *testing.T) {
|
||||
t.Run("empty_data", func(t *testing.T) {
|
||||
result := Get(nil, "$.a.b")
|
||||
result, err := Get(nil, "$.a.b")
|
||||
if err == nil {
|
||||
t.Errorf("Expected error for empty data")
|
||||
return
|
||||
}
|
||||
if len(result) > 0 {
|
||||
t.Errorf("Expected empty result, got %v", result)
|
||||
}
|
||||
@@ -218,7 +231,11 @@ func TestEdgeCases(t *testing.T) {
|
||||
data := map[string]interface{}{
|
||||
"42": "answer",
|
||||
}
|
||||
result := Get(data, "$.42")
|
||||
result, err := Get(data, "$.42")
|
||||
if err != nil {
|
||||
t.Errorf("Get() returned error: %v", err)
|
||||
return
|
||||
}
|
||||
if len(result) == 0 || result[0].Value != "answer" {
|
||||
t.Errorf("Expected 'answer', got %v", result)
|
||||
}
|
||||
@@ -266,7 +283,11 @@ func TestGetWithPaths(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := Get(testData, tt.path)
|
||||
result, err := Get(testData, tt.path)
|
||||
if err != nil {
|
||||
t.Errorf("Get() returned error: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if lengths match
|
||||
if len(result) != len(tt.expected) {
|
||||
|
Reference in New Issue
Block a user