diff options
author | Matt Ward <ward.matt@gmail.com> | 2015-04-17 18:39:43 +0300 |
---|---|---|
committer | Matt Ward <ward.matt@gmail.com> | 2015-04-17 18:40:34 +0300 |
commit | 4466894b95a36a355aa6fec0778a3e67444bc6ea (patch) | |
tree | 710141d0d95f4307db123b4a1857ff88ccada716 | |
parent | f85c390dc353caead8654c99aebbd04cc77d8e9a (diff) |
[AspNet] Add test to check html completion works after code block
After a Razor code block @{ } there was no html tag completion
since the Razor parser could not find the end bracket so the
current state was set to RazorCodeBlockState and not
RazorRootState. Added a test to ensure the code completion works
with the fix made to the SimpleBracketMatcher.
6 files changed, 132 insertions, 3 deletions
diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet.csproj b/main/src/addins/AspNet/MonoDevelop.AspNet.csproj index ee2ba03bb0..c677d7b0c5 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet.csproj +++ b/main/src/addins/AspNet/MonoDevelop.AspNet.csproj @@ -341,6 +341,7 @@ <Compile Include="Projects\AspNetProjectTemplateWizardPage.cs" /> <Compile Include="Projects\AspNetStringTagProvider.cs" /> <Compile Include="Commands\MethodDeclarationAtCaret.cs" /> + <Compile Include="Razor\Dom\RazorWorkbenchService.cs" /> </ItemGroup> <ItemGroup> <None Include="Makefile.am" /> diff --git a/main/src/addins/AspNet/Properties/AssemblyInfo.cs b/main/src/addins/AspNet/Properties/AssemblyInfo.cs index 6508a7210d..cc2f7ae245 100644 --- a/main/src/addins/AspNet/Properties/AssemblyInfo.cs +++ b/main/src/addins/AspNet/Properties/AssemblyInfo.cs @@ -1,9 +1,11 @@ // Autogenerated from MonoDevelop.AspNet.addin.xml using System.Reflection; +using System.Runtime.CompilerServices; [assembly: AssemblyProduct ("MonoDevelop")] [assembly: AssemblyTitle ("ASP.NET Project Support")] [assembly: AssemblyDescription ("Support for ASP.NET projects, including editing, compiling, previewing and deploying to remote servers.")] [assembly: AssemblyVersion ("2.6")] [assembly: AssemblyCopyright ("MIT X11")] +[assembly: InternalsVisibleTo("MonoDevelop.AspNet.Tests")] diff --git a/main/src/addins/AspNet/Razor/Dom/RazorCodeFragment.cs b/main/src/addins/AspNet/Razor/Dom/RazorCodeFragment.cs index 8ceb4103b9..c4327c1364 100644 --- a/main/src/addins/AspNet/Razor/Dom/RazorCodeFragment.cs +++ b/main/src/addins/AspNet/Razor/Dom/RazorCodeFragment.cs @@ -48,9 +48,7 @@ namespace MonoDevelop.AspNet.Razor.Dom public ITextDocument Document {
get {
- if (IdeApp.Workbench.ActiveDocument != null && IdeApp.Workbench.ActiveDocument.Editor != null)
- return IdeApp.Workbench.ActiveDocument.Editor;
- return null;
+ return RazorWorkbenchService.ActiveDocument;
}
}
diff --git a/main/src/addins/AspNet/Razor/Dom/RazorWorkbenchService.cs b/main/src/addins/AspNet/Razor/Dom/RazorWorkbenchService.cs new file mode 100644 index 0000000000..97280a15fd --- /dev/null +++ b/main/src/addins/AspNet/Razor/Dom/RazorWorkbenchService.cs @@ -0,0 +1,48 @@ +// +// RazorWorkbenchService.cs +// +// Author: +// Matt Ward <matt.ward@xamarin.com> +// +// Copyright (c) 2015 Xamarin Inc. (http://xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Editor; + +namespace MonoDevelop.AspNet.Razor.Dom +{ + internal static class RazorWorkbenchService + { + public static ITextDocument ActiveDocument { + get { + return GetActiveDocument (); + } + } + + internal static Func<ITextDocument> GetActiveDocument = () => { + if (IdeApp.Workbench.ActiveDocument != null && IdeApp.Workbench.ActiveDocument.Editor != null) + return IdeApp.Workbench.ActiveDocument.Editor; + return null; + }; + } +} + diff --git a/main/src/addins/AspNet/Tests/MonoDevelop.AspNet.Tests.csproj b/main/src/addins/AspNet/Tests/MonoDevelop.AspNet.Tests.csproj index cdde498cdf..ab4a23ff4f 100644 --- a/main/src/addins/AspNet/Tests/MonoDevelop.AspNet.Tests.csproj +++ b/main/src/addins/AspNet/Tests/MonoDevelop.AspNet.Tests.csproj @@ -55,6 +55,7 @@ <Compile Include="Razor\RazorCompletionTests.cs" /> <Compile Include="Html\HtmlParsingTests.cs" /> <Compile Include="Html\HtmlImplicitClosingTests.cs" /> + <Compile Include="Razor\Dom\RazorDocumentTrackerTests.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup> diff --git a/main/src/addins/AspNet/Tests/Razor/Dom/RazorDocumentTrackerTests.cs b/main/src/addins/AspNet/Tests/Razor/Dom/RazorDocumentTrackerTests.cs new file mode 100644 index 0000000000..f16fe1deb1 --- /dev/null +++ b/main/src/addins/AspNet/Tests/Razor/Dom/RazorDocumentTrackerTests.cs @@ -0,0 +1,79 @@ +// +// RazorDocumentTrackerTests.cs +// +// Author: +// Matt Ward <matt.ward@xamarin.com> +// +// Copyright (c) 2015 Xamarin Inc. (http://xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using MonoDevelop.AspNet.Razor.Dom; +using MonoDevelop.AspNet.Razor.Parser; +using MonoDevelop.Ide.Editor; +using MonoDevelop.Ide.Gui.Content; +using MonoDevelop.Xml.Parser; +using NUnit.Framework; +using UnitTests; + +namespace MonoDevelop.AspNet.Tests.Razor.Dom +{ + [TestFixture] + public class RazorDocumentTrackerTests : TestBase + { + Func<ITextDocument> originalGetActiveDocument; + TextEditor editor; + + [SetUp] + public void SetUp () + { + originalGetActiveDocument = RazorWorkbenchService.GetActiveDocument; + editor = TextEditorFactory.CreateNewEditor (); + editor.MimeType = "text/x-cshtml"; + RazorWorkbenchService.GetActiveDocument = () => { + return editor; + }; + } + + [TearDown] + public override void TearDown () + { + RazorWorkbenchService.GetActiveDocument = originalGetActiveDocument; + base.TearDown (); + } + + [Test] + public void StateShouldBeRazorRootStateAfterCodeBlock () + { + editor.Text = +@"@{ +} + +"; + var parser = new XmlParser (new RazorRootState (), false); + var tracker = new DocumentStateTracker<XmlParser> (parser, editor); + editor.CaretLine = 3; + tracker.UpdateEngine (); + + Assert.IsInstanceOf<RazorRootState> (tracker.Engine.CurrentState); + } + } +} + |