public void ParseSectionMethodThrowsArgNullExceptionOnNullContext() { // Arrange var parser = new HtmlMarkupParser(); // Act and Assert var exception = Assert.Throws<InvalidOperationException>(() => parser.ParseSection(null, true)); Assert.Equal(RazorResources.Parser_Context_Not_Set, exception.Message); }
public void ConstructorAcceptsActiveParserIfIsSameAsEitherCodeOrMarkupParser() { var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); var errorSink = new ErrorSink(); new ParserContext( new SeekableTextReader(TextReader.Null), codeParser, markupParser, codeParser, errorSink); new ParserContext( new SeekableTextReader(TextReader.Null), codeParser, markupParser, markupParser, errorSink); }
public void DecorateMarkupParserReturnsIncomingParser() { // Arrange var expected = new HtmlMarkupParser(); // Act var actual = CreateHost().DecorateMarkupParser(expected); // Assert Assert.Same(expected, actual); }
public void ConstructorWithCodeLanguageAndMarkupParserSetsPropertiesAppropriately() { // Arrange var language = new CSharpRazorCodeLanguage(); var expected = new HtmlMarkupParser(); // Act var host = new RazorEngineHost(language, () => expected); // Assert VerifyCommonDefaults(host); Assert.Same(language, host.CodeLanguage); Assert.Same(expected, host.CreateMarkupParser()); }
public void ConstructorInitializesProperties() { // Arrange var expectedBuffer = new SeekableTextReader(TextReader.Null); var expectedCodeParser = new CSharpCodeParser(); var expectedMarkupParser = new HtmlMarkupParser(); // Act var context = new ParserContext(expectedBuffer, expectedCodeParser, expectedMarkupParser, expectedCodeParser, new ErrorSink()); // Assert Assert.NotNull(context.Source); Assert.Same(expectedCodeParser, context.CodeParser); Assert.Same(expectedMarkupParser, context.MarkupParser); Assert.Same(expectedCodeParser, context.ActiveParser); }
private static List<Span> ParseDocument(string documentContents, IList<RazorError> errors = null) { errors = errors ?? new List<RazorError>(); var markupParser = new HtmlMarkupParser(); var codeParser = new TestMvcCSharpRazorCodeParser(); var context = new ParserContext( new SeekableTextReader(documentContents), codeParser, markupParser, markupParser, new ErrorSink()); codeParser.Context = context; markupParser.Context = context; markupParser.ParseDocument(); ParserResults results = context.CompleteParse(); foreach (RazorError error in results.ParserErrors) { errors.Add(error); } return results.Document.Flatten().ToList(); }
private ParserContext SetupTestContext(string document, Action<TextReader> positioningAction) { var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); return SetupTestContext(document, positioningAction, codeParser, markupParser, codeParser); }
private ParserContext SetupTestContext(string document) { var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); return SetupTestContext(document, b => { }, codeParser, markupParser, codeParser); }
public void SwitchActiveParserSetsCodeParserAsActiveIfMarkupParserCurrentlyActive() { // Arrange var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); var context = SetupTestContext("barbazbiz", b => b.Read(), codeParser, markupParser, markupParser); Assert.Same(markupParser, context.ActiveParser); // Act context.SwitchActiveParser(); // Assert Assert.Same(codeParser, context.ActiveParser); }