From 969ccae25c4a6ce786c0849866cf8811cb399c90 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 22 Aug 2025 10:10:37 +0200 Subject: [PATCH] Use diffs for tests --- processor/surgical_json_test.go | 42 ++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/processor/surgical_json_test.go b/processor/surgical_json_test.go index 5f34425..4ced636 100644 --- a/processor/surgical_json_test.go +++ b/processor/surgical_json_test.go @@ -44,7 +44,7 @@ modified = true expected: `{ "name": "test", "value": 42 -,"newField":"added"}`, // sjson.Set() adds new fields in compact format +,"newField": "added"}`, // sjson.Set() adds new fields in compact format }, { name: "Modify nested field", @@ -94,6 +94,11 @@ modified = true result = result[:cmd.From] + cmd.With + result[cmd.To:] } + diff := cmp.Diff(result, tt.expected) + if diff != "" { + t.Errorf("Differences:\n%s", diff) + } + // Check the actual result matches expected if result != tt.expected { t.Errorf("Expected:\n%s\n\nGot:\n%s", tt.expected, result) @@ -180,6 +185,11 @@ modified = true result = result[:cmd.From] + cmd.With + result[cmd.To:] } + diff := cmp.Diff(result, expected) + if diff != "" { + t.Errorf("Differences:\n%s", diff) + } + // Check that the result matches expected (preserves formatting and changes weight) if result != expected { t.Errorf("Expected:\n%s\n\nGot:\n%s", expected, result) @@ -502,6 +512,11 @@ func TestSurgicalJSONPreservesFormatting2(t *testing.T) { result = result[:cmd.From] + cmd.With + result[cmd.To:] } + diff := cmp.Diff(result, expected) + if diff != "" { + t.Errorf("Differences:\n%s", diff) + } + // Check that the result matches expected (preserves formatting and changes weight) if result != expected { t.Errorf("Expected:\n%s\n\nGot:\n%s", expected, result) @@ -593,7 +608,11 @@ func TestRetardedJSONEditing(t *testing.T) { for _, cmd := range commands { result = result[:cmd.From] + cmd.With + result[cmd.To:] } - + + diff := cmp.Diff(result, expected) + if diff != "" { + t.Errorf("Differences:\n%s", diff) + } // Check that the weight was changed if result != expected { @@ -601,7 +620,6 @@ func TestRetardedJSONEditing(t *testing.T) { } } - func TestRetardedJSONEditing2(t *testing.T) { original := ` { @@ -780,8 +798,7 @@ func TestRetardedJSONEditing2(t *testing.T) { ], "ParentTags": [] } - ,"AdditionalStats": {"(Value=\"BaseDeepMiningDrillSpeed_+%\")":4000}} - } + ,"AdditionalStats": {"(Value=\"BaseDeepMiningDrillSpeed_+%\")":4000}} ] } ` @@ -819,9 +836,12 @@ func TestRetardedJSONEditing2(t *testing.T) { result = result[:cmd.From] + cmd.With + result[cmd.To:] } - - diff := cmp.Diff(result, expected) - if diff != "" { - t.Errorf("Differences:\n%s", diff) - } -} \ No newline at end of file + diff := cmp.Diff(result, expected) + if diff != "" { + t.Errorf("Differences:\n%s", diff) + } + + if result != expected { + t.Errorf("Expected:\n%s\nGot:\n%s", expected, result) + } +}