public void IsCSharpOpenCurlyBrace_Blocks_ReturnFalse() { // Arrange var child = SyntaxFactory.MarkupBlock(); // Act var result = DefaultRazorIndentationFactsService.IsCSharpOpenCurlyBrace(child); // Assert Assert.False(result); }
public void GetIndentLevelOfLine_AddsTabsAndSpacesOnlyAtBeginningOfLine() { // Arrange var text = " \t \tHello\t World.\t "; var service = new DefaultRazorIndentationFactsService(); // Act var indentLevel = service.GetIndentLevelOfLine(text, 4); // Assert Assert.Equal(11, indentLevel); }
public void GetIndentLevelOfLine_NoIndent() { // Arrange var text = "Hello World."; var service = new DefaultRazorIndentationFactsService(); // Act var indentLevel = service.GetIndentLevelOfLine(text, 4); // Assert Assert.Equal(0, indentLevel); }
public void IsCSharpOpenCurlyBrace_SpanWithHtmlSymbol_ReturnFalse() { // Arrange var childBuilder = new SpanBuilder(SourceLocation.Zero); childBuilder.Accept(SyntaxFactory.Token(SyntaxKind.Text, "hello")); var child = childBuilder.Build(); // Act var result = DefaultRazorIndentationFactsService.IsCSharpOpenCurlyBrace(child); // Assert Assert.False(result); }
public void IsCSharpOpenCurlyBrace_SpanWithLeftBrace_ReturnTrue() { // Arrange var childBuilder = new SpanBuilder(SourceLocation.Zero); childBuilder.Accept(SyntaxFactory.Token(SyntaxKind.LeftBrace, "{")); var child = childBuilder.Build(); // Act var result = DefaultRazorIndentationFactsService.IsCSharpOpenCurlyBrace(child); // Assert Assert.True(result); }
public void IsCSharpOpenCurlyBrace_SpanWithUnsupportedSymbolType_ReturnFalse(string content, object symbolTypeObject) { // Arrange var symbolType = (SyntaxKind)symbolTypeObject; var childBuilder = new SpanBuilder(SourceLocation.Zero); childBuilder.Accept(SyntaxFactory.Token(symbolType, content)); var child = childBuilder.Build(); // Act var result = DefaultRazorIndentationFactsService.IsCSharpOpenCurlyBrace(child); // Assert Assert.False(result); }
public void IsCSharpOpenCurlyBrace_SpanWithHtmlSymbol_ReturnFalse() { // Arrange var builder = SyntaxListBuilder <SyntaxToken> .Create(); builder.Add(SyntaxFactory.Token(SyntaxKind.Text, "hello")); var child = SyntaxFactory.MarkupTextLiteral(builder.ToList()); // Act var result = DefaultRazorIndentationFactsService.IsCSharpOpenCurlyBrace(child); // Assert Assert.False(result); }
public void IsCSharpOpenCurlyBrace_SpanWithLeftBrace_ReturnTrue() { // Arrange var builder = SyntaxListBuilder <SyntaxToken> .Create(); builder.Add(SyntaxFactory.Token(SyntaxKind.LeftBrace, "{")); var child = SyntaxFactory.RazorMetaCode(builder.ToList()); // Act var result = DefaultRazorIndentationFactsService.IsCSharpOpenCurlyBrace(child); // Assert Assert.True(result); }
public void IsCSharpOpenCurlyBrace_SpanWithLeftBrace_ReturnTrue() { // Arrange var childBuilder = new SpanBuilder(SourceLocation.Zero); childBuilder.Accept(new CSharpSymbol("{", CSharpSymbolType.LeftBrace)); var child = childBuilder.Build(); // Act var result = DefaultRazorIndentationFactsService.IsCSharpOpenCurlyBrace(child); // Assert Assert.True(result); }
public void IsCSharpOpenCurlyBrace_Blocks_ReturnFalse() { // Arrange var child = new BlockBuilder() { Type = BlockKindInternal.Markup, }.Build(); // Act var result = DefaultRazorIndentationFactsService.IsCSharpOpenCurlyBrace(child); // Assert Assert.False(result); }
public void GetPreviousLineEndIndex_ReturnsPreviousLine() { // Arrange var textSnapshot = new StringTextSnapshot(@"@{ <p>Hello World</p> }"); var line = textSnapshot.GetLineFromLineNumber(2); // Act var previousLineEndIndex = DefaultRazorIndentationFactsService.GetPreviousLineEndIndex(textSnapshot, line); // Assert Assert.Equal(24 + Environment.NewLine.Length, previousLineEndIndex); }
public void IsCSharpOpenCurlyBrace_SpanWithUnsupportedSymbolType_ReturnFalse(string content, object symbolTypeObject) { // Arrange var symbolType = (SyntaxKind)symbolTypeObject; var builder = SyntaxListBuilder <SyntaxToken> .Create(); builder.Add(SyntaxFactory.Token(symbolType, content)); var child = SyntaxFactory.MarkupTextLiteral(builder.ToList()); // Act var result = DefaultRazorIndentationFactsService.IsCSharpOpenCurlyBrace(child); // Assert Assert.False(result); }
public void IsCSharpOpenCurlyBrace_MultipleSymbols_ReturnFalse() { // Arrange var childBuilder = new SpanBuilder(SourceLocation.Zero); childBuilder.Accept(new CSharpToken("hello", CSharpTokenType.Identifier)); childBuilder.Accept(new CSharpToken(",", CSharpTokenType.Comma)); var child = childBuilder.Build(); // Act var result = DefaultRazorIndentationFactsService.IsCSharpOpenCurlyBrace(child); // Assert Assert.False(result); }
public void GetDesiredIndentation_ReturnsCorrectIndentation_ForMarkupWithinCodeBlock() { // Arrange var source = new StringTextSnapshot($@"@{{ <div> "); var syntaxTree = GetSyntaxTree(source); var service = new DefaultRazorIndentationFactsService(); // Act var indentation = service.GetDesiredIndentation( syntaxTree, source, source.GetLineFromLineNumber(2), indentSize: 4, tabSize: 4); // Assert Assert.Equal(4, indentation); }
public void GetDesiredIndentation_ReturnsNull_IfOwningSpanIsCode() { // Arrange var source = new StringTextSnapshot($@" @{{ "); var syntaxTree = GetSyntaxTree(source); var service = new DefaultRazorIndentationFactsService(); // Act var indentation = service.GetDesiredIndentation( syntaxTree, source, source.GetLineFromLineNumber(2), indentSize: 4, tabSize: 1); // Assert Assert.Null(indentation); }
public void GetDesiredIndentation_ReturnsNull_IfOwningSpanIsNone() { // Arrange var customDirective = DirectiveDescriptor.CreateSingleLineDirective("custom"); var source = new StringTextSnapshot($@" @custom "); var syntaxTree = GetSyntaxTree(source, new[] { customDirective }); var service = new DefaultRazorIndentationFactsService(); // Act var indentation = service.GetDesiredIndentation( syntaxTree, source, source.GetLineFromLineNumber(2), indentSize: 4, tabSize: 1); // Assert Assert.Null(indentation); }
public void GetDesiredIndentation_ReturnsCorrectIndentation_ForMarkupWithinDirectiveBlock() { // Arrange var customDirective = DirectiveDescriptor.CreateRazorBlockDirective("custom"); var source = new StringTextSnapshot($@"@custom {{ <div> }}"); var syntaxTree = GetSyntaxTree(source, new[] { customDirective }); var service = new DefaultRazorIndentationFactsService(); // Act var indentation = service.GetDesiredIndentation( syntaxTree, source, source.GetLineFromLineNumber(3), indentSize: 4, tabSize: 4); // Assert Assert.Equal(4, indentation); }
public void GetDesiredIndentation_ReturnsNull_IfOwningSpanDoesNotExist() { // Arrange var source = new StringTextSnapshot($@" <div> <div> </div> </div> "); var syntaxTree = GetSyntaxTree(new StringTextSnapshot("something else")); var service = new DefaultRazorIndentationFactsService(); // Act var indentation = service.GetDesiredIndentation( syntaxTree, source, source.GetLineFromLineNumber(3), indentSize: 4, tabSize: 1); // Assert Assert.Null(indentation); }