예제 #1
0
        public void StartsWith(string input, char c, bool expected)
        {
            var substring = new Substring(input, 1, 2);
            var actual    = Substring.StartsWith(substring, c);

            Assert.Equal(expected, actual);
        }
예제 #2
0
        private static Substring TrimSquareBrackets(Substring key)
        {
            //Only trim a single layer of brackets.
            if (key.StartsWith('[') && key.EndsWith(']'))
            {
                return(new Substring(key, 1, key.Length - 2));
            }

            return(key);
        }
예제 #3
0
        void tStartsWith(String haystack, String needle, bool expectedSensitive, bool expectedIgnoreCase)
        {
            haystackAString._()._(haystack);
            haystackSubstring.Set("01" + haystack + "234", 2, haystack.Length);


            if (needle != null)
            {
                UT_EQ(expectedSensitive, haystackAString.StartsWith(needle, Case.Sensitive));
                UT_EQ(expectedIgnoreCase, haystackAString.StartsWith(needle, Case.Ignore));
                UT_EQ(expectedSensitive, haystackSubstring.StartsWith(needle, Case.Sensitive));
                UT_EQ(expectedIgnoreCase, haystackSubstring.StartsWith(needle, Case.Ignore));
                needleAString._()._(needle);
                UT_EQ(expectedSensitive, haystackAString.StartsWith(needleAString, Case.Sensitive));
                UT_EQ(expectedIgnoreCase, haystackAString.StartsWith(needleAString, Case.Ignore));
                UT_EQ(expectedSensitive, haystackSubstring.StartsWith(needleAString, Case.Sensitive));
                UT_EQ(expectedIgnoreCase, haystackSubstring.StartsWith(needleAString, Case.Ignore));

                needleSubstring.Set("XY" + needle + "Z", 2, needle.Length).Trim();
                UT_EQ(expectedSensitive, haystackAString.StartsWith(needleSubstring, Case.Sensitive));
                UT_EQ(expectedIgnoreCase, haystackAString.StartsWith(needleSubstring, Case.Ignore));
                UT_EQ(expectedSensitive, haystackSubstring.StartsWith(needleSubstring, Case.Sensitive));
                UT_EQ(expectedIgnoreCase, haystackSubstring.StartsWith(needleSubstring, Case.Ignore));
            }
            else
            {
                UT_EQ(expectedSensitive, haystackAString.StartsWith(needle, Case.Sensitive));
                UT_EQ(expectedIgnoreCase, haystackAString.StartsWith(needle, Case.Ignore));
                UT_EQ(expectedSensitive, haystackAString.StartsWith((AString)null, Case.Sensitive));
                UT_EQ(expectedIgnoreCase, haystackAString.StartsWith((AString)null, Case.Ignore));
                UT_EQ(expectedSensitive, haystackAString.StartsWith((Substring)null, Case.Sensitive));
                UT_EQ(expectedIgnoreCase, haystackAString.StartsWith((Substring)null, Case.Ignore));

                UT_EQ(expectedSensitive, haystackSubstring.StartsWith(needle, Case.Sensitive));
                UT_EQ(expectedIgnoreCase, haystackSubstring.StartsWith(needle, Case.Ignore));
                UT_EQ(expectedSensitive, haystackSubstring.StartsWith((AString)null, Case.Sensitive));
                UT_EQ(expectedIgnoreCase, haystackSubstring.StartsWith((AString)null, Case.Ignore));
                UT_EQ(expectedSensitive, haystackSubstring.StartsWith((Substring)null, Case.Sensitive));
                UT_EQ(expectedIgnoreCase, haystackSubstring.StartsWith((Substring)null, Case.Ignore));
            }
        }