Skip to content

Commit

Permalink
fix quoted in_list data values for excel
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickomatic committed Feb 13, 2024
1 parent 9017878 commit 4ab2d9b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

* Fix bug where styles weren't being applied to Excel files
* Fix a bug where the spreadsheet was not getting re-compiled if a .csvpo file existed
* Fix quoted `in_list` validations like `validate=in_list('foo bar', 'bar foo')`
* Fix `</<=/>/>=` lexing
* Don't allow (throw an error) if there are multiple infinite fills

Expand Down
43 changes: 40 additions & 3 deletions src/target/excel/cell_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,17 @@ impl From<CellValidation> for u::DataValidation {
"\"{}\"",
&values
.into_iter()
.map(|v| v.to_string())
.map(|v| v.to_string().replace('"', ""))
.collect::<Vec<String>>()
.join(",")
.join(", ")
);

validation!(
v,
List,
Equal,
list_as_string,
format!("Value in list {list_as_string}")
format!("Value in list: {list_as_string}")
)
}

Expand All @@ -222,3 +222,40 @@ impl From<CellValidation> for u::DataValidation {
v
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::ast::*;

#[test]
fn custom() {
let cv: CellValidation = CellValidation(
a1_notation::Address::new(0, 0),
DataValidation::Custom("foo".to_string()),
);
let dv: u::DataValidation = cv.into();

assert!(dv.get_show_input_message());
assert_eq!(dv.get_prompt(), "Custom formula: foo");
assert_eq!(dv.get_formula1(), "foo");
}

// TODO: cover more scenarios

#[test]
fn value_in_list() {
let cv: CellValidation = CellValidation(
a1_notation::Address::new(0, 0),
DataValidation::ValueInList(vec![
Node::reference("foo").into(),
Node::reference("foo bar").into(),
]),
);
let dv: u::DataValidation = cv.into();

assert!(dv.get_show_input_message());
assert_eq!(dv.get_prompt(), "Value in list: \"foo, foo bar\"");
assert_eq!(dv.get_formula1(), "\"foo, foo bar\"");
}
}

0 comments on commit 4ab2d9b

Please sign in to comment.