Пример #1
0
        public void TrimEndSubstring(string input, char trimChar, string expected)
        {
            var substring = new Substring(input);

            substring = Substring.TrimEnd(substring, trimChar);

            Assert.Equal(expected, substring.ToString());
        }
Пример #2
0
        public void SimpleSubstring(string input, string expected)
        {
            var substring = new Substring(input);

            substring = new Substring(substring, 1, 2);

            Assert.Equal(expected, substring.ToString());
        }
Пример #3
0
            public string ToHumanReadableString()
            {
                var result = string.Empty;

                if (isWildcard)
                {
                    result += "Any";
                }
                if (!usage.isEmpty)
                {
                    if (result != string.Empty)
                    {
                        result += ' ' + usage.ToString();
                    }
                    else
                    {
                        result += usage.ToString();
                    }
                }

                if (!layout.isEmpty)
                {
                    if (result != string.Empty)
                    {
                        result += ' ' + layout.ToString();
                    }
                    else
                    {
                        result += layout.ToString();
                    }
                }

                if (!name.isEmpty && !isWildcard)
                {
                    if (result != string.Empty)
                    {
                        result += ' ' + name.ToString();
                    }
                    else
                    {
                        result += name.ToString();
                    }
                }
                return(result);
            }
Пример #4
0
 public void StrictSubstring()
 {
     var s = new Substring("Hello", 2, 2);
     s.Base.Should().Be("Hello");
     s.Length.Should().Be(2);
     s.StartingOffset.Should().Be(2);
     s.EndingOffset.Should().Be(4);
     s.ToString().Should().Be("ll");
 }
Пример #5
0
 public void FullSubstring()
 {
     var s = new Substring("Hello", 0);
     s.Base.Should().Be("Hello");
     s.Length.Should().Be("Hello".Length);
     s.StartingOffset.Should().Be(0);
     s.EndingOffset.Should().Be(s.Length);
     s.ToString().Should().Be("Hello");
 }
Пример #6
0
 public void EmptyString()
 {
     var s = new Substring(string.Empty, 0);
     s.Base.Should().Be(string.Empty);
     s.Length.Should().Be(0);
     s.StartingOffset.Should().Be(0);
     s.EndingOffset.Should().Be(0);
     s.ToString().Should().BeEmpty();
 }
Пример #7
0
        public void StrictSubstring()
        {
            var s = new Substring("Hello", 2, 2);

            s.Base.Should().Be("Hello");
            s.Length.Should().Be(2);
            s.StartingOffset.Should().Be(2);
            s.EndingOffset.Should().Be(4);
            s.ToString().Should().Be("ll");
        }
Пример #8
0
        public void EmptyString()
        {
            var s = new Substring(string.Empty, 0);

            s.Base.Should().Be(string.Empty);
            s.Length.Should().Be(0);
            s.StartingOffset.Should().Be(0);
            s.EndingOffset.Should().Be(0);
            s.ToString().Should().BeEmpty();
        }
Пример #9
0
        public void FullSubstring()
        {
            var s = new Substring("Hello", 0);

            s.Base.Should().Be("Hello");
            s.Length.Should().Be("Hello".Length);
            s.StartingOffset.Should().Be(0);
            s.EndingOffset.Should().Be(s.Length);
            s.ToString().Should().Be("Hello");
        }
