Exemple #1
0
        public string TrimStartWithMax(string input, string startsWith, StringComparison comparisonType, int max)
        {
            PexAssume.IsNotNull(input);
            PexAssume.IsNotNull(startsWith);

            int    count;
            string result = CommonStringExtensions.TrimStart(input, startsWith, comparisonType, max, out count);

            PexAssert.IsNotNull(result);
            PexAssert.IsTrue(result.Length <= input.Length);

            bool isStartsWithNotEmpty = startsWith.Length > 0;

            if (isStartsWithNotEmpty)
            {
                int originalStartsWithCount = CommonStringExtensions.CountSubstringStart(input, startsWith, comparisonType);
                int resultStartsWithCount   = CommonStringExtensions.CountSubstringStart(result, startsWith, comparisonType);

                PexAssert.IsTrue(resultStartsWithCount == 0 ||
                                 resultStartsWithCount == originalStartsWithCount - max);
                PexAssert.IsTrue(originalStartsWithCount - resultStartsWithCount == count);
            }

            return(result);
        }
        public int CountSubstringStart(string input, string startsWith, StringComparison comparisonType)
        {
            int result = CommonStringExtensions.CountSubstringStart(input, startsWith, comparisonType);

            PexAssert.IsTrue(result >= 0);

            return(result);
        }
        public string TrimEndOnce(string input, string startsWith, StringComparison comparisonType)
        {
            string result = CommonStringExtensions.TrimEndOnce(input, startsWith, comparisonType);

            PexAssert.IsNotNull(result);
            PexAssert.IsTrue(result.Length <= input.Length);

            int originalStartsWithCount = CommonStringExtensions.CountSubstringStart(input, startsWith);
            int resultStartsWithCount   = CommonStringExtensions.CountSubstringStart(result, startsWith);

            PexAssert.IsTrue(originalStartsWithCount - resultStartsWithCount <= 1);

            return(result);
        }