Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Ward <ward.matt@gmail.com>2015-04-17 18:32:08 +0300
committerMatt Ward <ward.matt@gmail.com>2015-04-17 18:40:34 +0300
commitf85c390dc353caead8654c99aebbd04cc77d8e9a (patch)
tree0784e1f6e708f5883ca877e9ee062d9b82ae3ed8
parent1e75952860c60c7e5d7bc70568a3bb3f2dea2a98 (diff)
[Ide] Fix simple bracket matching not finding match
The SimpleBracketMatcher is used by the ASP.NET Razor parser to find matching brackets for code blocks but was failing to find the end of a code block because the wrong bracket was being search for.
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Util/SimpleBracketMatcher.cs4
-rw-r--r--main/tests/UnitTests/MonoDevelop.Ide.Editor/SimpleBracketMatcherTests.cs55
-rw-r--r--main/tests/UnitTests/UnitTests.csproj1
3 files changed, 58 insertions, 2 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Util/SimpleBracketMatcher.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Util/SimpleBracketMatcher.cs
index edfba9f8f7..b7cc92bb45 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Util/SimpleBracketMatcher.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Util/SimpleBracketMatcher.cs
@@ -43,11 +43,11 @@ namespace MonoDevelop.Ide.Editor.Util
int bracket = openBrackets.IndexOf (ch);
int result;
if (bracket >= 0) {
- result = SearchMatchingBracketForward (document, offset + 1, openBrackets [bracket], closingBrackets [bracket]);
+ result = SearchMatchingBracketForward (document, offset + 1, closingBrackets [bracket], openBrackets [bracket]);
} else {
bracket = closingBrackets.IndexOf (ch);
if (bracket >= 0) {
- result = SearchMatchingBracketBackward (document, offset - 1, closingBrackets [bracket], openBrackets [bracket]);
+ result = SearchMatchingBracketBackward (document, offset - 1, openBrackets [bracket], closingBrackets [bracket]);
} else {
result = -1;
}
diff --git a/main/tests/UnitTests/MonoDevelop.Ide.Editor/SimpleBracketMatcherTests.cs b/main/tests/UnitTests/MonoDevelop.Ide.Editor/SimpleBracketMatcherTests.cs
new file mode 100644
index 0000000000..82cbe2ca27
--- /dev/null
+++ b/main/tests/UnitTests/MonoDevelop.Ide.Editor/SimpleBracketMatcherTests.cs
@@ -0,0 +1,55 @@
+//
+// SimpleBracketMatcherTests.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 Mono.TextEditor;
+using MonoDevelop.Ide.Editor.Util;
+using NUnit.Framework;
+using UnitTests;
+
+namespace MonoDevelop.Ide.Editor
+{
+ [TestFixture]
+ public class SimpleBracketMatcherTests : TestBase
+ {
+ [TestCase ("{}", 0, 1)]
+ [TestCase ("{}", 1, 0)]
+ public void MatchingBracketTests (string text, int offset, int expectedOffsetMatch)
+ {
+ var editor = TextEditorFactory.CreateNewEditor ();
+ editor.MimeType = "text/x-csharp";
+ editor.Text = text;
+ var document = new TextDocument (text);
+
+ int actualOffset = SimpleBracketMatcher.GetMatchingBracketOffset (editor, offset);
+ int actualOffset2 = document.GetMatchingBracketOffset (offset);
+
+ Assert.AreEqual (actualOffset2, actualOffset);
+ Assert.AreEqual (expectedOffsetMatch, actualOffset);
+ }
+ }
+}
+
diff --git a/main/tests/UnitTests/UnitTests.csproj b/main/tests/UnitTests/UnitTests.csproj
index 37e796a3fe..17110b2d79 100644
--- a/main/tests/UnitTests/UnitTests.csproj
+++ b/main/tests/UnitTests/UnitTests.csproj
@@ -282,6 +282,7 @@
<Compile Include="MonoDevelop.Ide.Editor\Tests\MonoTextEditorImplementationTests.cs" />
<Compile Include="MonoDevelop.Ide.Editor\Commands\CodeCommentTests.cs" />
<Compile Include="MonoDevelop.Ide.Editor\TextEditorProjectionTests.cs" />
+ <Compile Include="MonoDevelop.Ide.Editor\SimpleBracketMatcherTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\md.targets" />