Example #1
0
        public void TryCreate()
        {
            var st = new StringTable(0);

            PartialSymbol p;

            XAssert.IsTrue(PartialSymbol.TryCreate(st, @"AAA.CCC", out p));
            XAssert.AreEqual(@"AAA.CCC", p.ToString(st));

            XAssert.IsFalse(PartialSymbol.TryCreate(st, @"C.:AAA", out p));
            XAssert.IsFalse(PartialSymbol.TryCreate(st, @"AAA:", out p));
            XAssert.IsFalse(PartialSymbol.TryCreate(st, @":AAA", out p));
            XAssert.IsFalse(PartialSymbol.TryCreate(st, @"..", out p));
            XAssert.IsFalse(PartialSymbol.TryCreate(st, @".", out p));
            XAssert.IsFalse(PartialSymbol.TryCreate(st, @"B.", out p));
            XAssert.IsFalse(PartialSymbol.TryCreate(st, @"B..", out p));

            p = PartialSymbol.Create(st, string.Empty);
            XAssert.AreEqual(string.Empty, p.ToString(st));

            p = PartialSymbol.Create(st, "BBB");
            XAssert.AreEqual("BBB", p.ToString(st));

            SymbolAtom a1 = SymbolAtom.Create(st, "AAA");
            SymbolAtom a2 = SymbolAtom.Create(st, "BBB");
            SymbolAtom a3 = SymbolAtom.Create(st, "CCC");

            p = PartialSymbol.Create(a1, a2, a3);
            XAssert.AreEqual(@"AAA.BBB.CCC", p.ToString(st));
        }
Example #2
0
        public void Combine()
        {
            var           st = new StringTable(0);
            PartialSymbol p1 = PartialSymbol.Create(st, "AAA");
            SymbolAtom    a1 = SymbolAtom.Create(st, "BBB");
            PartialSymbol p2 = p1.Combine(a1);

            XAssert.AreEqual(@"AAA.BBB", p2.ToString(st));

            p1 = PartialSymbol.Create(st, string.Empty);
            p2 = p1.Combine(a1);
            XAssert.AreEqual(@"BBB", p2.ToString(st));

            p1 = PartialSymbol.Create(st, "AAA");
            SymbolAtom a2 = SymbolAtom.Create(st, "CCC");

            p2 = p1.Combine(a1, a2);
            XAssert.AreEqual(@"AAA.BBB.CCC", p2.ToString(st));

            p1 = PartialSymbol.Create(st, "AAA");
            a2 = SymbolAtom.Create(st, "CCC");
            SymbolAtom a3 = SymbolAtom.Create(st, "DDD");

            p2 = p1.Combine(a1, a2, a3);
            XAssert.AreEqual(@"AAA.BBB.CCC.DDD", p2.ToString(st));

            PartialSymbol p3 = p1.Combine(p2);

            XAssert.AreEqual(@"AAA.AAA.BBB.CCC.DDD", p3.ToString(st));
        }
Example #3
0
        public void Conversion()
        {
            var           st = new StringTable(0);
            SymbolAtom    a1 = SymbolAtom.Create(st, "AAA");
            PartialSymbol p1 = PartialSymbol.Create(a1);

            XAssert.AreEqual("AAA", p1.ToString(st));
        }
Example #4
0
        public void Concat()
        {
            var st = new StringTable(0);

            PartialSymbol rp  = PartialSymbol.Create(st, @"AAA.BBB");
            SymbolAtom    p1  = SymbolAtom.Create(st, "XXX");
            PartialSymbol rp2 = rp.Concat(st, p1);

            XAssert.AreEqual(@"AAA.BBBXXX", rp2.ToString(st));
        }
Example #5
0
        public void ToStringTest()
        {
            var st = new StringTable(0);

            Assert.Throws <NotImplementedException>(() =>
            {
                PartialSymbol rp = PartialSymbol.Create(st, @"AAA");
#pragma warning disable 618
                rp.ToString();
#pragma warning restore 618
            });
        }
Example #6
0
        public void GetName()
        {
            var st = new StringTable(0);

            PartialSymbol rp   = PartialSymbol.Create(st, @"AAA");
            SymbolAtom    atom = rp.GetName();

            XAssert.AreEqual(@"AAA", atom.ToString(st));

            rp   = PartialSymbol.Create(st, @"AAA.BBB");
            atom = rp.GetName();
            XAssert.AreEqual(@"BBB", atom.ToString(st));
        }
