コード例 #1
0
        public void Equals_2()
        {
            var s1 = new InlineBuilder();
            var s2 = new InlineBuilder();

            s1.Append("abc").Append("def");
            s2.Append("abcdef");
            s1.ToInlineString().Equals(s2.ToInlineString()).Is(true);
            s2.ToInlineString().Equals(s1.ToInlineString()).Is(true);
        }
コード例 #2
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
        }
コード例 #3
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);
        }
コード例 #4
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();
        }
コード例 #5
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());
        }
コード例 #6
0
        /// <summary>
        /// Parse an XML fragment representing a source/target content into <see cref="InlineString"/>.
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        protected static InlineString GetInlineString(string text)
        {
            var inline = new InlineBuilder();

            foreach (var elem in XElement.Parse(text).Elements("Elements").Elements())
            {
                switch (elem.Name.LocalName)
                {
                case "Text":
                    inline.Add((string)elem.Element("Value") ?? "");
                    break;

                case "Tag":
                    inline.Add(GetInlineTag(elem));
                    break;

                default:
                    // Just in case...
                    inline.Add(new InlineTag(Tag.S, "*", "", elem.Name.LocalName, null, null, elem.ToString()));
                    break;
                }
            }
            return(inline.ToInlineString());
        }
コード例 #7
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);
        }