FIX: Correct order when stringify -(A1^1.22) and (-A1)^1.22 (#484)
Fixes #483
This commit is contained in:
committed by
GitHub
parent
c88bcb94ae
commit
1edfb2df1c
@@ -520,6 +520,7 @@ fn stringify(
|
|||||||
let x = match **left {
|
let x = match **left {
|
||||||
BooleanKind(_)
|
BooleanKind(_)
|
||||||
| NumberKind(_)
|
| NumberKind(_)
|
||||||
|
| UnaryKind { .. }
|
||||||
| StringKind(_)
|
| StringKind(_)
|
||||||
| ReferenceKind { .. }
|
| ReferenceKind { .. }
|
||||||
| RangeKind { .. }
|
| RangeKind { .. }
|
||||||
@@ -535,7 +536,6 @@ fn stringify(
|
|||||||
| FunctionKind { .. }
|
| FunctionKind { .. }
|
||||||
| InvalidFunctionKind { .. }
|
| InvalidFunctionKind { .. }
|
||||||
| ArrayKind(_)
|
| ArrayKind(_)
|
||||||
| UnaryKind { .. }
|
|
||||||
| ErrorKind(_)
|
| ErrorKind(_)
|
||||||
| ParseErrorKind { .. }
|
| ParseErrorKind { .. }
|
||||||
| OpSumKind { .. }
|
| OpSumKind { .. }
|
||||||
@@ -630,7 +630,6 @@ fn stringify(
|
|||||||
| OpRangeKind { .. }
|
| OpRangeKind { .. }
|
||||||
| OpConcatenateKind { .. }
|
| OpConcatenateKind { .. }
|
||||||
| OpProductKind { .. }
|
| OpProductKind { .. }
|
||||||
| OpPowerKind { .. }
|
|
||||||
| FunctionKind { .. }
|
| FunctionKind { .. }
|
||||||
| InvalidFunctionKind { .. }
|
| InvalidFunctionKind { .. }
|
||||||
| ArrayKind(_)
|
| ArrayKind(_)
|
||||||
@@ -643,7 +642,7 @@ fn stringify(
|
|||||||
| ParseErrorKind { .. }
|
| ParseErrorKind { .. }
|
||||||
| EmptyArgKind => false,
|
| EmptyArgKind => false,
|
||||||
|
|
||||||
OpSumKind { .. } | UnaryKind { .. } => true,
|
OpPowerKind { .. } | OpSumKind { .. } | UnaryKind { .. } => true,
|
||||||
};
|
};
|
||||||
if needs_parentheses {
|
if needs_parentheses {
|
||||||
format!(
|
format!(
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ mod test_arrays;
|
|||||||
mod test_general;
|
mod test_general;
|
||||||
mod test_implicit_intersection;
|
mod test_implicit_intersection;
|
||||||
mod test_issue_155;
|
mod test_issue_155;
|
||||||
|
mod test_issue_483;
|
||||||
mod test_move_formula;
|
mod test_move_formula;
|
||||||
mod test_ranges;
|
mod test_ranges;
|
||||||
mod test_stringify;
|
mod test_stringify;
|
||||||
|
|||||||
27
base/src/expressions/parser/tests/test_issue_483.rs
Normal file
27
base/src/expressions/parser/tests/test_issue_483.rs
Normal file
@@ -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");
|
||||||
|
}
|
||||||
@@ -68,6 +68,7 @@ mod test_geomean;
|
|||||||
mod test_get_cell_content;
|
mod test_get_cell_content;
|
||||||
mod test_implicit_intersection;
|
mod test_implicit_intersection;
|
||||||
mod test_issue_155;
|
mod test_issue_155;
|
||||||
|
mod test_issue_483;
|
||||||
mod test_ln;
|
mod test_ln;
|
||||||
mod test_log;
|
mod test_log;
|
||||||
mod test_log10;
|
mod test_log10;
|
||||||
|
|||||||
13
base/src/test/test_issue_483.rs
Normal file
13
base/src/test/test_issue_483.rs
Normal file
@@ -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());
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user