Example #7
0
        public void GetParent()
        {
            var st = new StringTable(0);

            PartialSymbol rp     = PartialSymbol.Create(st, @"AAA");
            PartialSymbol parent = rp.GetParent();

            XAssert.AreEqual(string.Empty, parent.ToString(st));

            rp     = PartialSymbol.Create(st, @"AAA.BBB");
            parent = rp.GetParent();
            XAssert.AreEqual(@"AAA", parent.ToString(st));

            rp     = PartialSymbol.Create(st, @"AAA.BBB.CCC");
            parent = rp.GetParent();
            XAssert.AreEqual(@"AAA.BBB", parent.ToString(st));
        }
Example #8
0
        public void IsInitialized()
        {
            PartialSymbol p = default(PartialSymbol);

            XAssert.IsFalse(p.IsValid);

            var st = new StringTable(0);

            p = PartialSymbol.Create(st, @"AAA.CCC");
            XAssert.AreEqual(@"AAA.CCC", p.ToString(st));
            XAssert.IsTrue(p.IsValid);
            XAssert.IsFalse(p.IsEmpty);

            p = PartialSymbol.Create(st, string.Empty);
            XAssert.IsTrue(p.IsValid);
            XAssert.IsTrue(p.IsEmpty);
        }
Example #9
0
        public void Combine()
        {
            var        idt = new SymbolTable();
            FullSymbol a1  = FullSymbol.Create(idt, @"C");
            SymbolAtom p1  = SymbolAtom.Create(idt.StringTable, "A");
            FullSymbol a2  = a1.Combine(idt, p1);

            XAssert.AreEqual(@"C.A", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C.X");
            p1 = SymbolAtom.Create(idt.StringTable, "A");
            a2 = a1.Combine(idt, p1);
            XAssert.AreEqual(@"C.X.A", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C.X");
            p1 = SymbolAtom.Create(idt.StringTable, "A");
            SymbolAtom p2 = SymbolAtom.Create(idt.StringTable, "B");

            a2 = a1.Combine(idt, p1, p2);
            XAssert.AreEqual(@"C.X.A.B", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C.X");
            p1 = SymbolAtom.Create(idt.StringTable, "A");
            p2 = SymbolAtom.Create(idt.StringTable, "B");
            SymbolAtom p3 = SymbolAtom.Create(idt.StringTable, "C");

            a2 = a1.Combine(idt, p1, p2, p3);
            XAssert.AreEqual(@"C.X.A.B.C", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C");
            PartialSymbol rp = PartialSymbol.Create(idt.StringTable, @"A.B");

            a2 = a1.Combine(idt, rp);
            XAssert.AreEqual(@"C.A.B", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C.X");
            rp = PartialSymbol.Create(idt.StringTable, @"A.B");
            a2 = a1.Combine(idt, rp);
            XAssert.AreEqual(@"C.X.A.B", a2.ToString(idt));
        }
Example #10
0
        public void Equality()
        {
            var           st = new StringTable(0);
            PartialSymbol a1 = PartialSymbol.Create(st, @"AAA.CCC");
            PartialSymbol a2 = PartialSymbol.Create(st, @"AAA.CCC");
            PartialSymbol a3 = PartialSymbol.Create(st, @"BBB.CCC");

            XAssert.IsTrue(a1.Equals(a1));
            XAssert.IsTrue(a1.Equals(a2));
            XAssert.IsTrue(a2.Equals(a1));
            XAssert.IsFalse(a1.Equals(a3));
            XAssert.IsFalse(a2.Equals(a3));

            XAssert.IsTrue(a1.Equals((object)a1));
            XAssert.IsTrue(a1.Equals((object)a2));
            XAssert.IsTrue(a2.Equals((object)a1));
            XAssert.IsFalse(a1.Equals((object)a3));
            XAssert.IsFalse(a2.Equals((object)a3));
            XAssert.IsFalse(a2.Equals("XYZ"));

            XAssert.IsTrue(a1 == a2);
            XAssert.IsTrue(a2 == a1);
            XAssert.IsFalse(a1 == a3);
            XAssert.IsFalse(a2 == a3);

            XAssert.IsFalse(a1 != a2);
            XAssert.IsFalse(a2 != a1);
            XAssert.IsTrue(a1 != a3);
            XAssert.IsTrue(a2 != a3);

            int h1 = a1.GetHashCode();
            int h2 = a2.GetHashCode();

            XAssert.AreEqual(h1, h2);

            a1 = PartialSymbol.Create(st, string.Empty);
            XAssert.AreEqual(0, a1.GetHashCode());

            XAssert.IsFalse(a1.Equals(a2));
        }