Example #1
0
        internal void EvaluateData(
            IEnumerable <TagHelperDescriptor> descriptors,
            string documentContent,
            MarkupBlock expectedOutput,
            IEnumerable <RazorDiagnostic> expectedErrors,
            string tagHelperPrefix = null,
            RazorParserFeatureFlags featureFlags = null)
        {
            var syntaxTree        = ParseDocument(documentContent);
            var errorSink         = new ErrorSink();
            var parseTreeRewriter = new TagHelperParseTreeRewriter(
                tagHelperPrefix,
                descriptors,
                featureFlags ?? syntaxTree.Options.FeatureFlags);

            var actualTree = parseTreeRewriter.Rewrite(syntaxTree.Root, errorSink);

            var allErrors    = syntaxTree.Diagnostics.Concat(errorSink.Errors);
            var actualErrors = allErrors
                               .OrderBy(error => error.Span.AbsoluteIndex)
                               .ToList();

            EvaluateRazorErrors(actualErrors, expectedErrors.ToList());
            EvaluateParseTree(actualTree, expectedOutput);
        }
Example #2
0
        public void Rewrite_Moves_Whitespace_Preceeding_ExpressionBlock_To_Parent_Block()
        {
            // Arrange
            var factory = new SpanFactory();
            var start   = new MarkupBlock(
                factory.Markup("test"),
                new ExpressionBlock(
                    factory.Code("    ").AsExpression(),
                    factory.CodeTransition(SyntaxConstants.TransitionString),
                    factory.Code("foo").AsExpression()),
                factory.Markup("test"));
            var rewriter = new WhiteSpaceRewriter();

            // Act
            var rewritten = rewriter.Rewrite(start);

            factory.Reset();

            // Assert
            ParserTestBase.EvaluateParseTree(
                rewritten,
                new MarkupBlock(
                    factory.Markup("test"),
                    factory.Markup("    "),
                    new ExpressionBlock(
                        factory.CodeTransition(SyntaxConstants.TransitionString),
                        factory.Code("foo").AsExpression()),
                    factory.Markup("test")));
        }
Example #3
0
        internal void RunParseTreeRewriterTest(
            string documentContent,
            MarkupBlock expectedOutput,
            IEnumerable <RazorDiagnostic> errors,
            params string[] tagNames)
        {
            var descriptors = BuildDescriptors(tagNames);

            EvaluateData(descriptors, documentContent, expectedOutput, errors);
        }
Example #4
0
 internal void RunParseTreeRewriterTest(
     string documentContent,
     MarkupBlock expectedOutput,
     params string[] tagNames)
 {
     RunParseTreeRewriterTest(
         documentContent,
         expectedOutput,
         errors: Enumerable.Empty <RazorDiagnostic>(),
         tagNames: tagNames);
 }