Files
IronCalc/base/src/test/test_sheet_markup.rs
Varun Hegde 2b03b3e3b9 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 )
2024-09-14 17:37:31 +02:00

28 lines
803 B
Rust

#![allow(clippy::unwrap_used)]
use crate::test::util::new_empty_model;
#[test]
fn test_sheet_markup() {
let mut model = new_empty_model();
model._set("A1", "Item");
model._set("B1", "Cost");
model._set("A2", "Rent");
model._set("B2", "$600");
model._set("A3", "Electricity");
model._set("B3", "$200");
model._set("A4", "Total");
model._set("B4", "=SUM(B2:B3)");
let mut style = model.get_style_for_cell(0, 1, 1).unwrap();
style.font.b = true;
model.set_cell_style(0, 1, 1, &style).unwrap();
model.set_cell_style(0, 1, 2, &style).unwrap();
model.set_cell_style(0, 4, 1, &style).unwrap();
assert_eq!(
model.get_sheet_markup(0),
Ok("**Item**|**Cost**\nRent|$600\nElectricity|$200\n**Total**|=SUM(B2:B3)".to_string()),
)
}