FIX: Fix a bug were a new column style would introduce an invalid format
This commit is contained in:
committed by
Nicolás Hatcher Andrés
parent
1e8441a674
commit
a10d1f4615
@@ -15,6 +15,7 @@ mod test_on_area_selection;
|
|||||||
mod test_on_expand_selected_range;
|
mod test_on_expand_selected_range;
|
||||||
mod test_on_paste_styles;
|
mod test_on_paste_styles;
|
||||||
mod test_paste_csv;
|
mod test_paste_csv;
|
||||||
|
mod test_recursive;
|
||||||
mod test_rename_sheet;
|
mod test_rename_sheet;
|
||||||
mod test_row_column;
|
mod test_row_column;
|
||||||
mod test_sheet_state;
|
mod test_sheet_state;
|
||||||
|
|||||||
42
base/src/test/user_model/test_recursive.rs
Normal file
42
base/src/test/user_model/test_recursive.rs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#![allow(clippy::unwrap_used)]
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
constants::LAST_ROW, expressions::types::Area, test::util::new_empty_model, UserModel,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn two_columns() {
|
||||||
|
let model = new_empty_model();
|
||||||
|
let mut model = UserModel::from_model(model);
|
||||||
|
|
||||||
|
// Set style in column C (column 3)
|
||||||
|
let column_c_range = Area {
|
||||||
|
sheet: 0,
|
||||||
|
row: 1,
|
||||||
|
column: 3,
|
||||||
|
width: 1,
|
||||||
|
height: LAST_ROW,
|
||||||
|
};
|
||||||
|
model
|
||||||
|
.update_range_style(&column_c_range, "fill.bg_color", "#333444")
|
||||||
|
.unwrap();
|
||||||
|
model.set_user_input(0, 5, 3, "2").unwrap();
|
||||||
|
|
||||||
|
// Set Style in column G (column 7)
|
||||||
|
let column_g_range = Area {
|
||||||
|
sheet: 0,
|
||||||
|
row: 1,
|
||||||
|
column: 7,
|
||||||
|
width: 1,
|
||||||
|
height: LAST_ROW,
|
||||||
|
};
|
||||||
|
|
||||||
|
model
|
||||||
|
.update_range_style(&column_g_range, "fill.bg_color", "#333444")
|
||||||
|
.unwrap();
|
||||||
|
model.set_user_input(0, 5, 6, "42").unwrap();
|
||||||
|
// Set formula in G5: =F5*C5
|
||||||
|
model.set_user_input(0, 5, 7, "=F5*C5").unwrap();
|
||||||
|
|
||||||
|
assert_eq!(model.get_formatted_cell_value(0, 5, 7).unwrap(), "84");
|
||||||
|
}
|
||||||
@@ -312,7 +312,7 @@ impl Default for Styles {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone, Default)]
|
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct Style {
|
pub struct Style {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub alignment: Option<Alignment>,
|
pub alignment: Option<Alignment>,
|
||||||
@@ -323,6 +323,19 @@ pub struct Style {
|
|||||||
pub quote_prefix: bool,
|
pub quote_prefix: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Style {
|
||||||
|
fn default() -> Self {
|
||||||
|
Style {
|
||||||
|
alignment: None,
|
||||||
|
num_fmt: "general".to_string(),
|
||||||
|
fill: Fill::default(),
|
||||||
|
font: Font::default(),
|
||||||
|
border: Border::default(),
|
||||||
|
quote_prefix: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct NumFmt {
|
pub struct NumFmt {
|
||||||
pub num_fmt_id: i32,
|
pub num_fmt_id: i32,
|
||||||
|
|||||||
@@ -50,8 +50,9 @@ impl Units {
|
|||||||
fn get_units_from_format_string(num_fmt: &str) -> Option<Units> {
|
fn get_units_from_format_string(num_fmt: &str) -> Option<Units> {
|
||||||
let mut parser = Parser::new(num_fmt);
|
let mut parser = Parser::new(num_fmt);
|
||||||
parser.parse();
|
parser.parse();
|
||||||
|
let parts = parser.parts.first()?;
|
||||||
// We only care about the first part (positive number)
|
// We only care about the first part (positive number)
|
||||||
match &parser.parts[0] {
|
match parts {
|
||||||
ParsePart::Number(part) => {
|
ParsePart::Number(part) => {
|
||||||
if part.percent > 0 {
|
if part.percent > 0 {
|
||||||
Some(Units::Percentage {
|
Some(Units::Percentage {
|
||||||
|
|||||||
Reference in New Issue
Block a user