Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
Add tests to verify flexibility of await keyword.
Browse files Browse the repository at this point in the history
Added sample files to evaluate accuracy of generated code for the await keyword.  Also added a line mapping test to ensure that we're mapping the keyword correctly.
  • Loading branch information
NTaylorMullen committed Mar 18, 2014
1 parent 50314ca commit 4cfef3c
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,39 @@ public void ConstructorRequiresNonNullHost()
[InlineData("LayoutDirective")]
[InlineData("ConditionalAttributes")]
[InlineData("ResolveUrl")]
[InlineData("Await")]
public void CSharpCodeGeneratorCorrectlyGeneratesRunTimeCode(string testType)
{
RunTest(testType);
}

[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesMappingsForAwait()
{
RunTest("Await",
"Await.DesignTime",
designTimeMode: true,
tabTest: TabTest.Tabs,
expectedDesignTimePragmas: new List<LineMapping>()
{
BuildLineMapping(12, 0, 12, 173, 9, 0, 76),
BuildLineMapping(192, 9, 39, 637, 30, 15, 11),
BuildLineMapping(247, 10, 38, 750, 35, 14, 11),
BuildLineMapping(304, 11, 39, 832, 40, 12, 14),
BuildLineMapping(371, 12, 46, 919, 46, 13, 1),
BuildLineMapping(376, 12, 51, 1027, 52, 18, 11),
BuildLineMapping(391, 12, 66, 1115, 57, 18, 1),
BuildLineMapping(448, 13, 49, 1224, 63, 19, 5),
BuildLineMapping(578, 18, 42, 1332, 68, 15, 15),
BuildLineMapping(640, 19, 41, 1452, 73, 17, 22),
BuildLineMapping(711, 20, 42, 1545, 78, 12, 39),
BuildLineMapping(806, 21, 49, 1657, 84, 13, 1),
BuildLineMapping(811, 21, 54, 1765, 90, 18, 27),
BuildLineMapping(842, 21, 85, 1873, 95, 22, 1),
BuildLineMapping(902, 22, 52, 1982, 101, 19, 19)
});
}

[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesMappingsForSimpleUnspacedIf()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
<Compile Include="RazorTemplateEngineTest.cs" />
<Compile Include="StringTextBuffer.cs" />
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Output\CodeTree.cs" />
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Output\Await.cs" />
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Output\Await.DesignTime.cs" />
<Compile Include="Text\BufferingTextReaderTest.cs" />
<Compile Include="Text\LineTrackingStringBufferTest.cs" />
<Compile Include="Text\LookaheadTextReaderTestBase.cs" />
Expand Down Expand Up @@ -317,6 +319,7 @@
<ItemGroup>
<None Include="packages.config" />
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Source\CodeTree.cshtml" />
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Source\Await.cshtml" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
namespace TestOutput
{
using System;
using System.Threading.Tasks;

public class Await
{
private static object @__o;
#line 1 "Await.cshtml"

public async Task<string> Foo()
{
return "Bar";
}

#line default
#line hidden
private void @__RazorDesignTimeHelpers__()
{
#pragma warning disable 219
#pragma warning restore 219
}
#line hidden
public Await()
{
}

public override async Task ExecuteAsync()
{
#line 1 "------------------------------------------"
__o = await Foo();

#line default
#line hidden
#line 1 "------------------------------------------"
__o = await Foo();

#line default
#line hidden
#line 12 "Await.cshtml"
await Foo();

#line default
#line hidden

#line 13 "Await.cshtml"


#line default
#line hidden

#line 1 "------------------------------------------"
__o = await Foo();

#line default
#line hidden
#line 13 "Await.cshtml"


#line default
#line hidden

#line 1 "------------------------------------------"
__o = await;

#line default
#line hidden
#line 1 "------------------------------------------"
__o = await Foo(1, 2);

#line default
#line hidden
#line 1 "------------------------------------------"
__o = await Foo("bob", true);

#line default
#line hidden
#line 21 "Await.cshtml"
await Foo(something, hello: "world");

#line default
#line hidden

#line 22 "Await.cshtml"


#line default
#line hidden

#line 1 "------------------------------------------"
__o = await Foo(boolValue: false);

#line default
#line hidden
#line 22 "Await.cshtml"


#line default
#line hidden

#line 1 "------------------------------------------"
__o = await ("wrrronggg");

#line default
#line hidden
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
namespace TestOutput
{
using System;
using System.Threading.Tasks;

public class Await
{
#line 1 "Await.cshtml"

public async Task<string> Foo()
{
return "Bar";
}

#line default
#line hidden
#line hidden
public Await()
{
}

public override async Task ExecuteAsync()
{
WriteLiteral("\r\n<section>\r\n <h1>Basic Asynchronous Expression Test</h1>\r\n <p>Basic Asynch" +
"ronous Expression: ");
Write(
#line 10 "Await.cshtml"
await Foo()

#line default
#line hidden
);

WriteLiteral("</p>\r\n <p>Basic Asynchronous Template: ");
Write(
#line 11 "Await.cshtml"
await Foo()

#line default
#line hidden
);

WriteLiteral("</p>\r\n <p>Basic Asynchronous Statement: ");
#line 12 "Await.cshtml"
await Foo();

#line default
#line hidden

WriteLiteral("</p>\r\n <p>Basic Asynchronous Statement Nested: <b>");
Write(
#line 13 "Await.cshtml"
await Foo()

#line default
#line hidden
);

WriteLiteral("</b> ");
#line 13 "Await.cshtml"


#line default
#line hidden

WriteLiteral("</p>\r\n <p>Basic Incomplete Asynchronous Statement: ");
Write(
#line 14 "Await.cshtml"
await

#line default
#line hidden
);

WriteLiteral("</p>\r\n</section>\r\n\r\n<section>\r\n <h1>Advanced Asynchronous Expression Test</h1>" +
"\r\n <p>Advanced Asynchronous Expression: ");
Write(
#line 19 "Await.cshtml"
await Foo(1, 2)

#line default
#line hidden
);

WriteLiteral("</p>\r\n <p>Advanced Asynchronous Template: ");
Write(
#line 20 "Await.cshtml"
await Foo("bob", true)

#line default
#line hidden
);

WriteLiteral("</p>\r\n <p>Advanced Asynchronous Statement: ");
#line 21 "Await.cshtml"
await Foo(something, hello: "world");

#line default
#line hidden

WriteLiteral("</p>\r\n <p>Advanced Asynchronous Statement Nested: <b>");
Write(
#line 22 "Await.cshtml"
await Foo(boolValue: false)

#line default
#line hidden
);

WriteLiteral("</b> ");
#line 22 "Await.cshtml"


#line default
#line hidden

WriteLiteral("</p>\r\n <p>Advanced Incomplete Asynchronous Statement: ");
Write(
#line 23 "Await.cshtml"
await ("wrrronggg")

#line default
#line hidden
);

WriteLiteral("</p>\r\n</section>");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@functions {
public async Task<string> Foo()
{
return "Bar";
}
}

<section>
<h1>Basic Asynchronous Expression Test</h1>
<p>Basic Asynchronous Expression: @await Foo()</p>
<p>Basic Asynchronous Template: @(await Foo())</p>
<p>Basic Asynchronous Statement: @{ await Foo(); }</p>
<p>Basic Asynchronous Statement Nested: @{ <b>@await Foo()</b> }</p>
<p>Basic Incomplete Asynchronous Statement: @await</p>
</section>

<section>
<h1>Advanced Asynchronous Expression Test</h1>
<p>Advanced Asynchronous Expression: @await Foo(1, 2)</p>
<p>Advanced Asynchronous Template: @(await Foo("bob", true))</p>
<p>Advanced Asynchronous Statement: @{ await Foo(something, hello: "world"); }</p>
<p>Advanced Asynchronous Statement Nested: @{ <b>@await Foo(boolValue: false)</b> }</p>
<p>Advanced Incomplete Asynchronous Statement: @await ("wrrronggg")</p>
</section>

0 comments on commit 4cfef3c

Please sign in to comment.