示例#1
0
        public void TestSymbolHashCode()
        {
            string s = "foo";

            ISymbol  sym1    = TransitFactory.Symbol("foo");
            ISymbol  sym2    = TransitFactory.Symbol("!foo".Substring(1));
            ISymbol  sym3    = TransitFactory.Symbol("bar");
            IKeyword keyword = TransitFactory.Keyword("bar");

            Assert.AreEqual(sym1.GetHashCode(), sym2.GetHashCode());
            Assert.IsFalse(sym3.GetHashCode() == sym1.GetHashCode());
            Assert.IsFalse(keyword.GetHashCode() == sym1.GetHashCode());
            Assert.IsFalse(s.GetHashCode() == sym1.GetHashCode());
        }
示例#2
0
        public void TestKeywordHashCode()
        {
            string s = "foo";

            IKeyword k1     = TransitFactory.Keyword("foo");
            IKeyword k2     = TransitFactory.Keyword("!foo".Substring(1));
            IKeyword k3     = TransitFactory.Keyword("bar");
            ISymbol  symbol = TransitFactory.Symbol("bar");

            Assert.AreEqual(k1.GetHashCode(), k2.GetHashCode());
            Assert.IsFalse(k3.GetHashCode() == k1.GetHashCode());
            Assert.IsFalse(symbol.GetHashCode() == k1.GetHashCode());
            Assert.IsFalse(s.GetHashCode() == k1.GetHashCode());
        }
示例#3
0
        public void TestUseISymbolAsDictionaryKey()
        {
            IDictionary <object, object> d = new Dictionary <object, object>();

            d.Add(TransitFactory.Symbol("foo"), 1);
            d.Add("foo", 2);
            d.Add(TransitFactory.Symbol("bar"), 3);
            d.Add("bar", 4);

            Assert.AreEqual(1, d[TransitFactory.Symbol("foo")]);
            Assert.AreEqual(2, d["foo"]);
            Assert.AreEqual(3, d[TransitFactory.Symbol("bar")]);
            Assert.AreEqual(4, d["bar"]);
        }
示例#4
0
        public void TestSymbolEquality()
        {
            string s = "foo";

            ISymbol sym1 = TransitFactory.Symbol("foo");
            ISymbol sym2 = TransitFactory.Symbol("!foo".Substring(1));
            ISymbol sym3 = TransitFactory.Symbol("bar");

            Assert.AreEqual(sym1, sym2);
            Assert.AreEqual(sym2, sym1);
            Assert.IsFalse(sym1.Equals(sym3));
            Assert.IsFalse(sym3.Equals(sym1));
            Assert.IsFalse(s.Equals(sym1));
            Assert.IsFalse(sym1.Equals(s));
        }
示例#5
0
        public void TestSymbolComparator()
        {
            List <ISymbol> l = new List <ISymbol> {
                { TransitFactory.Symbol("bbb") },
                { TransitFactory.Symbol("ccc") },
                { TransitFactory.Symbol("abc") },
                { TransitFactory.Symbol("dab") }
            };

            l.Sort();

            Assert.AreEqual("abc", l[0].ToString());
            Assert.AreEqual("bbb", l[1].ToString());
            Assert.AreEqual("ccc", l[2].ToString());
            Assert.AreEqual("dab", l[3].ToString());
        }
示例#6
0
 public void TestWriteSymbol()
 {
     Assert.AreEqual(ScalarVerbose("\"~$foo\""), WriteJsonVerbose(TransitFactory.Symbol("foo")));
 }
示例#7
0
 public object FromRepresentation(object representation)
 {
     return(TransitFactory.Symbol((string)representation));
 }