Пример #1
0
        Commit ResolveRequiredMigrator(IRepository repository, Commit branchTip, System.Collections.Immutable.IImmutableList <Migrator> migrators)
        {
            RequiredMigrator = migrators.Count > 0 ? migrators[0] : null;
            if (RequiredMigrator != null && RequiredMigrator.CommitId != BranchTarget)
            {
                IsPartialMerge = true;

                branchTip    = repository.Lookup <Commit>(RequiredMigrator.CommitId);
                BranchTarget = RequiredMigrator.CommitId;
            }

            return(branchTip);
        }
        public void Remove_NullEqualityComparer()
        {
            var collection = ImmutableSegmentedList.Create(1, 2, 3);
            var modified   = collection.Remove(2, null);

            Assert.Equal(new[] { 1, 3 }, modified);

            // Try again through the explicit interface implementation.
            System.Collections.Immutable.IImmutableList <int> collectionIface = collection;
            var modified2 = collectionIface.Remove(2, null);

            Assert.Equal(new[] { 1, 3 }, modified2);
        }
        public void RemoveTest()
        {
            ImmutableSegmentedList <int> list = ImmutableSegmentedList <int> .Empty;

            for (int i = 1; i <= 10; i++)
            {
                list = list.Add(i * 10);
            }

            list = list.Remove(30);
            Assert.Equal(9, list.Count);
            Assert.False(list.Contains(30));

            list = list.Remove(100);
            Assert.Equal(8, list.Count);
            Assert.False(list.Contains(100));

            list = list.Remove(10);
            Assert.Equal(7, list.Count);
            Assert.False(list.Contains(10));

            var removeList = new int[] { 20, 70 };

            list = list.RemoveAll(removeList.Contains);
            Assert.Equal(5, list.Count);
            Assert.False(list.Contains(20));
            Assert.False(list.Contains(70));

            System.Collections.Immutable.IImmutableList <int> list2 = ImmutableSegmentedList <int> .Empty;
            for (int i = 1; i <= 10; i++)
            {
                list2 = list2.Add(i * 10);
            }

            list2 = System.Collections.Immutable.ImmutableList.Remove(list2, 30);
            Assert.Equal(9, list2.Count);
            Assert.False(list2.Contains(30));

            list2 = System.Collections.Immutable.ImmutableList.Remove(list2, 100);
            Assert.Equal(8, list2.Count);
            Assert.False(list2.Contains(100));

            list2 = System.Collections.Immutable.ImmutableList.Remove(list2, 10);
            Assert.Equal(7, list2.Count);
            Assert.False(list2.Contains(10));

            list2 = list2.RemoveAll(removeList.Contains);
            Assert.Equal(5, list2.Count);
            Assert.False(list2.Contains(20));
            Assert.False(list2.Contains(70));
        }
        public void ReplaceWithEqualityComparerTest()
        {
            var list = ImmutableSegmentedList.Create(new Person {
                Name = "Andrew", Age = 20
            });
            var newAge = new Person {
                Name = "Andrew", Age = 21
            };
            var updatedList = list.Replace(newAge, newAge, new NameOnlyEqualityComparer());

            Assert.Equal(newAge.Age, updatedList[0].Age);

            // Try again with a null equality comparer, which should use the default EQ.
            updatedList = list.Replace(list[0], newAge);
            Assert.False(IsSame(list, updatedList));

            // Finally, try one last time using the interface implementation.
            System.Collections.Immutable.IImmutableList <Person> iface = list;
            var updatedIface = System.Collections.Immutable.ImmutableList.Replace(iface, list[0], newAge);

            Assert.NotSame(iface, updatedIface);
        }
Пример #5
0
        private int alignToOpenToken(ITextSnapshotLine currentLine)
        {
            int indentValue = 0;

            try
            {
                int lineNumber = currentLine.LineNumber;
                //
                var buffer = _textView.TextBuffer;
                // Try to retrieve an already parsed list of Tags
                XSharpClassifier xsClassifier = null;
                if (buffer.Properties.ContainsProperty(typeof(XSharpClassifier)))
                {
                    xsClassifier = buffer.Properties[typeof(XSharpClassifier)] as XSharpClassifier;
                }

                if (xsClassifier != null)
                {
                    //
                    ITextSnapshot snapshot = xsClassifier.Snapshot;
                    SnapshotSpan  Span     = new SnapshotSpan(snapshot, 0, snapshot.Length);
                    System.Collections.Immutable.IImmutableList <Microsoft.VisualStudio.Text.Classification.ClassificationSpan> classifications = xsClassifier.GetRegionTags();
                    // We cannot use SortedList, because we may have several Classification that start at the same position
                    List <Microsoft.VisualStudio.Text.Classification.ClassificationSpan> sortedTags = new List <Microsoft.VisualStudio.Text.Classification.ClassificationSpan>();
                    foreach (var tag in classifications)
                    {
                        sortedTags.Add(tag);
                    }
                    sortedTags.Sort((a, b) => a.Span.Start.Position.CompareTo(b.Span.Start.Position));
                    //
                    Stack <Microsoft.VisualStudio.Text.Classification.ClassificationSpan> startStack = new Stack <Microsoft.VisualStudio.Text.Classification.ClassificationSpan>();
                    foreach (var tag in sortedTags)
                    {
                        // Is it a Region ?
                        if (tag.ClassificationType.IsOfType(ColorizerConstants.XSharpRegionStartFormat))
                        {
                            startStack.Push(tag);
                        }
                        else if (tag.ClassificationType.IsOfType(ColorizerConstants.XSharpRegionStopFormat))
                        {
                            //
                            var startTag  = startStack.Pop();
                            var startLine = startTag.Span.Start.GetContainingLine();
                            // Looking for an End

                            var endLine = tag.Span.End.GetContainingLine();
                            if (endLine.LineNumber == lineNumber)
                            {
                                // Where is the start ?
                                SnapshotSpan sSpan    = new SnapshotSpan(startLine.Start, startLine.End);
                                String       lineText = sSpan.GetText();
                                lineText = lineText.Replace("\t", new String(' ', _tabSize));
                                //
                                indentValue = (lineText.Length - lineText.TrimStart().Length);
                                break;
                            }
                        }
                    }
                }
            }
            finally
            {
            }
            //
            return(indentValue);
        }
Пример #6
0
        private bool hasRegions()
        {
            bool result = false;
            //
            var buffer = _textView.TextBuffer;
            // Try to retrieve an already parsed list of Tags
            XSharpClassifier xsClassifier = null;

            if (buffer.Properties.ContainsProperty(typeof(XSharpClassifier)))
            {
                xsClassifier = buffer.Properties[typeof(XSharpClassifier)] as XSharpClassifier;
            }
            if (xsClassifier != null)
            {
                System.Collections.Immutable.IImmutableList <Microsoft.VisualStudio.Text.Classification.ClassificationSpan> classifications = xsClassifier.GetRegionTags();
                result = (classifications.Count > 0);
            }
            return(result);
        }