public void ParseRecordExpressionTest()
        {
            //Create parser and parse tokens
            ExpressionParser expressionParser = new ExpressionParser(Init("{token1:\"token1\", token2:10, token3:'symbol}"));
            RecordExpression expression       = expressionParser.ParseRecordExpression();

            //Test Record contents
            Assert.AreEqual(3, expression.GetRecords().Count);
            List <ISyntaxNode> .Enumerator recordEnumerator = expression.GetRecords().GetEnumerator();

            recordEnumerator.MoveNext();
            KeyValuePair current = (KeyValuePair)recordEnumerator.Current;

            Assert.AreEqual("token1", current.GetKey());
            Assert.AreEqual(typeof(TextExpression), current.GetValue().GetType());
            Assert.AreEqual("\"token1\"", current.GetValue().ToString());

            recordEnumerator.MoveNext();
            current = (KeyValuePair)recordEnumerator.Current;

            Assert.AreEqual("token2", current.GetKey());
            Assert.AreEqual(typeof(NumExpression), current.GetValue().GetType());
            Assert.AreEqual(10, ((NumExpression)current.GetValue()).GetNum());

            recordEnumerator.MoveNext();
            current = (KeyValuePair)recordEnumerator.Current;

            Assert.AreEqual("token3", current.GetKey());
            Assert.AreEqual(typeof(SymExpression), current.GetValue().GetType());
            Assert.AreEqual("'symbol", current.GetValue().ToString());
        }
 public bool Add(KeyValuePair <KEY, VALUE> item)
 {
     if (!backingDictionary.ContainsKey(item.GetKey()))
     {
         orderedQueue.Add(item.GetKey());
     }
     backingDictionary[item.GetKey()] = item.GetValue();
     return(true);
 }
Beispiel #3
0
 public bool Remove(KeyValuePair <KEY, VALUE> item)
 {
     if (backingDictionary.ContainsKey(item.GetKey()) &&
         backingDictionary[item.GetKey()].Equals(item.GetValue()))
     {
         Remove(item.GetKey());
     }
     return(false);
 }
Beispiel #4
0
 public override bool Equals(object o)
 {
     if (o is KeyValuePair <KEY, VALUE> )
     {
         KeyValuePair <KEY, VALUE> p = (KeyValuePair <KEY, VALUE>)o;
         return(GetKey().Equals(p.GetKey()) &&
                GetValue().Equals(p.GetValue()));
     }
     return(false);
 }
        public void ParseKeyValuePairTest()
        {
            //Create parser and parse tokens
            ExpressionParser expressionParser = new ExpressionParser(Init("token1:\"value1\""));
            KeyValuePair     keyValuePair     = expressionParser.ParseKeyValuePair();

            //Check key
            Assert.AreEqual("token1", keyValuePair.GetKey());

            //Check value
            Assert.AreEqual(typeof(TextExpression), keyValuePair.GetValue().GetType());
            TextExpression textExpression = (TextExpression)keyValuePair.GetValue();

            Assert.AreEqual("value1", textExpression.GetText());
        }
Beispiel #6
0
        /// <summary>
        /// Interpret RecordExpression
        /// </summary>
        /// <param name="expression">RecordExpression to interpret</param>
        public override void Visit(RecordExpression expression)
        {
            //convert record to textvalue
            String tempRecord = "{";

            for (int i = 0; i < expression.GetRecords().Count; i++)
            {
                KeyValuePair pair = (KeyValuePair)expression.GetRecords().Get(i);

                //Convert KeyValuePair to textual representation
                tempRecord += pair.GetKey() + ":";
                pair.GetValue().AcceptVisitor(this);
                tempRecord += TextValue;

                //Add seperator
                if (i != (expression.GetRecords().Count - 1))
                {
                    tempRecord += ",";
                }
            }

            tempRecord += "}";
            TextValue   = tempRecord;
        }
 public bool Contains(KeyValuePair <KEY, VALUE> item)
 {
     return(backingDictionary.ContainsKey(item.GetKey()) &&
            backingDictionary[item.GetKey()].Equals(item.GetValue()));
 }
Beispiel #8
0
 public bool Add(KeyValuePair <KEY, VALUE> item)
 {
     backingDictionary.Add(item.GetKey(), item.GetValue());
     return(true);
 }