diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 298cb900381..045fc2ee3af 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -16,7 +16,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase private static readonly CSharpCompilation DefaultBaseCompilation = MvcShim.BaseCompilation.WithAssemblyName("AppCode"); public CodeGenerationIntegrationTest() - : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X") + : base(layer: TestProject.Layer.Compiler, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X") { Configuration = new(RazorLanguageVersion.Version_1_1, "MVC-1.1", Extensions: []); } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 0a73859b82a..bc3aa19c9c1 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -18,7 +18,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase private static readonly CSharpCompilation DefaultBaseCompilation = MvcShim.BaseCompilation.WithAssemblyName("AppCode"); public CodeGenerationIntegrationTest() - : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X") + : base(layer: TestProject.Layer.Compiler, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X") { Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: []); } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/InstrumentationPassIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/InstrumentationPassIntegrationTest.cs index 612436e2661..5d5111e1d30 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/InstrumentationPassIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/InstrumentationPassIntegrationTest.cs @@ -19,7 +19,7 @@ public class InstrumentationPassIntegrationTest : IntegrationTestBase private static readonly CSharpCompilation DefaultBaseCompilation = MvcShim.BaseCompilation.WithAssemblyName("AppCode"); public InstrumentationPassIntegrationTest() - : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X") + : base(layer: TestProject.Layer.Compiler, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X") { Configuration = new(RazorLanguageVersion.Version_2_0, "MVC-2.1", Extensions: []); } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 7adf529b0f4..af08fa81b31 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -18,7 +18,7 @@ public class CodeGenerationIntegrationTest : IntegrationTestBase private static readonly CSharpCompilation DefaultBaseCompilation = MvcShim.BaseCompilation.WithAssemblyName("AppCode"); public CodeGenerationIntegrationTest() - : base(layer: TestProject.Layer.Compiler, generateBaselines: null, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions") + : base(layer: TestProject.Layer.Compiler, projectDirectoryHint: "Microsoft.AspNetCore.Mvc.Razor.Extensions") { Configuration = new(RazorLanguageVersion.Latest, "MVC-3.0", Extensions: []); } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/Legacy/CSharpBlockTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/Legacy/CSharpBlockTest.cs index 1816c4ef71e..be9741e66d2 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/Legacy/CSharpBlockTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/Legacy/CSharpBlockTest.cs @@ -3,7 +3,6 @@ #nullable disable -using System; using Xunit; namespace Microsoft.AspNetCore.Razor.Language.Legacy; @@ -40,7 +39,7 @@ public void CSharpBlock_SingleLineControlFlowStatement() } [Fact] - public void LocalFunctionsWithRazor() + public void LocalFunctionsWithRazor_MissingSemicolon() { ParseDocumentTest( @"@{ @@ -52,6 +51,19 @@ void Foo() }"); } + [Fact] + public void LocalFunctionsWithRazor() + { + ParseDocumentTest( +@"@{ + void Foo() + { + var time = DateTime.Now; + Hello the time is @time + } +}"); + } + [Fact] public void LocalFunctionsWithGenerics() { diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor.cspans.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor.cspans.txt index f95d5c5c11a..af641cedaef 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor.cspans.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor.cspans.txt @@ -1,13 +1,14 @@ -Markup span at (0:0,0 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [118] ) -Transition span at (0:0,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [118] ) -MetaCode span at (1:0,1 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [118] ) -Code span at (2:0,2 [66] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [118] ) -Markup span at (68:4,8 [8] ) (Accepts:None) - Parent: Tag block at (68:4,8 [8] ) -Markup span at (76:4,16 [18] ) (Accepts:Any) - Parent: Markup block at (68:4,8 [42] ) -Transition span at (94:4,34 [1] ) (Accepts:None) - Parent: Expression block at (94:4,34 [5] ) -Code span at (95:4,35 [4] ) (Accepts:NonWhitespace) - Parent: Expression block at (94:4,34 [5] ) -Markup span at (99:4,39 [9] ) (Accepts:None) - Parent: Tag block at (99:4,39 [9] ) -Markup span at (108:4,48 [2] ) (Accepts:None) - Parent: Markup block at (68:4,8 [42] ) -Code span at (110:5,0 [7] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [118] ) -MetaCode span at (117:6,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [118] ) -Markup span at (118:6,1 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [118] ) +Markup span at (0:0,0 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [119] ) +Transition span at (0:0,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [119] ) +MetaCode span at (1:0,1 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [119] ) +Code span at (2:0,2 [59] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [119] ) +Markup span at (61:4,0 [8] ) (Accepts:Any) - Parent: Markup block at (61:4,0 [50] ) +Markup span at (69:4,8 [8] ) (Accepts:None) - Parent: Tag block at (69:4,8 [8] ) +Markup span at (77:4,16 [18] ) (Accepts:Any) - Parent: Markup block at (61:4,0 [50] ) +Transition span at (95:4,34 [1] ) (Accepts:None) - Parent: Expression block at (95:4,34 [5] ) +Code span at (96:4,35 [4] ) (Accepts:NonWhitespace) - Parent: Expression block at (95:4,34 [5] ) +Markup span at (100:4,39 [9] ) (Accepts:None) - Parent: Tag block at (100:4,39 [9] ) +Markup span at (109:4,48 [2] ) (Accepts:None) - Parent: Markup block at (61:4,0 [50] ) +Code span at (111:5,0 [7] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [119] ) +MetaCode span at (118:6,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [119] ) +Markup span at (119:6,1 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [119] ) diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor.stree.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor.stree.txt index 8420f91abfd..127e67d4d4a 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor.stree.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor.stree.txt @@ -1,16 +1,16 @@ -RazorDocument - [0..118)::118 - [@{LF void Foo()LF {LF var time = DateTime.NowLF Hello the time is @timeLF }LF}] - MarkupBlock - [0..118)::118 +RazorDocument - [0..119)::119 - [@{LF void Foo()LF {LF var time = DateTime.Now;LF Hello the time is @timeLF }LF}] + MarkupBlock - [0..119)::119 MarkupTextLiteral - [0..0)::0 - [] - Gen - SpanEditHandler;Accepts:Any Marker;[]; - CSharpCodeBlock - [0..118)::118 - CSharpStatement - [0..118)::118 + CSharpCodeBlock - [0..119)::119 + CSharpStatement - [0..119)::119 CSharpTransition - [0..1)::1 - Gen - SpanEditHandler;Accepts:None Transition;[@]; - CSharpStatementBody - [1..118)::117 + CSharpStatementBody - [1..119)::118 RazorMetaCode - [1..2)::1 - Gen - SpanEditHandler;Accepts:None LeftBrace;[{]; - CSharpCodeBlock - [2..117)::115 - CSharpStatementLiteral - [2..68)::66 - [LF void Foo()LF {LF var time = DateTime.NowLF ] - Gen - AutoCompleteEditHandler;Accepts:Any,AutoComplete:[];AtEOL + CSharpCodeBlock - [2..118)::116 + CSharpStatementLiteral - [2..61)::59 - [LF void Foo()LF {LF var time = DateTime.Now;LF] - Gen - AutoCompleteEditHandler;Accepts:Any,AutoComplete:[];AtEOL NewLine;[LF]; Whitespace;[ ]; Keyword;[void]; @@ -32,15 +32,17 @@ Identifier;[DateTime]; Dot;[.]; Identifier;[Now]; + Semicolon;[;]; NewLine;[LF]; - Whitespace;[ ]; - MarkupBlock - [68..110)::42 - MarkupElement - [68..108)::40 - MarkupStartTag - [68..76)::8 - [] - Gen - SpanEditHandler;Accepts:None + MarkupBlock - [61..111)::50 + MarkupTextLiteral - [61..69)::8 - [ ] - Gen - SpanEditHandler;Accepts:Any + Whitespace;[ ]; + MarkupElement - [69..109)::40 + MarkupStartTag - [69..77)::8 - [] - Gen - SpanEditHandler;Accepts:None OpenAngle;[<]; Text;[strong]; CloseAngle;[>]; - MarkupTextLiteral - [76..94)::18 - [Hello the time is ] - Gen - SpanEditHandler;Accepts:Any + MarkupTextLiteral - [77..95)::18 - [Hello the time is ] - Gen - SpanEditHandler;Accepts:Any Text;[Hello]; Whitespace;[ ]; Text;[the]; @@ -49,27 +51,27 @@ Whitespace;[ ]; Text;[is]; Whitespace;[ ]; - CSharpCodeBlock - [94..99)::5 - CSharpImplicitExpression - [94..99)::5 - CSharpTransition - [94..95)::1 - Gen - SpanEditHandler;Accepts:None + CSharpCodeBlock - [95..100)::5 + CSharpImplicitExpression - [95..100)::5 + CSharpTransition - [95..96)::1 - Gen - SpanEditHandler;Accepts:None Transition;[@]; - CSharpImplicitExpressionBody - [95..99)::4 - CSharpCodeBlock - [95..99)::4 - CSharpExpressionLiteral - [95..99)::4 - [time] - Gen - ImplicitExpressionEditHandler;Accepts:NonWhitespace;ImplicitExpression[RTD];K14 + CSharpImplicitExpressionBody - [96..100)::4 + CSharpCodeBlock - [96..100)::4 + CSharpExpressionLiteral - [96..100)::4 - [time] - Gen - ImplicitExpressionEditHandler;Accepts:NonWhitespace;ImplicitExpression[RTD];K14 Identifier;[time]; - MarkupEndTag - [99..108)::9 - [] - Gen - SpanEditHandler;Accepts:None + MarkupEndTag - [100..109)::9 - [] - Gen - SpanEditHandler;Accepts:None OpenAngle;[<]; ForwardSlash;[/]; Text;[strong]; CloseAngle;[>]; - MarkupTextLiteral - [108..110)::2 - [LF] - Gen - SpanEditHandler;Accepts:None + MarkupTextLiteral - [109..111)::2 - [LF] - Gen - SpanEditHandler;Accepts:None NewLine;[LF]; - CSharpStatementLiteral - [110..117)::7 - [ }LF] - Gen - SpanEditHandler;Accepts:Any + CSharpStatementLiteral - [111..118)::7 - [ }LF] - Gen - SpanEditHandler;Accepts:Any Whitespace;[ ]; RightBrace;[}]; NewLine;[LF]; - RazorMetaCode - [117..118)::1 - Gen - SpanEditHandler;Accepts:None + RazorMetaCode - [118..119)::1 - Gen - SpanEditHandler;Accepts:None RightBrace;[}]; - MarkupTextLiteral - [118..118)::0 - [] - Gen - SpanEditHandler;Accepts:Any + MarkupTextLiteral - [119..119)::0 - [] - Gen - SpanEditHandler;Accepts:Any Marker;[]; EndOfFile;[]; diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor_MissingSemicolon.cspans.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor_MissingSemicolon.cspans.txt new file mode 100644 index 00000000000..8593df46fdf --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor_MissingSemicolon.cspans.txt @@ -0,0 +1,6 @@ +Markup span at (0:0,0 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [118] ) +Transition span at (0:0,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [118] ) +MetaCode span at (1:0,1 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [118] ) +Code span at (2:0,2 [115] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [118] ) +MetaCode span at (117:6,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [118] ) +Markup span at (118:6,1 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [118] ) diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor_MissingSemicolon.stree.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor_MissingSemicolon.stree.txt new file mode 100644 index 00000000000..57a35b3daff --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/LocalFunctionsWithRazor_MissingSemicolon.stree.txt @@ -0,0 +1,61 @@ +RazorDocument - [0..118)::118 - [@{LF void Foo()LF {LF var time = DateTime.NowLF Hello the time is @timeLF }LF}] + MarkupBlock - [0..118)::118 + MarkupTextLiteral - [0..0)::0 - [] - Gen - SpanEditHandler;Accepts:Any + Marker;[]; + CSharpCodeBlock - [0..118)::118 + CSharpStatement - [0..118)::118 + CSharpTransition - [0..1)::1 - Gen - SpanEditHandler;Accepts:None + Transition;[@]; + CSharpStatementBody - [1..118)::117 + RazorMetaCode - [1..2)::1 - Gen - SpanEditHandler;Accepts:None + LeftBrace;[{]; + CSharpCodeBlock - [2..117)::115 + CSharpStatementLiteral - [2..117)::115 - [LF void Foo()LF {LF var time = DateTime.NowLF Hello the time is @timeLF }LF] - Gen - AutoCompleteEditHandler;Accepts:Any,AutoComplete:[];AtEOL + NewLine;[LF]; + Whitespace;[ ]; + Keyword;[void]; + Whitespace;[ ]; + Identifier;[Foo]; + LeftParenthesis;[(]; + RightParenthesis;[)]; + NewLine;[LF]; + Whitespace;[ ]; + LeftBrace;[{]; + NewLine;[LF]; + Whitespace;[ ]; + Identifier;[var]; + Whitespace;[ ]; + Identifier;[time]; + Whitespace;[ ]; + Assign;[=]; + Whitespace;[ ]; + Identifier;[DateTime]; + Dot;[.]; + Identifier;[Now]; + NewLine;[LF]; + Whitespace;[ ]; + LessThan;[<]; + Identifier;[strong]; + GreaterThan;[>]; + Identifier;[Hello]; + Whitespace;[ ]; + Identifier;[the]; + Whitespace;[ ]; + Identifier;[time]; + Whitespace;[ ]; + Keyword;[is]; + Whitespace;[ ]; + Identifier;[@time]; + LessThan;[<]; + Slash;[/]; + Identifier;[strong]; + GreaterThan;[>]; + NewLine;[LF]; + Whitespace;[ ]; + RightBrace;[}]; + NewLine;[LF]; + RazorMetaCode - [117..118)::1 - Gen - SpanEditHandler;Accepts:None + RightBrace;[}]; + MarkupTextLiteral - [118..118)::0 - [] - Gen - SpanEditHandler;Accepts:Any + Marker;[]; + EndOfFile;[]; diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/NestedCodeBlockWithCSharpAt.stree.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/NestedCodeBlockWithCSharpAt.stree.txt index 48d1ebcc920..dfd27784734 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/NestedCodeBlockWithCSharpAt.stree.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/NestedCodeBlockWithCSharpAt.stree.txt @@ -26,8 +26,7 @@ Whitespace;[ ]; Assign;[=]; Whitespace;[ ]; - Transition;[@]; - Identifier;[x]; + Identifier;[@x]; Semicolon;[;]; Whitespace;[ ]; Keyword;[if]; diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/TreatsAtSignsAfterFirstPairAsPartOfCSharpStatement.diag.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/TreatsAtSignsAfterFirstPairAsPartOfCSharpStatement.diag.txt new file mode 100644 index 00000000000..bd189123b2f --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/TreatsAtSignsAfterFirstPairAsPartOfCSharpStatement.diag.txt @@ -0,0 +1,5 @@ +(1,14): Error RZ1009: The "@" character must be followed by a ":", "(", or a C# identifier. If you intended to switch to markup, use an HTML start tag, for example: + +@if(isLoggedIn) { +

Hello, @user!

+} diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/TreatsAtSignsAfterFirstPairAsPartOfCSharpStatement.stree.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/TreatsAtSignsAfterFirstPairAsPartOfCSharpStatement.stree.txt index 1c05c134e87..92e7344e94e 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/TreatsAtSignsAfterFirstPairAsPartOfCSharpStatement.stree.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpBlockTest/TreatsAtSignsAfterFirstPairAsPartOfCSharpStatement.stree.txt @@ -17,9 +17,8 @@ Transition;[@]; CSharpStatementLiteral - [12..28)::16 - [@@@class.Foo() }] - Gen - SpanEditHandler;Accepts:Any Transition;[@]; - Transition;[@]; - Transition;[@]; - Keyword;[class]; + Identifier;[@]; + Identifier;[@class]; Dot;[.]; Identifier;[Foo]; LeftParenthesis;[(]; diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpErrorTest/CorrectlyParsesMarkupIncorrectyAssumedToBeWithinAStatement.cspans.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpErrorTest/CorrectlyParsesMarkupIncorrectyAssumedToBeWithinAStatement.cspans.txt index 0c501dcbe11..5b64c1ef4d0 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpErrorTest/CorrectlyParsesMarkupIncorrectyAssumedToBeWithinAStatement.cspans.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpErrorTest/CorrectlyParsesMarkupIncorrectyAssumedToBeWithinAStatement.cspans.txt @@ -1,10 +1,3 @@ Markup span at (0:0,0 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [65] ) Transition span at (0:0,0 [1] ) (Accepts:None) - Parent: Statement block at (0:0,0 [65] ) -Code span at (1:0,1 [43] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [65] ) -Markup span at (44:2,4 [3] ) (Accepts:None) - Parent: Tag block at (44:2,4 [3] ) -Markup span at (47:2,7 [7] ) (Accepts:Any) - Parent: Markup block at (44:2,4 [20] ) -Transition span at (54:2,14 [1] ) (Accepts:None) - Parent: Expression block at (54:2,14 [4] ) -Code span at (55:2,15 [3] ) (Accepts:NonWhitespace) - Parent: Expression block at (54:2,14 [4] ) -Markup span at (58:2,18 [4] ) (Accepts:None) - Parent: Tag block at (58:2,18 [4] ) -Markup span at (62:2,22 [2] ) (Accepts:None) - Parent: Markup block at (44:2,4 [20] ) -Code span at (64:3,0 [1] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [65] ) +Code span at (1:0,1 [64] ) (Accepts:Any) - Parent: Statement block at (0:0,0 [65] ) diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpErrorTest/CorrectlyParsesMarkupIncorrectyAssumedToBeWithinAStatement.stree.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpErrorTest/CorrectlyParsesMarkupIncorrectyAssumedToBeWithinAStatement.stree.txt index d429dd01e28..48348aff7f7 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpErrorTest/CorrectlyParsesMarkupIncorrectyAssumedToBeWithinAStatement.stree.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpErrorTest/CorrectlyParsesMarkupIncorrectyAssumedToBeWithinAStatement.stree.txt @@ -5,7 +5,7 @@ CSharpCodeBlock - [0..65)::65 CSharpTransition - [0..1)::1 - Gen - SpanEditHandler;Accepts:None Transition;[@]; - CSharpStatementLiteral - [1..44)::43 - [if(foo) {LF var foo = "foo bar bazLF ] - Gen - SpanEditHandler;Accepts:Any + CSharpStatementLiteral - [1..65)::64 - [if(foo) {LF var foo = "foo bar bazLF

Foo is @foo

LF}] - Gen - SpanEditHandler;Accepts:Any Keyword;[if]; LeftParenthesis;[(]; Identifier;[foo]; @@ -23,32 +23,18 @@ StringLiteral;["foo bar baz];RZ1000(26:1,14 [1] ) NewLine;[LF]; Whitespace;[ ]; - MarkupBlock - [44..64)::20 - MarkupElement - [44..62)::18 - MarkupStartTag - [44..47)::3 - [

] - Gen - SpanEditHandler;Accepts:None - OpenAngle;[<]; - Text;[p]; - CloseAngle;[>]; - MarkupTextLiteral - [47..54)::7 - [Foo is ] - Gen - SpanEditHandler;Accepts:Any - Text;[Foo]; - Whitespace;[ ]; - Text;[is]; - Whitespace;[ ]; - CSharpCodeBlock - [54..58)::4 - CSharpImplicitExpression - [54..58)::4 - CSharpTransition - [54..55)::1 - Gen - SpanEditHandler;Accepts:None - Transition;[@]; - CSharpImplicitExpressionBody - [55..58)::3 - CSharpCodeBlock - [55..58)::3 - CSharpExpressionLiteral - [55..58)::3 - [foo] - Gen - ImplicitExpressionEditHandler;Accepts:NonWhitespace;ImplicitExpression[RTD];K14 - Identifier;[foo]; - MarkupEndTag - [58..62)::4 - [

] - Gen - SpanEditHandler;Accepts:None - OpenAngle;[<]; - ForwardSlash;[/]; - Text;[p]; - CloseAngle;[>]; - MarkupTextLiteral - [62..64)::2 - [LF] - Gen - SpanEditHandler;Accepts:None - NewLine;[LF]; - CSharpStatementLiteral - [64..65)::1 - [}] - Gen - SpanEditHandler;Accepts:Any + LessThan;[<]; + Identifier;[p]; + GreaterThan;[>]; + Identifier;[Foo]; + Whitespace;[ ]; + Keyword;[is]; + Whitespace;[ ]; + Identifier;[@foo]; + LessThan;[<]; + Slash;[/]; + Identifier;[p]; + GreaterThan;[>]; + NewLine;[LF]; RightBrace;[}]; EndOfFile;[]; diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/Functions_SingleLineControlFlowStatement_Error.cspans.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/Functions_SingleLineControlFlowStatement_Error.cspans.txt index 3cac90b8815..b4a77535316 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/Functions_SingleLineControlFlowStatement_Error.cspans.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/Functions_SingleLineControlFlowStatement_Error.cspans.txt @@ -24,13 +24,6 @@ Code span at (309:11,29 [4] ) (Accepts:NonWhitespace) - Parent: Expression block Markup span at (313:11,33 [6] ) (Accepts:None) - Parent: Markup block at (292:11,12 [27] ) Code span at (319:12,0 [31] ) (Accepts:Any) - Parent: Statement block at (14:1,12 [391] ) Code span at (350:13,29 [1] ) (Accepts:Any) - Parent: Statement block at (14:1,12 [391] ) -Code span at (351:13,30 [20] ) (Accepts:Any) - Parent: Statement block at (14:1,12 [391] ) -Markup span at (371:13,50 [8] ) (Accepts:None) - Parent: Tag block at (371:13,50 [8] ) -Markup span at (379:13,58 [0] ) (Accepts:Any) - Parent: Markup block at (371:13,50 [27] ) -Transition span at (379:13,58 [1] ) (Accepts:None) - Parent: Expression block at (379:13,58 [8] ) -Code span at (380:13,59 [7] ) (Accepts:NonWhitespace) - Parent: Expression block at (379:13,58 [8] ) -Markup span at (387:13,66 [9] ) (Accepts:None) - Parent: Tag block at (387:13,66 [9] ) -Markup span at (396:13,75 [2] ) (Accepts:None) - Parent: Markup block at (371:13,50 [27] ) -Code span at (398:14,0 [7] ) (Accepts:Any) - Parent: Statement block at (14:1,12 [391] ) +Code span at (351:13,30 [54] ) (Accepts:Any) - Parent: Statement block at (14:1,12 [391] ) MetaCode span at (405:15,0 [3] ) (Accepts:None) - Parent: Directive block at (2:1,0 [406] ) Markup span at (408:16,0 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [408] ) diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/Functions_SingleLineControlFlowStatement_Error.stree.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/Functions_SingleLineControlFlowStatement_Error.stree.txt index 9ccc4f4e85a..287ce9bd8fd 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/Functions_SingleLineControlFlowStatement_Error.stree.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/Functions_SingleLineControlFlowStatement_Error.stree.txt @@ -170,34 +170,19 @@ Whitespace;[ ]; CSharpEphemeralTextLiteral - [350..351)::1 - [@] - Gen - SpanEditHandler;Accepts:Any Transition;[@]; - CSharpStatementLiteral - [351..371)::20 - [@SomeGitHubUserName ] - Gen - SpanEditHandler;Accepts:Any + CSharpStatementLiteral - [351..405)::54 - [@SomeGitHubUserName @messageLF }LF] - Gen - SpanEditHandler;Accepts:Any Transition;[@]; Identifier;[SomeGitHubUserName]; Whitespace;[ ]; - MarkupBlock - [371..398)::27 - MarkupElement - [371..396)::25 - MarkupStartTag - [371..379)::8 - [] - Gen - SpanEditHandler;Accepts:None - OpenAngle;[<]; - Text;[strong]; - CloseAngle;[>]; - MarkupTextLiteral - [379..379)::0 - [] - Gen - SpanEditHandler;Accepts:Any - Marker;[]; - CSharpCodeBlock - [379..387)::8 - CSharpImplicitExpression - [379..387)::8 - CSharpTransition - [379..380)::1 - Gen - SpanEditHandler;Accepts:None - Transition;[@]; - CSharpImplicitExpressionBody - [380..387)::7 - CSharpCodeBlock - [380..387)::7 - CSharpExpressionLiteral - [380..387)::7 - [message] - Gen - ImplicitExpressionEditHandler;Accepts:NonWhitespace;ImplicitExpression[RTD];K15 - Identifier;[message]; - MarkupEndTag - [387..396)::9 - [] - Gen - SpanEditHandler;Accepts:None - OpenAngle;[<]; - ForwardSlash;[/]; - Text;[strong]; - CloseAngle;[>]; - MarkupTextLiteral - [396..398)::2 - [LF] - Gen - SpanEditHandler;Accepts:None - NewLine;[LF]; - CSharpStatementLiteral - [398..405)::7 - [ }LF] - Gen - SpanEditHandler;Accepts:Any + LessThan;[<]; + Identifier;[strong]; + GreaterThan;[>]; + Identifier;[@message]; + LessThan;[<]; + Slash;[/]; + Identifier;[strong]; + GreaterThan;[>]; + NewLine;[LF]; Whitespace;[ ]; RightBrace;[}]; NewLine;[LF]; diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/MarkupInFunctionsBlock_ParsesMarkupWithExpressionsMethod.cspans.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/MarkupInFunctionsBlock_ParsesMarkupWithExpressionsMethod.cspans.txt index 7680f528f82..33e57780641 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/MarkupInFunctionsBlock_ParsesMarkupWithExpressionsMethod.cspans.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/MarkupInFunctionsBlock_ParsesMarkupWithExpressionsMethod.cspans.txt @@ -3,13 +3,6 @@ Transition span at (2:1,0 [1] ) (Accepts:None) - Parent: Directive block at (2:1 MetaCode span at (3:1,1 [9] ) (Accepts:None) - Parent: Directive block at (2:1,0 [76] ) None span at (12:1,10 [1] ) (Accepts:AllWhitespace) - Parent: Directive block at (2:1,0 [76] ) MetaCode span at (13:1,11 [1] ) (Accepts:None) - Parent: Directive block at (2:1,0 [76] ) -Code span at (14:1,12 [42] ) (Accepts:Any) - Parent: Statement block at (14:1,12 [61] ) -Markup span at (56:2,40 [4] ) (Accepts:None) - Parent: Tag block at (56:2,40 [4] ) -Markup span at (60:2,44 [0] ) (Accepts:Any) - Parent: Markup block at (56:2,40 [19] ) -Transition span at (60:2,44 [1] ) (Accepts:None) - Parent: Expression block at (60:2,44 [8] ) -Code span at (61:2,45 [7] ) (Accepts:NonWhitespace) - Parent: Expression block at (60:2,44 [8] ) -Markup span at (68:2,52 [5] ) (Accepts:None) - Parent: Tag block at (68:2,52 [5] ) -Markup span at (73:2,57 [2] ) (Accepts:None) - Parent: Markup block at (56:2,40 [19] ) -Code span at (75:3,0 [0] ) (Accepts:Any) - Parent: Statement block at (14:1,12 [61] ) +Code span at (14:1,12 [61] ) (Accepts:Any) - Parent: Directive block at (2:1,0 [76] ) MetaCode span at (75:3,0 [3] ) (Accepts:None) - Parent: Directive block at (2:1,0 [76] ) Markup span at (78:4,0 [0] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [78] ) diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/MarkupInFunctionsBlock_ParsesMarkupWithExpressionsMethod.stree.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/MarkupInFunctionsBlock_ParsesMarkupWithExpressionsMethod.stree.txt index 1f1a5ee88e7..e17cfa466cb 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/MarkupInFunctionsBlock_ParsesMarkupWithExpressionsMethod.stree.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/TestFiles/ParserTests/CSharpFunctionsTest/MarkupInFunctionsBlock_ParsesMarkupWithExpressionsMethod.stree.txt @@ -15,7 +15,7 @@ RazorMetaCode - [13..14)::1 - Gen - AutoCompleteEditHandler;Accepts:None,AutoComplete:[];AtEnd LeftBrace;[{]; CSharpCodeBlock - [14..75)::61 - CSharpStatementLiteral - [14..56)::42 - [LF void Announcment(string message) => ] - Gen - CodeBlockEditHandler;Accepts:Any;CodeBlock + CSharpStatementLiteral - [14..75)::61 - [LF void Announcment(string message) =>

@message

LF] - Gen - CodeBlockEditHandler;Accepts:Any;CodeBlock NewLine;[LF]; Whitespace;[ ]; Keyword;[void]; @@ -29,31 +29,15 @@ Whitespace;[ ]; GreaterThanEqual;[=>]; Whitespace;[ ]; - MarkupBlock - [56..75)::19 - MarkupElement - [56..73)::17 - MarkupStartTag - [56..60)::4 - [

] - Gen - SpanEditHandler;Accepts:None - OpenAngle;[<]; - Text;[h3]; - CloseAngle;[>]; - MarkupTextLiteral - [60..60)::0 - [] - Gen - SpanEditHandler;Accepts:Any - Marker;[]; - CSharpCodeBlock - [60..68)::8 - CSharpImplicitExpression - [60..68)::8 - CSharpTransition - [60..61)::1 - Gen - SpanEditHandler;Accepts:None - Transition;[@]; - CSharpImplicitExpressionBody - [61..68)::7 - CSharpCodeBlock - [61..68)::7 - CSharpExpressionLiteral - [61..68)::7 - [message] - Gen - ImplicitExpressionEditHandler;Accepts:NonWhitespace;ImplicitExpression[RTD];K15 - Identifier;[message]; - MarkupEndTag - [68..73)::5 - [

] - Gen - SpanEditHandler;Accepts:None - OpenAngle;[<]; - ForwardSlash;[/]; - Text;[h3]; - CloseAngle;[>]; - MarkupTextLiteral - [73..75)::2 - [LF] - Gen - SpanEditHandler;Accepts:None - NewLine;[LF]; - CSharpStatementLiteral - [75..75)::0 - [] - Gen - SpanEditHandler;Accepts:Any - Marker;[]; + LessThan;[<]; + Identifier;[h3]; + GreaterThan;[>]; + Identifier;[@message]; + LessThan;[<]; + Slash;[/]; + Identifier;[h3]; + GreaterThan;[>]; + NewLine;[LF]; RazorMetaCode - [75..78)::3 - Gen - SpanEditHandler;Accepts:None RightBrace;[}]; NewLine;[LF]; diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 7e13fc1b3b1..10a38aed0b9 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests; public class CodeGenerationIntegrationTest(bool designTime = false) - : IntegrationTestBase(layer: TestProject.Layer.Compiler, generateBaselines: null) + : IntegrationTestBase(layer: TestProject.Layer.Compiler) { [IntegrationTestFact] public void SingleLineControlFlowStatements() => RunTest(); diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentBindIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentBindIntegrationTest.cs index cd63ebec355..9e7d2f1f4b0 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentBindIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentBindIntegrationTest.cs @@ -3,9 +3,7 @@ #nullable disable -using System; using System.Globalization; -using Microsoft.AspNetCore.Components; using Xunit; namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests; @@ -41,7 +39,7 @@ public static class BindAttributes }"); // Assert - var diagnostic = Assert.Single(result.Diagnostics); + var diagnostic = Assert.Single(result.RazorDiagnostics); Assert.Equal("RZ9989", diagnostic.Id); Assert.Equal(""" The attribute '@bind-value' was matched by multiple bind attributes. Duplicates: @@ -62,7 +60,7 @@ public void BindFallback_InvalidSyntax_TooManyParts() }"); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ9991", diagnostic.Id); } @@ -77,7 +75,7 @@ public void BindFallback_InvalidSyntax_TrailingDash() }"); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ9991", diagnostic.Id); } @@ -91,11 +89,11 @@ @using Microsoft.AspNetCore.Components.Web @functions { public string page { get; set; } = ""text""; -}", throwOnFailure: false); +}"); // Assert Assert.Collection( - generated.Diagnostics, + generated.RazorDiagnostics, d => Assert.Equal("RZ2005", d.Id), d => Assert.Equal("RZ1011", d.Id)); } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentChildContentIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentChildContentIntegrationTest.cs index 80727f454df..99660d4ebac 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentChildContentIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentChildContentIntegrationTest.cs @@ -4,7 +4,6 @@ #nullable disable using System.Globalization; -using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Razor.Language.Components; using Microsoft.CodeAnalysis.CSharp; using Xunit; @@ -70,7 +69,7 @@ Some Content "); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.ChildContentSetByAttributeAndBody.Id, diagnostic.Id); } @@ -90,7 +89,7 @@ Some Content "); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.ChildContentSetByAttributeAndBody.Id, diagnostic.Id); } @@ -109,7 +108,7 @@ public void ChildContent_ExplicitChildContent_UnrecogizedContent_ProducesDiagnos "); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.ChildContentMixedWithExplicitChildContent.Id, diagnostic.Id); Assert.Equal(""" Unrecognized child content inside component 'RenderChildContent'. The component 'RenderChildContent' accepts child content through the following top-level items: 'ChildContent'. @@ -135,7 +134,7 @@ public void ChildContent_ExplicitChildContent_UnrecogizedElement_ProducesDiagnos // Assert Assert.Collection( - generated.Diagnostics, + generated.RazorDiagnostics, d => Assert.Equal("RZ10012", d.Id), d => Assert.Equal("RZ9996", d.Id)); } @@ -156,7 +155,7 @@ public void ChildContent_ExplicitChildContent_StartsWithCharThatIsOtherLetterCat // Assert Assert.Collection( - generated.Diagnostics, + generated.RazorDiagnostics, d => Assert.Equal("RZ10012", d.Id), d => Assert.Equal("RZ9996", d.Id)); } @@ -177,7 +176,7 @@ public void ChildContent_ExplicitChildContent_StartsWithCharThatIsOtherLetterCat // Assert Assert.Collection( - generated.Diagnostics, + generated.RazorDiagnostics, d => Assert.Equal("RZ9996", d.Id)); } @@ -195,7 +194,7 @@ public void ChildContent_ExplicitChildContent_UnrecogizedAttribute_ProducesDiagn "); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.ChildContentHasInvalidAttribute.Id, diagnostic.Id); } @@ -213,7 +212,7 @@ public void ChildContent_ExplicitChildContent_InvalidParameterName_ProducesDiagn "); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.ChildContentHasInvalidParameter.Id, diagnostic.Id); } @@ -235,7 +234,7 @@ public void ChildContent_ExplicitChildContent_RepeatedParameterName_GeneratesDia "); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.ChildContentRepeatedParameterName.Id, diagnostic.Id); Assert.Equal(""" The child content element 'ChildContent' of component 'RenderChildContentString' uses the same parameter name ('context') as enclosing child content element 'ChildContent' of component 'RenderChildContentString'. Specify the parameter name like: ' to resolve the ambiguity @@ -255,7 +254,7 @@ public void ChildContent_ContextParameterNameOnComponent_Invalid_ProducesDiagnos "); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.ChildContentHasInvalidParameterOnComponent.Id, diagnostic.Id); Assert.Equal( "Invalid parameter name. The parameter name attribute 'Context' on component 'RenderChildContentString' can only include literal text.", @@ -276,7 +275,7 @@ public void ChildContent_ExplicitChildContent_ContainsDirectiveAttribute_Produce "); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.ChildContentHasInvalidAttribute.Id, diagnostic.Id); Assert.Equal( "Unrecognized attribute '@key' on child content element 'ChildContent'.", diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs index 68b9c85fa53..d5490001526 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests; public class ComponentCodeGenerationTestBase(bool designTime = false) - : RazorBaselineIntegrationTestBase(layer: TestProject.Layer.Compiler, generateBaselines: null) + : RazorBaselineIntegrationTestBase(layer: TestProject.Layer.Compiler) { private RazorConfiguration _configuration; @@ -521,7 +521,7 @@ @typeparam TItem CompileToAssembly(generated); AdditionalSyntaxTrees.Add(Parse(generated.CodeDocument.GetCSharpDocument().GeneratedCode)); - var useGenerated = CompileToCSharp("UseTestComponent.cshtml", @" + var useGenerated = CompileToCSharp("UseTestComponent.cshtml", cshtmlContent: @" @using Test

@context[0].description

@@ -599,7 +599,7 @@ @typeparam TItem2 CompileToAssembly(generated); AdditionalSyntaxTrees.Add(Parse(generated.CodeDocument.GetCSharpDocument().GeneratedCode)); - var useGenerated = CompileToCSharp("UseTestComponent.cshtml", @" + var useGenerated = CompileToCSharp("UseTestComponent.cshtml", cshtmlContent: @" @using Test

@context

@@ -742,7 +742,7 @@ public class Tag : ITag CompileToAssembly(generated); AdditionalSyntaxTrees.Add(Parse(generated.CodeDocument.GetCSharpDocument().GeneratedCode)); - var useGenerated = CompileToCSharp("UseTestComponent.cshtml", @" + var useGenerated = CompileToCSharp("UseTestComponent.cshtml", cshtmlContent: @" @using Test

@context

@@ -819,7 +819,7 @@ public class Tag : ITag CompileToAssembly(generated); AdditionalSyntaxTrees.Add(Parse(generated.CodeDocument.GetCSharpDocument().GeneratedCode)); - var useGenerated = CompileToCSharp("UseTestComponent.cshtml", @" + var useGenerated = CompileToCSharp("UseTestComponent.cshtml", cshtmlContent: @" @using Test

@context

@@ -913,11 +913,10 @@ public class CoolnessMeter : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var assembly = CompileToAssembly(generated, throwOnFailure: false); - // This has some errors - Assert.Collection( - assembly.Diagnostics.OrderBy(d => d.Id), - d => Assert.Equal("CS1503", d.Id)); + CompileToAssembly(generated, + // x:\dir\subdir\Test\TestComponent.cshtml(1,28): error CS1503: Argument 1: cannot convert from 'string' to 'int' + // "very-cool" + Diagnostic(ErrorCode.ERR_BadArgType, @"""very-cool""").WithArguments("1", "string", "int").WithLocation(1, 28)); } [IntegrationTestFact] @@ -1109,9 +1108,9 @@ public class ComponentWithEditorRequiredParameters : ComponentBase "); AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: false); + CompileToAssembly(generated); - var diagnostics = Assert.Single(generated.Diagnostics); + var diagnostics = Assert.Single(generated.RazorDiagnostics); Assert.Equal(RazorDiagnosticSeverity.Warning, diagnostics.Severity); Assert.Equal("RZ2012", diagnostics.Id); } @@ -1139,7 +1138,7 @@ public class ComponentWithEditorRequiredParameters : ComponentBase AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); CompileToAssembly(generated); - Assert.Empty(generated.Diagnostics); + Assert.Empty(generated.RazorDiagnostics); } [IntegrationTestFact] @@ -1165,7 +1164,7 @@ public class ComponentWithEditorRequiredParameters : ComponentBase AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); CompileToAssembly(generated); - Assert.Empty(generated.Diagnostics); + Assert.Empty(generated.RazorDiagnostics); } [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/7395")] @@ -1196,7 +1195,7 @@ public class ComponentWithEditorRequiredParameters : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); CompileToAssembly(generated); - Assert.Empty(generated.Diagnostics); + Assert.Empty(generated.RazorDiagnostics); } [IntegrationTestFact] @@ -1220,9 +1219,9 @@ public class ComponentWithEditorRequiredChildContent : ComponentBase "); AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: false); + CompileToAssembly(generated); - var diagnostics = Assert.Single(generated.Diagnostics); + var diagnostics = Assert.Single(generated.RazorDiagnostics); Assert.Equal(RazorDiagnosticSeverity.Warning, diagnostics.Severity); Assert.Equal("RZ2012", diagnostics.Id); } @@ -1253,7 +1252,7 @@ public class ComponentWithEditorRequiredChildContent : ComponentBase AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); CompileToAssembly(generated); - Assert.Empty(generated.Diagnostics); + Assert.Empty(generated.RazorDiagnostics); } [IntegrationTestFact] @@ -1280,7 +1279,7 @@ public class ComponentWithEditorRequiredChildContent : ComponentBase AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); CompileToAssembly(generated); - Assert.Empty(generated.Diagnostics); + Assert.Empty(generated.RazorDiagnostics); } [IntegrationTestFact] @@ -1311,7 +1310,7 @@ public class ComponentWithEditorRequiredChildContent : ComponentBase AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); CompileToAssembly(generated); - Assert.Empty(generated.Diagnostics); + Assert.Empty(generated.RazorDiagnostics); } [IntegrationTestFact] @@ -1340,9 +1339,9 @@ public class ComponentWithEditorRequiredChildContent : ComponentBase "); AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: false); + CompileToAssembly(generated); - var diagnostics = Assert.Single(generated.Diagnostics); + var diagnostics = Assert.Single(generated.RazorDiagnostics); Assert.Equal(RazorDiagnosticSeverity.Warning, diagnostics.Severity); Assert.Equal("RZ2012", diagnostics.Id); } @@ -1376,7 +1375,7 @@ public class ComponentWithEditorRequiredChildContent : ComponentBase AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); CompileToAssembly(generated); - Assert.Empty(generated.Diagnostics); + Assert.Empty(generated.RazorDiagnostics); } [IntegrationTestFact, WorkItem("https://github.com/dotnet/aspnetcore/issues/18042")] @@ -1439,7 +1438,7 @@ public void AddAttribute_ImplicitStringConversion_Bind() using Microsoft.AspNetCore.Components; namespace Test; - + public class MyClass { public static implicit operator string(MyClass c) => throw null!; @@ -1452,16 +1451,16 @@ public class MyComponent : ComponentBase [Parameter] public EventCallback> MyParameterChanged { get; set; } - + [Parameter] public bool BoolParameter { get; set; } - + [Parameter] public string StringParameter { get; set; } = null!; - + [Parameter] public System.Delegate DelegateParameter { get; set; } = null!; - + [Parameter] public object ObjectParameter { get; set; } = null!; } @@ -1493,7 +1492,7 @@ public void AddAttribute_ImplicitStringConversion_CustomEvent() using Microsoft.AspNetCore.Components; namespace Test; - + public class MyClass { public static implicit operator string(MyClass c) => throw null!; @@ -1506,16 +1505,16 @@ public class MyComponent : ComponentBase [Parameter] public EventCallback MyEvent { get; set; } - + [Parameter] public bool BoolParameter { get; set; } - + [Parameter] public string StringParameter { get; set; } = null!; - + [Parameter] public System.Delegate DelegateParameter { get; set; } = null!; - + [Parameter] public object ObjectParameter { get; set; } = null!; } @@ -1548,7 +1547,7 @@ public void AddAttribute_ImplicitStringConversion_BindUnknown() using Microsoft.AspNetCore.Components; namespace Test; - + public class MyClass { public static implicit operator string(MyClass c) => throw null!; @@ -1581,7 +1580,7 @@ public void AddAttribute_ImplicitStringConversion_BindUnknown_Assignment() using Microsoft.AspNetCore.Components; namespace Test; - + public class MyClass { public static implicit operator string(MyClass c) => throw null!; @@ -1615,7 +1614,7 @@ public void AddAttribute_ImplicitBooleanConversion() using Microsoft.AspNetCore.Components; namespace Test; - + public class MyClass { public static implicit operator bool(MyClass c) => throw null!; @@ -1625,7 +1624,7 @@ public class MyComponent : ComponentBase { [Parameter] public MyClass MyParameter { get; set; } - + [Parameter] public bool BoolParameter { get; set; } } @@ -1651,7 +1650,7 @@ public void AddComponentParameter() @typeparam T - + @code { [Parameter] public T Param { get; set; } @@ -1788,12 +1787,19 @@ public class MyComponent : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var assembly = CompileToAssembly(generated, throwOnFailure: false); - // This has some errors - Assert.Collection( - assembly.Diagnostics.OrderBy(d => d.Id), - d => Assert.Equal("CS0029", d.Id), - d => Assert.Equal("CS1503", d.Id)); + CompileToAssembly(generated, DesignTime + ? [// x:\dir\subdir\Test\TestComponent.cshtml(1,27): error CS1503: Argument 1: cannot convert from 'string' to 'int' + // ParentValue + Diagnostic(ErrorCode.ERR_BadArgType, "ParentValue").WithArguments("1", "string", "int").WithLocation(1, 27), + // (30,127): error CS0029: Cannot implicitly convert type 'int' to 'string' + // __builder.AddComponentParameter(2, "ValueChanged", (global::System.Action)(__value => ParentValue = __value)); + Diagnostic(ErrorCode.ERR_NoImplicitConv, "__value").WithArguments("int", "string").WithLocation(37, 38)] + : [// x:\dir\subdir\Test\TestComponent.cshtml(1,27): error CS1503: Argument 1: cannot convert from 'string' to 'int' + // ParentValue + Diagnostic(ErrorCode.ERR_BadArgType, "ParentValue").WithArguments("1", "string", "int").WithLocation(1, 27), + // (30,127): error CS0029: Cannot implicitly convert type 'int' to 'string' + // __builder.AddComponentParameter(2, "ValueChanged", (global::System.Action)(__value => ParentValue = __value)); + Diagnostic(ErrorCode.ERR_NoImplicitConv, "__value").WithArguments("int", "string").WithLocation(30, 127)]); } [IntegrationTestFact] @@ -1860,12 +1866,21 @@ public class MyComponent : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var assembly = CompileToAssembly(generated, throwOnFailure: false); - // This has some errors - Assert.Collection( - assembly.Diagnostics.OrderBy(d => d.Id), - d => Assert.Equal("CS1503", d.Id), - d => Assert.Equal("CS1503", d.Id)); + CompileToAssembly(generated, DesignTime + ? [// x:\dir\subdir\Test\TestComponent.cshtml(1,27): error CS1503: Argument 1: cannot convert from 'string' to 'int' + // ParentValue + Diagnostic(ErrorCode.ERR_BadArgType, "ParentValue").WithArguments("1", "string", "int").WithLocation(1, 27), + // (37,13): error CS1503: Argument 2: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to 'Microsoft.AspNetCore.Components.EventCallback' + // global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => ParentValue = __value, ParentValue))); + Diagnostic(ErrorCode.ERR_BadArgType, "global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => ParentValue = __value, ParentValue)").WithArguments("2", "Microsoft.AspNetCore.Components.EventCallback", "Microsoft.AspNetCore.Components.EventCallback").WithLocation(37, 13)] + : [// x:\dir\subdir\Test\TestComponent.cshtml(1,27): error CS1503: Argument 1: cannot convert from 'string' to 'int' + // ParentValue + Diagnostic(ErrorCode.ERR_BadArgType, "ParentValue").WithArguments("1", "string", "int").WithLocation(1, 27), + // (37,13): error CS1503: Argument 2: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to 'Microsoft.AspNetCore.Components.EventCallback' + // global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => ParentValue = __value, ParentValue))); + Diagnostic(ErrorCode.ERR_BadArgType, "global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => ParentValue = __value, ParentValue)").WithArguments("2", "Microsoft.AspNetCore.Components.EventCallback", "Microsoft.AspNetCore.Components.EventCallback").WithLocation(30, 320) + ] + ); } [IntegrationTestFact] @@ -2060,12 +2075,21 @@ public class MyComponent : ComponentBase public int ParentValue { get; set; } = 42; }"); - var assembly = CompileToAssembly(generated, throwOnFailure: false); - // This has some errors - Assert.Collection( - assembly.Diagnostics.OrderBy(d => d.Id), - d => Assert.Equal("CS0029", d.Id), - d => Assert.Equal("CS1662", d.Id)); + + CompileToAssembly(generated, DesignTime + ? [// (31,227): error CS0029: Cannot implicitly convert type 'int' to 'string' + // __builder.AddComponentParameter(3, "ValueExpression", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck>>(() => ParentValue)); + Diagnostic(ErrorCode.ERR_NoImplicitConv, "ParentValue").WithArguments("int", "string").WithLocation(38, 179), + // (31,227): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type + // __builder.AddComponentParameter(3, "ValueExpression", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck>>(() => ParentValue)); + Diagnostic(ErrorCode.ERR_CantConvAnonMethReturns, "ParentValue").WithArguments("lambda expression").WithLocation(38, 179)] + : [// (31,227): error CS0029: Cannot implicitly convert type 'int' to 'string' + // __builder.AddComponentParameter(3, "ValueExpression", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck>>(() => ParentValue)); + Diagnostic(ErrorCode.ERR_NoImplicitConv, "ParentValue").WithArguments("int", "string").WithLocation(31, 227), + // (31,227): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type + // __builder.AddComponentParameter(3, "ValueExpression", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck>>(() => ParentValue)); + Diagnostic(ErrorCode.ERR_CantConvAnonMethReturns, "ParentValue").WithArguments("lambda expression").WithLocation(31, 227) + ]); } [IntegrationTestFact] @@ -2477,11 +2501,10 @@ public class MyComponent : ComponentBase // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - - var error = Assert.Single(result.Diagnostics); - // Argument 1: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to '...' (System.Action/System.Func) - Assert.Equal("CS1503", error.Id); + CompileToAssembly(generated, + // x:\dir\subdir\Test\TestComponent.cshtml(1,61): error CS1503: Argument 2: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to 'System.Action' + // UpdateValue + Diagnostic(ErrorCode.ERR_BadArgType, "UpdateValue").WithArguments("2", "Microsoft.AspNetCore.Components.EventCallback", "System.Action").WithLocation(1, 61)); } [IntegrationTestFact] @@ -2516,11 +2539,10 @@ public class CustomValue // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - - var error = Assert.Single(result.Diagnostics); - // Argument 1: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to '...' (System.Action/System.Func) - Assert.Equal("CS1503", error.Id); + CompileToAssembly(generated, + // x:\dir\subdir\Test\TestComponent.cshtml(1,61): error CS1503: Argument 2: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to 'System.Action' + // UpdateValue + Diagnostic(ErrorCode.ERR_BadArgType, "UpdateValue").WithArguments("2", "Microsoft.AspNetCore.Components.EventCallback", "System.Action").WithLocation(1, 61)); } [IntegrationTestFact] @@ -2555,12 +2577,10 @@ public class CustomValue // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - - var error = Assert.Single(result.Diagnostics); - // Argument 1: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to '...' (System.Action/System.Func) - Assert.Equal("CS1503", error.Id); - + CompileToAssembly(generated, + // x:\dir\subdir\Test\TestComponent.cshtml(1,82): error CS1503: Argument 2: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to 'System.Action' + // UpdateValue + Diagnostic(ErrorCode.ERR_BadArgType, "UpdateValue").WithArguments("2", "Microsoft.AspNetCore.Components.EventCallback", "System.Action").WithLocation(1, 82)); } [IntegrationTestFact] @@ -2593,11 +2613,10 @@ @typeparam TParam // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - - var error = Assert.Single(result.Diagnostics); - // Argument 1: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to '...' (System.Action/System.Func) - Assert.Equal("CS1503", error.Id); + CompileToAssembly(generated, + // x:\dir\subdir\Test\TestComponent.cshtml(2,61): error CS1503: Argument 2: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to 'System.Action' + // UpdateValue + Diagnostic(ErrorCode.ERR_BadArgType, "UpdateValue").WithArguments("2", "Microsoft.AspNetCore.Components.EventCallback", "System.Action").WithLocation(2, 61)); } [IntegrationTestFact] @@ -2630,11 +2649,10 @@ @typeparam TParam // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - - var error = Assert.Single(result.Diagnostics); - // Argument 1: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to '...' (System.Action/System.Func) - Assert.Equal("CS1503", error.Id); + CompileToAssembly(generated, + // x:\dir\subdir\Test\TestComponent.cshtml(2,77): error CS1503: Argument 2: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to 'System.Action' + // UpdateValue + Diagnostic(ErrorCode.ERR_BadArgType, "UpdateValue").WithArguments("2", "Microsoft.AspNetCore.Components.EventCallback", "System.Action").WithLocation(2, 77)); } [IntegrationTestFact] @@ -3035,11 +3053,10 @@ public class MyComponent : ComponentBase // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - - var error = Assert.Single(result.Diagnostics); - // Argument 1: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to '...' (System.Action/System.Func) - Assert.Equal("CS1503", error.Id); + CompileToAssembly(generated, + // x:\dir\subdir\Test\TestComponent.cshtml(1,63): error CS1503: Argument 1: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to 'System.Action' + // UpdateValue + Diagnostic(ErrorCode.ERR_BadArgType, "UpdateValue").WithArguments("1", "Microsoft.AspNetCore.Components.EventCallback", "System.Action").WithLocation(1, 63)); } [IntegrationTestFact] @@ -3420,11 +3437,10 @@ public class MyComponent : ComponentBase // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var assembly = CompileToAssembly(generated, throwOnFailure: false); - // This has some errors - Assert.Collection( - assembly.Diagnostics.OrderBy(d => d.Id), - d => Assert.Equal("CS8030", d.Id)); + CompileToAssembly(generated, + // x:\dir\subdir\Test\TestComponent.cshtml(1,94): error CS8030: Anonymous function converted to a void returning delegate cannot return a value + // (value => { ParentValue = value; return Task.CompletedTask; }) + Diagnostic(ErrorCode.ERR_RetNoObjectRequiredLambda, "return").WithLocation(1, 94)); } [IntegrationTestFact] @@ -3845,10 +3861,10 @@ public static class BindAttributes public string ParentValue { get; set; } = ""hi""; public void UpdateValue(string value) => ParentValue = value; -}", throwOnFailure: false); +}"); // Assert - Assert.Collection(generated.Diagnostics, + Assert.Collection(generated.RazorDiagnostics, diagnostic => Assert.Equal("RZ10015", diagnostic.Id)); AssertDocumentNodeMatchesBaseline(generated.CodeDocument); @@ -3877,10 +3893,10 @@ public static class BindAttributes public string ParentValue { get; set; } = ""hi""; public void UpdateValue(string value) => ParentValue = value; -}", throwOnFailure: false); +}"); // Assert - Assert.Collection(generated.Diagnostics, + Assert.Collection(generated.RazorDiagnostics, diagnostic => Assert.Equal("RZ10016", diagnostic.Id)); AssertDocumentNodeMatchesBaseline(generated.CodeDocument); @@ -3909,10 +3925,10 @@ public static class BindAttributes public string ParentValue { get; set; } = ""hi""; public void UpdateValue(string value) => ParentValue = value; -}", throwOnFailure: false); +}"); // Assert - Assert.Collection(generated.Diagnostics, + Assert.Collection(generated.RazorDiagnostics, diagnostic => Assert.Equal("RZ10018", diagnostic.Id), diagnostic => Assert.Equal("RZ10015", diagnostic.Id)); @@ -3953,10 +3969,10 @@ public class MyComponent : ComponentBase public int ParentValue { get; set; } = 42; public void UpdateValue(int value) => ParentValue = value; -}", throwOnFailure: false); +}"); // Assert - Assert.Collection(generated.Diagnostics, + Assert.Collection(generated.RazorDiagnostics, diagnostic => Assert.Equal("RZ10020", diagnostic.Id)); AssertDocumentNodeMatchesBaseline(generated.CodeDocument); @@ -3986,10 +4002,10 @@ public static class BindAttributes public void UpdateValue(string value) => ParentValue = value; public void AfterUpdate() { } -}", throwOnFailure: false); +}"); // Assert - Assert.Collection(generated.Diagnostics, + Assert.Collection(generated.RazorDiagnostics, diagnostic => Assert.Equal("RZ10019", diagnostic.Id)); AssertDocumentNodeMatchesBaseline(generated.CodeDocument); @@ -4018,10 +4034,10 @@ public static class BindAttributes public string ParentValue { get; set; } = ""hi""; public void UpdateValue(string value) => ParentValue = value; -}", throwOnFailure: false); +}"); // Assert - Assert.Collection(generated.Diagnostics, + Assert.Collection(generated.RazorDiagnostics, diagnostic => Assert.Equal("RZ10016", diagnostic.Id)); } @@ -4047,10 +4063,10 @@ public static class BindAttributes public string ParentValue { get; set; } = ""hi""; public void UpdateValue(string value) => ParentValue = value; -}", throwOnFailure: false); +}"); // Assert - Assert.Collection(generated.Diagnostics, + Assert.Collection(generated.RazorDiagnostics, diagnostic => Assert.Equal("RZ10017", diagnostic.Id)); } @@ -4661,11 +4677,11 @@ @using Test3 // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); + var result = CompileToAssembly(generated); if (DesignTime) { - Assert.Collection(generated.Diagnostics, d => + Assert.Collection(generated.RazorDiagnostics, d => { Assert.Equal("RZ9985", d.Id); Assert.Equal(RazorDiagnosticSeverity.Error, d.Severity); @@ -4708,14 +4724,14 @@ public class SomeComponent : ComponentBase @using static Test2.SomeComponent @using Foo = Test3 - ", throwOnFailure: false); + "); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: false); + CompileToAssembly(generated); } - + [IntegrationTestFact] public void Component_WithMultipleUsingDirectives() { @@ -4894,10 +4910,10 @@ @preservewhitespace someVariable @code { bool someVariable = false; } -", throwOnFailure: false); +"); // Assert - Assert.Collection(generated.Diagnostics, d => { Assert.Equal("RZ1038", d.Id); }); + Assert.Collection(generated.RazorDiagnostics, d => { Assert.Equal("RZ1038", d.Id); }); } [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/7169")] @@ -4925,21 +4941,13 @@ @inherits BaseComponent // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var compiled = CompileToAssembly(generated, throwOnFailure: false); - if (DesignTime) - { - compiled.Diagnostics.Verify( - // x:\dir\subdir\Test\TestComponent.cshtml(4,7): warning CS8602: Dereference of a possibly null reference. - // __o = _field.ToString(); - Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "_field").WithLocation(4, 7)); - } - else - { - compiled.Diagnostics.Verify( - // x:\dir\subdir\Test\TestComponent.cshtml(4,3): warning CS8602: Dereference of a possibly null reference. - // __builder.AddContent(1, _field.ToString()); - Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "_field").WithLocation(4, 3)); - } + CompileToAssembly(generated, DesignTime + ? // x:\dir\subdir\Test\TestComponent.cshtml(4,7): warning CS8602: Dereference of a possibly null reference. + // __o = _field.ToString(); + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "_field").WithLocation(4, 7) + : // x:\dir\subdir\Test\TestComponent.cshtml(4,7): warning CS8602: Dereference of a possibly null reference. + // __o = _field.ToString(); + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "_field").WithLocation(4, 3)); } [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/7169")] @@ -4963,30 +4971,29 @@ @inherits BaseComponent @(_field.ToString()) """, nullableEnable: false, - throwOnFailure: false); + expectedCSharpDiagnostics: + // (18,62): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source. + // public partial class TestComponent : BaseComponent + Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(18, 62)); // Assert - Assert.Empty(generated.Diagnostics); + Assert.Empty(generated.RazorDiagnostics); AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var compiled = CompileToAssembly(generated, throwOnFailure: false); - if (DesignTime) - { - compiled.Diagnostics.Verify( + CompileToAssembly(generated, DesignTime + ? [ // x:\dir\subdir\Test\TestComponent.cshtml(1,21): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source. // BaseComponent __typeHelper = default!; Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(1, 21), // (14,62): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source. // public partial class TestComponent : BaseComponent - Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(14, 62)); - } - else - { - compiled.Diagnostics.Verify( + Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(14, 62) + ] + : [ // (14,62): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source. // public partial class TestComponent : BaseComponent - Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(14, 62)); - } + Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(14, 62) + ]); } #endregion @@ -5464,11 +5471,10 @@ private void Increment(ChangeEventArgs e) { AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - - // Cannot convert from method group to Action - this isn't a great error message, but it's - // what the compiler gives us. - Assert.Collection(result.Diagnostics, d => { Assert.Equal("CS1503", d.Id); }); + CompileToAssembly(generated, + // x:\dir\subdir\Test\TestComponent.cshtml(2,24): error CS1503: Argument 2: cannot convert from 'method group' to 'Microsoft.AspNetCore.Components.EventCallback' + // Increment + Diagnostic(ErrorCode.ERR_BadArgType, "Increment").WithArguments("2", "method group", "Microsoft.AspNetCore.Components.EventCallback").WithLocation(2, 24)); } [IntegrationTestFact] @@ -5504,8 +5510,7 @@ public class MyType // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument, verifyLinePragmas: DesignTime); - var result = CompileToAssembly(generated, throwOnFailure: false); - result.Diagnostics.Verify( + CompileToAssembly(generated, // x:\dir\subdir\Test\TestComponent.cshtml(4,17): warning CS0169: The field 'TestComponent.counter' is never used // private int counter; Diagnostic(ErrorCode.WRN_UnreferencedField, "counter").WithArguments("Test.TestComponent.counter").WithLocation(4, 17)); @@ -5547,8 +5552,7 @@ public class MyType // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument, verifyLinePragmas: DesignTime); - var result = CompileToAssembly(generated, throwOnFailure: false); - result.Diagnostics.Verify( + var result = CompileToAssembly(generated, // x:\dir\subdir\Test\TestComponent.cshtml(4,17): warning CS0169: The field 'TestComponent.counter' is never used // private int counter; Diagnostic(ErrorCode.WRN_UnreferencedField, "counter").WithArguments("Test.TestComponent.counter").WithLocation(4, 17)); @@ -6326,7 +6330,7 @@ public class Column : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.GenericComponentTypeInferenceUnderspecified.Id, diagnostic.Id); } @@ -6606,7 +6610,7 @@ public class Column : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.GenericComponentMissingTypeArgument.Id, diagnostic.Id); } @@ -6787,7 +6791,7 @@ public class Column : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.GenericComponentTypeInferenceUnderspecified.Id, diagnostic.Id); } @@ -6935,7 +6939,7 @@ public class Column : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.GenericComponentTypeInferenceUnderspecified.Id, diagnostic.Id); } @@ -7032,7 +7036,7 @@ public class Grid : ComponentBase public partial class GridColumn : ComponentBase { } - + public class X { } """)); @@ -8153,7 +8157,7 @@ public void GenericComponent_TypeParameterOrdering() // Arrange AdditionalSyntaxTrees.Add(Parse(""" using Microsoft.AspNetCore.Components; - + namespace Test; public interface IInterfaceConstraint { } @@ -9433,12 +9437,48 @@ @using System.Reflection @layout MainLayout @Foo
Hello
-", throwOnFailure: false, fileKind: FileKinds.ComponentImport); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: false); +", fileKind: FileKinds.ComponentImport, expectedCSharpDiagnostics: [ + // (4,31): error CS0246: The type or namespace name 'ComponentBase' could not be found (are you missing a using directive or an assembly reference?) + // public class MainLayout : ComponentBase, ILayoutComponent + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "ComponentBase").WithArguments("ComponentBase").WithLocation(4, 31), + // (4,46): error CS0246: The type or namespace name 'ILayoutComponent' could not be found (are you missing a using directive or an assembly reference?) + // public class MainLayout : ComponentBase, ILayoutComponent + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "ILayoutComponent").WithArguments("ILayoutComponent").WithLocation(4, 46), + // (6,16): error CS0246: The type or namespace name 'RenderFragment' could not be found (are you missing a using directive or an assembly reference?) + // public RenderFragment Body { get; set; } + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "RenderFragment").WithArguments("RenderFragment").WithLocation(6, 16)]); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated, DesignTime + ? [// (4,31): error CS0246: The type or namespace name 'ComponentBase' could not be found (are you missing a using directive or an assembly reference?) + // public class MainLayout : ComponentBase, ILayoutComponent + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "ComponentBase").WithArguments("ComponentBase").WithLocation(4, 31), + // (4,46): error CS0246: The type or namespace name 'ILayoutComponent' could not be found (are you missing a using directive or an assembly reference?) + // public class MainLayout : ComponentBase, ILayoutComponent + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "ILayoutComponent").WithArguments("ILayoutComponent").WithLocation(4, 46), + // (6,16): error CS0246: The type or namespace name 'RenderFragment' could not be found (are you missing a using directive or an assembly reference?) + // public RenderFragment Body { get; set; } + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "RenderFragment").WithArguments("RenderFragment").WithLocation(6, 16), + // x:\dir\subdir\Test\_Imports.razor(5,2): error CS0103: The name 'Foo' does not exist in the current context + // Foo + Diagnostic(ErrorCode.ERR_NameNotInContext, "Foo").WithArguments("Foo").WithLocation(5, 7)] + : [// (4,31): error CS0246: The type or namespace name 'ComponentBase' could not be found (are you missing a using directive or an assembly reference?) + // public class MainLayout : ComponentBase, ILayoutComponent + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "ComponentBase").WithArguments("ComponentBase").WithLocation(4, 31), + // (4,46): error CS0246: The type or namespace name 'ILayoutComponent' could not be found (are you missing a using directive or an assembly reference?) + // public class MainLayout : ComponentBase, ILayoutComponent + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "ILayoutComponent").WithArguments("ILayoutComponent").WithLocation(4, 46), + // (6,16): error CS0246: The type or namespace name 'RenderFragment' could not be found (are you missing a using directive or an assembly reference?) + // public RenderFragment Body { get; set; } + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "RenderFragment").WithArguments("RenderFragment").WithLocation(6, 16), + // x:\dir\subdir\Test\_Imports.razor(5,2): error CS0103: The name 'Foo' does not exist in the current context + // Foo + Diagnostic(ErrorCode.ERR_NameNotInContext, "Foo").WithArguments("Foo").WithLocation(5, 2), + // (33,13): error CS0103: The name '__builder' does not exist in the current context + // __builder.AddContent(0, + Diagnostic(ErrorCode.ERR_NameNotInContext, "__builder").WithArguments("__builder").WithLocation(33, 13)]); } [IntegrationTestFact] @@ -9457,7 +9497,7 @@ public class Counter : ComponentBase """)); // Act - var generated = CompileToCSharp("Index.razor", """ + var generated = CompileToCSharp("Index.razor", cshtmlContent: """ @using global::MyComponents @@ -9527,7 +9567,7 @@ public class Counter2 : ComponentBase ")); // Act - var generated = CompileToCSharp("Pages/Counter.razor", @" + var generated = CompileToCSharp("Pages/Counter.razor", cshtmlContent: @" @namespace New.Test "); @@ -9700,7 +9740,7 @@ public void DuplicateMarkupAttributes_IsAnError() AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.DuplicateMarkupAttribute.Id, diagnostic.Id); } @@ -9720,7 +9760,7 @@ @using Microsoft.AspNetCore.Components.Web AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.DuplicateMarkupAttributeDirective.Id, diagnostic.Id); } @@ -9739,7 +9779,7 @@ public void DuplicateMarkupAttributes_Multiple_IsAnError() AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - Assert.All(generated.Diagnostics, d => + Assert.All(generated.RazorDiagnostics, d => { Assert.Same(ComponentDiagnosticFactory.DuplicateMarkupAttribute.Id, d.Id); }); @@ -9766,7 +9806,7 @@ @using Microsoft.AspNetCore.Components.Web AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.DuplicateMarkupAttributeDirective.Id, diagnostic.Id); } @@ -9790,7 +9830,7 @@ @using Microsoft.AspNetCore.Components.Web AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.DuplicateMarkupAttributeDirective.Id, diagnostic.Id); } @@ -9814,7 +9854,7 @@ @using Microsoft.AspNetCore.Components.Web AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.DuplicateMarkupAttributeDirective.Id, diagnostic.Id); } @@ -9843,7 +9883,7 @@ public class MyComponent : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.DuplicateComponentParameter.Id, diagnostic.Id); } @@ -9872,7 +9912,7 @@ public class MyComponent : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - Assert.All(generated.Diagnostics, d => + Assert.All(generated.RazorDiagnostics, d => { Assert.Same(ComponentDiagnosticFactory.DuplicateComponentParameter.Id, d.Id); }); @@ -9903,7 +9943,7 @@ public class MyComponent : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.DuplicateComponentParameter.Id, diagnostic.Id); } @@ -9938,7 +9978,7 @@ public class MyComponent : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.DuplicateComponentParameterDirective.Id, diagnostic.Id); } @@ -9973,7 +10013,7 @@ public class MyComponent : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.DuplicateComponentParameterDirective.Id, diagnostic.Id); } @@ -10008,7 +10048,7 @@ public class MyComponent : ComponentBase AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.DuplicateComponentParameterDirective.Id, diagnostic.Id); } @@ -10111,7 +10151,7 @@ public class SurveyPrompt : ComponentBase // This has some errors Assert.Collection( - generated.Diagnostics.OrderBy(d => d.Id), + generated.RazorDiagnostics.OrderBy(d => d.Id), d => Assert.Equal("RZ1034", d.Id), d => Assert.Equal("RZ1035", d.Id)); } @@ -10222,12 +10262,11 @@ public enum MyEnum // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - result.Diagnostics.Verify( + CompileToAssembly(generated, // x:\dir\subdir\Test\TestComponent.cshtml(1,31): error CS0119: 'TestComponent.MyEnum' is a type, which is not valid in the given context // MyEnum Diagnostic(ErrorCode.ERR_BadSKunknown, "MyEnum").WithArguments("Test.TestComponent.MyEnum", "type").WithLocation(1, 31)); - Assert.NotEmpty(generated.Diagnostics); + Assert.NotEmpty(generated.RazorDiagnostics); } [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/9346")] @@ -10262,12 +10301,11 @@ public enum MyEnum // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - result.Diagnostics.Verify( + CompileToAssembly(generated, // x:\dir\subdir\Test\TestComponent.cshtml(1,31): error CS0119: 'TestComponent.MyEnum' is a type, which is not valid in the given context // MyEnum Diagnostic(ErrorCode.ERR_BadSKunknown, "MyEnum").WithArguments("Test.TestComponent.MyEnum", "type").WithLocation(1, 31)); - Assert.NotEmpty(generated.Diagnostics); + Assert.NotEmpty(generated.RazorDiagnostics); } [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/9346")] @@ -10298,19 +10336,21 @@ public class MyComponent : ComponentBase // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - result.Diagnostics.Verify( - // x:\dir\subdir\Test\TestComponent.cshtml(1,32): error CS1003: Syntax error, ',' expected - // x - Diagnostic(ErrorCode.ERR_SyntaxError, "").WithArguments(",").WithLocation(1, 32), - DesignTime - // (27,91): error CS1501: No overload for method 'TypeCheck' takes 2 arguments - // __o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck( - ? Diagnostic(ErrorCode.ERR_BadArgCount, "TypeCheck").WithArguments("TypeCheck", "2").WithLocation(27, 91) - // (21,138): error CS1501: No overload for method 'TypeCheck' takes 2 arguments - // __builder.AddComponentParameter(1, "StringProperty", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck( - : Diagnostic(ErrorCode.ERR_BadArgCount, "TypeCheck").WithArguments("TypeCheck", "2").WithLocation(21, 138)); - Assert.NotEmpty(generated.Diagnostics); + CompileToAssembly(generated, DesignTime + ? [// x:\dir\subdir\Test\TestComponent.cshtml(1,32): error CS1003: Syntax error, ',' expected + // x + Diagnostic(ErrorCode.ERR_SyntaxError, "").WithArguments(",").WithLocation(1, 32), + // (27,91): error CS1501: No overload for method 'TypeCheck' takes 2 arguments + // __o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck( + Diagnostic(ErrorCode.ERR_BadArgCount, "TypeCheck").WithArguments("TypeCheck", "2").WithLocation(27, 91)] + : [// x:\dir\subdir\Test\TestComponent.cshtml(1,32): error CS1003: Syntax error, ',' expected + // x + Diagnostic(ErrorCode.ERR_SyntaxError, "").WithArguments(",").WithLocation(1, 32), + // (27,91): error CS1501: No overload for method 'TypeCheck' takes 2 arguments + // __o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck( + Diagnostic(ErrorCode.ERR_BadArgCount, "TypeCheck").WithArguments("TypeCheck", "2").WithLocation(21, 138)] + ); + Assert.NotEmpty(generated.RazorDiagnostics); } [IntegrationTestFact] @@ -10443,6 +10483,21 @@ public void ScriptTag_Razor7() CompileToAssembly(generated); } + [IntegrationTestFact] + public void AtTransitions() + { + var generated = CompileToCSharp(""" + @{ + var x = "hello"; + @x x = "world"; @x + } + """); + + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + #endregion #region LinePragmas @@ -10494,18 +10549,18 @@ public void ProducesStandardLinePragmaForCSharpCode() [Parameter] public int IncrementAmount { get; set; } } -", throwOnFailure: false); +"); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: false); + CompileToAssembly(generated); } [IntegrationTestFact] - public void CanProduceLinePragmasForComponentWithRenderFragment() + public void CanProduceLinePragmasForComponentWithRenderFragment_01() { - var generated = CompileToCSharp(@" + var code = @"
@ActionText @if (!Collapsed) @@ -10526,12 +10581,73 @@ void Toggle() { Collapsed = !Collapsed; } -}", throwOnFailure: false); +}"; + + DiagnosticDescription[] expectedDiagnostics = [ + // x:\dir\subdir\Test\TestComponent.cshtml(13,67): error CS1525: Invalid expression term '<' + // public RenderFragment ChildContent { get; set; } = (context) =>

@context

+ Diagnostic(ErrorCode.ERR_InvalidExprTerm, "<").WithArguments("<").WithLocation(13, 67), + // x:\dir\subdir\Test\TestComponent.cshtml(13,67): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement + // public RenderFragment ChildContent { get; set; } = (context) =>

@context

+ Diagnostic(ErrorCode.ERR_IllegalStatement, """ +

@context

+ [Parameter] + """.NormalizeLineEndings()).WithLocation(13, 67), + // x:\dir\subdir\Test\TestComponent.cshtml(13,68): error CS0103: The name 'p' does not exist in the current context + // public RenderFragment ChildContent { get; set; } = (context) =>

@context

+ Diagnostic(ErrorCode.ERR_NameNotInContext, "p").WithArguments("p").WithLocation(13, 68), + // x:\dir\subdir\Test\TestComponent.cshtml(13,79): error CS1525: Invalid expression term '/' + // public RenderFragment ChildContent { get; set; } = (context) =>

@context

+ Diagnostic(ErrorCode.ERR_InvalidExprTerm, "/").WithArguments("/").WithLocation(13, 79), + // x:\dir\subdir\Test\TestComponent.cshtml(13,80): error CS0103: The name 'p' does not exist in the current context + // public RenderFragment ChildContent { get; set; } = (context) =>

@context

+ Diagnostic(ErrorCode.ERR_NameNotInContext, "p").WithArguments("p").WithLocation(13, 80), + // x:\dir\subdir\Test\TestComponent.cshtml(14,4): error CS0103: The name 'Parameter' does not exist in the current context + // [Parameter] + Diagnostic(ErrorCode.ERR_NameNotInContext, "Parameter").WithArguments("Parameter").WithLocation(14, 4), + // x:\dir\subdir\Test\TestComponent.cshtml(14,14): error CS1002: ; expected + // [Parameter] + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(14, 14)] + ; + + var generated = CompileToCSharp(code, expectedDiagnostics); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: false); + CompileToAssembly(generated, expectedDiagnostics); + } + + [IntegrationTestFact] + public void CanProduceLinePragmasForComponentWithRenderFragment_02() + { + var generated = CompileToCSharp(@" +
+ @ActionText + @if (!Collapsed) + { +
+ @ChildContent +
+ } +
+@code +{ + [Parameter] + public RenderFragment ChildContent { get; set; } = (context) => @

@context

; + [Parameter] + public bool Collapsed { get; set; } + string ActionText { get => Collapsed ? ""Expand"" : ""Collapse""; } + void Toggle() + { + Collapsed = !Collapsed; + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); } [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/9359")] @@ -10558,12 +10674,12 @@ public void RenderMode_Directive_FullyQualified() { var generated = CompileToCSharp(""" @rendermode Microsoft.AspNetCore.Components.Web.RenderMode.Server - """, throwOnFailure: true); + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] @@ -10571,12 +10687,12 @@ public void RenderMode_Directive_SimpleExpression() { var generated = CompileToCSharp(""" @rendermode @(Microsoft.AspNetCore.Components.Web.RenderMode.Server) - """, throwOnFailure: true); + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] @@ -10590,12 +10706,12 @@ @rendermode @(Microsoft.AspNetCore.Components.Web.RenderMode.Server) [Parameter] public int Count { get; set; } } - """, throwOnFailure: true); + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] @@ -10608,12 +10724,12 @@ public void RenderMode_Directive_SimpleExpression_NotFirst() public int Count { get; set; } } @rendermode @(Microsoft.AspNetCore.Components.Web.RenderMode.Server) - """, throwOnFailure: true); + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] @@ -10627,12 +10743,12 @@ @rendermode @(new TestComponent.MyRenderMode("This is some text")) #pragma warning disable CS9113 public class MyRenderMode(string Text) : Microsoft.AspNetCore.Components.IComponentRenderMode { } } - """, throwOnFailure: true); + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] @@ -10642,25 +10758,25 @@ public void RenderMode_Directive_WithNamespaces() @namespace Custom.Namespace @rendermode Microsoft.AspNetCore.Components.Web.RenderMode.Server - """, throwOnFailure: true); + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] public void RenderMode_Attribute_With_SimpleIdentifier() { var generated = CompileToCSharp($""" - <{ComponentName} @rendermode="Microsoft.AspNetCore.Components.Web.RenderMode.Server" /> - """, throwOnFailure: true); + <{ComponentName} @rendermode="Microsoft.AspNetCore.Components.Web.RenderMode.Server" /> + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] @@ -10674,13 +10790,13 @@ class MyRenderMode : Microsoft.AspNetCore.Components.IComponentRenderMode { public string Extra {get;set;} } - } - """, throwOnFailure: true); + } + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] @@ -10694,13 +10810,13 @@ public void RenderMode_Attribute_With_Existing_Attributes() [Parameter]public string P1 {get; set;} [Parameter]public string P2 {get; set;} - } - """, throwOnFailure: true); + } + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] @@ -10709,12 +10825,12 @@ public void Duplicate_RenderMode() var generated = CompileToCSharp($$""" <{{ComponentName}} @rendermode="Microsoft.AspNetCore.Components.Web.RenderMode.Server" @rendermode="Value2" /> - """, throwOnFailure: true); + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] @@ -10723,12 +10839,12 @@ public void RenderMode_Multiple_Components() var generated = CompileToCSharp($$""" <{{ComponentName}} @rendermode="Microsoft.AspNetCore.Components.Web.RenderMode.Server" /> <{{ComponentName}} @rendermode="Microsoft.AspNetCore.Components.Web.RenderMode.Server" /> - """, throwOnFailure: true); + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] @@ -10750,12 +10866,12 @@ public void RenderMode_Child_Components() [Parameter] public RenderFragment ChildContent { get; set; } } - """, throwOnFailure: true); + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] @@ -10770,12 +10886,12 @@ public void RenderMode_With_TypeInference() { [Parameter] public TRenderMode RenderModeParam { get; set;} } - """, throwOnFailure: true); + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact] @@ -10783,12 +10899,12 @@ public void RenderMode_With_Ternary() { var generated = CompileToCSharp($$""" <{{ComponentName}} @rendermode="@(true ? Microsoft.AspNetCore.Components.Web.RenderMode.Server : null)" /> - """, throwOnFailure: true); + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/9343")] @@ -10796,12 +10912,12 @@ public void RenderMode_With_Null_Nullable_Disabled() { var generated = CompileToCSharp($$""" <{{ComponentName}} @rendermode="null" /> - """, throwOnFailure: true, nullableEnable: false); + """, nullableEnable: false); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/9343")] @@ -10809,12 +10925,12 @@ public void RenderMode_With_Null_Nullable_Enabled() { var generated = CompileToCSharp($$""" <{{ComponentName}} @rendermode="null" /> - """, throwOnFailure: true, nullableEnable: true); + """, nullableEnable: true); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated, throwOnFailure: true); + CompileToAssembly(generated); } [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/9343")] @@ -10831,14 +10947,12 @@ public class RenderModeContainer RenderModeContainer? Container => null; } <{{ComponentName}} @rendermode="@(Container.RenderMode)" /> - """, throwOnFailure: true, nullableEnable: true); + """, nullableEnable: true); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - - result.Diagnostics.Verify( + CompileToAssembly(generated, DesignTime // x:\dir\subdir\Test\TestComponent.cshtml(10,29): warning CS8602: Dereference of a possibly null reference. // Container.RenderMode @@ -10898,8 +11012,7 @@ @using Microsoft.AspNetCore.Components.Web // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - result.Diagnostics.Verify( + CompileToAssembly(generated, // x:\dir\subdir\Test\TestComponent.cshtml(2,55): error CS1503: Argument 1: cannot convert from 'int' to 'string' // x Diagnostic(ErrorCode.ERR_BadArgType, "x").WithArguments("1", "int", "string").WithLocation(2, 55)); @@ -10920,19 +11033,13 @@ @using Microsoft.AspNetCore.Components.Web // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - if (DesignTime) - { - result.Diagnostics.Verify( + CompileToAssembly(generated, DesignTime + ? [ // x:\dir\subdir\Test\TestComponent.cshtml(2,74): error CS1503: Argument 1: cannot convert from 'int' to 'string' // x - Diagnostic(ErrorCode.ERR_BadArgType, "x").WithArguments("1", "int", "string").WithLocation(2, 74)); - } - else - { - result.Diagnostics.Verify(); - } - Assert.NotEmpty(generated.Diagnostics); + Diagnostic(ErrorCode.ERR_BadArgType, "x").WithArguments("1", "int", "string").WithLocation(2, 74) + ] + : []); } [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/9077")] @@ -10966,8 +11073,7 @@ @using Microsoft.AspNetCore.Components.Web // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - result.Diagnostics.Verify( + CompileToAssembly(generated, // x:\dir\subdir\Test\TestComponent.cshtml(2,55): error CS0103: The name 'x' does not exist in the current context // x Diagnostic(ErrorCode.ERR_NameNotInContext, "x").WithArguments("x").WithLocation(2, 55)); @@ -10985,14 +11091,14 @@ @using Microsoft.AspNetCore.Components.Web // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - var result = CompileToAssembly(generated, throwOnFailure: false); - result.Diagnostics.Verify(DesignTime - // (41,85): error CS7036: There is no argument given that corresponds to the required parameter 'value' of 'RuntimeHelpers.TypeCheck(T)' - // global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck(); - ? Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "TypeCheck").WithArguments("value", "Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck(T)").WithLocation(41, 85) - // (37,105): error CS7036: There is no argument given that corresponds to the required parameter 'value' of 'RuntimeHelpers.TypeCheck(T)' - // string __formName = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck(); - : Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "TypeCheck").WithArguments("value", "Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck(T)").WithLocation(37, 105)); + CompileToAssembly(generated, DesignTime + ? [// (41,85): error CS7036: There is no argument given that corresponds to the required parameter 'value' of 'RuntimeHelpers.TypeCheck(T)' + // global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck(); + Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "TypeCheck").WithArguments("value", "Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck(T)").WithLocation(41, 85)] + : [// (41,85): error CS7036: There is no argument given that corresponds to the required parameter 'value' of 'RuntimeHelpers.TypeCheck(T)' + // global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck(); + Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "TypeCheck").WithArguments("value", "Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck(T)").WithLocation(37, 105)] + ); } [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/9077")] diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDeclarationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDeclarationIntegrationTest.cs index 7a95be30bcf..78da8387095 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDeclarationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDeclarationIntegrationTest.cs @@ -149,16 +149,10 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components. ", generated); // Act 2 - var assembly = CompileToAssembly(generated, throwOnFailure: false); - - // Assert 2 - var diagnostic = Assert.Single(assembly.Diagnostics); - - // This error should map to line 2 of the generated file, the test - // says 1 because Roslyn's line/column data structures are 0-based. - var position = diagnostic.Location.GetMappedLineSpan(); - Assert.EndsWith(".cshtml", position.Path); - Assert.Equal(1, position.StartLinePosition.Line); + CompileToAssembly(generated, + // /dir/subdir/Test/TestComponent.cshtml(2,12): error CS0246: The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?) + // public StringBuilder Builder { get; set; } + Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "StringBuilder").WithArguments("StringBuilder").WithLocation(2, 12)); } public class BaseClass : IComponent diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDiagnosticRazorIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDiagnosticRazorIntegrationTest.cs index 6610bd4816e..69716543e13 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDiagnosticRazorIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDiagnosticRazorIntegrationTest.cs @@ -22,7 +22,7 @@ public void RejectsEndTagWithNoStartTag() "Line1\nLine2\nLine3"); // Assert - Assert.Collection(result.Diagnostics, + Assert.Collection(result.RazorDiagnostics, item => { Assert.Equal("RZ9981", item.Id); @@ -42,7 +42,7 @@ public void OldCodeBlockAttributeSyntax_ReportsError() }"); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ9979", diagnostic.Id); Assert.NotNull(diagnostic.GetMessage(CultureInfo.CurrentCulture)); } @@ -70,7 +70,7 @@ @tagHelperPrefix th "); // Assert - Assert.Collection(result.Diagnostics, + Assert.Collection(result.RazorDiagnostics, item => { Assert.Equal("RZ9978", item.Id); @@ -102,7 +102,7 @@ public void DirectiveAttribute_ComplexContent_ReportsError() }"); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ9986", diagnostic.Id); Assert.Equal( "Component attributes do not support complex content (mixed C# and markup). Attribute: '@key', text: 'Foo @Text'", @@ -113,14 +113,14 @@ public void DirectiveAttribute_ComplexContent_ReportsError() public void Component_StartsWithLowerCase_ReportsError() { // Arrange & Act - var generated = CompileToCSharp("lowerCase.razor", @" + var generated = CompileToCSharp("lowerCase.razor", cshtmlContent: @" @functions { public string Text { get; set; } = ""text""; -}", throwOnFailure: false); +}"); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ10011", diagnostic.Id); Assert.Equal( "Component 'lowerCase' starts with a lowercase character. Component names cannot start with a lowercase character.", @@ -141,7 +141,7 @@ public void Component_NotFound_ReportsWarning(bool supportLocalizedComponentName }", supportLocalizedComponentNames: supportLocalizedComponentNames); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ10012", diagnostic.Id); Assert.Equal(RazorDiagnosticSeverity.Warning, diagnostic.Severity); Assert.Equal( @@ -161,7 +161,7 @@ public void Component_NotFound_StartsWithOtherLetter_WhenLocalizedComponentNames }", supportLocalizedComponentNames: true); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ10012", diagnostic.Id); Assert.Equal(RazorDiagnosticSeverity.Warning, diagnostic.Severity); Assert.Equal( @@ -181,7 +181,7 @@ public void Component_NotFound_StartsWithOtherLetter_WhenLocalizedComponentNames }", supportLocalizedComponentNames: false); // Assert - Assert.Empty(generated.Diagnostics); + Assert.Empty(generated.RazorDiagnostics); } [Fact] @@ -192,7 +192,7 @@ public void Element_DoesNotStartWithLowerCase_OverrideWithBang_NoWarning() "); // Assert - Assert.Empty(generated.Diagnostics); + Assert.Empty(generated.RazorDiagnostics); } [Fact] @@ -213,7 +213,7 @@ public class MyComponent : ComponentBase "); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ10013", diagnostic.Id); Assert.Equal( "The start tag name 'MyComponent' does not match the end tag name 'mycomponent'. Components must have matching start and end tag names (case-sensitive).", diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDiscoveryIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDiscoveryIntegrationTest.cs index 76998cd4edd..dac3556aad0 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDiscoveryIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDiscoveryIntegrationTest.cs @@ -76,7 +76,7 @@ public void ComponentDiscovery_CanFindComponent_DefinedinCshtml() // Arrange // Act - var result = CompileToCSharp("UniqueName.cshtml", string.Empty); + var result = CompileToCSharp("UniqueName.cshtml", cshtmlContent: string.Empty); // Assert var bindings = result.CodeDocument.GetTagHelperContext(); @@ -89,7 +89,7 @@ public void ComponentDiscovery_CanFindComponent_WithTypeParameter() // Arrange // Act - var result = CompileToCSharp("UniqueName.cshtml", @" + var result = CompileToCSharp("UniqueName.cshtml", cshtmlContent: @" @typeparam TItem @functions { [Parameter] public TItem Item { get; set; } @@ -106,7 +106,7 @@ public void ComponentDiscovery_CanFindComponent_WithTypeParameterAndSemicolon() // Arrange // Act - var result = CompileToCSharp("UniqueName.cshtml", @" + var result = CompileToCSharp("UniqueName.cshtml", cshtmlContent: @" @typeparam TItem; @functions { [Parameter] public TItem Item { get; set; } @@ -123,7 +123,7 @@ public void ComponentDiscovery_CanFindComponent_WithMultipleTypeParameters() // Arrange // Act - var result = CompileToCSharp("UniqueName.cshtml", @" + var result = CompileToCSharp("UniqueName.cshtml", cshtmlContent: @" @typeparam TItem1 @typeparam TItem2 @typeparam TItem3 @@ -142,7 +142,7 @@ public void ComponentDiscovery_CanFindComponent_WithMultipleTypeParametersAndMix // Arrange // Act - var result = CompileToCSharp("UniqueName.cshtml", @" + var result = CompileToCSharp("UniqueName.cshtml", cshtmlContent: @" @typeparam TItem1 @typeparam TItem2; @typeparam TItem3 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentFilePathIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentFilePathIntegrationTest.cs index b432bab3617..f4f815cce12 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentFilePathIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentFilePathIntegrationTest.cs @@ -23,7 +23,7 @@ public void FileNameIsInvalidClassName_SanitizesInvalidClassName() var result = CompileToAssembly("Filename with spaces.cshtml", ""); // Assert - Assert.Empty(result.Diagnostics); + Assert.Empty(result.CSharpDiagnostics); var type = Assert.Single(result.Assembly.GetTypes().Where(t => t.GetCustomAttributes(inherit: false).All(a => a.GetType().Name != "CompilerGeneratedAttribute"))); Assert.Equal(DefaultRootNamespace, type.Namespace); @@ -43,7 +43,7 @@ public void CreatesClassWithCorrectNameAndNamespace(string relativePath, string var result = CompileToAssembly(relativePath, ""); // Assert - Assert.Empty(result.Diagnostics); + Assert.Empty(result.CSharpDiagnostics); var type = Assert.Single(result.Assembly.GetTypes().Where(t => t.GetCustomAttributes(inherit: false).All(a => a.GetType().Name != "CompilerGeneratedAttribute"))); Assert.Equal(expectedNamespace, type.Namespace); diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentGenericTypeIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentGenericTypeIntegrationTest.cs index ecab49e994a..17637d275bb 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentGenericTypeIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentGenericTypeIntegrationTest.cs @@ -93,7 +93,7 @@ public void GenericComponent_WithoutAnyTypeParameters_TriggersDiagnostic() "); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.GenericComponentTypeInferenceUnderspecified.Id, diagnostic.Id); Assert.Equal(""" The type of component 'GenericContext' cannot be inferred based on the values provided. Consider specifying the type arguments directly using the following attributes: 'TItem'. @@ -112,7 +112,7 @@ public void GenericComponent_WithMissingTypeParameters_TriggersDiagnostic() "); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Same(ComponentDiagnosticFactory.GenericComponentMissingTypeArgument.Id, diagnostic.Id); Assert.Equal(""" The component 'MultipleGenericParameter' is missing required type arguments. Specify the missing types using the attributes: 'TItem2', 'TItem3'. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentImportsIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentImportsIntegrationTest.cs index 3f9f66275cb..0b52c303460 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentImportsIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentImportsIntegrationTest.cs @@ -16,33 +16,33 @@ public class ComponentImportsIntegrationTest : RazorIntegrationTestBase public void NoErrorsForUsingStatements() { // Arrange/Act - var result = CompileToCSharp("_Imports.razor", @" + var result = CompileToCSharp("_Imports.razor", cshtmlContent: @" @using System.Text @using System.Reflection @* This is allowed in imports *@ "); // Assert - Assert.Empty(result.Diagnostics); + Assert.Empty(result.RazorDiagnostics); } [Fact] public void NoErrorsForRazorComments() { // Arrange/Act - var result = CompileToCSharp("_Imports.razor", @" + var result = CompileToCSharp("_Imports.razor", cshtmlContent: @" @* This is allowed in imports *@ "); // Assert - Assert.Empty(result.Diagnostics); + Assert.Empty(result.RazorDiagnostics); } [Fact] public void NoErrorsForSupportedDirectives() { // Arrange/Act - var result = CompileToCSharp("_Imports.razor", @" + var result = CompileToCSharp("_Imports.razor", cshtmlContent: @" @inject FooService Foo @typeparam TItem @implements ISomeInterface @@ -50,19 +50,19 @@ @inherits SomeNamespace.SomeBaseType "); // Assert - Assert.Empty(result.Diagnostics); + Assert.Empty(result.RazorDiagnostics); } [Fact] public void ErrorsForPageDirective() { // Arrange/Act - var result = CompileToCSharp("_Imports.razor", @" + var result = CompileToCSharp("_Imports.razor", cshtmlContent: @" @page ""/"" "); // Assert - Assert.Collection(result.Diagnostics, + Assert.Collection(result.RazorDiagnostics, item => { Assert.Equal("RZ9987", item.Id); @@ -74,14 +74,14 @@ public void ErrorsForPageDirective() public void ErrorsForTagHelperDirectives() { // Arrange/Act - var result = CompileToCSharp("_Imports.razor", @" + var result = CompileToCSharp("_Imports.razor", cshtmlContent: @" @addTagHelper *, TestAssembly @removeTagHelper *, TestAssembly @tagHelperPrefix th: "); // Assert - Assert.Collection(result.Diagnostics, + Assert.Collection(result.RazorDiagnostics, item => { Assert.Equal("RZ9978", item.Id); @@ -106,7 +106,7 @@ public void ErrorsForTagHelperDirectives() public void ErrorsForFunctionsDirective() { // Arrange/Act - var result = CompileToCSharp("_Imports.razor", @" + var result = CompileToCSharp("_Imports.razor", cshtmlContent: @" @functions { public class Test { @@ -115,7 +115,7 @@ public class Test "); // Assert - Assert.Collection(result.Diagnostics, + Assert.Collection(result.RazorDiagnostics, item => { Assert.Equal("RZ10003", item.Id); @@ -127,13 +127,13 @@ public class Test public void ErrorsForSectionDirective() { // Arrange/Act - var result = CompileToCSharp("_Imports.razor", @" + var result = CompileToCSharp("_Imports.razor", cshtmlContent: @" @section Foo { } "); // Assert - Assert.Collection(result.Diagnostics, + Assert.Collection(result.RazorDiagnostics, item => { Assert.Equal("RZ10003", item.Id); @@ -145,12 +145,12 @@ @section Foo { public void ErrorsForMarkup() { // Arrange/Act - var result = CompileToCSharp("_Imports.razor", @" + var result = CompileToCSharp("_Imports.razor", cshtmlContent: @"
asdf
"); // Assert - Assert.Collection(result.Diagnostics, + Assert.Collection(result.RazorDiagnostics, item => { Assert.Equal("RZ10003", item.Id); @@ -162,7 +162,7 @@ public void ErrorsForMarkup() public void ErrorsForCode() { // Arrange/Act - var result = CompileToCSharp("_Imports.razor", @" + var result = CompileToCSharp("_Imports.razor", cshtmlContent: @" @Foo @(Bar) @{ @@ -170,7 +170,7 @@ public void ErrorsForCode() }"); // Assert - Assert.Collection(result.Diagnostics, + Assert.Collection(result.RazorDiagnostics, item => { Assert.Equal("RZ10003", item.Id); diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentRenderModeAttributeIntegrationTests.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentRenderModeAttributeIntegrationTests.cs index 195361db37a..fcfb1f28e4c 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentRenderModeAttributeIntegrationTests.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentRenderModeAttributeIntegrationTests.cs @@ -20,12 +20,12 @@ public void RenderMode_Attribute_With_Diagnostics() { var generated = CompileToCSharp($$""" <{{ComponentName}} @rendermode="@Microsoft.AspNetCore.Components.Web.RenderMode.Server)" /> - """, throwOnFailure: true); + """); // Assert //x:\dir\subdir\Test\TestComponent.cshtml(1, 29): Error RZ9986: Component attributes do not support complex content(mixed C# and markup). Attribute: '@rendermode', text: 'Microsoft.AspNetCore.Components.Web.RenderMode.Server)' - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ9986", diagnostic.Id); } @@ -34,11 +34,11 @@ public void RenderMode_Attribute_On_Html_Element() { var generated = CompileToCSharp(""" - """, throwOnFailure: true); + """); // Assert //x:\dir\subdir\Test\TestComponent.cshtml(1,21): Error RZ10023: Attribute 'rendermode' is only valid when used on a component. - var diag = Assert.Single(generated.Diagnostics); + var diag = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ10023", diag.Id); } @@ -49,12 +49,12 @@ public void RenderMode_Attribute_On_Component_With_Directive() @rendermode Microsoft.AspNetCore.Components.Web.RenderMode.Server <{{ComponentName}} @rendermode="Microsoft.AspNetCore.Components.Web.RenderMode.Server" /> - """, throwOnFailure: true); + """); // Assert // x:\dir\subdir\Test\TestComponent.cshtml(3,29): Error RZ10024: Cannot override render mode for component 'Test.TestComponent' as it explicitly declares one. - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ10024", diagnostic.Id); } } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentRenderModeDirectiveIntegrationTests.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentRenderModeDirectiveIntegrationTests.cs index a9379e8abd5..ed897de6451 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentRenderModeDirectiveIntegrationTests.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentRenderModeDirectiveIntegrationTests.cs @@ -80,7 +80,7 @@ public void RenderMode_Missing_Value() // Assert // Error RZ1041: The 'rendermode' directive expects an identifier or explicit razor expression. - var diagnostic = Assert.Single(compilationResult.Diagnostics); + var diagnostic = Assert.Single(compilationResult.RazorDiagnostics); Assert.Equal("RZ1041", diagnostic.Id); } @@ -95,7 +95,7 @@ @rendermode Microsoft.AspNetCore.Components.Web.RenderMode.Server // Assert //Error RZ2001: The 'rendermode' directive may only occur once per document. - var diagnostic = Assert.Single(compilationResult.Diagnostics); + var diagnostic = Assert.Single(compilationResult.RazorDiagnostics); Assert.Equal("RZ2001", diagnostic.Id); } @@ -106,10 +106,9 @@ public void RenderMode_With_InvalidIdentifier() @rendermode NoExist """); - Assert.Empty(compilationResult.Diagnostics); + Assert.Empty(compilationResult.RazorDiagnostics); - var assemblyResult = CompileToAssembly(compilationResult, throwOnFailure: false); - assemblyResult.Diagnostics.Verify( + CompileToAssembly(compilationResult, // x:\dir\subdir\Test\TestComponent.cshtml(25,101): error CS0103: The name 'NoExist' does not exist in the current context // NoExist Diagnostic(ErrorCode.ERR_NameNotInContext, "NoExist").WithArguments("NoExist").WithLocation(25, 101) @@ -123,10 +122,9 @@ public void LanguageVersion() @rendermode Microsoft.AspNetCore.Components.Web.RenderMode.Server """, configuration: Configuration with { LanguageVersion = RazorLanguageVersion.Version_7_0 }); - Assert.Empty(compilationResult.Diagnostics); + Assert.Empty(compilationResult.RazorDiagnostics); - var assemblyResult = CompileToAssembly(compilationResult, throwOnFailure: false); - assemblyResult.Diagnostics.Verify( + CompileToAssembly(compilationResult, // x:\dir\subdir\Test\TestComponent.cshtml(1,2): error CS0103: The name 'rendermode' does not exist in the current context // __builder.AddContent(0, rendermode); Diagnostic(ErrorCode.ERR_NameNotInContext, "rendermode").WithArguments("rendermode").WithLocation(1, 2) @@ -145,10 +143,9 @@ @rendermode Foo } """, configuration: Configuration with { LanguageVersion = RazorLanguageVersion.Version_7_0 }); - Assert.Empty(compilationResult.Diagnostics); + Assert.Empty(compilationResult.RazorDiagnostics); - var assemblyResult = CompileToAssembly(compilationResult, throwOnFailure: true); - assemblyResult.Diagnostics.Verify(); + CompileToAssembly(compilationResult); } [Fact] @@ -163,10 +160,9 @@ @rendermode Foo } """, configuration: Configuration with { LanguageVersion = RazorLanguageVersion.Version_8_0 }); - Assert.Empty(compilationResult.Diagnostics); + Assert.Empty(compilationResult.RazorDiagnostics); - var assemblyResult = CompileToAssembly(compilationResult, throwOnFailure: false); - assemblyResult.Diagnostics.Verify( + CompileToAssembly(compilationResult, // x:\dir\subdir\Test\TestComponent.cshtml(34,101): error CS0103: The name 'Foo' does not exist in the current context // Foo Diagnostic(ErrorCode.ERR_NameNotInContext, "Foo").WithArguments("Foo").WithLocation(34, 101), @@ -186,12 +182,11 @@ @rendermode myRenderMode { Microsoft.AspNetCore.Components.IComponentRenderMode myRenderMode = new Microsoft.AspNetCore.Components.Web.ServerRenderMode(); } - """, throwOnFailure: true); + """); - Assert.Empty(compilationResult.Diagnostics); + Assert.Empty(compilationResult.RazorDiagnostics); - var assemblyResult = CompileToAssembly(compilationResult, throwOnFailure: false); - assemblyResult.Diagnostics.Verify( + CompileToAssembly(compilationResult, // x:\dir\subdir\Test\TestComponent.cshtml(34, 101): error CS0120: An object reference is required for the non-static field, method, or property 'TestComponent.myRenderMode' // myRenderMode Diagnostic(ErrorCode.ERR_ObjectRequired, "myRenderMode").WithArguments("Test.TestComponent.myRenderMode").WithLocation(34, 101) @@ -207,11 +202,11 @@ @rendermode myRenderMode { static Microsoft.AspNetCore.Components.IComponentRenderMode myRenderMode = new Microsoft.AspNetCore.Components.Web.ServerRenderMode(); } - """, throwOnFailure: true); + """); - Assert.Empty(compilationResult.Diagnostics); + Assert.Empty(compilationResult.RazorDiagnostics); - var assemblyResult = CompileToAssembly(compilationResult, throwOnFailure: true); + CompileToAssembly(compilationResult); } [Fact] @@ -223,12 +218,11 @@ @rendermode TestComponent.myRenderMode { internal static Microsoft.AspNetCore.Components.IComponentRenderMode myRenderMode = new Microsoft.AspNetCore.Components.Web.ServerRenderMode(); } - """, throwOnFailure: true); + """); - Assert.Empty(compilationResult.Diagnostics); + Assert.Empty(compilationResult.RazorDiagnostics); - var assemblyResult = CompileToAssembly(compilationResult, throwOnFailure: false); - assemblyResult.Diagnostics.Verify(); + CompileToAssembly(compilationResult); } [Fact] diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentTemplateIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentTemplateIntegrationTest.cs index 0d179dbb115..e63c17fcdaa 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentTemplateIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentTemplateIntegrationTest.cs @@ -21,10 +21,10 @@ public void Template_ImplicitExpressionInMarkupAttribute_CreatesDiagnostic() // Arrange // Act - var generated = CompileToCSharp(@"
"" />", throwOnFailure: false); + var generated = CompileToCSharp(@"
"" />"); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ1005", diagnostic.Id); } @@ -37,7 +37,7 @@ public void Template_ExplicitExpressionInMarkupAttribute_CreatesDiagnostic() var generated = CompileToCSharp(@"
)"" />"); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ9994", diagnostic.Id); } @@ -59,11 +59,11 @@ public class MyComponent : ComponentBase ")); // Act - var generated = CompileToCSharp(@"
"" />", throwOnFailure: false); + var generated = CompileToCSharp(@""" />"); // Assert Assert.Collection( - generated.Diagnostics, + generated.RazorDiagnostics, d => Assert.Equal("RZ9986", d.Id), d => Assert.Equal("RZ1005", d.Id)); } @@ -86,7 +86,7 @@ public class MyComponent : ComponentBase var generated = CompileToCSharp(@")"" />"); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ9994", diagnostic.Id); } @@ -99,7 +99,7 @@ public void Template_ExplicitExpressionInRef_CreatesDiagnostic() var generated = CompileToCSharp(@"
)"" />"); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ9994", diagnostic.Id); } @@ -113,7 +113,7 @@ public void Template_ExplicitExpressionInBind_CreatesDiagnostic() var generated = CompileToCSharp(@")"" />"); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ9994", diagnostic.Id); } @@ -126,7 +126,7 @@ public void Template_ExplicitExpressionInEventHandler_CreatesDiagnostic() var generated = CompileToCSharp(@")"" />"); // Assert - var diagnostic = Assert.Single(generated.Diagnostics); + var diagnostic = Assert.Single(generated.RazorDiagnostics); Assert.Equal("RZ9994", diagnostic.Id); } } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentTypingTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentTypingTest.cs index a2fca9ff8e5..5c5df9d5e1a 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentTypingTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentTypingTest.cs @@ -3,10 +3,8 @@ #nullable disable -using System; -using System.Linq; +using Microsoft.CodeAnalysis; using Xunit; -using Xunit.Sdk; namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests; @@ -61,44 +59,27 @@ public class ModelState for (var i = 0; i <= text.Length; i++) { - try - { - CompileToCSharp(text.Substring(0, i), throwOnFailure: false); - } - catch (Exception ex) - { - throw new XunitException($@" -Code generation failed on iteration {i} with source text: -{text.Substring(0, i)} - -Exception: -{ex} -"); - } + CompileToCSharp(text.Substring(0, i)); } } [Fact] // Regression test for #1068 public void Regression_1068() { - // Arrange - - // Act - var generated = CompileToCSharp(@" + CompileToCSharp(@" @functions { Test.ModelState ModelState { get; set; } } -", throwOnFailure: false); - - // Assert +", + // /dir/subdir/Test/TestComponent.cshtml(3,10): error CS0234: The type or namespace name 'ModelState' does not exist in the namespace 'Test' (are you missing an assembly reference?) + // Test.ModelState ModelState { get; set; } + Diagnostic(ErrorCode.ERR_DottedTypeNameNotFoundInNS, "ModelState").WithArguments("ModelState", "Test").WithLocation(3, 10)); } [Fact] public void MalformedAttributeContent() { - // Act - // Arrange AdditionalSyntaxTrees.Add(Parse(@" using System; using Microsoft.AspNetCore.Components; @@ -124,8 +105,6 @@ public class ModelState