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.
@@ -83,7 +83,7 @@ dependencies = [
83
83
 
84
84
  [[package]]
85
85
  name = "csv_validation"
86
- version = "0.0.9"
86
+ version = "0.0.10"
87
87
  dependencies = [
88
88
  "csv",
89
89
  "flate2",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "csv_validation"
3
- version = "0.0.9"
3
+ version = "0.0.10"
4
4
  edition = "2021"
5
5
 
6
6
  # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: csv_validation
3
- Version: 0.0.9
3
+ Version: 0.0.10
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -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
- match value.parse::<f64>() {
101
- Ok(value) => Ok(value >= *min),
102
- Err(_) => Ok(false)
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
- match value.parse::<f64>() {
107
- Ok(value) => Ok(value <= *max),
108
- Err(_) => Ok(false)
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