Пример #1
0
        public void TestNameLiteralMatcher()
        {
            NameLiteralMatcher matcher   = new NameLiteralMatcher();
            StringTokenizer    data      = new StringTokenizer("'A' 'name_0xA2' '' 'n\\ame' 'Bob bobson' '\"Bob\"' 'eof");
            SourcePosition     streamPos = new SourcePosition(0, 0, 0);

            // Match basic name
            Assert.IsNotNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, " ");
            data.Advance();
            // Match name with underscore and digit
            Assert.AreEqual(matcher.MatchNext(data, ref streamPos, Log).Value, "name_0xA2");
            Assert.AreEqual(data.CurrentItem, " ");
            data.Advance();
            // Match empty name
            Assert.AreEqual(matcher.MatchNext(data, ref streamPos, Log).Value, "");
            Assert.AreEqual(data.CurrentItem, " ");
            data.Advance();
            // Fail escape char
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, "'");
            data.Advance(8);
            // Fail whitespace
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, "'");
            data.Advance(13);
            // Fail quotes
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, "'");
            data.Advance(8);
            // Ensure discarding of name that reaches eof without closing single-quote
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, "'");
        }
Пример #2
0
        public void TestNameLiteralMatcher()
        {
            NameLiteralMatcher matcher = new NameLiteralMatcher();
            StringTokenizer data = new StringTokenizer("'A' 'name_0xA2' '' 'n\\ame' 'Bob bobson' '\"Bob\"' 'eof");
            SourcePosition streamPos = new SourcePosition(0, 0, 0);

            // Match basic name
            Assert.IsNotNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, " ");
            data.Advance();
            // Match name with underscore and digit
            Assert.AreEqual(matcher.MatchNext(data, ref streamPos, Log).Value, "name_0xA2");
            Assert.AreEqual(data.CurrentItem, " ");
            data.Advance();
            // Match empty name
            Assert.AreEqual(matcher.MatchNext(data, ref streamPos, Log).Value, "");
            Assert.AreEqual(data.CurrentItem, " ");
            data.Advance();
            // Fail escape char
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, "'");
            data.Advance(8);
            // Fail whitespace
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, "'");
            data.Advance(13);
            // Fail quotes
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, "'");
            data.Advance(8);
            // Ensure discarding of name that reaches eof without closing single-quote
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, "'");
        }