Пример #10
0
        public void SubstringConstructor()
        {
            AString astr = new AString();
            AString res  = new AString();

            constructorTest("a", res, false); UT_EQ("a", res);
            constructorTest(" a", res, false); UT_EQ(" a", res);
            constructorTest("a ", res, false); UT_EQ("a ", res);
            constructorTest("a b", res, false); UT_EQ("a b", res);
            constructorTest(" a b", res, false); UT_EQ(" a b", res);
            constructorTest("a b ", res, false); UT_EQ("a b ", res);

            constructorTest("a", res, true); UT_EQ("a", res);
            constructorTest(" a", res, true); UT_EQ("a", res);
            constructorTest("a ", res, true); UT_EQ("a", res);
            constructorTest("a b", res, true); UT_EQ("a b", res);
            constructorTest(" a b", res, true); UT_EQ("a b", res);
            constructorTest("a b ", res, true); UT_EQ("a b", res);

            // changing whitespaces
            {
                {
                    astr.Clear()._("xy xz abc xy");
                    Substring subs = new Substring();
                    subs.Set(astr).Trim("xy ".ToCharArray());
                    subs.CopyTo(res);
                    UT_EQ("z abc", res);
                }

                {
                    Substring subs = new Substring("xy xz abc xy");
                    subs.TrimStart("xy ".ToCharArray());
                    subs.TrimEnd("xy ".ToCharArray());
                    subs.CopyTo(res);
                    UT_EQ("z abc", res);
                }
            }

            // test other constructors
            {
                astr.Clear()._(" astring ");
                UT_TRUE((new Substring()).IsEmpty());
                UT_TRUE((new Substring()).IsNull());
                UT_EQ("astring", (new Substring(astr)).Trim().ToString());
                UT_EQ("str", (new Substring(astr, 2, 3)).ToString());
                UT_EQ("", (new Substring(astr, 20, 3)).ToString());
                UT_TRUE((new Substring(astr, 20, 3)).IsEmpty());
                UT_FALSE((new Substring(astr, 20, 3)).IsNull());


                Substring s2 = new Substring(astr); s2.Trim();
                UT_EQ("astring", new Substring(s2.ToString()).ToString());
                UT_EQ("str", (new Substring((new Substring(astr, 2, 3)))).ToString());
            }
        }
Пример #11
0
        public void SubstringOfSubstring()
        {
            var s = new Substring("Hello World", 3, 6);
            var t = new Substring(s, 1);

            t.Base.Should().Be("Hello World");
            t.Length.Should().Be(5);
            t.StartingOffset.Should().Be(4);
            t.EndingOffset.Should().Be(9);
            t.ToString().Should().Be("o Wor");
        }
Пример #12
0
        public void GetHashCodeIsDifferentForDifferentSubstrings()
        {
            var ss1 = new Substring("Hello", 2, 1);

            ss1.ToString().Should().Be("l");

            var ss2 = new Substring("Hello", 3, 1);

            ss2.ToString().Should().Be("l");

            ss1.GetHashCode().Should().NotBe(ss2.GetHashCode());
        }
Пример #13
0
        public void DifferentSubstringsAreNotEqual()
        {
            var ss1 = new Substring("Hello", 2, 1);

            ss1.ToString().Should().Be("l");

            var ss2 = new Substring("Hello", 3, 1);

            ss2.ToString().Should().Be("l");

            ss1.Equals(ss2).Should().BeFalse();
            ss1.Equals(ss2 as object).Should().BeFalse();
            (ss1 == ss2).Should().BeFalse();
            (ss1 != ss2).Should().BeTrue();
        }
Пример #14
0
        public void EmptySubstrings()
        {
            var s = new Substring("Hello", 2, 0);
            s.Base.Should().Be("Hello");
            s.Length.Should().Be(0);
            s.StartingOffset.Should().Be(2);
            s.EndingOffset.Should().Be(2);
            s.ToString().Should().BeEmpty();

            var s2 = new Substring("Hello", 5, 0);
            s2.Base.Should().Be("Hello");
            s2.Length.Should().Be(0);
            s2.StartingOffset.Should().Be(5);
            s2.EndingOffset.Should().Be(5);
            s2.ToString().Should().BeEmpty();
        }
Пример #15
0
        public void EmptySubstrings()
        {
            var s = new Substring("Hello", 2, 0);

            s.Base.Should().Be("Hello");
            s.Length.Should().Be(0);
            s.StartingOffset.Should().Be(2);
            s.EndingOffset.Should().Be(2);
            s.ToString().Should().BeEmpty();

            var s2 = new Substring("Hello", 5, 0);

            s2.Base.Should().Be("Hello");
            s2.Length.Should().Be(0);
            s2.StartingOffset.Should().Be(5);
            s2.EndingOffset.Should().Be(5);
            s2.ToString().Should().BeEmpty();
        }
