예제 #1
0
        private ITuple _2EntriesHaveNotKey()
        {
            IList <ITupleEntry> col = new List <ITupleEntry>();

            col.Add(TupleEntry.OfPair(null, "v0"));
            col.Add(TupleEntry.OfValue("v1"));
            return(Tuple.FromCollection(col));
        }
예제 #2
0
        public void FromCollection_WhenCollectionIncludesNullSpecified_ThrowsException()
        {
            // Arrange

            // Act

            // Assert
            Assert.Throws <System.NullReferenceException>(() =>
            {
                Tuple.FromCollection(new ITupleEntry[] { TupleEntry.OfValue("v0"), null }.ToList());
            });
        }
        public void OfValue_WhenNullSpecified_ThrowsException()
        {
            // Arrange

            // Act

            // Assert
            Assert.Throws <ArgumentNullException>(() =>
            {
                ITupleEntry e0 = TupleEntry.OfValue(null);
            });
        }
        public void OfValue_WhenNonEmptyStringSpecified_ReturnsInstanceHasNotKey()
        {
            // Arrange

            // Act
            ITupleEntry e0 = TupleEntry.OfValue("v0");

            // Assert
            Assert.AreEqual(false, e0.HasKey);
            Assert.AreEqual(null, e0.Key);
            Assert.AreEqual("v0", e0.Value);
        }
예제 #5
0
        public void OfValue_WhenNotNullValueSpecified_ReturnsInstance()
        {
            // Arrange
            ITuple t0 = Tuple.FromCollection(new ITupleEntry[] {
                TupleEntry.OfValue("v0"), TupleEntry.OfPair("k1", "v1")
            }.ToList());
            IParameterValue pv0 = TupleParameterValue.OfValue(t0);
            IParameterValue pv1 = TupleParameterValue.OfValue(Tuple.Empty);

            // Act

            // Assert
            Assert.That(pv0.StringValue, Is.EqualTo("(v0,k1=v1)"));
            Assert.That(pv1.StringValue, Is.EqualTo("()"));
        }
        public void Equals_When2InstanceRepresentSameValue_ReturnsTrue()
        {
            // Arrange
            ITupleEntry e0 = TupleEntry.OfPair("a", "b");
            ITupleEntry e1 = TupleEntry.OfPair("a", "c");
            ITupleEntry e2 = TupleEntry.OfPair("a", "b");
            ITupleEntry e3 = TupleEntry.OfPair(null, "b");
            ITupleEntry e4 = TupleEntry.OfValue("b");

            // Act

            // Assert
            Assert.AreEqual(false, e0.Equals(null));
            Assert.AreEqual(false, e0.Equals(e1));
            Assert.AreEqual(true, e0.Equals(e2));
            Assert.AreEqual(false, e0.Equals(e3));
            Assert.AreEqual(true, e4.Equals(e3));
        }
        public ITuple Parse(Input input)
        {
            Check(input, '(');
            input.GoNext();
            List <ITupleEntry> entries = new List <ITupleEntry>();

            while (!input.EndOfFile && input.Current != ')')
            {
                StringBuilder sb0    = new StringBuilder();
                StringBuilder sb1    = new StringBuilder();
                bool          hasKey = false;

                while (!input.EndOfFile && (input.Current != ')' && input.Current != ','))
                {
                    if (input.Current == '=')
                    {
                        hasKey = true;
                        input.GoNext();
                    }
                    (hasKey ? sb1 : sb0).Append(input.Current);
                    input.GoNext();
                }
                if (hasKey)
                {
                    entries.Add(TupleEntry.OfPair(sb0.ToString(), sb1.ToString()));
                }
                else
                {
                    entries.Add(TupleEntry.OfValue(sb0.ToString()));
                }
                if (input.Current == ')')
                {
                    break;
                }
                input.GoNext();
            }
            Check(input, ')');
            input.GoNext();
            return(Tuple.FromCollection(entries));
        }