Пример #1
0
        public void TodayTest()
        {
            string     parsedText = null;
            DateTime   dateTime   = DateTime.MinValue;
            TaskParser parser     = TaskParser.Instance;

            DateTime expected = DateTime.Now;

            Assert.IsTrue(parser.TryParse("Something today",
                                          out parsedText,
                                          out dateTime));
            Assert.AreEqual("Something", parsedText, "#0");
            Assert.AreEqual(expected.Year, dateTime.Year, "#1");
            Assert.AreEqual(expected.Month, dateTime.Month, "#2");
            Assert.AreEqual(expected.Day, dateTime.Day, "#3");
            dateTime = DateTime.MinValue;

            Assert.IsTrue(parser.TryParse("Buy meat today for lunch",
                                          out parsedText,
                                          out dateTime));
            Assert.AreEqual("Buy meat for lunch", parsedText, "#4");
            Assert.AreEqual(expected.Year, dateTime.Year, "#5");
            Assert.AreEqual(expected.Month, dateTime.Month, "#6");
            Assert.AreEqual(expected.Day, dateTime.Day, "#7");
            dateTime = DateTime.MinValue;

            Assert.IsTrue(parser.TryParse("GET BEER TODAY, RIGHT NOW!",
                                          out parsedText,
                                          out dateTime));
            Assert.AreEqual("GET BEER, RIGHT NOW!", parsedText, "#8");
            Assert.AreEqual(expected.Year, dateTime.Year, "#9");
            Assert.AreEqual(expected.Month, dateTime.Month, "#10");
            Assert.AreEqual(expected.Day, dateTime.Day, "#11");
        }
Пример #2
0
        public void OthersTest()
        {
            string     parsedText = null;
            DateTime   dateTime   = DateTime.MinValue;
            TaskParser parser     = TaskParser.Instance;

            DateTime expected = GetWeekdayDate(DayOfWeek.Monday);

            Assert.IsTrue(parser.TryParse("Something mon",               // as in Monday
                                          out parsedText,
                                          out dateTime),
                          "#0");
            Assert.AreEqual("Something", parsedText, "#1");
            Assert.AreEqual(expected.Year, dateTime.Year, "#2");
            Assert.AreEqual(expected.Month, dateTime.Month, "#3");
            Assert.AreEqual(expected.Day, dateTime.Day, "#4");
            dateTime = DateTime.MinValue;

            expected = GetMonthDate(3, 11);
            Assert.IsTrue(parser.TryParse("Something March 11",
                                          out parsedText,
                                          out dateTime),
                          "#5");
            Assert.AreEqual("Something", parsedText, "#6");
            Assert.AreEqual(expected.Year, dateTime.Year, "#7");
            Assert.AreEqual(expected.Month, dateTime.Month, "#8");
            Assert.AreEqual(expected.Day, dateTime.Day, "#9");
            dateTime = DateTime.MinValue;

            expected = GetMonthDate(4, 22);
            Assert.IsTrue(parser.TryParse("Something April 22nd",
                                          out parsedText,
                                          out dateTime),
                          "#10");
            Assert.AreEqual("Something", parsedText, "#11");
            Assert.AreEqual(expected.Year, dateTime.Year, "#12");
            Assert.AreEqual(expected.Month, dateTime.Month, "#13");
            Assert.AreEqual(expected.Day, dateTime.Day, "#14");
            dateTime = DateTime.MinValue;

            expected = GetMonthDate(-1, 12);
            Assert.IsTrue(parser.TryParse("Something 12th",
                                          out parsedText,
                                          out dateTime),
                          "#15");
            Assert.AreEqual("Something", parsedText, "#16");
            Assert.AreEqual(expected.Year, dateTime.Year, "#17");
            Assert.AreEqual(expected.Month, dateTime.Month, "#18");
            Assert.AreEqual(expected.Day, dateTime.Day, "#19");
        }
