public void HandlesInlineAdditionSuccessful_InsertBetweenParentesisAfterOtherService()
        {
            var addition     = "IService myService";
            var contextStart = "public SomeClass(IOtherService otherService";
            var contextEnd   = ")";

            var styleProvider = new BaseCodeStyleProvider();
            var output        = styleProvider.AdaptInlineAddition(addition, contextStart, contextEnd);

            Assert.Equal(", IService myService", output);
        }
Esempio n. 2
0
        private int FindAndModifyContextLine(string mergeLine, int diffTrivia)
        {
            var macroInlineAdditionStart = _codeStyleProvider.InlineCommentStart + MergeMacros.MacroStartGroup + _codeStyleProvider.InlineCommentEnd;
            var macroInlineAdditionEnd   = _codeStyleProvider.InlineCommentStart + MergeMacros.MacroEndGroup + _codeStyleProvider.InlineCommentEnd;

            var mergeLineStart = mergeLine.Substring(0, mergeLine.IndexOf(macroInlineAdditionStart));
            var mergeLineEnd   = mergeLine.Substring(mergeLine.IndexOf(macroInlineAdditionEnd) + macroInlineAdditionEnd.Length, mergeLine.Length - mergeLine.IndexOf(macroInlineAdditionEnd) - macroInlineAdditionEnd.Length);

            var additionStartIndex = mergeLine.IndexOf(macroInlineAdditionStart) + macroInlineAdditionStart.Length;
            var additionEndIndex   = mergeLine.IndexOf(macroInlineAdditionEnd);

            var addition    = mergeLine.Substring(additionStartIndex, additionEndIndex - additionStartIndex);
            var lineIndex   = _result.SafeIndexOf(mergeLineStart.WithLeadingTrivia(diffTrivia), _lastContextLineIndex, true, true);
            var insertIndex = _result[lineIndex].Length;

            if (lineIndex != -1 && !_result[lineIndex].Contains(addition))
            {
                if (_codeStyleProvider != null)
                {
                    var nextChar = string.Empty;

                    if (mergeLineEnd != string.Empty)
                    {
                        insertIndex = _result[lineIndex].IndexOf(mergeLineEnd);
                        nextChar    = mergeLineEnd.Substring(1);
                    }

                    // Get complete line content until insert index
                    var lineStart = insertIndex > 0 ? _result[lineIndex].Substring(0, insertIndex) : string.Empty;

                    addition = _codeStyleProvider.AdaptInlineAddition(addition, lineStart, mergeLineEnd);
                }

                _result[lineIndex] = _result[lineIndex].Insert(insertIndex, addition);
            }

            return(lineIndex);
        }