diff options
| -rw-r--r-- | lib/data_types/value.ml | 7 | ||||
| -rw-r--r-- | tests/importCSV_test.ml | 13 |
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/data_types/value.ml b/lib/data_types/value.ml index 6bf85ae..5c54369 100644 --- a/lib/data_types/value.ml +++ b/lib/data_types/value.ml @@ -1,6 +1,6 @@ external show_float : string -> float -> string = "show_float" -let match_date = Re.Str.regexp {|[0-9]+/[0-9]+/[0-9]+|} +let match_number = Re.Str.regexp {|[0-9]+$|} type t = | Null @@ -19,5 +19,6 @@ let to_string locale = function | false -> c | true -> (* If the string is a date, do not escape it *) - if Re.Str.string_match match_date c 0 then c - else String.concat "" [ "=\""; c; "\"" ]) + if Re.Str.string_match match_number c 0 then + String.concat "" [ "=\""; c; "\"" ] + else c) diff --git a/tests/importCSV_test.ml b/tests/importCSV_test.ml index 748c58b..c5d017a 100644 --- a/tests/importCSV_test.ml +++ b/tests/importCSV_test.ml @@ -11,6 +11,18 @@ let float_repr = in () +let significant_zero = + "leading 0" >:: fun () -> + Alcotest.(check string) + "00123" "=\"00123\"" + ImportDataTypes.Value.(to_string "C" (Content "00123")); + Alcotest.(check string) + "0.0123" "0.0123" + ImportDataTypes.Value.(to_string "C" (Content "0.0123")); + Alcotest.(check string) + "00123 A" "00123 A" + ImportDataTypes.Value.(to_string "C" (Content "00123 A")) + let test_suit = [ ( "Column A" >:: fun () -> @@ -30,6 +42,7 @@ let test_suit = in () ); float_repr; + significant_zero; ] let tests = "importCSV_test" >::: test_suit |