Пример #3
0
        public void WeekdayTest()
        {
            string     parsedText = null;
            DateTime   dateTime   = DateTime.MinValue;
            TaskParser parser     = TaskParser.Instance;

            DateTime expected = GetWeekdayDate(DayOfWeek.Monday);

            Assert.IsTrue(parser.TryParse("Something on Monday",
                                          out parsedText,
                                          out dateTime),
                          "#0");
            Assert.AreEqual("Something", parsedText, "#1");
            Assert.AreEqual(expected.Year, dateTime.Year, "#2");
            Assert.AreEqual(expected.Month, dateTime.Month, "#3");
            Assert.AreEqual(expected.Day, dateTime.Day, "#4");
            dateTime = DateTime.MinValue;

            expected = GetWeekdayDate(DayOfWeek.Friday);
            Assert.IsTrue(parser.TryParse("Something due on Friday",
                                          out parsedText,
                                          out dateTime),
                          "#5");
            Assert.AreEqual("Something", parsedText, "#6");
            Assert.AreEqual(expected.Year, dateTime.Year, "#7");
            Assert.AreEqual(expected.Month, dateTime.Month, "#8");
            Assert.AreEqual(expected.Day, dateTime.Day, "#9");
            dateTime = DateTime.MinValue;

            expected = GetWeekdayDate(DayOfWeek.Sunday);
            Assert.IsTrue(parser.TryParse("Something next sunday",
                                          out parsedText,
                                          out dateTime),
                          "#10");
            Assert.AreEqual("Something", parsedText, "#11");
            Assert.AreEqual(expected.Year, dateTime.Year, "#12");
            Assert.AreEqual(expected.Month, dateTime.Month, "#13");
            Assert.AreEqual(expected.Day, dateTime.Day, "#14");
            dateTime = DateTime.MinValue;

            expected = GetWeekdayDate(DayOfWeek.Wednesday);
            Assert.IsTrue(parser.TryParse("Something next wed",
                                          out parsedText,
                                          out dateTime),
                          "#15");
            Assert.AreEqual("Something", parsedText, "#16");
            Assert.AreEqual(expected.Year, dateTime.Year, "#17");
            Assert.AreEqual(expected.Month, dateTime.Month, "#18");
            Assert.AreEqual(expected.Day, dateTime.Day, "#19");
        }
Пример #4
0
        public void OrdinalTest()
        {
            string     parsedText = null;
            DateTime   dateTime   = DateTime.MinValue;
            TaskParser parser     = TaskParser.Instance;

            DateTime expected = GetMonthDate(DateTime.Now.Month, 1);

            Assert.IsTrue(parser.TryParse("Something on 1st",
                                          out parsedText,
                                          out dateTime),
                          "#0");
            Assert.AreEqual("Something", parsedText, "#1");
            Assert.AreEqual(expected.Year, dateTime.Year, "#2");
            Assert.AreEqual(expected.Month, dateTime.Month, "#3");
            Assert.AreEqual(expected.Day, dateTime.Day, "#4");
            dateTime = DateTime.MinValue;

            expected = GetMonthDate(DateTime.Now.Month, 2);
            Assert.IsTrue(parser.TryParse("Something due 2nd",
                                          out parsedText,
                                          out dateTime));
            Assert.AreEqual("Something", parsedText, "#5");
            Assert.AreEqual(expected.Year, dateTime.Year, "#6");
            Assert.AreEqual(expected.Month, dateTime.Month, "#7");
            Assert.AreEqual(expected.Day, dateTime.Day, "#8");
            dateTime = DateTime.MinValue;

            expected = GetMonthDate(-1, 15);
            Assert.IsTrue(parser.TryParse("Something due by 15th",
                                          out parsedText,
                                          out dateTime));
            Assert.AreEqual("Something", parsedText, "#9");
            Assert.AreEqual(expected.Year, dateTime.Year, "#10");
            Assert.AreEqual(expected.Month, dateTime.Month, "#11");
            Assert.AreEqual(expected.Day, dateTime.Day, "#12");
            dateTime = DateTime.MinValue;

            // Event this is an invalid date in English
            // we don't care about it, and we parse it
            expected = GetMonthDate(-1, 15);
            Assert.IsTrue(parser.TryParse("Something important on 15nd",
                                          out parsedText,
                                          out dateTime),
                          "#13");
            Assert.AreEqual("Something important", parsedText, "#14");
            Assert.AreEqual(expected.Year, dateTime.Year, "#15");
            Assert.AreEqual(expected.Month, dateTime.Month, "#16");
            Assert.AreEqual(expected.Day, dateTime.Day, "#17");
        }
