public void TestGetQuotedString_MissingCloseQuote()
        {
            var  cursor    = new PatternCursor("'abc");
            char openQuote = GetNextCharacter(cursor);

            Assert.Throws <InvalidPatternException>(() => cursor.GetQuotedString(openQuote));
        }
        public void TestGetQuotedString_EscapeAtEnd()
        {
            var cursor = new PatternCursor("'abc\\");

            Assert.AreEqual('\'', GetNextCharacter(cursor));
            Assert.Throws <InvalidPatternException>(() => cursor.GetQuotedString('\''));
        }
Exemple #3
0
        public void GetQuotedString_Invalid(string pattern)
        {
            var cursor = new PatternCursor(pattern);

            Assert.AreEqual('\'', GetNextCharacter(cursor));
            Assert.Throws <InvalidPatternException>(() => cursor.GetQuotedString('\''));
        }
        public void TestGetQuotedString_HandlesEscapedCloseQuote()
        {
            var    cursor    = new PatternCursor("'ab\\'c'");
            char   openQuote = GetNextCharacter(cursor);
            string actual    = cursor.GetQuotedString(openQuote);

            Assert.AreEqual("ab'c", actual);
            Assert.IsFalse(cursor.MoveNext());
        }
        public void TestGetQuotedString_HandlesDoubleQuote()
        {
            var    cursor    = new PatternCursor("\"abc\"");
            char   openQuote = GetNextCharacter(cursor);
            string actual    = cursor.GetQuotedString(openQuote);

            Assert.AreEqual("abc", actual);
            Assert.IsFalse(cursor.MoveNext());
        }
        public void TestGetQuotedString_Empty()
        {
            var    cursor    = new PatternCursor("''");
            char   openQuote = GetNextCharacter(cursor);
            string actual    = cursor.GetQuotedString(openQuote);

            Assert.AreEqual(string.Empty, actual);
            Assert.IsFalse(cursor.MoveNext());
        }
        public void TestGetQuotedString_HandlesOtherQuote()
        {
            var cursor = new PatternCursor("[abc]");

            GetNextCharacter(cursor);
            string actual = cursor.GetQuotedString(']');

            Assert.AreEqual("abc", actual);
            Assert.IsFalse(cursor.MoveNext());
        }
        public void TestGetQuotedString()
        {
            var cursor = new PatternCursor("'abc'");

            Assert.AreEqual('\'', GetNextCharacter(cursor));
            string actual = cursor.GetQuotedString('\'');

            Assert.AreEqual("abc", actual);
            Assert.IsFalse(cursor.MoveNext());
        }
Exemple #9
0
        public void GetQuotedString_Valid(string pattern, string expected)
        {
            var cursor = new PatternCursor(pattern);

            Assert.AreEqual('\'', GetNextCharacter(cursor));
            string actual = cursor.GetQuotedString('\'');

            Assert.AreEqual(expected, actual);
            Assert.IsFalse(cursor.MoveNext());
        }
        public void TestGetQuotedString_NotAtEnd()
        {
            var    cursor    = new PatternCursor("'abc'more");
            char   openQuote = GetNextCharacter(cursor);
            string actual    = cursor.GetQuotedString(openQuote);

            Assert.AreEqual("abc", actual);
            ValidateCurrentCharacter(cursor, 4, '\'');

            Assert.AreEqual('m', GetNextCharacter(cursor));
        }
Exemple #11
0
        private static void AssertValidNodaPattern(CultureInfo culture, string pattern)
        {
            PatternCursor cursor = new PatternCursor(pattern);

            while (cursor.MoveNext())
            {
                if (cursor.Current == '\'')
                {
                    cursor.GetQuotedString('\'');
                }
                else
                {
                    Assert.IsTrue(ExpectedCharacters.Contains(cursor.Current),
                                  "Pattern '" + pattern + "' contains unquoted, unexpected characters");
                }
            }
            // Check that the pattern parses
            LocalTimePattern.Create(pattern, culture);
        }
        private static void AssertValidNodaPattern(CultureInfo culture, string pattern)
        {
            PatternCursor cursor = new PatternCursor(pattern);

            while (cursor.MoveNext())
            {
                if (cursor.Current == '\'')
                {
                    cursor.GetQuotedString('\'');
                }
                else
                {
                    // We'll never do anything "special" with non-ascii characters anyway,
                    // so we don't mind if they're not quoted.
                    if (cursor.Current < '\u0080')
                    {
                        Assert.IsTrue(ExpectedCharacters.Contains(cursor.Current),
                                      "Pattern '" + pattern + "' contains unquoted, unexpected characters");
                    }
                }
            }
            // Check that the pattern parses
            LocalTimePattern.Create(pattern, culture);
        }