Пример #16
0
 public void SubstringOfSubstring()
 {
     var s = new Substring("Hello World", 3, 6);
     var t = new Substring(s, 1);
     t.Base.Should().Be("Hello World");
     t.Length.Should().Be(5);
     t.StartingOffset.Should().Be(4);
     t.EndingOffset.Should().Be(9);
     t.ToString().Should().Be("o Wor");
 }
Пример #17
0
        public void CompareTo()
        {
            Substring tss = new Substring();

            // null string comparison

            String nullString = null;

            UT_TRUE(tss.CompareTo(nullString) == 0);
            UT_TRUE(tss.Equals(nullString));

            tss.Set("");
            UT_TRUE(tss.CompareTo(nullString) != 0);
            UT_TRUE(!tss.Equals(nullString));

            tss.SetNull();
            UT_TRUE(tss.CompareTo(nullString) == 0);
            UT_TRUE(tss.Equals(nullString));

            String t = "abcde";

            tss = new Substring("01" + t + "234", 2, t.Length);

            int result, resSys;

            result = tss.CompareTo(t);                                     UT_EQ(t.CompareTo(t), result);
            result = tss.CompareTo(t + "x");                               UT_EQ(t.CompareTo(t + "x"), result);
            result = tss.CompareTo(t.Substring(0, t.Length - 1));             UT_EQ(t.CompareTo(t.Substring(0, t.Length - 1)), result);
            result = tss.CompareTo("pad" + t, Case.Sensitive, 3);   UT_EQ(0, result);
            result = tss.CompareTo("pad" + t, Case.Sensitive, 3, 2);   UT_EQ(1, result);


            // greater/smaller strings
            {
                String greater  = "x";
                String greater2 = "abcdef";
                String smaller  = "aaa";
                String smaller2 = "abcd";
                result = tss.CompareTo(greater);  resSys = t.CompareTo(greater); UT_TRUE(result == resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0));
                result = tss.CompareTo(greater2);  resSys = t.CompareTo(greater2); UT_TRUE(result == resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0));
                result = tss.CompareTo(smaller);  resSys = t.CompareTo(smaller); UT_TRUE(result == resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0));
                result = tss.CompareTo(smaller2);  resSys = t.CompareTo(smaller2); UT_TRUE(result == resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0));
                String ut = t.ToUpper();
                UT_FALSE(0 == tss.CompareTo(ut));
                UT_FALSE(0 == tss.CompareTo(ut, Case.Sensitive));
                UT_TRUE(0 == tss.CompareTo(ut, Case.Ignore));
            }

            {
                AString greater  = new AString("x");
                AString greater2 = new AString("abcdef");
                AString smaller  = new AString("aaa");
                AString smaller2 = new AString("abcd");
                result = tss.CompareTo(greater);  resSys = t.CompareTo(greater.ToString()); UT_TRUE(result == resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0));
                result = tss.CompareTo(greater2);  resSys = t.CompareTo(greater2.ToString()); UT_TRUE(result == resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0));
                result = tss.CompareTo(smaller);  resSys = t.CompareTo(smaller.ToString()); UT_TRUE(result == resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0));
                result = tss.CompareTo(smaller2);  resSys = t.CompareTo(smaller2.ToString()); UT_TRUE(result == resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0));
                AString ut = new AString(t.ToUpper());
                UT_FALSE(0 == tss.CompareTo(ut));
                UT_FALSE(0 == tss.CompareTo(ut, Case.Sensitive));
                UT_TRUE(0 == tss.CompareTo(ut, Case.Ignore));
            }
            {
                Substring greater  = new Substring("123x", 3);
                Substring greater2 = new Substring("123abcdef", 3);
                Substring smaller  = new Substring("123aaa", 3);
                Substring smaller2 = new Substring("123abcd", 3);
                result = tss.CompareTo(greater);  resSys = t.CompareTo(greater.ToString()); UT_TRUE(result == resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0));
                result = tss.CompareTo(greater2);  resSys = t.CompareTo(greater2.ToString()); UT_TRUE(result == resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0));
                result = tss.CompareTo(smaller);  resSys = t.CompareTo(smaller.ToString()); UT_TRUE(result == resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0));
                result = tss.CompareTo(smaller2);  resSys = t.CompareTo(smaller2.ToString()); UT_TRUE(result == resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0));
                Substring ut = new Substring(t.ToUpper());
                UT_FALSE(0 == tss.CompareTo(ut));
                UT_FALSE(0 == tss.CompareTo(ut, Case.Sensitive));
                UT_TRUE(0 == tss.CompareTo(ut, Case.Ignore));
            }
        }