Пример #5
0
        public void YearTest()
        {
            string     parsedText = null;
            DateTime   dateTime   = DateTime.MinValue;
            TaskParser parser     = TaskParser.Instance;

            DateTime expected = DateTime.Now.AddYears(1);

            Assert.IsTrue(parser.TryParse("Something next year",
                                          out parsedText,
                                          out dateTime),
                          "#0");
            Assert.AreEqual("Something", parsedText, "#1");
            Assert.AreEqual(expected.Year, dateTime.Year, "#2");
            Assert.AreEqual(expected.Month, dateTime.Month, "#3");
            Assert.AreEqual(expected.Day, dateTime.Day, "#4");
            dateTime = DateTime.MinValue;

            expected = DateTime.Now.AddYears(5);
            Assert.IsTrue(parser.TryParse("Buy a house in 5 years",
                                          out parsedText,
                                          out dateTime),
                          "#5");
            Assert.AreEqual("Buy a house", parsedText, "#6");
            Assert.AreEqual(expected.Year, dateTime.Year, "#7");
            Assert.AreEqual(expected.Month, dateTime.Month, "#8");
            Assert.AreEqual(expected.Day, dateTime.Day, "#9");
            dateTime = DateTime.MinValue;

            Assert.IsFalse(parser.TryParse("Sleep in -1 years",
                                           out parsedText,
                                           out dateTime),
                           "#10");
            dateTime = DateTime.MinValue;

            // Even though this is invalid English, we accept it
            expected = DateTime.Now.AddYears(1);
            Assert.IsTrue(parser.TryParse("Something in years",
                                          out parsedText,
                                          out dateTime),
                          "#11");
            Assert.AreEqual(expected.Year, dateTime.Year, "#12");
            Assert.AreEqual(expected.Month, dateTime.Month, "#13");
            Assert.AreEqual(expected.Day, dateTime.Day, "#14");
            dateTime = DateTime.MinValue;
        }
Пример #6
0
        public void WeekTest()
        {
            string     parsedText = null;
            DateTime   dateTime   = DateTime.MinValue;
            TaskParser parser     = TaskParser.Instance;

            DateTime expected = DateTime.Now.AddDays(7);

            Assert.IsTrue(parser.TryParse("Something next week",
                                          out parsedText,
                                          out dateTime),
                          "#0");
            Assert.AreEqual("Something", parsedText, "#1");
            Assert.AreEqual(expected.Year, dateTime.Year, "#2");
            Assert.AreEqual(expected.Month, dateTime.Month, "#3");
            Assert.AreEqual(expected.Day, dateTime.Day, "#4");
            dateTime = DateTime.MinValue;

            expected = DateTime.Now.AddDays(7 * 2);
            Assert.IsTrue(parser.TryParse("Something in 2 weeks",
                                          out parsedText,
                                          out dateTime),
                          "#5");
            Assert.AreEqual("Something", parsedText, "#6");
            Assert.AreEqual(expected.Year, dateTime.Year, "#7");
            Assert.AreEqual(expected.Month, dateTime.Month, "#8");
            Assert.AreEqual(expected.Day, dateTime.Day, "#9");
            dateTime = DateTime.MinValue;

            Assert.IsFalse(parser.TryParse("Something in -1 week",
                                           out parsedText,
                                           out dateTime),
                           "#10");
            dateTime = DateTime.MinValue;

            // Even though this is invalid English, we accept it
            expected = DateTime.Now.AddDays(7);
            Assert.IsTrue(parser.TryParse("Something in weeks",
                                          out parsedText,
                                          out dateTime),
                          "#11");
            Assert.AreEqual(expected.Year, dateTime.Year, "#12");
            Assert.AreEqual(expected.Month, dateTime.Month, "#13");
            Assert.AreEqual(expected.Day, dateTime.Day, "#14");
            dateTime = DateTime.MinValue;
        }
