From 2994bb3b5a3cef5b56854998105c01f89d5df5a2 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 23 Jun 2026 15:51:19 +0000 Subject: [PATCH 1/2] Add tests for edge cases in recursive_sort This commit adds a new `test_recursive_sort_edge_cases` function to `src/utils.rs` to cover multiple edge cases that could occur when sorting JSON arrays. The tests evaluate sorting behavior on: - Arrays containing empty objects - Deeply nested arrays - Primitives mixed with Null values - Objects with integer identification keys - Objects with Null identification keys Co-authored-by: ffalcinelli <1167082+ffalcinelli@users.noreply.github.com> --- src/utils.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/utils.rs b/src/utils.rs index b1c2751..1a58fdd 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -446,4 +446,49 @@ mod tests { }) ); } + + #[test] + fn test_recursive_sort_edge_cases() { + // 1. Array of empty objects + let mut val_empty_objs = serde_json::json!([{}, {}]); + recursive_sort(&mut val_empty_objs); + assert_eq!(val_empty_objs, serde_json::json!([{}, {}])); + + // 2. Array of arrays of arrays + let mut val_deep_arrays = serde_json::json!([[[2, 1]], [[4, 3]]]); + recursive_sort(&mut val_deep_arrays); + assert_eq!(val_deep_arrays, serde_json::json!([[[1, 2]], [[3, 4]]])); + + // 3. Array with Null mixed with primitives + let mut val_mixed_null = serde_json::json!([1, null, "a"]); + recursive_sort(&mut val_mixed_null); + // Does not sort because not all are string/number/boolean + assert_eq!(val_mixed_null, serde_json::json!([1, null, "a"])); + + // 4. Integer sort keys + let mut val_int_keys = serde_json::json!([ + { "id": 2, "val": "b" }, + { "id": 1, "val": "a" }, + { "id": 10, "val": "c" } + ]); + recursive_sort(&mut val_int_keys); + // Sorted by exact string representation of the numbers: "1", "10", "2" + assert_eq!(val_int_keys, serde_json::json!([ + { "id": 1, "val": "a" }, + { "id": 10, "val": "c" }, + { "id": 2, "val": "b" } + ])); + + // 5. Null sort keys + let mut val_null_keys = serde_json::json!([ + { "id": null, "val": "b" }, + { "id": 1, "val": "a" } + ]); + recursive_sort(&mut val_null_keys); + // string representations: "null" vs "1" + assert_eq!(val_null_keys, serde_json::json!([ + { "id": 1, "val": "a" }, + { "id": null, "val": "b" } + ])); + } } From 6b4fb11c4aa0164236bfa68e0c53a07c1e819c52 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 23 Jun 2026 16:11:35 +0000 Subject: [PATCH 2/2] Fix cargo fmt issues in test_recursive_sort_edge_cases Ran `cargo fmt` to properly format the added test case array assertions. Co-authored-by: ffalcinelli <1167082+ffalcinelli@users.noreply.github.com> --- src/utils.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 1a58fdd..f99b578 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -473,11 +473,14 @@ mod tests { ]); recursive_sort(&mut val_int_keys); // Sorted by exact string representation of the numbers: "1", "10", "2" - assert_eq!(val_int_keys, serde_json::json!([ - { "id": 1, "val": "a" }, - { "id": 10, "val": "c" }, - { "id": 2, "val": "b" } - ])); + assert_eq!( + val_int_keys, + serde_json::json!([ + { "id": 1, "val": "a" }, + { "id": 10, "val": "c" }, + { "id": 2, "val": "b" } + ]) + ); // 5. Null sort keys let mut val_null_keys = serde_json::json!([ @@ -486,9 +489,12 @@ mod tests { ]); recursive_sort(&mut val_null_keys); // string representations: "null" vs "1" - assert_eq!(val_null_keys, serde_json::json!([ - { "id": 1, "val": "a" }, - { "id": null, "val": "b" } - ])); + assert_eq!( + val_null_keys, + serde_json::json!([ + { "id": 1, "val": "a" }, + { "id": null, "val": "b" } + ]) + ); } }