Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit 1767332

Browse files
committed
Use expect-test for GitDiff test assertions
- Replace manual JSON structure assertions with expect-test - Provides detailed verification of complete FileChange structure - Shows exact diff content including hunks and line changes - More maintainable and comprehensive test validation - Automatically updates when data structure changes
1 parent 224403f commit 1767332

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

server/src/ide/test.rs

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -577,14 +577,52 @@ async fn test_gitdiff_function() {
577577
assert!(result.is_ok());
578578
let changes = result.unwrap();
579579

580-
// Should be an array with one file change (src/main.rs)
581-
if let serde_json::Value::Array(arr) = changes {
582-
assert_eq!(arr.len(), 1);
583-
if let serde_json::Value::Object(file_change) = &arr[0] {
584-
assert_eq!(file_change.get("path").unwrap(), "src/main.rs");
585-
assert_eq!(file_change.get("status").unwrap(), "Modified");
586-
}
587-
} else {
588-
panic!("Expected array of file changes");
589-
}
580+
// Verify the structure using expect-test
581+
use expect_test::expect;
582+
expect![[r#"
583+
Array [
584+
Object {
585+
"additions": Number(1),
586+
"deletions": Number(1),
587+
"hunks": Array [
588+
Object {
589+
"header": String("@@ -1,3 +1,3 @@"),
590+
"lines": Array [
591+
Object {
592+
"content": String("fn main() {"),
593+
"line_type": String("Context"),
594+
"new_line_number": Number(1),
595+
"old_line_number": Number(1),
596+
},
597+
Object {
598+
"content": String(" println!(\"Hello\");"),
599+
"line_type": String("Removed"),
600+
"new_line_number": Null,
601+
"old_line_number": Number(2),
602+
},
603+
Object {
604+
"content": String(" println!(\"Hello, World!\");"),
605+
"line_type": String("Added"),
606+
"new_line_number": Number(2),
607+
"old_line_number": Null,
608+
},
609+
Object {
610+
"content": String("}"),
611+
"line_type": String("Context"),
612+
"new_line_number": Number(3),
613+
"old_line_number": Number(3),
614+
},
615+
],
616+
"new_lines": Number(3),
617+
"new_start": Number(1),
618+
"old_lines": Number(3),
619+
"old_start": Number(1),
620+
},
621+
],
622+
"path": String("src/main.rs"),
623+
"status": String("Modified"),
624+
},
625+
]
626+
"#]]
627+
.assert_debug_eq(&changes);
590628
}

0 commit comments

Comments
 (0)