public void CalculatePaddingForIfSpanWith5Spaces(bool designTime, bool isIndentingWithTabs, int tabSize)
        {
            // Arrange
            RazorEngineHost host = CreateHost(designTime, isIndentingWithTabs, tabSize);

            Span span = GenerateSpan(@"    @if (true)", SpanKind.Code, 2, "if (true)");

            var paddingBuilder = new CSharpPaddingBuilder(host);

            // Act
            int padding = paddingBuilder.CalculatePadding(span, 1);

            // Assert
            Assert.Equal(4, padding);
        }
        public void CalculatePaddingForEmptySpanReturnsZero()
        {
            // Arrange
            RazorEngineHost host = CreateHost(designTime: true);

            Span span = new Span(new SpanBuilder());

            var paddingBuilder = new CSharpPaddingBuilder(host);

            // Act
            int padding = paddingBuilder.CalculatePadding(span, 0);

            // Assert
            Assert.Equal(0, padding);
        }
        public void CalculatePaddingForEmptySpanWith4Spaces(bool designTime, bool isIndentingWithTabs, int tabSize)
        {
            // Arrange
            var host = CreateHost(designTime, isIndentingWithTabs, tabSize);

            var span = GenerateSpan(@"    @{", SpanKind.Code, 3, "");

            var paddingBuilder = new CSharpPaddingBuilder(host);

            // Act
            var padding = paddingBuilder.CalculatePadding(span, 1);

            // Assert
            Assert.Equal(5, padding);
        }
Beispiel #4
0
 public CSharpCodeVisitor(CSharpCodeWriter writer, CodeBuilderContext context)
     : base(writer, context)
 {
     _paddingBuilder = new CSharpPaddingBuilder(context.Host);
 }
Beispiel #5
0
 public CSharpCodeVisitor(CSharpCodeWriter writer, CodeBuilderContext context)
     : base(writer, context)
 {
     _paddingBuilder   = new CSharpPaddingBuilder(context.Host);
     TagHelperRenderer = new CSharpTagHelperCodeRenderer(this, writer, context);
 }
        public void VerifyPaddingForIfSpanWith4Spaces(bool designTime, bool isIndentingWithTabs, int tabSize, int numTabs, int numSpaces)
        {
            // Arrange
            RazorEngineHost host = CreateHost(designTime, isIndentingWithTabs, tabSize);

            // no new lines involved
            Span spanFlat = GenerateSpan("    @if (true)", SpanKind.Code, 2, "if (true)");
            Span spanNewlines = GenerateSpan("\t<div>\r\n    @if (true)", SpanKind.Code, 3, "if (true)");

            var paddingBuilder = new CSharpPaddingBuilder(host);

            // Act
            string paddingFlat = paddingBuilder.BuildStatementPadding(spanFlat);


            string paddingNewlines = paddingBuilder.BuildStatementPadding(spanNewlines);

            // Assert
            string code = " if (true)";
            VerifyPadded(numTabs, numSpaces, code, paddingFlat);
            VerifyPadded(numTabs, numSpaces, code, paddingNewlines);
        }
        public void CalculatePaddingForOpenedIf(bool designTime, bool isIndentingWithTabs, int tabSize, int numTabs, int numSpaces)
        {
            // Arrange
            RazorEngineHost host = CreateHost(designTime, isIndentingWithTabs, tabSize);

            string text = "\r\n<html>\r\n<body>\r\n\t\t@if (true) { \r\n</body>\r\n</html>";

            Span span = GenerateSpan(text, SpanKind.Code, 3, "if (true) { \r\n");

            var paddingBuilder = new CSharpPaddingBuilder(host);

            // Act
            string padding = paddingBuilder.BuildStatementPadding(span);

            // Assert
            string code = " if (true) { \r\n";

            VerifyPadded(numTabs, numSpaces, code, padding);
        }
        public void VerifyPaddingForIfSpanWith4Spaces(bool designTime, bool isIndentingWithTabs, int tabSize, int numTabs, int numSpaces)
        {
            // Arrange
            var host = CreateHost(designTime, isIndentingWithTabs, tabSize);

            // no new lines involved
            var spanFlat = GenerateSpan("    @if (true)", SpanKind.Code, 2, "if (true)");
            var spanNewlines = GenerateSpan("\t<div>" + Environment.NewLine + "    @if (true)", SpanKind.Code, 5, "if (true)");

            var paddingBuilder = new CSharpPaddingBuilder(host);

            // Act
            var paddingFlat = paddingBuilder.BuildStatementPadding(spanFlat);
            var paddingNewlines = paddingBuilder.BuildStatementPadding(spanNewlines);

            // Assert
            var code = " if (true)";
            VerifyPadded(numTabs, numSpaces, code, paddingFlat);
            VerifyPadded(numTabs, numSpaces, code, paddingNewlines);
        }
        public void CalculatePaddingForOpenedIf(bool designTime, bool isIndentingWithTabs, int tabSize, int numTabs, int numSpaces)
        {
            // Arrange
            var host = CreateHost(designTime, isIndentingWithTabs, tabSize);

            var text = string.Format("{0}<html>{0}<body>{0}\t\t@if (true) {{ {0}</body>{0}</html>", Environment.NewLine);

            var code = "if (true) { " + Environment.NewLine;
            var span = GenerateSpan(text, SpanKind.Code, 7, code);

            var paddingBuilder = new CSharpPaddingBuilder(host);

            // Act
            var padding = paddingBuilder.BuildStatementPadding(span);

            // Assert
            VerifyPadded(numTabs, numSpaces, code, padding);
        }