From c03817858302d05eecf1bb5cb16731d8bd27151c Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sun, 8 Jul 2018 15:23:51 -0400 Subject: [PATCH] testFuzzyAMPMProblem is causing us issues --- build_pycompat.py | 28 ++++++++++++++ src/tests/pycompat_parser.rs | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/build_pycompat.py b/build_pycompat.py index 036233f..a63cf54 100644 --- a/build_pycompat.py +++ b/build_pycompat.py @@ -86,6 +86,14 @@ tests = { 'test_fuzzy_tokens_tzinfo': [ 'Today is 25 of September of 2003, exactly at 10:49:41 with timezone -03:00.' ], + 'test_fuzzy_simple': [ + 'I have a meeting on March 1, 1974', # testFuzzyAMPMProblem + 'On June 8th, 2020, I am going to be the first man on Mars', # testFuzzyAMPMProblem + 'Meet me at the AM/PM on Sunset at 3:00 AM on December 3rd, 2003', # testFuzzyAMPMProblem + 'Meet me at 3:00 AM on December 3rd, 2003 at the AM/PM on Sunset', # testFuzzyAMPMProblem + 'Jan 29, 1945 14:45 AM I going to see you there?', # testFuzzyIgnoreAMPM + '2017-07-17 06:15:', # test_idx_check + ], 'test_parse_default_ignore': [ ], } @@ -172,6 +180,13 @@ def test_fuzzy_tokens_tzinfo(i, s): tokens=r_tokens ) + +def test_fuzzy_simple(i, s): + d = parse(s, fuzzy=True) + + return TEST_FUZZY_SIMPLE.format(i=i, d=d, s=s) + + # Here lies all the ugly junk. TEST_HEADER = ''' extern crate chrono; @@ -449,6 +464,19 @@ fn test_fuzzy_tokens_tzinfo{i}() {{ None, false, HashMap::new()); }}\n''' +TEST_FUZZY_SIMPLE = ''' +#[test] +fn test_fuzzy_simple{i}() {{ + let info = ParserInfo::default(); + let pdt = PyDateTime {{ + year: {d.year}, month: {d.month}, day: {d.day}, + hour: {d.hour}, minute: {d.minute}, second: {d.second}, + micros: {d.microsecond}, tzo: None + }}; + parse_fuzzy_and_assert(pdt, None, info, "{s}", None, None, true, false, + None, false, HashMap::new()); +}}\n''' + if __name__ == '__main__': main() \ No newline at end of file diff --git a/src/tests/pycompat_parser.rs b/src/tests/pycompat_parser.rs index 647f7a5..624ee7d 100644 --- a/src/tests/pycompat_parser.rs +++ b/src/tests/pycompat_parser.rs @@ -1757,3 +1757,75 @@ fn test_fuzzy_tokens_tzinfo0() { parse_fuzzy_and_assert(pdt, Some(tokens), info, "Today is 25 of September of 2003, exactly at 10:49:41 with timezone -03:00.", None, None, true, true, None, false, HashMap::new()); } + +#[test] +fn test_fuzzy_simple0() { + let info = ParserInfo::default(); + let pdt = PyDateTime { + year: 1974, month: 3, day: 1, + hour: 0, minute: 0, second: 0, + micros: 0, tzo: None + }; + parse_fuzzy_and_assert(pdt, None, info, "I have a meeting on March 1, 1974", None, None, true, false, + None, false, HashMap::new()); +} + +#[test] +fn test_fuzzy_simple1() { + let info = ParserInfo::default(); + let pdt = PyDateTime { + year: 2020, month: 6, day: 8, + hour: 0, minute: 0, second: 0, + micros: 0, tzo: None + }; + parse_fuzzy_and_assert(pdt, None, info, "On June 8th, 2020, I am going to be the first man on Mars", None, None, true, false, + None, false, HashMap::new()); +} + +#[test] +fn test_fuzzy_simple2() { + let info = ParserInfo::default(); + let pdt = PyDateTime { + year: 2003, month: 12, day: 3, + hour: 3, minute: 0, second: 0, + micros: 0, tzo: None + }; + parse_fuzzy_and_assert(pdt, None, info, "Meet me at the AM/PM on Sunset at 3:00 AM on December 3rd, 2003", None, None, true, false, + None, false, HashMap::new()); +} + +#[test] +fn test_fuzzy_simple3() { + let info = ParserInfo::default(); + let pdt = PyDateTime { + year: 2003, month: 12, day: 3, + hour: 3, minute: 0, second: 0, + micros: 0, tzo: None + }; + parse_fuzzy_and_assert(pdt, None, info, "Meet me at 3:00 AM on December 3rd, 2003 at the AM/PM on Sunset", None, None, true, false, + None, false, HashMap::new()); +} + +#[test] +fn test_fuzzy_simple4() { + let info = ParserInfo::default(); + let pdt = PyDateTime { + year: 1945, month: 1, day: 29, + hour: 14, minute: 45, second: 0, + micros: 0, tzo: None + }; + parse_fuzzy_and_assert(pdt, None, info, "Jan 29, 1945 14:45 AM I going to see you there?", None, None, true, false, + None, false, HashMap::new()); +} + +#[test] +fn test_fuzzy_simple5() { + let info = ParserInfo::default(); + let pdt = PyDateTime { + year: 2017, month: 7, day: 17, + hour: 6, minute: 15, second: 0, + micros: 0, tzo: None + }; + parse_fuzzy_and_assert(pdt, None, info, "2017-07-17 06:15:", None, None, true, false, + None, false, HashMap::new()); +}