Exemplo n.º 1
0
 public void AddFirst()
 {
     TokenQueue tq = new TokenQueue("One Two");
     tq.ConsumeWord();
     tq.AddFirst("Three");
     Assert.AreEqual("Three Two", tq.Remainder());
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 private void ByAttribute()
 {
     TokenQueue cq = new TokenQueue(tq.ChompBalanced('[', ']')); // content queue
     string key = cq.ConsumeToAny(AttributeEvals); // eq, not, start, end, contain, match, (no val)
     Validate.NotEmpty(key);
     cq.ConsumeWhitespace();
     if (cq.IsEmpty())
     {
         if (key.StartsWith("^", StringComparison.Ordinal))
         {
             evals.Add(new Evaluator.AttributeStarting(key.Substring(1))); /*substring*/
         }
         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(), RegexOptions.Compiled)));
         }
         else
         {
             throw new Selector.SelectorParseException("Could not parse attribute query '{0}': unexpected token at '{1}'", query, cq.Remainder());
         }
     }
 }