diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2014-02-05 12:43:55 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2014-02-05 12:43:55 +0400 |
commit | 81cdcdce32801cff89bbf9d9b68f75520972d119 (patch) | |
tree | 30712316a00c52d2db4c560fa87e88a58b007fd9 /main/tests | |
parent | 0ffb3f980e75f5a8b6143dcec19a8055758dc060 (diff) |
[SourceEditor] Added json indentation engine.
Diffstat (limited to 'main/tests')
-rw-r--r-- | main/tests/UnitTests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs | 100 | ||||
-rw-r--r-- | main/tests/UnitTests/UnitTests.csproj | 3 |
2 files changed, 102 insertions, 1 deletions
diff --git a/main/tests/UnitTests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs b/main/tests/UnitTests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs new file mode 100644 index 0000000000..969489013c --- /dev/null +++ b/main/tests/UnitTests/MonoDevelop.SourceEditor/JSonIndentEngineTests.cs @@ -0,0 +1,100 @@ +// +// JSonIndentEngineTests.cs +// +// Author: +// Mike Krüger <mkrueger@xamarin.com> +// +// Copyright (c) 2014 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 NUnit.Framework; +using MonoDevelop.Ide.CodeCompletion; +using ICSharpCode.NRefactory.CSharp; +using System.Text; +using ICSharpCode.NRefactory.Editor; +using MonoDevelop.SourceEditor.JSon; +using Mono.TextEditor; + +namespace MonoDevelop.SourceEditor +{ + [TestFixture] + public class JSonIndentEngineTests + { + public static IDocumentIndentEngine CreateEngine (string text) + { + var sb = new StringBuilder (); + int offset = 0; + for (int i = 0; i < text.Length; i++) { + var ch = text [i]; + if (ch == '$') { + offset = i; + continue; + } + sb.Append (ch); + } + + var data = new TextEditorData (); + data.Text = sb.ToString (); + var csi = new JSonIndentEngine (data); + var result = new CacheIndentEngine (csi); + result.Update (offset); + return result; + } + + [Test] + public void TestBracketIndentation () + { + var engine = CreateEngine ( + @" +{ +$ +"); + Assert.AreEqual ("\t", engine.ThisLineIndent); + Assert.AreEqual ("\t", engine.NextLineIndent); + } + + [Test] + public void TestBodyIndentation () + { + var engine = CreateEngine ( + @" +{ + ""foo"":""bar"", +$ +"); + Assert.AreEqual ("\t", engine.ThisLineIndent); + Assert.AreEqual ("\t", engine.NextLineIndent); + } + + [Test] + public void TestArrayIndentation () + { + var engine = CreateEngine ( + @" +{ + ""test"":[ +$ +"); + Assert.AreEqual ("\t\t", engine.ThisLineIndent); + Assert.AreEqual ("\t\t", engine.NextLineIndent); + } + } +} + diff --git a/main/tests/UnitTests/UnitTests.csproj b/main/tests/UnitTests/UnitTests.csproj index 693cfae5a2..1de46c8677 100644 --- a/main/tests/UnitTests/UnitTests.csproj +++ b/main/tests/UnitTests/UnitTests.csproj @@ -3,7 +3,7 @@ <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProductVersion>9.0.21022</ProductVersion> + <ProductVersion>8.0.30703</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{1497D0A8-AFF1-4938-BC22-BE79B358BA5B}</ProjectGuid> <OutputType>Library</OutputType> @@ -287,6 +287,7 @@ <Compile Include="MonoDevelop.Refactoring\ProjectGroupingProviderTests.cs" /> <Compile Include="MonoDevelop.Refactoring\FileGroupingProviderTests.cs" /> <Compile Include="MonoDevelop.Ide.Gui\LogViewTests.cs" /> + <Compile Include="MonoDevelop.SourceEditor\JSonIndentEngineTests.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="..\..\md.targets" /> |