Пример #18
0
        public void GetHashCodeIsDifferentForDifferentSubstrings()
        {
            var ss1 = new Substring("Hello", 2, 1);
            ss1.ToString().Should().Be("l");

            var ss2 = new Substring("Hello", 3, 1);
            ss2.ToString().Should().Be("l");

            ss1.GetHashCode().Should().NotBe(ss2.GetHashCode());
        }
Пример #19
0
        public void DifferentSubstringsAreNotEqual()
        {
            var ss1 = new Substring("Hello", 2, 1);
            ss1.ToString().Should().Be("l");

            var ss2 = new Substring("Hello", 3, 1);
            ss2.ToString().Should().Be("l");

            ss1.Equals(ss2).Should().BeFalse();
            ss1.Equals(ss2 as object).Should().BeFalse();
            (ss1 == ss2).Should().BeFalse();
            (ss1 != ss2).Should().BeTrue();
        }
Пример #20
0
        public void Consume()
        {
            // null substring
            {
                Substring s = new Substring();
                Substring r = new Substring("oldval");
                UT_EQ('\0', s.Consume( ));
                UT_EQ(0, s.Consume(0, r)); UT_TRUE(r.IsNull());
                UT_EQ(0, s.Consume(5, r)); UT_TRUE(r.IsNull());
                UT_EQ(false, s.Consume('a'));
                UT_EQ(false, s.Consume("word"));
                UT_EQ('\0', s.ConsumeFromEnd( ));
                UT_EQ(0, s.ConsumeFromEnd(0));
                UT_EQ(0, s.ConsumeFromEnd(5));
                UT_EQ(false, s.ConsumeFromEnd('a'));
                UT_EQ(false, s.ConsumeFromEnd("word"));
            }

            // empty substring
            {
                Substring s = new Substring("aaaaaaaaaaaa");
                Substring r = new Substring("oldval");
                s.Start = 5;
                s.End   = 4;
                UT_EQ('\0', s.Consume( ));
                UT_EQ(0, s.Consume(0, r)); UT_TRUE(r.IsNotNull()); UT_TRUE(r.IsEmpty());
                UT_EQ(0, s.Consume(5, r)); UT_TRUE(r.IsNotNull()); UT_TRUE(r.IsEmpty());
                UT_EQ(false, s.Consume('a'));
                UT_EQ(false, s.Consume("word"));
                UT_EQ('\0', s.ConsumeFromEnd( ));
                UT_EQ(0, s.ConsumeFromEnd(0));
                UT_EQ(0, s.ConsumeFromEnd(5));
                UT_EQ(false, s.ConsumeFromEnd('a'));
                UT_EQ(false, s.ConsumeFromEnd("word"));
            }

            // substring of length 1
            {
                Substring s = new Substring("aaaaaaaaaaaa");
                Substring r = new Substring("oldval");

                s.Start = s.End = 5; UT_EQ('a', s.Consume( )); UT_EQ(0, s.Length());
                s.Start = s.End = 5; UT_EQ(1, s.Consume(0)); UT_EQ(1, s.Length());
                s.Start = s.End = 5; UT_EQ(0, s.Consume(1, r)); UT_EQ(0, s.Length()); UT_TRUE(r.Equals("a"));
                s.Start = s.End = 5; UT_EQ(0, s.Consume(5, r)); UT_EQ(0, s.Length()); UT_TRUE(r.Equals("a"));
                s.Start = s.End = 5; UT_EQ(true, s.Consume('a')); UT_EQ(0, s.Length());
                s.Start = s.End = 5; UT_EQ(false, s.Consume('b')); UT_EQ(1, s.Length());
                s.Start = s.End = 5; UT_EQ(false, s.Consume("word")); UT_EQ(1, s.Length());
                s.Start = s.End = 5; UT_EQ('a', s.ConsumeFromEnd( )); UT_EQ(0, s.Length());
                s.Start = s.End = 5; UT_EQ(1, s.ConsumeFromEnd(0)); UT_EQ(1, s.Length());
                s.Start = s.End = 5; UT_EQ(0, s.ConsumeFromEnd(1)); UT_EQ(0, s.Length());
                s.Start = s.End = 5; UT_EQ(0, s.ConsumeFromEnd(5)); UT_EQ(0, s.Length());
                s.Start = s.End = 5; UT_EQ(true, s.ConsumeFromEnd('a')); UT_EQ(0, s.Length());
                s.Start = s.End = 5; UT_EQ(false, s.ConsumeFromEnd('b')); UT_EQ(1, s.Length());
                s.Start = s.End = 5; UT_EQ(false, s.ConsumeFromEnd("word")); UT_EQ(1, s.Length());
            }

            // substring of length 2
            {
                Substring s = new Substring("12ab3456");
                Substring r = new Substring("oldval");

                s.Start = 2; s.End = 3; UT_EQ('a', s.Consume( )); UT_EQ(1, s.Length());
                UT_EQ('b', s.Consume( )); UT_EQ(0, s.Length());
                s.Start = 2; s.End = 3; UT_EQ('b', s.ConsumeFromEnd( )); UT_EQ(1, s.Length());
                UT_EQ('a', s.ConsumeFromEnd( )); UT_EQ(0, s.Length());

                s.Start = 2; s.End = 3; UT_EQ(2, s.Consume(0, r)); UT_EQ(2, s.Length()); UT_TRUE(r.IsNotNull()); UT_TRUE(r.IsEmpty());
                s.Start = 2; s.End = 3; UT_EQ(1, s.Consume(1, r)); UT_EQ(1, s.Length()); UT_TRUE(r.Equals("a"));
                s.Start = 2; s.End = 3; UT_EQ(0, s.Consume(2, r)); UT_EQ(0, s.Length()); UT_TRUE(r.Equals("ab"));
                s.Start = 2; s.End = 3; UT_EQ(0, s.Consume(3, r)); UT_EQ(0, s.Length()); UT_TRUE(r.Equals("ab"));
                s.Start = 2; s.End = 3; UT_EQ(2, s.ConsumeFromEnd(0, r)); UT_EQ(2, s.Length()); UT_TRUE(r.IsNotNull()); UT_TRUE(r.IsEmpty());
                s.Start = 2; s.End = 3; UT_EQ(1, s.ConsumeFromEnd(1, r)); UT_EQ(1, s.Length()); UT_TRUE(r.Equals("b"));
                s.Start = 2; s.End = 3; UT_EQ(0, s.ConsumeFromEnd(2, r)); UT_EQ(0, s.Length()); UT_TRUE(r.Equals("ab"));
                s.Start = 2; s.End = 3; UT_EQ(0, s.ConsumeFromEnd(3, r)); UT_EQ(0, s.Length()); UT_TRUE(r.Equals("ab"));

                s.Start = 2; s.End = 3; UT_EQ(false, s.Consume('b')); UT_EQ(2, s.Length());
                UT_EQ(true, s.Consume('a')); UT_EQ(1, s.Length());
                UT_EQ(true, s.Consume('b')); UT_EQ(0, s.Length());
                UT_EQ(false, s.Consume('a')); UT_EQ(0, s.Length());
                UT_EQ(false, s.Consume('b')); UT_EQ(0, s.Length());
                s.Start = 2; s.End = 3; UT_EQ(false, s.ConsumeFromEnd('a')); UT_EQ(2, s.Length());
                UT_EQ(true, s.ConsumeFromEnd('b')); UT_EQ(1, s.Length());
                UT_EQ(true, s.ConsumeFromEnd('a')); UT_EQ(0, s.Length());
                UT_EQ(false, s.ConsumeFromEnd('b')); UT_EQ(0, s.Length());
                UT_EQ(false, s.ConsumeFromEnd('a')); UT_EQ(0, s.Length());

                s.Start = 2; s.End = 3; UT_EQ(false, s.Consume("word")); UT_EQ(2, s.Length());
                s.Start = 2; s.End = 3; UT_EQ(false, s.Consume("AB")); UT_EQ(2, s.Length());
                s.Start = 2; s.End = 3; UT_EQ(true, s.Consume("ab")); UT_EQ(0, s.Length());
                s.Start = 2; s.End = 3; UT_EQ(false, s.ConsumeFromEnd("word")); UT_EQ(2, s.Length());
                s.Start = 2; s.End = 3; UT_EQ(false, s.ConsumeFromEnd("AB")); UT_EQ(2, s.Length());
                s.Start = 2; s.End = 3; UT_EQ(true, s.ConsumeFromEnd("ab")); UT_EQ(0, s.Length());
            }

            // 3 words
            {
                Substring s = new Substring("word1 word2 word3");

                UT_EQ('w', s.Consume( ));
                UT_EQ('o', s.Consume( ));
                UT_EQ('r', s.Consume( ));
                UT_EQ('d', s.Consume( ));
                UT_EQ('1', s.Consume( ));

                UT_EQ(false, s.Consume('w'));
                UT_EQ(true, s.Consume('w', Whitespaces.Trim));
                UT_EQ(true, s.Consume('o', Whitespaces.Trim));
                UT_EQ(false, s.Consume('o', Whitespaces.Trim));
                UT_EQ(true, s.Consume('r', Whitespaces.Trim));
                UT_EQ(false, s.Consume("D2", Whitespaces.Trim));
                UT_EQ(false, s.Consume("D2"));
                UT_EQ(true, s.Consume("d2"));

                UT_EQ(2, s.Consume(4));
                UT_EQ("d3", s.ToString());

                s = new Substring("word1 word2 word3");

                UT_EQ('3', s.ConsumeFromEnd( ));
                UT_EQ('d', s.ConsumeFromEnd( ));
                UT_EQ('r', s.ConsumeFromEnd( ));
                UT_EQ('o', s.ConsumeFromEnd( ));
                UT_EQ('w', s.ConsumeFromEnd( ));

                UT_EQ(false, s.ConsumeFromEnd('2'));
                UT_EQ(true, s.ConsumeFromEnd('2', Whitespaces.Trim));
                UT_EQ(true, s.ConsumeFromEnd('d', Whitespaces.Trim));
                UT_EQ(false, s.ConsumeFromEnd('d', Whitespaces.Trim));
                UT_EQ(true, s.ConsumeFromEnd('r', Whitespaces.Trim));
                UT_EQ(false, s.ConsumeFromEnd("WO", Whitespaces.Trim));
                UT_EQ(false, s.ConsumeFromEnd("WO"));
                UT_EQ(true, s.ConsumeFromEnd("wo"));

                UT_EQ(2, s.ConsumeFromEnd(4));
                UT_EQ("wo", s.ToString());
            }

            // consume AString, Substring
            {
                Substring s        = new Substring("word1 word2 word3 word4");
                Substring sConsume = new Substring("1234word12", 4, 4);
                AString   aConsume = new AString("word");

                UT_EQ(true, s.Consume(sConsume));
                UT_EQ(false, s.Consume(sConsume));
                UT_EQ('1', s.Consume( ));
                UT_EQ(false, s.Consume(sConsume));
                UT_EQ(true, s.Consume(sConsume, Whitespaces.Trim));
                UT_EQ('2', s.Consume( ));
                UT_EQ(' ', s.Consume( ));

                UT_EQ(true, s.Consume(aConsume));
                UT_EQ(false, s.Consume(aConsume));
                UT_EQ('3', s.Consume( ));
                UT_EQ(false, s.Consume(aConsume));
                UT_EQ(true, s.Consume(aConsume, Whitespaces.Trim));

                s.Set("1word  2word 3word  4word");

                UT_EQ(true, s.ConsumeFromEnd(sConsume));
                UT_EQ(false, s.ConsumeFromEnd(sConsume));
                UT_EQ('4', s.ConsumeFromEnd( ));
                UT_EQ(false, s.ConsumeFromEnd(sConsume));
                UT_EQ(true, s.ConsumeFromEnd(sConsume, Whitespaces.Trim));
                UT_EQ('3', s.ConsumeFromEnd( ));
                UT_EQ(' ', s.ConsumeFromEnd( ));

                UT_EQ(true, s.ConsumeFromEnd(aConsume));
                UT_EQ(false, s.ConsumeFromEnd(aConsume));
                UT_EQ('2', s.ConsumeFromEnd( ));
                UT_EQ(false, s.ConsumeFromEnd(aConsume));
                UT_EQ(true, s.ConsumeFromEnd(aConsume, Whitespaces.Trim));
            }
        }
