Skip to content

Commit 9569779

Browse files
Copilotkv9898
andauthored
Add test for BackendState format_options reflecting R option changes (#1)
* Initial plan * Add test for format_options state change after R option modification Co-authored-by: kv9898 <105025148+kv9898@users.noreply.github.com> * Improve error handling in test_format_options_state_change Co-authored-by: kv9898 <105025148+kv9898@users.noreply.github.com> * Remove unnecessary move keyword in closure Co-authored-by: kv9898 <105025148+kv9898@users.noreply.github.com>
1 parent 35f1c6a commit 9569779

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

crates/ark/tests/data_explorer.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,3 +3108,63 @@ fn test_single_row_data_frame_column_profiles() {
31083108
});
31093109
}
31103110
}
3111+
3112+
#[test]
3113+
fn test_format_options_state_change() {
3114+
let _lock = r_test_lock();
3115+
3116+
// Save the current R options so we can restore them later
3117+
let (original_scipen, original_digits) = r_task(|| {
3118+
let scipen_obj = harp::parse_eval_global("getOption('scipen')").expect("Failed to get scipen option");
3119+
let digits_obj = harp::parse_eval_global("getOption('digits')").expect("Failed to get digits option");
3120+
let scipen: i64 = scipen_obj.try_into().unwrap_or(0);
3121+
let digits: i64 = digits_obj.try_into().unwrap_or(7);
3122+
(scipen, digits)
3123+
});
3124+
3125+
// Set known R options for testing
3126+
r_task(|| {
3127+
harp::parse_eval_global("options(scipen = 0, digits = 7)").unwrap();
3128+
});
3129+
3130+
// Open a data explorer with mtcars
3131+
let setup = TestSetup::new("mtcars");
3132+
let socket = setup.socket();
3133+
3134+
// Get the initial state and verify format_options
3135+
TestAssertions::assert_state(&socket, |state| {
3136+
let format_options = state.format_options.as_ref().expect("format_options should be present");
3137+
3138+
// With scipen=0, digits=7:
3139+
// max_integral_digits = (0 + 5).max(1) = 5
3140+
// large_num_digits = (7 - 5).max(0) = 2
3141+
// small_num_digits = (0 + 6).max(1) = 6
3142+
assert_eq!(format_options.max_integral_digits, 5);
3143+
assert_eq!(format_options.large_num_digits, 2);
3144+
assert_eq!(format_options.small_num_digits, 6);
3145+
});
3146+
3147+
// Change R options to different values
3148+
r_task(|| {
3149+
harp::parse_eval_global("options(scipen = 10, digits = 10)").unwrap();
3150+
});
3151+
3152+
// Get the state again and verify format_options changed
3153+
TestAssertions::assert_state(&socket, |state| {
3154+
let format_options = state.format_options.as_ref().expect("format_options should be present");
3155+
3156+
// With scipen=10, digits=10:
3157+
// max_integral_digits = (10 + 5).max(1) = 15
3158+
// large_num_digits = (10 - 5).max(0) = 5
3159+
// small_num_digits = (10 + 6).max(1) = 16
3160+
assert_eq!(format_options.max_integral_digits, 15);
3161+
assert_eq!(format_options.large_num_digits, 5);
3162+
assert_eq!(format_options.small_num_digits, 16);
3163+
});
3164+
3165+
// Restore original R options
3166+
r_task(|| {
3167+
let restore_cmd = format!("options(scipen = {}, digits = {})", original_scipen, original_digits);
3168+
harp::parse_eval_global(&restore_cmd).expect("Failed to restore original R options");
3169+
});
3170+
}

0 commit comments

Comments
 (0)