diff --git a/base/src/expressions/parser/stringify.rs b/base/src/expressions/parser/stringify.rs index cef7549..c0f8933 100644 --- a/base/src/expressions/parser/stringify.rs +++ b/base/src/expressions/parser/stringify.rs @@ -520,6 +520,7 @@ fn stringify( let x = match **left { BooleanKind(_) | NumberKind(_) + | UnaryKind { .. } | StringKind(_) | ReferenceKind { .. } | RangeKind { .. } @@ -535,7 +536,6 @@ fn stringify( | FunctionKind { .. } | InvalidFunctionKind { .. } | ArrayKind(_) - | UnaryKind { .. } | ErrorKind(_) | ParseErrorKind { .. } | OpSumKind { .. } @@ -630,7 +630,6 @@ fn stringify( | OpRangeKind { .. } | OpConcatenateKind { .. } | OpProductKind { .. } - | OpPowerKind { .. } | FunctionKind { .. } | InvalidFunctionKind { .. } | ArrayKind(_) @@ -643,7 +642,7 @@ fn stringify( | ParseErrorKind { .. } | EmptyArgKind => false, - OpSumKind { .. } | UnaryKind { .. } => true, + OpPowerKind { .. } | OpSumKind { .. } | UnaryKind { .. } => true, }; if needs_parentheses { format!( diff --git a/base/src/expressions/parser/tests/mod.rs b/base/src/expressions/parser/tests/mod.rs index e019d01..61d6771 100644 --- a/base/src/expressions/parser/tests/mod.rs +++ b/base/src/expressions/parser/tests/mod.rs @@ -3,6 +3,7 @@ mod test_arrays; mod test_general; mod test_implicit_intersection; mod test_issue_155; +mod test_issue_483; mod test_move_formula; mod test_ranges; mod test_stringify; diff --git a/base/src/expressions/parser/tests/test_issue_483.rs b/base/src/expressions/parser/tests/test_issue_483.rs new file mode 100644 index 0000000..678f39e --- /dev/null +++ b/base/src/expressions/parser/tests/test_issue_483.rs @@ -0,0 +1,27 @@ +#![allow(clippy::panic)] + +use std::collections::HashMap; + +use crate::expressions::parser::stringify::to_string; +use crate::expressions::parser::{Node, Parser}; +use crate::expressions::types::CellReferenceRC; + +#[test] +fn issue_483_parser() { + let worksheets = vec!["Sheet1".to_string()]; + let mut parser = Parser::new(worksheets, vec![], HashMap::new()); + + // Reference cell is Sheet1!A1 + let cell_reference = CellReferenceRC { + sheet: "Sheet1".to_string(), + row: 2, + column: 2, + }; + let t = parser.parse("-(A1^1.22)", &cell_reference); + assert!(matches!(t, Node::UnaryKind { .. })); + assert_eq!(to_string(&t, &cell_reference), "-(A1^1.22)"); + + let t = parser.parse("-A1^1.22", &cell_reference); + assert!(matches!(t, Node::OpPowerKind { .. })); + assert_eq!(to_string(&t, &cell_reference), "-A1^1.22"); +} diff --git a/base/src/test/mod.rs b/base/src/test/mod.rs index 3702a68..0905635 100644 --- a/base/src/test/mod.rs +++ b/base/src/test/mod.rs @@ -68,6 +68,7 @@ mod test_geomean; mod test_get_cell_content; mod test_implicit_intersection; mod test_issue_155; +mod test_issue_483; mod test_ln; mod test_log; mod test_log10; diff --git a/base/src/test/test_issue_483.rs b/base/src/test/test_issue_483.rs new file mode 100644 index 0000000..f784141 --- /dev/null +++ b/base/src/test/test_issue_483.rs @@ -0,0 +1,13 @@ +#![allow(clippy::unwrap_used)] + +use crate::test::util::new_empty_model; + +#[test] +fn issue_155() { + let mut model = new_empty_model(); + model._set("A1", "123"); + model._set("D2", "=-(A1^1.22)"); + model.evaluate(); + + assert_eq!(model._get_formula("D2"), "=-(A1^1.22)".to_string()); +}