Пример #21
0
 private static string ToHumanReadableString(Substring substring)
 {
     return(substring.ToString().Unescape("/*{<", "/*{<"));
 }
Пример #22
0
 /** ****************************************************************************************
  * This is for debugging purposes. E.g. this enables the \e Monodevelop IDE to display
  * object descriptions in the debugger.
  * @returns A human readable string representation of this object.
  ******************************************************************************************/
 public override String ToString()
 {
     return("Actual: \"" + Actual.ToString() + "\" Rest: \"" + Rest.ToString() + "\"");
 }
Пример #23
0
 public void Trim()
 {
     Substring subs = new Substring();
     {
         String t;
         t = ""; subs.Set(" pad " + t + " abc ", 5, t.Length).Trim();        UT_EQ("", subs.ToString());
         t = " "; subs.Set(" pad " + t + " abc ", 5, t.Length).Trim();        UT_EQ("", subs.ToString());
         t = "  "; subs.Set(" pad " + t + " abc ", 5, t.Length).Trim();        UT_EQ("", subs.ToString());
         t = "abc"; subs.Set(" pad " + t + " abc ", 5, t.Length).Trim();        UT_EQ("abc", subs.ToString());
         t = "abc"; subs.Set(" pad " + t + " abc ", 5, t.Length).Trim();        UT_EQ("abc", subs.ToString());
         t = " abc"; subs.Set(" pad " + t + " abc ", 5, t.Length).Trim();        UT_EQ("abc", subs.ToString());
         t = "  abc"; subs.Set(" pad " + t + " abc ", 5, t.Length).Trim();        UT_EQ("abc", subs.ToString());
         t = " \tabc"; subs.Set(" pad " + t + " abc ", 5, t.Length).Trim();        UT_EQ("abc", subs.ToString());
         t = "\t abc"; subs.Set(" pad " + t + " abc ", 5, t.Length).Trim();        UT_EQ("abc", subs.ToString());
         t = "abc\r\n"; subs.Set(" pad " + t + " abc ", 5, t.Length).Trim();        UT_EQ("abc", subs.ToString());
         t = "\tabc\r\n"; subs.Set(" pad " + t + " abc ", 5, t.Length).Trim();        UT_EQ("abc", subs.ToString());
         t = "\tabc\rx\n"; subs.Set(" pad " + t + " abc ", 5, t.Length).Trim();        UT_EQ("abc\rx", subs.ToString());
     }
 }
Пример #24
0
 private static void WriteContext(MarkupStreamWriter writer, Substring context, int maxContextLength)
 {
     if (context.Length < maxContextLength)
     {
         writer.Write(context.ToString());
     }
     else
     {
         int split = maxContextLength / 2;
         if (split > 0)
         {
             writer.Write(context.Extract(0, split).ToString());
             writer.WriteEllipsis();
             writer.Write(context.Extract(context.Length - split));
         }
     }
 }
Пример #25
0
        public void ToStringExtractsSubstring()
        {
            Substring substring = new Substring("abcde", new Range(2, 3));

            Assert.AreEqual("cde", substring.ToString());
        }
Пример #26
0
 public void ToStringExtractsSubstring()
 {
     Substring substring = new Substring("abcde", new Range(2, 3));
     Assert.AreEqual("cde", substring.ToString());
 }