Пример #7
0
        public void DateSeparatedTest()
        {
            string     parsedText = null;
            DateTime   dateTime   = DateTime.MinValue;
            TaskParser parser     = TaskParser.Instance;

            DateTime expected = GetMonthDate(11, 12);

            Assert.IsTrue(parser.TryParse("Something 11/12",               // as in Monday
                                          out parsedText,
                                          out dateTime),
                          "#0");
            Assert.AreEqual("Something", parsedText, "#1");
            Assert.AreEqual(expected.Year, dateTime.Year, "#2");
            Assert.AreEqual(expected.Month, dateTime.Month, "#3");
            Assert.AreEqual(expected.Day, dateTime.Day, "#4");
            dateTime = DateTime.MinValue;

            expected = GetMonthDate(3, 11);
            Assert.IsTrue(parser.TryParse("Something 3-11",
                                          out parsedText,
                                          out dateTime),
                          "#5");
            Assert.AreEqual("Something", parsedText, "#6");
            Assert.AreEqual(expected.Year, dateTime.Year, "#7");
            Assert.AreEqual(expected.Month, dateTime.Month, "#8");
            Assert.AreEqual(expected.Day, dateTime.Day, "#9");
            dateTime = DateTime.MinValue;

            expected = new DateTime(DateTime.Now.Year + 1, 1, 22);
            Assert.IsTrue(parser.TryParse(string.Format("Something 1/22/{0}",
                                                        DateTime.Now.Year + 1),
                                          out parsedText,
                                          out dateTime),
                          "#10");
            Assert.AreEqual("Something", parsedText, "#11");
            Assert.AreEqual(expected.Year, dateTime.Year, "#12");
            Assert.AreEqual(expected.Month, dateTime.Month, "#13");
            Assert.AreEqual(expected.Day, dateTime.Day, "#14");
            dateTime = DateTime.MinValue;

            expected = new DateTime(2011, 11, 11);
            Assert.IsTrue(parser.TryParse("Something 11-11-11 soon!",
                                          out parsedText,
                                          out dateTime),
                          "#15");
            Assert.AreEqual("Something soon!", parsedText, "#16");
            Assert.AreEqual(expected.Year, dateTime.Year, "#17");
            Assert.AreEqual(expected.Month, dateTime.Month, "#18");
            Assert.AreEqual(expected.Day, dateTime.Day, "#19");
            dateTime = DateTime.MinValue;

            // The year doesn't make sense, but is still valid
            expected = new DateTime(102, 1, 13);
            Assert.IsTrue(parser.TryParse("Something 1-13-102 soon!!",
                                          out parsedText,
                                          out dateTime),
                          "#20");
            Assert.AreEqual("Something soon!!", parsedText, "#21");
            Assert.AreEqual(expected.Year, dateTime.Year, "#22");
            Assert.AreEqual(expected.Month, dateTime.Month, "#23");
            Assert.AreEqual(expected.Day, dateTime.Day, "#24");
            dateTime = DateTime.MinValue;

            // Matches "11/11"
            expected = GetMonthDate(11, 11);
            Assert.IsTrue(parser.TryParse("Buy beer 11/11/3 for party",
                                          out parsedText,
                                          out dateTime),
                          "#25");
            Assert.AreEqual("Buy beer/3 for party", parsedText, "#26");
            Assert.AreEqual(expected.Year, dateTime.Year, "#27");
            Assert.AreEqual(expected.Month, dateTime.Month, "#28");
            Assert.AreEqual(expected.Day, dateTime.Day, "#29");
        }
