Use diffs for tests

This commit is contained in:
2025-08-22 10:10:37 +02:00
parent 5b46ff0efd
commit 969ccae25c

View File

@@ -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)
}
}
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)
}
}