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:
@@ -15,16 +15,26 @@ pub fn new_empty_model() -> Model {
|
||||
fn test_values() {
|
||||
let mut model = new_empty_model();
|
||||
// numbers
|
||||
model.set_user_input(0, 1, 1, "123.456".to_string());
|
||||
model
|
||||
.set_user_input(0, 1, 1, "123.456".to_string())
|
||||
.unwrap();
|
||||
// strings
|
||||
model.set_user_input(0, 2, 1, "Hello world!".to_string());
|
||||
model.set_user_input(0, 3, 1, "Hello world!".to_string());
|
||||
model.set_user_input(0, 4, 1, "你好世界!".to_string());
|
||||
model
|
||||
.set_user_input(0, 2, 1, "Hello world!".to_string())
|
||||
.unwrap();
|
||||
model
|
||||
.set_user_input(0, 3, 1, "Hello world!".to_string())
|
||||
.unwrap();
|
||||
model
|
||||
.set_user_input(0, 4, 1, "你好世界!".to_string())
|
||||
.unwrap();
|
||||
// booleans
|
||||
model.set_user_input(0, 5, 1, "TRUE".to_string());
|
||||
model.set_user_input(0, 6, 1, "FALSE".to_string());
|
||||
model.set_user_input(0, 5, 1, "TRUE".to_string()).unwrap();
|
||||
model.set_user_input(0, 6, 1, "FALSE".to_string()).unwrap();
|
||||
// errors
|
||||
model.set_user_input(0, 7, 1, "#VALUE!".to_string());
|
||||
model
|
||||
.set_user_input(0, 7, 1, "#VALUE!".to_string())
|
||||
.unwrap();
|
||||
|
||||
// noop
|
||||
model.evaluate();
|
||||
@@ -81,14 +91,16 @@ fn test_values() {
|
||||
#[test]
|
||||
fn test_formulas() {
|
||||
let mut model = new_empty_model();
|
||||
model.set_user_input(0, 1, 1, "5.5".to_string());
|
||||
model.set_user_input(0, 2, 1, "6.5".to_string());
|
||||
model.set_user_input(0, 3, 1, "7.5".to_string());
|
||||
model.set_user_input(0, 1, 1, "5.5".to_string()).unwrap();
|
||||
model.set_user_input(0, 2, 1, "6.5".to_string()).unwrap();
|
||||
model.set_user_input(0, 3, 1, "7.5".to_string()).unwrap();
|
||||
|
||||
model.set_user_input(0, 1, 2, "=A1*2".to_string());
|
||||
model.set_user_input(0, 2, 2, "=A2*2".to_string());
|
||||
model.set_user_input(0, 3, 2, "=A3*2".to_string());
|
||||
model.set_user_input(0, 4, 2, "=SUM(A1:B3)".to_string());
|
||||
model.set_user_input(0, 1, 2, "=A1*2".to_string()).unwrap();
|
||||
model.set_user_input(0, 2, 2, "=A2*2".to_string()).unwrap();
|
||||
model.set_user_input(0, 3, 2, "=A3*2".to_string()).unwrap();
|
||||
model
|
||||
.set_user_input(0, 4, 2, "=SUM(A1:B3)".to_string())
|
||||
.unwrap();
|
||||
|
||||
model.evaluate();
|
||||
let temp_file_name = "temp_file_test_formulas.xlsx";
|
||||
@@ -127,12 +139,12 @@ fn test_sheets() {
|
||||
#[test]
|
||||
fn test_named_styles() {
|
||||
let mut model = new_empty_model();
|
||||
model.set_user_input(0, 1, 1, "5.5".to_string());
|
||||
let mut style = model.get_style_for_cell(0, 1, 1);
|
||||
model.set_user_input(0, 1, 1, "5.5".to_string()).unwrap();
|
||||
let mut style = model.get_style_for_cell(0, 1, 1).unwrap();
|
||||
style.font.b = true;
|
||||
style.font.i = true;
|
||||
assert!(model.set_cell_style(0, 1, 1, &style).is_ok());
|
||||
let bold_style_index = model.get_cell_style_index(0, 1, 1);
|
||||
let bold_style_index = model.get_cell_style_index(0, 1, 1).unwrap();
|
||||
let e = model
|
||||
.workbook
|
||||
.styles
|
||||
|
||||
Reference in New Issue
Block a user