예제 #1
0
        public void chompBalanced()
        {
            TokenQueue tq = new TokenQueue(":contains(one (two) three) four");
            string pre = tq.ConsumeTo("(");
            string guts = tq.ChompBalanced('(', ')');
            string remainder = tq.Remainder();

            Assert.AreEqual(":contains", pre);
            Assert.AreEqual("one (two) three", guts);
            Assert.AreEqual(" four", remainder);
        }
예제 #2
0
        private void ByAttribute()
        {
            TokenQueue cq = new TokenQueue(_tq.ChompBalanced('[', ']')); // content queue
            string key = cq.ConsumeToAny("=", "!=", "^=", "$=", "*=", "~="); // eq, not, start, end, contain, match, (no val)

            if (string.IsNullOrEmpty(key))
            {
                throw new Exception("key is empty.");
            }

            cq.ConsumeWhitespace();

            if (cq.IsEmpty)
            {
                if (key.StartsWith("^"))
                {
                    _evals.Add(new Evaluator.AttributeStarting(key.Substring(1)));
                }
                else
                {
                    _evals.Add(new Evaluator.Attribute(key));
                }
            }
            else
            {
                if (cq.MatchChomp("="))
                {
                    _evals.Add(new Evaluator.AttributeWithValue(key, cq.Remainder()));
                }
                else if (cq.MatchChomp("!="))
                {
                    _evals.Add(new Evaluator.AttributeWithValueNot(key, cq.Remainder()));
                }
                else if (cq.MatchChomp("^="))
                {
                    _evals.Add(new Evaluator.AttributeWithValueStarting(key, cq.Remainder()));
                }
                else if (cq.MatchChomp("$="))
                {
                    _evals.Add(new Evaluator.AttributeWithValueEnding(key, cq.Remainder()));
                }
                else if (cq.MatchChomp("*="))
                {
                    _evals.Add(new Evaluator.AttributeWithValueContaining(key, cq.Remainder()));
                }
                else if (cq.MatchChomp("~="))
                {
                    _evals.Add(new Evaluator.AttributeWithValueMatching(key, new Regex(cq.Remainder())));
                }
                else
                {
                    throw new Selector.SelectorParseException("Could not parse attribute query '{0}': unexpected token at '{1}'", _query, cq.Remainder());
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Create a new QueryParser.
 /// </summary>
 /// <param name="query">query CSS query</param>
 private QueryParser(string query)
 {
     this._query = query;
     this._tq = new TokenQueue(query);
 }
예제 #4
0
 public void chompBalancedMatchesAsMuchAsPossible()
 {
     TokenQueue tq = new TokenQueue("unbalanced(something(or another");
     tq.ConsumeTo("(");
     string match = tq.ChompBalanced('(', ')');
     Assert.AreEqual("something(or another", match);
 }
예제 #5
0
 public void addFirst()
 {
     TokenQueue tq = new TokenQueue("One Two");
     tq.ConsumeWord();
     tq.AddFirst("Three");
     Assert.AreEqual("Three Two", tq.Remainder());
 }
예제 #6
0
        public void chompToIgnoreCase()
        {
            string t = "<textarea>one < two </TEXTarea>";
            TokenQueue tq = new TokenQueue(t);
            string data = tq.ChompToIgnoreCase("</textarea");
            Assert.AreEqual("<textarea>one < two ", data);

            tq = new TokenQueue("<textarea> one two < three </oops>");
            data = tq.ChompToIgnoreCase("</textarea");
            Assert.AreEqual("<textarea> one two < three </oops>", data);
        }