csv-validation 0.0.9__tar.gz → 0.0.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {csv_validation-0.0.9 → csv_validation-0.0.10}/Cargo.lock +1 -1
- {csv_validation-0.0.9 → csv_validation-0.0.10}/Cargo.toml +1 -1
- {csv_validation-0.0.9 → csv_validation-0.0.10}/PKG-INFO +1 -1
- {csv_validation-0.0.9 → csv_validation-0.0.10}/src/lib.rs +43 -6
- {csv_validation-0.0.9 → csv_validation-0.0.10}/.github/workflows/CI.yml +0 -0
- {csv_validation-0.0.9 → csv_validation-0.0.10}/.gitignore +0 -0
- {csv_validation-0.0.9 → csv_validation-0.0.10}/LICENSE +0 -0
- {csv_validation-0.0.9 → csv_validation-0.0.10}/README.md +0 -0
- {csv_validation-0.0.9 → csv_validation-0.0.10}/build.sh +0 -0
- {csv_validation-0.0.9 → csv_validation-0.0.10}/pyproject.toml +0 -0
- {csv_validation-0.0.9 → csv_validation-0.0.10}/test/empty_values.csv +0 -0
- {csv_validation-0.0.9 → csv_validation-0.0.10}/test/test_file.csv +0 -0
- {csv_validation-0.0.9 → csv_validation-0.0.10}/test/test_file.csv.gz +0 -0
- {csv_validation-0.0.9 → csv_validation-0.0.10}/test/test_validations.yml +0 -0
|
@@ -97,15 +97,25 @@ fn apply_validation(value: &str, validation: &Validation, regex_map: &HashMap<St
|
|
|
97
97
|
Ok(regex.is_match(value))
|
|
98
98
|
},
|
|
99
99
|
Validation::Min(min) => {
|
|
100
|
-
|
|
101
|
-
Ok(
|
|
102
|
-
|
|
100
|
+
if value.is_empty() {
|
|
101
|
+
Ok(true)
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
match value.parse::<f64>() {
|
|
105
|
+
Ok(value) => Ok(value >= *min),
|
|
106
|
+
Err(_) => Ok(false)
|
|
107
|
+
}
|
|
103
108
|
}
|
|
104
109
|
},
|
|
105
110
|
Validation::Max(max) => {
|
|
106
|
-
|
|
107
|
-
Ok(
|
|
108
|
-
|
|
111
|
+
if value.is_empty() {
|
|
112
|
+
Ok(true)
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
match value.parse::<f64>() {
|
|
116
|
+
Ok(value) => Ok(value <= *max),
|
|
117
|
+
Err(_) => Ok(false)
|
|
118
|
+
}
|
|
109
119
|
}
|
|
110
120
|
},
|
|
111
121
|
Validation::Values(values) => {
|
|
@@ -597,6 +607,33 @@ mod tests {
|
|
|
597
607
|
assert!(CSVValidator::from_string(&definition).is_err());
|
|
598
608
|
}
|
|
599
609
|
|
|
610
|
+
#[test]
|
|
611
|
+
fn test_csv_validator_min_max_validation() {
|
|
612
|
+
let definition = String::from("
|
|
613
|
+
columns:
|
|
614
|
+
- name: First Column
|
|
615
|
+
- name: Second Column
|
|
616
|
+
- name: Third Column
|
|
617
|
+
min: -23
|
|
618
|
+
max: 1978
|
|
619
|
+
");
|
|
620
|
+
let validator = CSVValidator::from_string(&definition).unwrap();
|
|
621
|
+
assert!(validator.validate("test/test_file.csv").unwrap());
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
#[test]
|
|
625
|
+
fn test_csv_validator_min_max_validation_empty_values_are_ok_by_default() {
|
|
626
|
+
let definition = String::from("
|
|
627
|
+
columns:
|
|
628
|
+
- name: First Column
|
|
629
|
+
min: -23
|
|
630
|
+
max: 1978
|
|
631
|
+
- name: Second Column
|
|
632
|
+
");
|
|
633
|
+
let validator = CSVValidator::from_string(&definition).unwrap();
|
|
634
|
+
assert!(validator.validate("test/empty_values.csv").unwrap());
|
|
635
|
+
}
|
|
636
|
+
|
|
600
637
|
#[test]
|
|
601
638
|
fn test_format_integer() {
|
|
602
639
|
let test_cases = vec![
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|