Ejemplo n.º 1
0
        public void TryParseDateFails(string[] tokens, int startIdx)
        {
            DateArgumentToken token = new DateArgumentToken("arg", false);

            var result = token.Matches(tokens, startIdx);

            DateTime parsedDate;
            bool     argValueExists = result.TryGetArgValue(token, out parsedDate);

            Assert.Equal(TokenMatchResult.None, result);
            Assert.False(argValueExists);
        }
Ejemplo n.º 2
0
        public static bool TryMatchDate(string dateStr, out DateTime date)
        {
            string[]      inputTokens = CommandParser.Tokenize(dateStr);
            int           startIdx    = 0;
            ArgumentToken token       = new DateArgumentToken("arg", false);

            if (TryMatchDate(token, DateTime.Today, inputTokens, startIdx, out TokenMatchResult result))
            {
                result.TryGetArgValue(token, out date);
                return(true);
            }

            date = DateTime.Today;
            return(false);
        }
Ejemplo n.º 3
0
        public void TryParseExplicitDate(string[] tokens, int startIdx, string expectedDateStr)
        {
            DateTime expected = DateTime.Parse(expectedDateStr);

            DateArgumentToken token = new DateArgumentToken("arg", false);

            var result = token.Matches(tokens, startIdx);

            DateTime parsedDate;
            bool     argValueExists = result.TryGetArgValue(token, out parsedDate);


            Assert.True(result.MatchOutcome == MatchOutcome.Full);
            Assert.True(argValueExists);
            Assert.Equal(expected, parsedDate);
        }
Ejemplo n.º 4
0
        public void TryParseYesterday()
        {
            DateTime currentDate = DateTime.Parse("01/02/2020");
            DateTime expected    = DateTime.Parse("01/01/2020");

            DateArgumentToken token = new DateArgumentToken("arg", false, currentDate);

            var result = token.Matches(new [] { "yesterday" }, 0);

            DateTime parsedDate;
            bool     argValueExists = result.TryGetArgValue(token, out parsedDate);


            Assert.True(result.MatchOutcome == MatchOutcome.Full);
            Assert.True(argValueExists);
            Assert.Equal(expected, parsedDate);
        }