Ejemplo n.º 1
0
        public void MovingBetweenTokens()
        {
            var           query = new TagQuery();
            TagQueryToken token;

            query.SetQuery("/first/second/third/fourth/fifth/sixth");
            Assert.AreEqual(6, query.Count());
            Assert.AreEqual(6, query.TokensLeft());
            token = query.Previous();
            Assert.IsNull(token);
            Assert.AreEqual(6, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("first", token.Name);
            Assert.AreEqual(5, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("second", token.Name);
            Assert.AreEqual(4, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("third", token.Name);
            Assert.AreEqual(3, query.TokensLeft());
            token = query.Previous();
            Assert.AreEqual("second", token.Name);
            Assert.AreEqual(4, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("third", token.Name);
            Assert.AreEqual(3, query.TokensLeft());
            token = query.Peek();
            Assert.AreEqual("fourth", token.Name);
            Assert.AreEqual(3, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("fourth", token.Name);
            Assert.AreEqual(2, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("fifth", token.Name);
            Assert.AreEqual(1, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("sixth", token.Name);
            Assert.AreEqual(0, query.TokensLeft());
            token = query.Next();
            Assert.IsNull(token);
            Assert.AreEqual(0, query.TokensLeft());
            token = query.Previous();
            Assert.AreEqual("fifth", token.Name);
            Assert.AreEqual(1, query.TokensLeft());
            query.MoveFirst();
            Assert.AreEqual(6, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("first", token.Name);
            Assert.AreEqual(5, query.TokensLeft());
        }
Ejemplo n.º 2
0
        public void Tokenization()
        {
            var           query = new TagQuery();
            TagQueryToken token;

            // Expected: first
            query = new TagQuery("/first");
            Assert.AreEqual(1, query.Count());
            Assert.AreEqual(1, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("first", token.Name);
            Assert.AreSame(query, token.Query);
            Assert.AreEqual(0, query.TokensLeft());
            token = query.Next();
            Assert.IsNull(token);
            Assert.AreEqual(0, query.TokensLeft());

            // Expected: first
            query.SetQuery("/first");
            Assert.AreEqual(1, query.Count());
            Assert.AreEqual(1, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("first", token.Name);
            Assert.AreSame(query, token.Query);
            Assert.AreEqual(0, query.TokensLeft());
            token = query.Next();
            Assert.IsNull(token);
            Assert.AreEqual(0, query.TokensLeft());

            // Expected: first, second, third
            query.SetQuery("/first/second/third");
            Assert.AreEqual(3, query.Count());
            Assert.AreEqual(3, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("first", token.Name);
            Assert.AreSame(query, token.Query);
            Assert.AreEqual(2, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("second", token.Name);
            Assert.AreSame(query, token.Query);
            Assert.AreEqual(1, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("third", token.Name);
            Assert.AreSame(query, token.Query);
            Assert.AreEqual(0, query.TokensLeft());
            token = query.Next();
            Assert.IsNull(token);
            Assert.AreEqual(0, query.TokensLeft());

            // Expected: first/slash, second\backslash, third!, extended/ÅÄÖ
            query.SetQuery(@"/first\/slash/second\\backslash/third!/extended\/ÅÄÖ");
            Assert.AreEqual(4, query.Count());
            Assert.AreEqual(4, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("first/slash", token.Name);
            Assert.AreSame(query, token.Query);
            Assert.AreEqual(3, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual(@"second\backslash", token.Name);
            Assert.AreSame(query, token.Query);
            Assert.AreEqual(2, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("third!", token.Name);
            Assert.AreSame(query, token.Query);
            Assert.AreEqual(1, query.TokensLeft());
            token = query.Next();
            Assert.AreEqual("extended/ÅÄÖ", token.Name);
            Assert.AreSame(query, token.Query);
            Assert.AreEqual(0, query.TokensLeft());
            token = query.Next();
            Assert.IsNull(token);
            Assert.AreEqual(0, query.TokensLeft());
        }