public static void CurrentAnalysisReturnsSemanticErrorsDetectedInTextBuffer() { var buffer = new FakeTextBuffer("<#@ template bad=\"puppy\" #>"); var target = TemplateAnalyzer.GetOrCreate(buffer); Assert.Equal(1, target.CurrentAnalysis.Errors.Count); }
public static void DisposeRemovesCompletionSourceFromTextBufferProperties() { ITextBuffer buffer = new FakeTextBuffer(string.Empty); var completionSource = buffer.Properties.GetOrCreateSingletonProperty(() => new TemplateCompletionSource(buffer)); completionSource.Dispose(); Assert.False(buffer.Properties.ContainsProperty(typeof(TemplateCompletionSource))); }
public void TextBufferChangeRemovesOldTagSpans() { var buffer = new FakeTextBuffer("<#"); var tagger = new TemplateClassificationTagger(buffer, this.registry); buffer.CurrentSnapshot = new FakeTextSnapshot(string.Empty); Assert.False(tagger.GetTaggedSpans(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length)).Any()); }
public static void GetOrCreateReturnsNewTemplateAnalyzerFirstTimeItIsRequestedForTextBuffer() { ITextBuffer buffer = new FakeTextBuffer(string.Empty); TemplateAnalyzer analyzer = TemplateAnalyzer.GetOrCreate(buffer); Assert.NotNull(analyzer); }
public static void TryCreateCompletionSourceReturnsTemplateCompletionSource() { var provider = new TemplateCompletionSourceProvider(); var buffer = new FakeTextBuffer(string.Empty); Assert.NotNull(provider.TryCreateCompletionSource(buffer)); }
private IEnumerable <ITagSpan <ClassificationTag> > GetTags(string text) { var buffer = new FakeTextBuffer(text); var tagger = new TemplateClassificationTagger(buffer, this.registry); var spans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length)); return(tagger.GetTags(spans)); }
public static void CurrentAnalysisReturnsLastTemplateAnalysisResult() { var buffer = new FakeTextBuffer("<#@"); var target = TemplateAnalyzer.GetOrCreate(buffer); TemplateAnalysis result = target.CurrentAnalysis; Assert.NotNull(result); }
public static void TryCreateCompletionSourceReturnsSameCompletionSourceForSameBuffer() { var provider = new TemplateCompletionSourceProvider(); var buffer = new FakeTextBuffer(string.Empty); var completionSource1 = provider.TryCreateCompletionSource(buffer); var completionSource2 = provider.TryCreateCompletionSource(buffer); Assert.Same(completionSource1, completionSource2); }
public static void GetOrCreateReturnsExistingTemplateAnalyzerSecondTimeItIsRequestedForTextBuffer() { ITextBuffer buffer = new FakeTextBuffer(string.Empty); TemplateAnalyzer analyzer1 = TemplateAnalyzer.GetOrCreate(buffer); TemplateAnalyzer analyzer2 = TemplateAnalyzer.GetOrCreate(buffer); Assert.Same(analyzer1, analyzer2); }
public static void CurrentAnalysisReturnsTextSnapshotForWhichItWasCreated() { var buffer = new FakeTextBuffer(string.Empty); var analyzer = TemplateAnalyzer.GetOrCreate(buffer); ITextSnapshot analysisSnapshot = analyzer.CurrentAnalysis.TextSnapshot; Assert.Same(buffer.CurrentSnapshot, analysisSnapshot); }
private static IEnumerable<ITagSpan<OutliningRegionTag>> GetTags(string input) { var buffer = new FakeTextBuffer(input); var tagger = new TemplateOutliningTagger(buffer); var snapshotSpans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length)); return tagger.GetTags(snapshotSpans); }
public static void CurrentAnalysisReturnsTemplateParsedFromTextBuffer() { var buffer = new FakeTextBuffer("<#@ template language=\"VB\" #>"); var target = TemplateAnalyzer.GetOrCreate(buffer); Template template = target.CurrentAnalysis.Template; Assert.NotNull(template); Assert.Equal(1, template.ChildNodes().Count()); }
public static void TryCreateQuickInfoSourceReturnsTemplateQuickInfoSource() { ITemplateEditorOptions options = OptionsWithQuickInfoTooltipsEnabled(true); var provider = new TemplateQuickInfoSourceProvider(options); var textBuffer = new FakeTextBuffer(string.Empty); IQuickInfoSource quickInfoSource = provider.TryCreateQuickInfoSource(textBuffer); Assert.Equal(typeof(TemplateQuickInfoSource), quickInfoSource.GetType()); }
public static void CurrentAnalysisReturnsDefaultTemplateIfParserCouldNotCreateOne() { var buffer = new FakeTextBuffer("<#@ t"); var target = TemplateAnalyzer.GetOrCreate(buffer); Template template = target.CurrentAnalysis.Template; Assert.NotNull(template); Assert.Equal(0, template.ChildNodes().Count()); }
private static IEnumerable <ITagSpan <OutliningRegionTag> > GetTags(string input) { var buffer = new FakeTextBuffer(input); var tagger = new TemplateOutliningTagger(buffer); var snapshotSpans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length)); return(tagger.GetTags(snapshotSpans)); }
public static void CreateTaggerReturnsSingleTaggerWhenCalledMultipleTimesForSameBuffer() { ITemplateEditorOptions options = OptionsWithTemplateOutliningEnabled(true); var provider = new TemplateOutliningTaggerProvider(options); var buffer = new FakeTextBuffer(string.Empty); var tagger1 = provider.CreateTagger <OutliningRegionTag>(buffer); var tagger2 = provider.CreateTagger <OutliningRegionTag>(buffer); Assert.Same(tagger1, tagger2); }
public static void CreateTaggerReturnsSameTaggerWhenCalledMultipleTimesForSameBuffer() { ITemplateEditorOptions options = OptionsWithSyntaxColorizationEnabled(true); var target = new TemplateClassificationTaggerProvider(options, new FakeClassificationTypeRegistryService()); var buffer = new FakeTextBuffer(string.Empty); var tagger1 = target.CreateTagger <ClassificationTag>(buffer); var tagger2 = target.CreateTagger <ClassificationTag>(buffer); Assert.Same(tagger1, tagger2); }
public static void TemplateChangedEventIsRaisedWhenTextBufferChanges() { var buffer = new FakeTextBuffer(string.Empty); var target = TemplateAnalyzer.GetOrCreate(buffer); bool templateChanged = false; target.TemplateChanged += (sender, args) => { templateChanged = true; }; buffer.CurrentSnapshot = new FakeTextSnapshot("42"); Assert.True(templateChanged); }
public static void TemplateChangeEventArgumentSuppliesCurrentTemplateAnalysis() { var buffer = new FakeTextBuffer(string.Empty); var target = TemplateAnalyzer.GetOrCreate(buffer); TemplateAnalysis eventArgument = null; target.TemplateChanged += (sender, args) => { eventArgument = args; }; buffer.CurrentSnapshot = new FakeTextSnapshot("42"); Assert.Same(target.CurrentAnalysis, eventArgument); }
public static void CreateTaggerReturnsSameTaggerWhenCalledMultipleTimesForSameBuffer() { ITemplateEditorOptions options = OptionsWithErrorUnderliningEnabled(true); var target = new TemplateErrorTaggerProvider(options); var buffer = new FakeTextBuffer(string.Empty); var tagger1 = target.CreateTagger <ErrorTag>(buffer); var tagger2 = target.CreateTagger <ErrorTag>(buffer); Assert.Same(tagger1, tagger2); }
public static void TryCreateQuickInfoSourceReturnsSameObjectWhenCalledMultipleTimesForSameBuffer() { ITemplateEditorOptions options = OptionsWithQuickInfoTooltipsEnabled(true); var provider = new TemplateQuickInfoSourceProvider(options); var textBuffer = new FakeTextBuffer(string.Empty); IQuickInfoSource source1 = provider.TryCreateQuickInfoSource(textBuffer); IQuickInfoSource source2 = provider.TryCreateQuickInfoSource(textBuffer); Assert.Same(source1, source2); }
public static void CurrentAnalysisReturnsUpdatedErrorsWhenTextBufferChanges() { var buffer = new FakeTextBuffer("<#@"); var target = TemplateAnalyzer.GetOrCreate(buffer); Assert.Equal(1, target.CurrentAnalysis.Errors.Count); // Need to touch lazy property before buffer change for test to be valid buffer.CurrentSnapshot = new FakeTextSnapshot(string.Empty); Assert.Equal(0, target.CurrentAnalysis.Errors.Count); }
public static void CurrentAnalysisReturnsUpdatedTemplateWhenTextBufferChanges() { var buffer = new FakeTextBuffer("<#@ template language=\"VB\" #>"); var target = TemplateAnalyzer.GetOrCreate(buffer); Assert.Equal(1, target.CurrentAnalysis.Template.ChildNodes().Count()); // Need to touch lazy Template before buffer change for test to be valid buffer.CurrentSnapshot = new FakeTextSnapshot(string.Empty); Assert.Equal(0, target.CurrentAnalysis.Template.ChildNodes().Count()); }
public void TextBufferChangeRaisesTagsChangedEvent() { var buffer = new FakeTextBuffer(string.Empty); var tagger = new TemplateClassificationTagger(buffer, this.registry); bool tagsChangedEventRaised = false; tagger.TagsChanged += (sender, args) => tagsChangedEventRaised = true; buffer.CurrentSnapshot = new FakeTextSnapshot("<#"); Assert.True(tagsChangedEventRaised); }
public static void GetTagsReturnsErrorSpanForSemanticError() { var buffer = new FakeTextBuffer("<#@ include file=\" \" #>"); var tagger = new TemplateErrorTagger(buffer); var snapshotSpans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length)); ITagSpan <ErrorTag> errorSpan = tagger.GetTags(snapshotSpans).Single(); Assert.Equal(new Span(12, 8), errorSpan.Span); Assert.Contains("File", (string)errorSpan.Tag.ToolTipContent, StringComparison.OrdinalIgnoreCase); }
public static void GetTagsReturnsErrorSpanForSemanticError() { var buffer = new FakeTextBuffer("<#@ include file=\" \" #>"); var tagger = new TemplateErrorTagger(buffer); var snapshotSpans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length)); ITagSpan<ErrorTag> errorSpan = tagger.GetTags(snapshotSpans).Single(); Assert.Equal(new Span(12, 8), errorSpan.Span); Assert.Contains("File", (string)errorSpan.Tag.ToolTipContent, StringComparison.OrdinalIgnoreCase); }
public static void CreateTaggerDoesNotCreateTemplateErrorReporterWhenErrorReportingIsDisabled() { ITemplateEditorOptions options = OptionsWithErrorReportingEnabled(false); var provider = new TemplateErrorReporterProvider(options, Substitute.For <SVsServiceProvider>(), Substitute.For <ITextDocumentFactoryService>()); ITextBuffer textBuffer = new FakeTextBuffer(string.Empty); provider.CreateTagger <ErrorTag>(textBuffer); Assert.False(textBuffer.Properties.ContainsProperty(typeof(TemplateErrorReporter))); }
public static void TemplateChangeRemovesOldTagSpans() { var buffer = new FakeTextBuffer(string.Empty); var tagger = new TestableTemplateTagger(buffer); tagger.CreateTagSpan(buffer.CurrentSnapshot.CreateTrackingSpan(new Span(), SpanTrackingMode.EdgeNegative), new ErrorTag()); buffer.CurrentSnapshot = new FakeTextSnapshot(string.Empty); Assert.False(tagger.GetTaggedSpans(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length)).Any()); }
public static void UpdateTagSpansRemovesOldSpans() { var buffer = new FakeTextBuffer(string.Empty); var tagger = new TestableTemplateTagger(buffer); tagger.CreateTagSpan(buffer.CurrentSnapshot.CreateTrackingSpan(new Span(), SpanTrackingMode.EdgeNegative), new ErrorTag()); tagger.UpdateTagSpans(new TemplateAnalysis(null, null, null)); Assert.Equal(0, tagger.GetTags(new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length))).Count()); }
private static IList<CompletionSet> AugmentCompletionSession(string text, int triggerPosition, out ITextSnapshot snapshot) { var buffer = new FakeTextBuffer(text); var completionSession = new FakeCompletionSession { TriggerPosition = triggerPosition }; using (var completionSource = new TemplateCompletionSource(buffer)) { var completionSets = new List<CompletionSet>(); completionSource.AugmentCompletionSession(completionSession, completionSets); snapshot = buffer.CurrentSnapshot; return completionSets; } }
public static void TemplateAnalyzerDoesNotPreventTemplateErrorTaggerFromGarbageCollection() { var buffer = new FakeTextBuffer(string.Empty); var analyzer = TemplateAnalyzer.GetOrCreate(buffer); var tagger = new WeakReference(new TestableTemplateTagger(buffer)); GC.Collect(2, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); Assert.NotNull(analyzer); Assert.False(tagger.IsAlive); }
public static void UpdateTagSpansCreatesNewTagSpans() { var buffer = new FakeTextBuffer(string.Empty); var tagger = new TestableTemplateTagger(buffer); bool tagsCreated = false; tagger.CreateTagSpansMethod = snapshot => tagsCreated = true; tagger.UpdateTagSpans(new TemplateAnalysis(null, null, null)); Assert.True(tagsCreated); }
public static void TemplateChangeCreatesNewTagSpans() { var buffer = new FakeTextBuffer(string.Empty); var tagger = new TestableTemplateTagger(buffer); bool tagsCreated = false; tagger.CreateTagSpansMethod = snapshot => tagsCreated = true; buffer.CurrentSnapshot = new FakeTextSnapshot(string.Empty); Assert.True(tagsCreated); }
public static void AugmentQuickInfoSessionReturnsDescriptionOfSyntaxNodeAtTriggerPoint() { var buffer = new FakeTextBuffer("<#@ assembly name=\"System\" #>"); var session = new FakeQuickInfoSession { SnapshotTriggerPoint = new SnapshotPoint(buffer.CurrentSnapshot, 5) }; using (var source = new TemplateQuickInfoSource(buffer)) { var quickInfoContent = new List<object>(); ITrackingSpan applicableToSpan; source.AugmentQuickInfoSession(session, quickInfoContent, out applicableToSpan); Assert.Contains("assembly", (string)quickInfoContent[0], StringComparison.Ordinal); } }
public static void AugmentQuickInfoSessionReturnsNoContentOrApplicableSpanWhenBufferIsEmpty() { var buffer = new FakeTextBuffer(string.Empty); var session = new FakeQuickInfoSession(); using (var source = new TemplateQuickInfoSource(buffer)) { var quickInfoContent = new List<object>(); ITrackingSpan applicableToSpan; source.AugmentQuickInfoSession(session, quickInfoContent, out applicableToSpan); Assert.Equal(0, quickInfoContent.Count); Assert.Null(applicableToSpan); } }
public static void AugmentQuickInfoSessionReturnsNoContentOrApplicableSpanWhenBufferContainsTemplateThatCouldNotBeParsed() { var buffer = new FakeTextBuffer("<#"); var session = new FakeQuickInfoSession { SnapshotTriggerPoint = new SnapshotPoint(buffer.CurrentSnapshot, 1) }; using (var source = new TemplateQuickInfoSource(buffer)) { var quickInfoContent = new List<object>(); ITrackingSpan applicableToSpan; source.AugmentQuickInfoSession(session, quickInfoContent, out applicableToSpan); Assert.Equal(0, quickInfoContent.Count); Assert.Null(applicableToSpan); } }
public static void AugmentQuickInfoSessionReturnsNoContentOrApplicableSpanSyntaxNodeAtTriggerPointHasNoDescription() { var buffer = new FakeTextBuffer("<# code #>"); var session = new FakeQuickInfoSession { SnapshotTriggerPoint = new SnapshotPoint(buffer.CurrentSnapshot, 3) }; using (var source = new TemplateQuickInfoSource(buffer)) { var quickInfoContent = new List<object>(); ITrackingSpan applicableToSpan; source.AugmentQuickInfoSession(session, quickInfoContent, out applicableToSpan); Assert.Equal(0, quickInfoContent.Count); Assert.Null(applicableToSpan); } }
private IEnumerable<ITagSpan<ClassificationTag>> GetTags(string text) { var buffer = new FakeTextBuffer(text); var tagger = new TemplateClassificationTagger(buffer, this.registry); var spans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length)); return tagger.GetTags(spans); }
public static void CreateTaggerReturnsSingleTaggerWhenCalledMultipleTimesForSameBuffer() { ITemplateEditorOptions options = OptionsWithTemplateOutliningEnabled(true); var provider = new TemplateOutliningTaggerProvider(options); var buffer = new FakeTextBuffer(string.Empty); var tagger1 = provider.CreateTagger<OutliningRegionTag>(buffer); var tagger2 = provider.CreateTagger<OutliningRegionTag>(buffer); Assert.Same(tagger1, tagger2); }
public static void AugmentQuickInfoSessionReturnsSpanOfSyntaxNodeProvidingDescription() { var buffer = new FakeTextBuffer("<#@ assembly name=\"System\" #>"); var session = new FakeQuickInfoSession { SnapshotTriggerPoint = new SnapshotPoint(buffer.CurrentSnapshot, 15) }; using (var source = new TemplateQuickInfoSource(buffer)) { var quickInfoContent = new List<object>(); ITrackingSpan applicableToSpan; source.AugmentQuickInfoSession(session, quickInfoContent, out applicableToSpan); Assert.Equal(new Span(13, 13), applicableToSpan.GetSpan(buffer.CurrentSnapshot).Span); } }
public static void CreateTaggerCreatesTemplateErrorReporterWhenErrorReportingIsEnabled() { ITemplateEditorOptions options = OptionsWithErrorReportingEnabled(true); var provider = new TemplateErrorReporterProvider(options, Substitute.For<SVsServiceProvider>(), Substitute.For<ITextDocumentFactoryService>()); ITextBuffer textBuffer = new FakeTextBuffer(string.Empty); provider.CreateTagger<ErrorTag>(textBuffer); Assert.True(textBuffer.Properties.ContainsProperty(typeof(TemplateErrorReporter))); }
public static void CreateTaggerReturnsSameTaggerWhenCalledMultipleTimesForSameBuffer() { ITemplateEditorOptions options = OptionsWithSyntaxColorizationEnabled(true); var target = new TemplateClassificationTaggerProvider(options, new FakeClassificationTypeRegistryService()); var buffer = new FakeTextBuffer(string.Empty); var tagger1 = target.CreateTagger<ClassificationTag>(buffer); var tagger2 = target.CreateTagger<ClassificationTag>(buffer); Assert.Same(tagger1, tagger2); }
public static void CreateTaggerReturnsSameTaggerWhenCalledMultipleTimesForSameBuffer() { ITemplateEditorOptions options = OptionsWithErrorUnderliningEnabled(true); var target = new TemplateErrorTaggerProvider(options); var buffer = new FakeTextBuffer(string.Empty); var tagger1 = target.CreateTagger<ErrorTag>(buffer); var tagger2 = target.CreateTagger<ErrorTag>(buffer); Assert.Same(tagger1, tagger2); }