diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2015-01-09 13:27:52 +0300 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2015-01-09 13:27:52 +0300 |
commit | 1e1f74edb04cfb5b95ccdf676d540af412c139ae (patch) | |
tree | e2d04bbc24e3f2f72e773792d2b27cb7050e4dad | |
parent | 0706ca86c472aec5916148397e042ca4ecb616d7 (diff) |
Fixed indentation bug.
-rw-r--r-- | ICSharpCode.NRefactory.CSharp/IndentEngine/IndentState.cs | 11 | ||||
-rw-r--r-- | ICSharpCode.NRefactory.Tests/IndentationTests/PreProcessorTests.cs | 18 |
2 files changed, 25 insertions, 4 deletions
diff --git a/ICSharpCode.NRefactory.CSharp/IndentEngine/IndentState.cs b/ICSharpCode.NRefactory.CSharp/IndentEngine/IndentState.cs index 6b05ce36..8867268e 100644 --- a/ICSharpCode.NRefactory.CSharp/IndentEngine/IndentState.cs +++ b/ICSharpCode.NRefactory.CSharp/IndentEngine/IndentState.cs @@ -1303,6 +1303,7 @@ namespace ICSharpCode.NRefactory.CSharp { if (!Engine.ifDirectiveEvalResults.Peek()) { + ExitState(); Engine.ifDirectiveEvalResults.Pop(); goto case PreProcessorDirective.If; } @@ -1319,7 +1320,9 @@ namespace ICSharpCode.NRefactory.CSharp } else { - // none if/elif directives were true -> continue with the previous state + // none if/elif directives were true -> exit comment state. + if (Engine.currentState is PreProcessorCommentState) + ExitState(); } break; case PreProcessorDirective.Define: @@ -1338,6 +1341,9 @@ namespace ICSharpCode.NRefactory.CSharp break; case PreProcessorDirective.Endif: // marks the end of this block + if (Engine.currentState is PreProcessorCommentState) + ExitState(); + Engine.ifDirectiveEvalResults.Pop(); Engine.ifDirectiveIndents.Pop(); break; @@ -1686,9 +1692,6 @@ namespace ICSharpCode.NRefactory.CSharp if (ch == '#' && Engine.isLineStart) { - // TODO: Return back only on #if/#elif/#else/#endif - // Ignore any of the other directives (especially #define/#undef) - ExitState(); ChangeState<PreProcessorState>(); } } diff --git a/ICSharpCode.NRefactory.Tests/IndentationTests/PreProcessorTests.cs b/ICSharpCode.NRefactory.Tests/IndentationTests/PreProcessorTests.cs index 6ef4d46c..2c7d15f3 100644 --- a/ICSharpCode.NRefactory.Tests/IndentationTests/PreProcessorTests.cs +++ b/ICSharpCode.NRefactory.Tests/IndentationTests/PreProcessorTests.cs @@ -351,5 +351,23 @@ class Foo Assert.AreEqual("\t\t\t", indent.ThisLineIndent); Assert.AreEqual("\t\t", indent.NextLineIndent); } + + [Test] + public void TestNestedPreprocessorCase() + { + var indent = Helper.CreateEngine(@" +namespace Foo { + #if false + class Foo + { + #if true + } + #endif + #endif + $ +}"); + Assert.AreEqual("\t", indent.ThisLineIndent); + Assert.AreEqual("\t", indent.NextLineIndent); + } } } |