-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
data validation: add integration tests
Feature #97
- Loading branch information
Showing
7 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Test case that compares a file generated by rust_xlsxwriter with a file | ||
// created by Excel. | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2024, John McNamara, [email protected] | ||
|
||
use crate::common; | ||
use rust_xlsxwriter::{DataValidation, Workbook, XlsxError}; | ||
|
||
// Create rust_xlsxwriter file to compare against Excel file. | ||
fn create_new_xlsx_file(filename: &str) -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
|
||
let worksheet = workbook.add_worksheet(); | ||
|
||
let data_validation = DataValidation::new().allow_list_strings(&["Foo", "Bar", "Baz"])?; | ||
|
||
worksheet.add_data_validation(1, 2, 1, 2, &data_validation)?; | ||
|
||
workbook.save(filename)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_data_validation01() { | ||
let test_runner = common::TestRunner::new() | ||
.set_name("data_validation01") | ||
.set_function(create_new_xlsx_file) | ||
.initialize(); | ||
|
||
test_runner.assert_eq(); | ||
test_runner.cleanup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Test case that compares a file generated by rust_xlsxwriter with a file | ||
// created by Excel. | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2024, John McNamara, [email protected] | ||
|
||
use crate::common; | ||
use rust_xlsxwriter::{DataValidation, Workbook, XlsxError}; | ||
|
||
// Create rust_xlsxwriter file to compare against Excel file. | ||
fn create_new_xlsx_file(filename: &str) -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
|
||
let worksheet = workbook.add_worksheet(); | ||
|
||
let data_validation = DataValidation::new() | ||
.allow_list_strings(&["Foo", "Bar", "Baz"])? | ||
.set_input_title("This is the input title")? | ||
.set_input_message("This is the input message")?; | ||
|
||
worksheet.add_data_validation(1, 2, 1, 2, &data_validation)?; | ||
|
||
workbook.save(filename)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_data_validation02() { | ||
let test_runner = common::TestRunner::new() | ||
.set_name("data_validation02") | ||
.set_function(create_new_xlsx_file) | ||
.initialize(); | ||
|
||
test_runner.assert_eq(); | ||
test_runner.cleanup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Test case that compares a file generated by rust_xlsxwriter with a file | ||
// created by Excel. | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright 2022-2024, John McNamara, [email protected] | ||
|
||
use crate::common; | ||
use rust_xlsxwriter::{DataValidation, Workbook, XlsxError}; | ||
|
||
// Create rust_xlsxwriter file to compare against Excel file. | ||
fn create_new_xlsx_file(filename: &str) -> Result<(), XlsxError> { | ||
let mut workbook = Workbook::new(); | ||
|
||
let worksheet = workbook.add_worksheet(); | ||
|
||
let data_validation = DataValidation::new() | ||
.allow_list_strings(&["Foo", "Bar", "Baz"])? | ||
.set_input_title("This is the input title")? | ||
.set_input_message("This is the input message")?; | ||
|
||
worksheet.add_data_validation(1, 2, 1, 2, &data_validation)?; | ||
|
||
let invalid_title = "This is the longest input title1"; | ||
let padding = ["a"; 221]; | ||
let invalid_message = "This is the longest input message ".to_string() + &padding.concat(); | ||
let list_values = [ | ||
"Foobar", "Foobas", "Foobat", "Foobau", "Foobav", "Foobaw", "Foobax", "Foobay", "Foobaz", | ||
"Foobba", "Foobbb", "Foobbc", "Foobbd", "Foobbe", "Foobbf", "Foobbg", "Foobbh", "Foobbi", | ||
"Foobbj", "Foobbk", "Foobbl", "Foobbm", "Foobbn", "Foobbo", "Foobbp", "Foobbq", "Foobbr", | ||
"Foobbs", "Foobbt", "Foobbu", "Foobbv", "Foobbw", "Foobbx", "Foobby", "Foobbz", "Foobca", | ||
"End", | ||
]; | ||
|
||
let data_validation = DataValidation::new() | ||
.allow_list_strings(&list_values)? | ||
.set_input_title(invalid_title)? | ||
.set_input_message(invalid_message)?; | ||
|
||
worksheet.add_data_validation(5, 3, 5, 3, &data_validation)?; | ||
|
||
workbook.save(filename)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_data_validation03() { | ||
let test_runner = common::TestRunner::new() | ||
.set_name("data_validation03") | ||
.set_function(create_new_xlsx_file) | ||
.initialize(); | ||
|
||
test_runner.assert_eq(); | ||
test_runner.cleanup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters