public void ParseModelKeyword_ErrorOnInheritsFollowedByModel() { // Arrange + Act List<RazorError> errors = new List<RazorError>(); var document = "@inherits Bar" + Environment.NewLine + "@model Foo"; var spans = ParseDocument(document, errors); // Assert var factory = SpanFactory.CreateCsHtml(); var expectedSpans = new Span[] { factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) .Accepts(AcceptedCharacters.None), factory.MetaCode("inherits ") .Accepts(AcceptedCharacters.None), factory.Code("Bar" + Environment.NewLine) .As(new SetBaseTypeChunkGenerator("Bar")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) .Accepts(AcceptedCharacters.None), factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Foo") .As(new ModelChunkGenerator("Foo")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; var expectedErrors = new[] { new RazorError( "The 'inherits' keyword is not allowed when a 'model' keyword is used.", new SourceLocation(9, 0, 9), length: 8) }; expectedSpans.Zip(spans, (exp, span) => new { expected = exp, span = span }).ToList().ForEach(i => Assert.Equal(i.expected, i.span)); Assert.Equal(expectedSpans, spans.ToArray()); Assert.Equal(expectedErrors, errors.ToArray()); }
public void ParseModelKeyword_ErrorOnMultipleModelStatements() { // Arrange + Act List<RazorError> errors = new List<RazorError>(); var document = "@model Foo" + Environment.NewLine + "@model Bar"; var spans = ParseDocument(document, errors); // Assert var factory = SpanFactory.CreateCsHtml(); var expectedSpans = new Span[] { factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) .Accepts(AcceptedCharacters.None), factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Foo" + Environment.NewLine) .As(new ModelChunkGenerator("Foo")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml(), factory.CodeTransition(SyntaxConstants.TransitionString) .Accepts(AcceptedCharacters.None), factory.MetaCode("model ") .Accepts(AcceptedCharacters.None), factory.Code("Bar") .As(new ModelChunkGenerator("Bar")) .Accepts(AcceptedCharacters.AnyExceptNewline), factory.EmptyHtml() }; var expectedErrors = new[] { new RazorError( "Only one 'model' statement is allowed in a file.", PlatformNormalizer.NormalizedSourceLocation(13, 1, 1), 5) }; expectedSpans.Zip(spans, (exp, span) => new { expected = exp, span = span }).ToList().ForEach(i => Assert.Equal(i.expected, i.span)); Assert.Equal(expectedSpans, spans.ToArray()); Assert.Equal(expectedErrors, errors.ToArray()); }