|
@@ -7,25 +7,30 @@ mod tests {
|
|
use flowy_grid_data_model::revision::FieldRevision;
|
|
use flowy_grid_data_model::revision::FieldRevision;
|
|
use strum::IntoEnumIterator;
|
|
use strum::IntoEnumIterator;
|
|
|
|
|
|
|
|
+ /// Testing when the input is not a number.
|
|
#[test]
|
|
#[test]
|
|
fn number_type_option_invalid_input_test() {
|
|
fn number_type_option_invalid_input_test() {
|
|
let type_option = NumberTypeOption::default();
|
|
let type_option = NumberTypeOption::default();
|
|
let field_type = FieldType::Number;
|
|
let field_type = FieldType::Number;
|
|
let field_rev = FieldBuilder::from_field_type(&field_type).build();
|
|
let field_rev = FieldBuilder::from_field_type(&field_type).build();
|
|
- assert_equal(&type_option, "", "", &field_type, &field_rev);
|
|
|
|
- assert_equal(&type_option, "abc", "", &field_type, &field_rev);
|
|
|
|
|
|
+
|
|
|
|
+ // Input is empty String
|
|
|
|
+ assert_number(&type_option, "", "", &field_type, &field_rev);
|
|
|
|
+
|
|
|
|
+ // Input is letter
|
|
|
|
+ assert_number(&type_option, "abc", "", &field_type, &field_rev);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// Testing the strip_currency_symbol function. It should return the string without the input symbol.
|
|
#[test]
|
|
#[test]
|
|
fn number_type_option_strip_symbol_test() {
|
|
fn number_type_option_strip_symbol_test() {
|
|
- let mut type_option = NumberTypeOption::new();
|
|
|
|
- type_option.format = NumberFormat::USD;
|
|
|
|
|
|
+ // Remove the $ symbol
|
|
assert_eq!(strip_currency_symbol("$18,443"), "18,443".to_owned());
|
|
assert_eq!(strip_currency_symbol("$18,443"), "18,443".to_owned());
|
|
-
|
|
|
|
- type_option.format = NumberFormat::Yuan;
|
|
|
|
- assert_eq!(strip_currency_symbol("$0.2"), "0.2".to_owned());
|
|
|
|
|
|
+ // Remove the ¥ symbol
|
|
|
|
+ assert_eq!(strip_currency_symbol("¥0.2"), "0.2".to_owned());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// Format the input number to the corresponding format string.
|
|
#[test]
|
|
#[test]
|
|
fn number_type_option_format_number_test() {
|
|
fn number_type_option_format_number_test() {
|
|
let mut type_option = NumberTypeOption::default();
|
|
let mut type_option = NumberTypeOption::default();
|
|
@@ -36,25 +41,26 @@ mod tests {
|
|
type_option.format = format;
|
|
type_option.format = format;
|
|
match format {
|
|
match format {
|
|
NumberFormat::Num => {
|
|
NumberFormat::Num => {
|
|
- assert_equal(&type_option, "18443", "18443", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "18443", "18443", &field_type, &field_rev);
|
|
}
|
|
}
|
|
NumberFormat::USD => {
|
|
NumberFormat::USD => {
|
|
- assert_equal(&type_option, "18443", "$18,443", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "18443", "$18,443", &field_type, &field_rev);
|
|
}
|
|
}
|
|
NumberFormat::Yen => {
|
|
NumberFormat::Yen => {
|
|
- assert_equal(&type_option, "18443", "¥18,443", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "18443", "¥18,443", &field_type, &field_rev);
|
|
}
|
|
}
|
|
NumberFormat::Yuan => {
|
|
NumberFormat::Yuan => {
|
|
- assert_equal(&type_option, "18443", "CN¥18,443", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "18443", "CN¥18,443", &field_type, &field_rev);
|
|
}
|
|
}
|
|
NumberFormat::EUR => {
|
|
NumberFormat::EUR => {
|
|
- assert_equal(&type_option, "18443", "€18.443", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "18443", "€18.443", &field_type, &field_rev);
|
|
}
|
|
}
|
|
_ => {}
|
|
_ => {}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// Format the input String to the corresponding format string.
|
|
#[test]
|
|
#[test]
|
|
fn number_type_option_format_str_test() {
|
|
fn number_type_option_format_str_test() {
|
|
let mut type_option = NumberTypeOption::default();
|
|
let mut type_option = NumberTypeOption::default();
|
|
@@ -65,33 +71,34 @@ mod tests {
|
|
type_option.format = format;
|
|
type_option.format = format;
|
|
match format {
|
|
match format {
|
|
NumberFormat::Num => {
|
|
NumberFormat::Num => {
|
|
- assert_equal(&type_option, "18443", "18443", &field_type, &field_rev);
|
|
|
|
- assert_equal(&type_option, "0.2", "0.2", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "18443", "18443", &field_type, &field_rev);
|
|
|
|
+ assert_number(&type_option, "0.2", "0.2", &field_type, &field_rev);
|
|
}
|
|
}
|
|
NumberFormat::USD => {
|
|
NumberFormat::USD => {
|
|
- assert_equal(&type_option, "$18,44", "$1,844", &field_type, &field_rev);
|
|
|
|
- assert_equal(&type_option, "$0.2", "$0.2", &field_type, &field_rev);
|
|
|
|
- assert_equal(&type_option, "", "", &field_type, &field_rev);
|
|
|
|
- assert_equal(&type_option, "abc", "", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "$18,44", "$1,844", &field_type, &field_rev);
|
|
|
|
+ assert_number(&type_option, "$0.2", "$0.2", &field_type, &field_rev);
|
|
|
|
+ assert_number(&type_option, "", "", &field_type, &field_rev);
|
|
|
|
+ assert_number(&type_option, "abc", "", &field_type, &field_rev);
|
|
}
|
|
}
|
|
NumberFormat::Yen => {
|
|
NumberFormat::Yen => {
|
|
- assert_equal(&type_option, "¥18,44", "¥1,844", &field_type, &field_rev);
|
|
|
|
- assert_equal(&type_option, "¥1844", "¥1,844", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "¥18,44", "¥1,844", &field_type, &field_rev);
|
|
|
|
+ assert_number(&type_option, "¥1844", "¥1,844", &field_type, &field_rev);
|
|
}
|
|
}
|
|
NumberFormat::Yuan => {
|
|
NumberFormat::Yuan => {
|
|
- assert_equal(&type_option, "CN¥18,44", "CN¥1,844", &field_type, &field_rev);
|
|
|
|
- assert_equal(&type_option, "CN¥1844", "CN¥1,844", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "CN¥18,44", "CN¥1,844", &field_type, &field_rev);
|
|
|
|
+ assert_number(&type_option, "CN¥1844", "CN¥1,844", &field_type, &field_rev);
|
|
}
|
|
}
|
|
NumberFormat::EUR => {
|
|
NumberFormat::EUR => {
|
|
- assert_equal(&type_option, "€18.44", "€18,44", &field_type, &field_rev);
|
|
|
|
- assert_equal(&type_option, "€0.5", "€0,5", &field_type, &field_rev);
|
|
|
|
- assert_equal(&type_option, "€1844", "€1.844", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "€18.44", "€18,44", &field_type, &field_rev);
|
|
|
|
+ assert_number(&type_option, "€0.5", "€0,5", &field_type, &field_rev);
|
|
|
|
+ assert_number(&type_option, "€1844", "€1.844", &field_type, &field_rev);
|
|
}
|
|
}
|
|
_ => {}
|
|
_ => {}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// Carry out the sign positive to input number
|
|
#[test]
|
|
#[test]
|
|
fn number_description_sign_test() {
|
|
fn number_description_sign_test() {
|
|
let mut type_option = NumberTypeOption {
|
|
let mut type_option = NumberTypeOption {
|
|
@@ -105,32 +112,32 @@ mod tests {
|
|
type_option.format = format;
|
|
type_option.format = format;
|
|
match format {
|
|
match format {
|
|
NumberFormat::Num => {
|
|
NumberFormat::Num => {
|
|
- assert_equal(&type_option, "18443", "18443", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "18443", "18443", &field_type, &field_rev);
|
|
}
|
|
}
|
|
NumberFormat::USD => {
|
|
NumberFormat::USD => {
|
|
- assert_equal(&type_option, "18443", "-$18,443", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "18443", "-$18,443", &field_type, &field_rev);
|
|
}
|
|
}
|
|
NumberFormat::Yen => {
|
|
NumberFormat::Yen => {
|
|
- assert_equal(&type_option, "18443", "-¥18,443", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "18443", "-¥18,443", &field_type, &field_rev);
|
|
}
|
|
}
|
|
NumberFormat::EUR => {
|
|
NumberFormat::EUR => {
|
|
- assert_equal(&type_option, "18443", "-€18.443", &field_type, &field_rev);
|
|
|
|
|
|
+ assert_number(&type_option, "18443", "-€18.443", &field_type, &field_rev);
|
|
}
|
|
}
|
|
_ => {}
|
|
_ => {}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fn assert_equal(
|
|
|
|
|
|
+ fn assert_number(
|
|
type_option: &NumberTypeOption,
|
|
type_option: &NumberTypeOption,
|
|
- cell_data: &str,
|
|
|
|
|
|
+ input_str: &str,
|
|
expected_str: &str,
|
|
expected_str: &str,
|
|
field_type: &FieldType,
|
|
field_type: &FieldType,
|
|
field_rev: &FieldRevision,
|
|
field_rev: &FieldRevision,
|
|
) {
|
|
) {
|
|
assert_eq!(
|
|
assert_eq!(
|
|
type_option
|
|
type_option
|
|
- .decode_cell_data(cell_data.to_owned().into(), field_type, field_rev)
|
|
|
|
|
|
+ .decode_cell_data(input_str.to_owned().into(), field_type, field_rev)
|
|
.unwrap()
|
|
.unwrap()
|
|
.to_string(),
|
|
.to_string(),
|
|
expected_str.to_owned()
|
|
expected_str.to_owned()
|