Ejemplo n.º 1
0
        public void Add_1()
        {
            var t1 = new InlineTag(Tag.S, "id", "rid", "name", "ctype", "display", "code");
            var t2 = new InlineTag(Tag.S, "ID", "RID", "NAME", "CTYPE", "DISPLAY", "CODE");

            var s = new InlineBuilder();

            s.Is();
            s.Add("");
            s.Is();
            s.Add("abc");
            s.Is("abc");
            s.Add("def");
            s.Is("abcdef");
            s.Add("");
            s.Is("abcdef");
            s.Add(t1);
            s.Is("abcdef", t1);
            s.Add("");
            s.Is("abcdef", t1);
            s.Add(t2);
            s.Is("abcdef", t1, t2);
            s.Add("");
            s.Is("abcdef", t1, t2);
            s.Add("xyz");
            s.Is("abcdef", t1, t2, "xyz");
        }
Ejemplo n.º 2
0
        public void Append_1()
        {
            var t1 = new InlineTag(Tag.S, "*", "*", "t1", null, null, null);
            var t2 = new InlineTag(Tag.S, "*", "*", "t2", null, null, null);

            var s = new InlineBuilder();

            s.Is();
            s.Append("");
            s.Is();
            s.Append("abc");
            s.Is("abc");
            s.Append("def");
            s.Is(new InlineText("abcdef"));
            s.Append("");
            s.Is(new InlineText("abcdef"));
            s.Append(t1);
            s.Is(new InlineText("abcdef"), t1);
            s.Append(t2);
            s.Is(new InlineText("abcdef"), t1, t2);
            s.Append("");
            s.Is(new InlineText("abcdef"), t1, t2);
            s.Append("xyz");
            s.Is(new InlineText("abcdef"), t1, t2, new InlineText("xyz"));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Inline"/> class.
 /// </summary>
 internal Inline(InlineTag tag, string content, int startIndex, int length)
 {
     this.Tag = tag;
     this.LiteralContentValue.Source     = content;
     this.LiteralContentValue.StartIndex = startIndex;
     this.LiteralContentValue.Length     = length;
 }
Ejemplo n.º 4
0
        public void Add_4()
        {
            var t1 = new InlineTag(Tag.S, "id", "rid", "name", "ctype", "display", "code");
            var t2 = new InlineTag(Tag.S, "ID", "RID", "NAME", "CTYPE", "DISPLAY", "CODE");

            var s = new InlineBuilder();

            s.Is();
            s.Add("");
            s.Is();
            s.Add("abc");
            s.Is("abc");
            s.Add(Ins);
            s.Add("def");
            s.Is("abc", Ins_("def"));
            s.Add("");
            s.Is("abc", Ins_("def"));
            s.Add(t1);
            s.Is("abc", Ins_("def"), Ins_(t1));
            s.Add("");
            s.Is("abc", Ins_("def"), Ins_(t1));
            s.Add(t2);
            s.Is("abc", Ins_("def"), Ins_(t1), Ins_(t2));
            s.Add("");
            s.Is("abc", Ins_("def"), Ins_(t1), Ins_(t2));
            s.Add(Del);
            s.Is("abc", Ins_("def"), Ins_(t1), Ins_(t2));
            s.Add("xyz");
            s.Is("abc", Ins_("def"), Ins_(t1), Ins_(t2), Del_("xyz"));
        }
Ejemplo n.º 5
0
 private static Syntax.Inline make_inlines(InlineTag t, Syntax.Inline contents)
 {
     Syntax.Inline e = new Syntax.Inline();
     e.Tag = t;
     e.Content.Inlines = contents;
     return e;
 }
Ejemplo n.º 6
0
        public void ToString_1()
        {
            var x = new InlineTag(Tag.S, "id", "rid", "name", "ctype", "display", "code");

            x.ToString().Is("code");
            x.ToString(InlineString.Render.TagCode).Is("code");
            x.ToString(InlineString.Render.TagDebug).Is("{name;id}");
            x.ToString(InlineString.Render.TagDisplay).Is("{display}");
            x.ToString(InlineString.Render.TagNone).Is("");
            x.ToString(InlineString.Render.TagNumber).Is("{0}");

            var a = new InlineTag(Tag.S, "x", "y", "a", "link", "{a}", "<a/>");

            a.ToString().Is("<a/>");
            a.ToString(InlineString.Render.TagCode).Is("<a/>");
            a.ToString(InlineString.Render.TagDebug).Is("{a;x}");
            a.ToString(InlineString.Render.TagDisplay).Is("{a}");
            a.ToString(InlineString.Render.TagNone).Is("");
            a.ToString(InlineString.Render.TagNumber).Is("{0}");

            var b = new InlineTag(Tag.S, "x", "y", "b", "link", "{b}", "<b/>");

            b.ToString().Is("<b/>");
            b.ToString(InlineString.Render.TagCode).Is("<b/>");
            b.ToString(InlineString.Render.TagDebug).Is("{b;x}");
            b.ToString(InlineString.Render.TagDisplay).Is("{b}");
            b.ToString(InlineString.Render.TagNone).Is("");
            b.ToString(InlineString.Render.TagNumber).Is("{0}");
        }
Ejemplo n.º 7
0
        public void Ctors_1()
        {
            var a = new InlineTag(Tag.S, "id", "rid", "a", "link", "{a}", "<a/>");

            a.TagType.Is(Tag.S);
            a.Id.Is("id");
            a.Rid.Is("rid");
            a.Name.Is("a");
            a.Ctype.Is("link");
            a.Display.Is("{a}");
            a.Code.Is("<a/>");

            AssertEx.Catch <ArgumentNullException>(() => new InlineTag(Tag.S, null, "rid", "a", null, "{a}", "<a/>"));
            AssertEx.Catch <ArgumentNullException>(() => new InlineTag(Tag.S, "id", null, "a", null, "{a}", "<a/>"));
            AssertEx.Catch <ArgumentNullException>(() => new InlineTag(Tag.S, "id", "rid", null, null, "{a}", "<a/>"));
            new InlineTag(Tag.S, "id", "rid", "a", null, null, null); // Throws nothing.

            var a2 = new InlineTag(Tag.B, "id", "rid", "a", "link", "{a}", "<a/>");

            a2.TagType.Is(Tag.B);
            a2.TagType.IsNot(Tag.E);

            var a3 = new InlineTag(Tag.E, "id", "rid", "a", "link", "{a}", "<a/>");

            a3.TagType.Is(Tag.E);
            a3.TagType.IsNot(Tag.B);
        }
Ejemplo n.º 8
0
        public void GetHashCode_1()
        {
            var t1 = new InlineTag(Tag.S, "*", "*", "t", null, null, null);
            var t2 = new InlineTag(Tag.S, "*", "*", "t", null, null, null);

            var s1 = new InlineBuilder();
            var s2 = new InlineBuilder();

            s1.ToInlineString().GetHashCode().Is(s2.ToInlineString().GetHashCode());

            s1.Append("abc");
            s1.ToInlineString().GetHashCode().IsNot(s2.ToInlineString().GetHashCode()); // very likely but not guaranteed
            s2.Append("abc");
            s1.ToInlineString().GetHashCode().Is(s2.ToInlineString().GetHashCode());
            s1.Append("def");
            s1.ToInlineString().GetHashCode().IsNot(s2.ToInlineString().GetHashCode()); // very likely but not guaranteed
            s2.Append("def");
            s1.ToInlineString().GetHashCode().Is(s2.ToInlineString().GetHashCode());
            s1.Append(t1);
            s1.ToInlineString().GetHashCode().IsNot(s2.ToInlineString().GetHashCode()); // very likely but not guaranteed
            s2.Append(t2);
            s1.ToInlineString().GetHashCode().Is(s2.ToInlineString().GetHashCode());

            s1.Append("xxx");
            s1.ToInlineString().GetHashCode().IsNot(s2.ToInlineString().GetHashCode()); // very likely but not guaranteed
            s2.Append("yyy");
            s1.ToInlineString().GetHashCode().IsNot(s2.ToInlineString().GetHashCode()); // very likely but not guaranteed
        }
Ejemplo n.º 9
0
        public void Equals_2()
        {
            var a = new InlineTag(Tag.S, "id", "rid", "a", "link", "{a}", "<a/>");

            a.Equals(new InlineTag(Tag.B, "id", "rid", "a", "link", "{a}", "<a/>")).IsFalse();
            a.Equals(new InlineTag(Tag.E, "id", "rid", "a", "link", "{a}", "<a/>")).IsFalse();
            a.Equals(new InlineTag(Tag.S, "ID", "rid", "a", "link", "{a}", "<a/>")).IsFalse();
            a.Equals(new InlineTag(Tag.S, "id", "RID", "a", "link", "{a}", "<a/>")).IsFalse();
            a.Equals(new InlineTag(Tag.S, "id", "rid", "A", "link", "{a}", "<a/>")).IsFalse();
            a.Equals(new InlineTag(Tag.S, "id", "rid", "a", "LINK", "{a}", "<a/>")).IsFalse();
            a.Equals(new InlineTag(Tag.S, "id", "rid", "a", "link", "{A}", "<a/>")).IsFalse();
            a.Equals(new InlineTag(Tag.S, "id", "rid", "a", "link", "{a}", "<A/>")).IsFalse();

            (a == new InlineTag(Tag.B, "id", "rid", "a", "link", "{a}", "<a/>")).IsFalse();
            (a == new InlineTag(Tag.E, "id", "rid", "a", "link", "{a}", "<a/>")).IsFalse();
            (a == new InlineTag(Tag.S, "ID", "rid", "a", "link", "{a}", "<a/>")).IsFalse();
            (a == new InlineTag(Tag.S, "id", "RID", "a", "link", "{a}", "<a/>")).IsFalse();
            (a == new InlineTag(Tag.S, "id", "rid", "A", "link", "{a}", "<a/>")).IsFalse();
            (a == new InlineTag(Tag.S, "id", "rid", "a", "LINK", "{a}", "<a/>")).IsFalse();
            (a == new InlineTag(Tag.S, "id", "rid", "a", "link", "{A}", "<a/>")).IsFalse();
            (a == new InlineTag(Tag.S, "id", "rid", "a", "link", "{a}", "<A/>")).IsFalse();

            (a != new InlineTag(Tag.B, "id", "rid", "a", "link", "{a}", "<a/>")).IsTrue();
            (a != new InlineTag(Tag.E, "id", "rid", "a", "link", "{a}", "<a/>")).IsTrue();
            (a != new InlineTag(Tag.S, "ID", "rid", "a", "link", "{a}", "<a/>")).IsTrue();
            (a != new InlineTag(Tag.S, "id", "RID", "a", "link", "{a}", "<a/>")).IsTrue();
            (a != new InlineTag(Tag.S, "id", "rid", "A", "link", "{a}", "<a/>")).IsTrue();
            (a != new InlineTag(Tag.S, "id", "rid", "a", "LINK", "{a}", "<a/>")).IsTrue();
            (a != new InlineTag(Tag.S, "id", "rid", "a", "link", "{A}", "<a/>")).IsTrue();
            (a != new InlineTag(Tag.S, "id", "rid", "a", "link", "{a}", "<A/>")).IsTrue();
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Inline"/> class.
 /// </summary>
 internal Inline(InlineTag tag, string content, int startIndex, int length)
 {
     this.Tag = tag;
     this.LiteralContentValue.Source = content;
     this.LiteralContentValue.StartIndex = startIndex;
     this.LiteralContentValue.Length = length;
 }
Ejemplo n.º 11
0
 // Create an inline with a literal string value.
 private static Syntax.Inline make_literal(InlineTag t, string s)
 {
     Syntax.Inline e = new Syntax.Inline();
     e.Tag = t;
     e.Content.Literal = s;
     return e;
 }
Ejemplo n.º 12
0
        public void Equals_1()
        {
            var t1 = new InlineTag(Tag.S, "*", "*", "t", null, null, null);
            var t2 = new InlineTag(Tag.S, "*", "*", "t", null, null, null);
            var s1 = new InlineBuilder();
            var s2 = new InlineBuilder();

            s1.ToInlineString().Equals(s2.ToInlineString()).Is(true);
            s2.ToInlineString().Equals(s1.ToInlineString()).Is(true);
            s1.Append("abc");
            s1.ToInlineString().Equals(s2.ToInlineString()).Is(false);
            s2.ToInlineString().Equals(s1.ToInlineString()).Is(false);
            s2.Append("abc");
            s1.ToInlineString().Equals(s2.ToInlineString()).Is(true);
            s2.ToInlineString().Equals(s1.ToInlineString()).Is(true);
            s1.Append("def");
            s1.ToInlineString().Equals(s2.ToInlineString()).Is(false);
            s2.ToInlineString().Equals(s1.ToInlineString()).Is(false);
            s2.Append("def");
            s1.ToInlineString().Equals(s2.ToInlineString()).Is(true);
            s2.ToInlineString().Equals(s1.ToInlineString()).Is(true);
            s1.Append(t1);
            s1.ToInlineString().Equals(s2.ToInlineString()).Is(false);
            s2.ToInlineString().Equals(s1.ToInlineString()).Is(false);
            s2.Append(t2);
            s1.ToInlineString().Equals(s2.ToInlineString()).Is(true);
            s2.ToInlineString().Equals(s1.ToInlineString()).Is(true);

            s1.Append("xxx");
            s2.Append("yyy");
            s1.ToInlineString().Equals(s2.ToInlineString()).Is(false);
            s2.ToInlineString().Equals(s1.ToInlineString()).Is(false);
        }
Ejemplo n.º 13
0
        public void Equals_3()
        {
            var a1 = new InlineTag(Tag.S, "id", "rid", "a", "link", "{a}", "<a/>");
            var a2 = new InlineTag(Tag.S, "id", "rid", "a", "link", "{a}", "<a/>");
            var b9 = new InlineTag(Tag.S, "id", "rid", "b", "link", "{b}", "<b/>");

            object x1 = a1;
            object x2 = a2;
            object y9 = b9;

            ReferenceEquals(a1, a2).IsFalse();
            a1.Equals(a1).IsTrue();
            a1.Equals(a2).IsTrue();
            a1.Equals(b9).IsFalse();
#pragma warning disable CS1718
            (a1 == a1).IsTrue();
            (a1 == a2).IsTrue();
            (a1 == b9).IsFalse();
            (a1 != a1).IsFalse();
            (a1 != a2).IsFalse();
            (a2 != b9).IsTrue();
#pragma warning restore CS1718

            x1.Equals(x1).IsTrue();
            x1.Equals(x2).IsTrue();
            x1.Equals(b9).IsFalse();
#pragma warning disable CS1718
            (x1 == x1).IsTrue();
            (x1 == x2).IsFalse();
            (x1 == y9).IsFalse();
            (x1 != x1).IsFalse();
            (x1 != x2).IsTrue();
            (x1 != y9).IsTrue();
#pragma warning restore CS1718

            a1.Equals(x1).IsTrue();
            a1.Equals(x2).IsTrue();
            a1.Equals(y9).IsFalse();
#pragma warning disable CS0253
            (a1 == x1).IsTrue();
            (a1 == x2).IsFalse();
            (a1 == y9).IsFalse();
            (a1 != x1).IsFalse();
            (a1 != x2).IsTrue();
            (a1 != y9).IsTrue();
#pragma warning restore CS0253

            x1.Equals(a1).IsTrue();
            x1.Equals(a2).IsTrue();
            x1.Equals(b9).IsFalse();
#pragma warning disable CS0252
            (x1 == a1).IsTrue();
            (x1 == a2).IsFalse();
            (x1 == b9).IsFalse();
            (x1 != a1).IsFalse();
            (x1 != a2).IsTrue();
            (x2 != b9).IsTrue();
#pragma warning restore CS0252
        }
Ejemplo n.º 14
0
        public void Equals_AND_GetHashCode_1()
        {
            var comp = InlineTag.LooseEqualityComparer;

            var a0 = new InlineTag(Tag.S, "id", "rid", "name", "ctype", "display", "code");

            var b1 = new InlineTag(Tag.B, "id", "rid", "name", "ctype", "display", "code");
            var b2 = new InlineTag(Tag.E, "id", "rid", "name", "ctype", "display", "code");
            var b3 = new InlineTag(Tag.S, "XX", "rid", "name", "ctype", "display", "code");
            var b4 = new InlineTag(Tag.S, "id", "XXX", "name", "ctype", "display", "code");
            var b5 = new InlineTag(Tag.S, "id", "rid", "XXXX", "ctype", "display", "code");

            var c1 = new InlineTag(Tag.S, "id", "rid", "name", "XXXXX", "display", "code");
            var c2 = new InlineTag(Tag.S, "id", "rid", "name", "ctype", "XXXXXXX", "code");
            var c3 = new InlineTag(Tag.S, "id", "rid", "name", "ctype", "display", "XXXX");
            var c4 = new InlineTag(Tag.S, "id", "rid", "name", null, "display", "code");
            var c5 = new InlineTag(Tag.S, "id", "rid", "name", "ctype", null, "code");
            var c6 = new InlineTag(Tag.S, "id", "rid", "name", "ctype", "display", null);

            var ab = new InlineTag[] { a0, b1, b2, b3, b4, b5 };

            for (int i = 0; i < ab.Length; i++)
            {
                for (int j = 0; j < ab.Length; j++)
                {
                    if (i != j)
                    {
                        var msg = string.Format("i = {0}, j = {1}", i, j);
                        comp.Equals(ab[i], ab[j]).IsFalse(msg);
                        comp.GetHashCode(ab[i]).IsNot(comp.GetHashCode(ab[j]), msg); // likely though not guaranteed
                    }
                }
            }

            var ac = new InlineTag[] { a0, c1, c2, c3, c4, c5, c6 };

            for (int i = 0; i < ac.Length; i++)
            {
                for (int j = 0; j < ac.Length; j++)
                {
                    var msg = string.Format("i = {0}, j = {1}", i, j);
                    comp.Equals(ac[i], ac[j]).IsTrue(msg);
                    comp.GetHashCode(ac[i]).Is(comp.GetHashCode(ac[j]), msg); // likely though not guaranteed
                }
            }

            var bb = new InlineTag[] { b1, b2, b3, b4, b5 };
            var cc = new InlineTag[] { c1, c2, c3, c4, c5, c6 };

            for (int i = 0; i < bb.Length; i++)
            {
                for (int j = 0; j < cc.Length; j++)
                {
                    var msg = string.Format("i = {0}, j = {1}", i, j);
                    comp.Equals(bb[i], cc[j]).IsFalse(msg);
                    comp.GetHashCode(bb[i]).IsNot(comp.GetHashCode(cc[j]), msg); // likely though not guaranteed
                }
            }
        }
Ejemplo n.º 15
0
        public void InlineTag_Is_1()
        {
            var a1 = new InlineTag(Tag.S, "id", "rid", "a", "link", "{a}", "<a/>");
            var b1 = new InlineTag(Tag.S, "id", "rid", "b", "link", "{b}", "<b/>");

            a1.Is(Tag.S, "id", "rid", "a", "link", "{a}", "<a/>");
            b1.Is(Tag.S, "id", "rid", "b", "link", "{b}", "<b/>");
        }
Ejemplo n.º 16
0
 // Create an inline with a linkable string value.
 private static Syntax.Inline make_linkable(InlineTag t, Syntax.Inline label, string url, string title)
 {
     Syntax.Inline e = new Syntax.Inline();
     e.Tag = t;
     e.Content.Linkable.Label = label;
     e.Content.Linkable.Url = url;
     e.Content.Linkable.Title = title;
     return e;
 }
Ejemplo n.º 17
0
        public void GetHashCode_1()
        {
            var a1 = new InlineTag(Tag.S, "id", "rid", "a", "link", "{a}", "<a/>");
            var a2 = new InlineTag(Tag.S, "id", "rid", "a", "link", "{a}", "<a/>");
            var b1 = new InlineTag(Tag.S, "id", "rid", "b", "link", "{b}", "<b/>");

            a1.GetHashCode().Is(a2.GetHashCode());
            a1.GetHashCode().IsNot(b1.GetHashCode()); // very likely but not guaranteed
        }
Ejemplo n.º 18
0
        public void Equals_3()
        {
            var t  = new InlineTag(Tag.S, "*", "*", "t", null, null, null);
            var s1 = new InlineBuilder();
            var s2 = new InlineBuilder();

            s1.Append("abc");
            s2.Append(t);
            s1.ToInlineString().Equals(s2.ToInlineString()).Is(false);
            s2.ToInlineString().Equals(s1.ToInlineString()).Is(false);
        }
Ejemplo n.º 19
0
        public void Ctors_4()
        {
            var a = new InlineTag(Tag.S, "id", "rid", "a", "link", null, null);

            a.TagType.Is(Tag.S);
            a.Id.Is("id");
            a.Rid.Is("rid");
            a.Name.Is("a");
            a.Ctype.Is("link");
            a.Display.Is(null as string);
            a.Code.Is(null as string);
        }
Ejemplo n.º 20
0
        public void ToString_2()
        {
            var x = new InlineTag(Tag.S, "id", "rid", "name", "ctype", "display", "code");

            foreach (InlineToString its in Enum.GetValues(typeof(InlineToString)))
            {
                if (its == InlineToString.TagMask)
                {
                    continue;                                // XXX
                }
                x.ToString(its).Is(x.ToString(its & InlineToString.TagMask), string.Format("its = {0}", its));
            }
        }
Ejemplo n.º 21
0
        public void Equals_4()
        {
            var t1 = new InlineTag(Tag.S, "*", "*", "t", null, "{t}", null);
            var t2 = new InlineTag(Tag.S, "*", "*", "t", null, "{T}", null);

            var s1 = new InlineBuilder();
            var s2 = new InlineBuilder();

            s1.Append(t1);
            s2.Append(t2);
            s1.ToInlineString().Equals(s2.ToInlineString()).IsFalse();
            s2.ToInlineString().Equals(s1.ToInlineString()).IsFalse();
        }
Ejemplo n.º 22
0
        private static Inline HandleOpenerCloser(Subject subj, InlineTag singleCharTag, InlineTag doubleCharTag)
        {
            bool canOpen, canClose;
            var  c         = subj.Buffer[subj.Position];
            var  numdelims = ScanEmphasisDelimiters(subj, c, out canOpen, out canClose);

            if (canClose)
            {
                // walk the stack and find a matching opener, if there is one
                var istack = InlineStack.FindMatchingOpener(subj.LastPendingInline, InlineStack.InlineStackPriority.Emphasis, c, numdelims, canOpen, out canClose);
                if (istack != null)
                {
                    var useDelims = MatchInlineStack(istack, subj, numdelims, null, singleCharTag, doubleCharTag);

                    if (useDelims > 0)
                    {
                        // if the closer was not fully used, move back a char or two and try again.
                        if (useDelims < numdelims)
                        {
                            subj.Position = subj.Position - numdelims + useDelims;

                            // use recursion only if it will not be very deep.
                            // however it cannot be used if the single char will not be parsed.
                            if (numdelims < 10)
                            {
                                return(HandleOpenerCloser(subj, singleCharTag, doubleCharTag));
                            }
                        }

                        return(null);
                    }
                }
            }

            var inlText = new Inline(subj.Buffer, subj.Position - numdelims, numdelims, subj.Position - numdelims, subj.Position, c);

            if (canOpen || canClose)
            {
                var istack = new InlineStack();
                istack.DelimiterCount = numdelims;
                istack.Delimiter      = c;
                istack.StartingInline = inlText;
                istack.Priority       = InlineStack.InlineStackPriority.Emphasis;
                istack.Flags          = (canOpen ? InlineStack.InlineStackFlags.Opener : 0)
                                        | (canClose ? (InlineStack.InlineStackFlags.Closer | InlineStack.InlineStackFlags.CloserOriginally) : 0);

                InlineStack.AppendStackEntry(istack, subj);
            }

            return(inlText);
        }
Ejemplo n.º 23
0
        public void GetHashCode_4()
        {
            // InlineTag.GetHashCode doesn't see Display string anymore,
            // Hence InlineString.GetHashCode, either.

            var t1 = new InlineTag(Tag.S, "*", "", "t", null, "{t}", null);
            var t2 = new InlineTag(Tag.S, "*", "", "t", null, "{T}", null);

            var s1 = new InlineBuilder();
            var s2 = new InlineBuilder();

            s1.Append(t1);
            s2.Append(t2);
            s1.ToInlineString().GetHashCode().Is(s2.ToInlineString().GetHashCode());
        }
Ejemplo n.º 24
0
        public void Add_Tag_1()
        {
            var t1 = new InlineTag(Tag.S, "id", "rid", "name", "ctype", "display", "code");
            var t2 = new InlineTag(Tag.S, "ID", "RID", "NAME", "CTYPE", "DISPLAY", "CODE");

            var s = new InlineBuilder();

            s.Is();
            s.Add(Tag.S, "id", "rid", "name", "ctype", "display", "code");
            s.Add(Ins);
            s.Add(Tag.S, "id", "rid", "name", "ctype", "display", "code");
            s.Add(Del);
            s.Add(Tag.S, "ID", "RID", "NAME", "CTYPE", "DISPLAY", "CODE");
            s.Add(Emp);
            s.Add(Tag.S, "ID", "RID", "NAME", "CTYPE", "DISPLAY", "CODE");
            s.Is(t1, Ins_(t1), Del_(t2), Emp_(t2));
        }
Ejemplo n.º 25
0
        private static string TextUntil(ConverterContext context, InlineTag tag)
        {
            var osb = new StringBuilder();

            while (context.Enumerable.MoveNext())
            {
                var element = context.Enumerable.Current;
                if (element.Inline == null || element.Inline.Tag == tag)
                {
                    break;
                }

                osb.Append(element.Inline.LiteralContent);
            }

            return(osb.ToString());
        }
Ejemplo n.º 26
0
        public void Ctors_2()
        {
            var a = new InlineText("a");
            var b = new InlineText("b");
            var t = new InlineTag(Tag.S, "*", "*", "t", null, null, null);

            new InlineString().Is();
            new InlineString("a").Is(new InlineText("a"));
            new InlineString(a).Is(new InlineText("a"));
            new InlineString(a, b).Is(new InlineText("ab"));
            new InlineString(t).Is(t);
            new InlineString(a, t).Is(new InlineText("a"), t);
            new InlineString(t, a).Is(t, new InlineText("a"));
            new InlineString(a, a).Is(new InlineText("aa"));
            new InlineString(a, t, a).Is(new InlineText("a"), t, new InlineText("a"));
            new InlineString(a, t, a, a).Is(new InlineText("a"), t, new InlineText("aa"));
            new InlineString(a, a, t, a).Is(new InlineText("aa"), t, new InlineText("a"));
        }
Ejemplo n.º 27
0
        public void Append_2()
        {
            var t = new InlineTag(Tag.S, "*", "*", "t", null, null, null);
            var s = new InlineBuilder();

            AssertEx.Catch <ArgumentNullException>(() => s.Append((string)null));
            AssertEx.Catch <ArgumentNullException>(() => s.Append((InlineTag)null));
            AssertEx.Is(s);

            s.Append(t);
            AssertEx.Catch <ArgumentNullException>(() => s.Append((string)null));
            AssertEx.Catch <ArgumentNullException>(() => s.Append((InlineTag)null));
            s.Is(t);

            s.Append("abc");
            AssertEx.Catch <ArgumentNullException>(() => s.Append((string)null));
            AssertEx.Catch <ArgumentNullException>(() => s.Append((InlineTag)null));
            s.Is(t, new InlineText("abc"));
        }
Ejemplo n.º 28
0
        public void ToString_3()
        {
            var a = new InlineTag(Tag.S, "id", "rid", "name", null, "display", "code");
            var b = new InlineTag(Tag.S, "id", "rid", "name", "ctype", null, "code");
            var c = new InlineTag(Tag.S, "id", "rid", "name", "ctype", "display", null);
            var d = new InlineTag(Tag.S, "id", "rid", "name", null, null, null);

            b.ToString(InlineString.Render.TagDisplay).Is("{name}");
            c.ToString(InlineString.Render.TagCode).Is("{*}");

            a.ToString().IsNotNull();
            b.ToString().IsNotNull();
            c.ToString().IsNotNull();
            d.ToString().IsNotNull();

            foreach (var option in TagOptions)
            {
                a.ToString(option).IsNotNull();
                b.ToString(option).IsNotNull();
                c.ToString(option).IsNotNull();
                d.ToString(option).IsNotNull();
            }
        }
Ejemplo n.º 29
0
        public void Equals_1()
        {
            var a1 = new InlineTag(Tag.S, "id", "rid", "a", "link", "{a}", "<a/>");
            var a2 = new InlineTag(Tag.S, "id", "rid", "a", "link", "{a}", "<a/>");
            var b1 = new InlineTag(Tag.S, "id", "rid", "b", "link", "{b}", "<b/>");

            a1.Equals(a1).IsTrue();
            a1.Equals(a2).IsTrue();
            a1.Equals(b1).IsFalse();
            a2.Equals(a1).IsTrue();
            a2.Equals(a2).IsTrue();
            a2.Equals(b1).IsFalse();
            b1.Equals(a1).IsFalse();
            b1.Equals(a2).IsFalse();
            b1.Equals(b1).IsTrue();

            a1.Equals(null).IsFalse();
            a1.Equals(new Object()).IsFalse();
            a1.Equals("a").IsFalse();

            a1.Is(a1);
            a1.Is(a2);
            a1.IsNot(b1);
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Inline"/> class.
 /// </summary>
 /// <param name="tag">The type of inline element. Should be one of the types that require literal content, for example, <see cref="InlineTag.Code"/>.</param>
 /// <param name="content">The literal contents of the inline element.</param>
 public Inline(InlineTag tag, string content)
 {
     this.Tag = tag;
     this.LiteralContent = content;
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Inline"/> class.
 /// </summary>
 /// <param name="tag">The type of inline element.</param>
 public Inline(InlineTag tag)
 {
     this.Tag = tag;
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Inline"/> class.
 /// </summary>
 /// <param name="tag">The type of inline element. Should be one of the types that contain child elements, for example, <see cref="InlineTag.Emphasis"/>.</param>
 /// <param name="content">The first descendant element of the inline that is being created.</param>
 public Inline(InlineTag tag, Inline content)
 {
     this.Tag        = tag;
     this.FirstChild = content;
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Inline"/> class.
 /// </summary>
 /// <param name="tag">The type of inline element. Should be one of the types that require literal content, for example, <see cref="InlineTag.Code"/>.</param>
 /// <param name="content">The literal contents of the inline element.</param>
 public Inline(InlineTag tag, string content)
 {
     this.Tag            = tag;
     this.LiteralContent = content;
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Inline"/> class.
 /// </summary>
 /// <param name="tag">The type of inline element.</param>
 public Inline(InlineTag tag)
 {
     this.Tag = tag;
 }
Ejemplo n.º 35
0
Archivo: Inline.cs Proyecto: zhitian/3P
 /// <summary>
 /// Initializes a new instance of the <see cref="Inline"/> class.
 /// </summary>
 /// <param name="tag">The type of inline element. Should be one of the types that require literal content, for example, <see cref="InlineTag.Code"/>.</param>
 /// <param name="content">The literal contents of the inline element.</param>
 public Inline(InlineTag tag, string content)
 {
     Tag            = tag;
     LiteralContent = content;
 }
Ejemplo n.º 36
0
 internal static InlineTag[] InitializeEmphasisDoubleCharTags(bool handleTilde = false)
 {
     var t = new InlineTag[handleTilde ? 127 : 97];
     t['_'] = t['*'] = InlineTag.Strong;
     return t;
 }
Ejemplo n.º 37
0
        private static Inline HandleOpenerCloser(Subject subj, InlineTag singleCharTag, InlineTag doubleCharTag, InlineParserParameters parameters)
        {
            bool canOpen, canClose;
            var c = subj.Buffer[subj.Position];
            var numdelims = ScanEmphasisDelimeters(subj, c, out canOpen, out canClose);

            if (canClose)
            {
                // walk the stack and find a matching opener, if there is one
                var istack = InlineStack.FindMatchingOpener(subj.LastPendingInline, InlineStack.InlineStackPriority.Emphasis, c, out canClose);
                if (istack != null)
                {
                    var useDelims = MatchInlineStack(istack, subj, numdelims, null, singleCharTag, doubleCharTag, parameters);

                    // if the closer was not fully used, move back a char or two and try again.
                    if (useDelims < numdelims)
                    {
                        subj.Position = subj.Position - numdelims + useDelims;

                        // use recursion only if it will not be very deep.
                        if (numdelims < 10)
                            return HandleOpenerCloser(subj, singleCharTag, doubleCharTag, parameters);
                    }

                    return null;
                }
            }

            var inlText = new Inline(subj.Buffer, subj.Position - numdelims, numdelims, subj.Position - numdelims, subj.Position, c);

            if (canOpen || canClose)
            {
                var istack = new InlineStack();
                istack.DelimeterCount = numdelims;
                istack.Delimeter = c;
                istack.StartingInline = inlText;
                istack.Priority = InlineStack.InlineStackPriority.Emphasis;
                istack.Flags = (canOpen ? InlineStack.InlineStackFlags.Opener : 0)
                             | (canClose ? InlineStack.InlineStackFlags.Closer : 0);

                InlineStack.AppendStackEntry(istack, subj);
            }

            return inlText;
        }
Ejemplo n.º 38
0
        internal static int MatchInlineStack(InlineStack opener, Subject subj, int closingDelimeterCount, InlineStack closer, InlineTag singleCharTag, InlineTag doubleCharTag, InlineParserParameters parameters)
        {
            // calculate the actual number of delimeters used from this closer
            int useDelims;
            var openerDelims = opener.DelimeterCount;

            if (closingDelimeterCount < 3 || openerDelims < 3)
            {
                useDelims = closingDelimeterCount <= openerDelims ? closingDelimeterCount : openerDelims;
                if (useDelims == 2 && doubleCharTag == 0)
                    useDelims = 1;
                if (useDelims == 1 && singleCharTag == 0)
                    return 0;
            }
            else if (singleCharTag == 0)
                useDelims = 2;
            else if (doubleCharTag == 0)
                useDelims = 1;
            else
                useDelims = closingDelimeterCount % 2 == 0 ? 2 : 1;

            Inline inl = opener.StartingInline;
            InlineTag tag = useDelims == 1 ? singleCharTag : doubleCharTag;
            if (openerDelims == useDelims)
            {
                // the opener is completely used up - remove the stack entry and reuse the inline element
                inl.Tag = tag;
                inl.LiteralContent = null;
                inl.FirstChild = inl.NextSibling;
                inl.NextSibling = null;

                InlineStack.RemoveStackEntry(opener, subj, closer?.Previous, parameters);
            }
            else
            {
                // the opener will only partially be used - stack entry remains (truncated) and a new inline is added.
                opener.DelimeterCount -= useDelims;
                inl.LiteralContent = inl.LiteralContent.Substring(0, opener.DelimeterCount);
                inl.SourceLastPosition -= useDelims;

                inl.NextSibling = new Inline(tag, inl.NextSibling);
                inl = inl.NextSibling;

                inl.SourcePosition = opener.StartingInline.SourcePosition + opener.DelimeterCount;
            }

            // there are two callers for this method, distinguished by the `closer` argument.
            // if closer == null it means the method is called during the initial subject parsing and the closer
            //   characters are at the current position in the subject. The main benefit is that there is nothing
            //   parsed that is located after the matched inline element.
            // if closer != null it means the method is called when the second pass for previously unmatched
            //   stack elements is done. The drawback is that there can be other elements after the closer.
            if (closer != null)
            {
                var clInl = closer.StartingInline;
                if ((closer.DelimeterCount -= useDelims) > 0)
                {
                    // a new inline element must be created because the old one has to be the one that
                    // finalizes the children of the emphasis
                    var newCloserInline = new Inline(clInl.LiteralContent.Substring(useDelims));
                    newCloserInline.SourcePosition = inl.SourceLastPosition = clInl.SourcePosition + useDelims;
                    newCloserInline.SourceLength = closer.DelimeterCount;
                    newCloserInline.NextSibling = clInl.NextSibling;

                    clInl.LiteralContent = null;
                    clInl.NextSibling = null;
                    inl.NextSibling = closer.StartingInline = newCloserInline;
                }
                else
                {
                    inl.SourceLastPosition = clInl.SourceLastPosition;

                    clInl.LiteralContent = null;
                    inl.NextSibling = clInl.NextSibling;
                    clInl.NextSibling = null;
                }
            }
            else if (subj != null)
            {
                inl.SourceLastPosition = subj.Position - closingDelimeterCount + useDelims;
                subj.LastInline = inl;
            }

            return useDelims;
        }
Ejemplo n.º 39
0
 // Create an inline with no value.
 private static Syntax.Inline make_simple(InlineTag t)
 {
     Syntax.Inline e = new Syntax.Inline();
     e.Tag = t;
     return e;
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Inline"/> class.
 /// </summary>
 /// <param name="tag">The type of inline element. Should be one of the types that contain child elements, for example, <see cref="InlineTag.Emphasis"/>.</param>
 /// <param name="content">The first descendant element of the inline that is being created.</param>
 public Inline(InlineTag tag, Inline content)
 {
     this.Tag = tag;
     this.FirstChild = content;
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Inline"/> class.
 /// </summary>
 /// <param name="tag">The type of inline element. Should be one of the types that contain child elements, for example, <see cref="InlineTag.Emphasis"/>.</param>
 /// <param name="content">The first descendant element of the inline that is being created.</param>
 public Inline(InlineTag tag, Inline content)
 {
     Tag        = tag;
     FirstChild = content;
 }