Пример #8
0
        public void DateTest()
        {
            string     parsedText = null;
            DateTime   dateTime   = DateTime.MinValue;
            TaskParser parser     = TaskParser.Instance;

            DateTime expected = GetMonthDate(12, 1);

            Assert.IsTrue(parser.TryParse("Something due by December 1st",
                                          out parsedText,
                                          out dateTime));
            Assert.AreEqual("Something", parsedText, "#0");
            Assert.AreEqual(expected.Year, dateTime.Year, "#1");
            Assert.AreEqual(expected.Month, dateTime.Month, "#2");
            Assert.AreEqual(expected.Day, dateTime.Day, "#3");
            dateTime = DateTime.MinValue;

            expected = GetMonthDate(12, 1);
            Assert.IsTrue(parser.TryParse("Something due Dec 1",
                                          out parsedText,
                                          out dateTime));
            Assert.AreEqual("Something", parsedText, "#4");
            Assert.AreEqual(expected.Year, dateTime.Year, "#5");
            Assert.AreEqual(expected.Month, dateTime.Month, "#6");
            Assert.AreEqual(expected.Day, dateTime.Day, "#7");
            dateTime = DateTime.MinValue;

            expected = GetMonthDate(12, -1);
            Assert.IsTrue(parser.TryParse("Something due before December",
                                          out parsedText,
                                          out dateTime));
            Assert.AreEqual("Something", parsedText, "#8");
            Assert.AreEqual(expected.Year, dateTime.Year, "#9");
            Assert.AreEqual(expected.Month, dateTime.Month, "#10");
            Assert.AreEqual(expected.Day, dateTime.Day, "#11");
            dateTime = DateTime.MinValue;

            expected = GetMonthDate(-1, 15);
            Assert.IsTrue(parser.TryParse("Something due by 15th",
                                          out parsedText,
                                          out dateTime));
            Assert.AreEqual("Something", parsedText, "#12");
            Assert.AreEqual(expected.Year, dateTime.Year, "#13");
            Assert.AreEqual(expected.Month, dateTime.Month, "#14");
            Assert.AreEqual(expected.Day, dateTime.Day, "#15");
            dateTime = DateTime.MinValue;

            // Invalid date, it should be 15th, but we accept it
            expected = GetMonthDate(-1, 15);
            Assert.IsTrue(parser.TryParse("Something important due by 15nd",
                                          out parsedText,
                                          out dateTime),
                          "#16");
            Assert.AreEqual("Something important", parsedText, "#17");
            Assert.AreEqual(expected.Year, dateTime.Year, "#18");
            Assert.AreEqual(expected.Month, dateTime.Month, "#19");
            Assert.AreEqual(expected.Day, dateTime.Day, "#20");

            expected = GetMonthDate(3, 15);
            Assert.IsTrue(parser.TryParse("Something important March 15th",
                                          out parsedText,
                                          out dateTime),
                          "#21");
            Assert.AreEqual("Something important", parsedText, "#22");
            Assert.AreEqual(expected.Year, dateTime.Year, "#23");
            Assert.AreEqual(expected.Month, dateTime.Month, "#24");
            Assert.AreEqual(expected.Day, dateTime.Day, "#25");

            expected = GetMonthDate(DateTime.Now.Month, 2);
            Assert.IsTrue(parser.TryParse(string.Format("Something important {0} 2nd",
                                                        expected.ToString("MMMM")),
                                          out parsedText,
                                          out dateTime),
                          "#26");
            Assert.AreEqual("Something important", parsedText, "#27");
            Assert.AreEqual(expected.Year, dateTime.Year, "#28");
            Assert.AreEqual(expected.Month, dateTime.Month, "#29");
            Assert.AreEqual(expected.Day, dateTime.Day, "#30");
        }