Error Handling of public Set functions (#88)
What are we trying to achieve ? ++ Currently all the major public set functions is panic prone and does not handle and return error. This PR tries to address to all those functions. What major errors that could happen in these functions ? ++ All the functions which are being made as error safe is being tested against invalid sheet, row and column values, which could given by user What are the list of functions whose return type has been altered ? **base/src/model.rs** 1. update_cell_with_text 2. update_cell_with_bool 3. update_cell_with_number 4. set_user_input 5. get_cell_style_index 6. get_style_for_cell 7. set_cell_with_string ++> New functions being added 1. set_cell_with_boolean 2. set_cell_with_number **base/src/styles.rs** 1. get_style_with_quote_prefix 3. get_style_with_format 4. get_style_without_quote_prefix 5. get_style **base/src/worksheet.rs** 1. update_cell 2. set_cell_style 3. set_cell_with_formula 4. set_cell_with_number 6. set_cell_with_string 8. set_cell_with_boolean 9. set_cell_with_error 10. cell_clear_contents 11. cell_clear_contents_with_style ++> Above is the comprehensive list of all functions being ( most are public, some are private ) altered for better error handling. As a side effect of changing function signature, there are many changes being done to other functions ( mostly adding "?" to enable to error propagation further )
This commit is contained in:
@@ -138,14 +138,14 @@ fn test_insert_sheet() {
|
||||
|
||||
// Insert the sheet at the end and check the formula
|
||||
assert!(model.insert_sheet("Bacchus", 1, None).is_ok());
|
||||
model.set_user_input(1, 3, 1, "42".to_string());
|
||||
model.set_user_input(1, 3, 1, "42".to_string()).unwrap();
|
||||
model.evaluate();
|
||||
assert_eq!(model._get_text("A1"), "42");
|
||||
assert_eq!(model._get_text("A2"), "#REF!");
|
||||
|
||||
// Insert a sheet in between the other two
|
||||
assert!(model.insert_sheet("Dionysus", 1, None).is_ok());
|
||||
model.set_user_input(1, 3, 1, "111".to_string());
|
||||
model.set_user_input(1, 3, 1, "111".to_string()).unwrap();
|
||||
model.evaluate();
|
||||
assert_eq!(model._get_text("A1"), "42");
|
||||
assert_eq!(model._get_text("A2"), "111");
|
||||
@@ -176,7 +176,7 @@ fn test_rename_sheet() {
|
||||
let mut model = new_empty_model();
|
||||
model.new_sheet();
|
||||
model._set("A1", "=NewSheet!A3");
|
||||
model.set_user_input(1, 3, 1, "25".to_string());
|
||||
model.set_user_input(1, 3, 1, "25".to_string()).unwrap();
|
||||
model.evaluate();
|
||||
assert_eq!(model._get_text("A1"), "#REF!");
|
||||
assert!(model.rename_sheet("Sheet2", "NewSheet").is_ok());
|
||||
@@ -189,7 +189,7 @@ fn test_rename_sheet_by_index() {
|
||||
let mut model = new_empty_model();
|
||||
model.new_sheet();
|
||||
model._set("A1", "=NewSheet!A1");
|
||||
model.set_user_input(1, 1, 1, "25".to_string());
|
||||
model.set_user_input(1, 1, 1, "25".to_string()).unwrap();
|
||||
model.evaluate();
|
||||
assert_eq!(model._get_text("A1"), "#REF!");
|
||||
assert!(model.rename_sheet_by_index(1, "NewSheet").is_ok());
|
||||
|
||||
Reference in New Issue
Block a user