1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections.Generic;
6
using ICSharpCode.AvalonEdit.AddIn;
7
using ICSharpCode.AvalonEdit.Document;
8
using ICSharpCode.AvalonEdit.Editing;
9
using ICSharpCode.AvalonEdit.Folding;
10
using ICSharpCode.RubyBinding;
11
using ICSharpCode.SharpDevelop.Dom;
12
using NUnit.Framework;
14
namespace RubyBinding.Tests.Parsing
17
public class ParseClassWithNewLineBeforeMethodTestFixture
19
ICompilationUnit compilationUnit;
22
FoldingSection methodFold = null;
23
FoldingSection classFold = null;
24
TextDocument document;
27
public void SetUpFixture()
29
string ruby = "class Test\r\n" +
35
DefaultProjectContent projectContent = new DefaultProjectContent();
36
RubyParser parser = new RubyParser();
37
compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby);
38
if (compilationUnit.Classes.Count > 0) {
39
c = compilationUnit.Classes[0];
40
if (c.Methods.Count > 0) {
41
method = c.Methods[0];
44
TextArea textArea = new TextArea();
45
document = new TextDocument();
46
textArea.Document = document;
47
textArea.Document.Text = ruby;
50
ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(textArea);
51
ParseInformation parseInfo = new ParseInformation(compilationUnit);
52
foldingStrategy.UpdateFoldings(parseInfo);
53
List<FoldingSection> folds = new List<FoldingSection>(foldingStrategy.FoldingManager.AllFoldings);
55
if (folds.Count > 0) {
58
if (folds.Count > 1) {
59
methodFold = folds[1];
65
public void ClassBodyRegion()
71
DomRegion region = new DomRegion(startLine, startColumn, endLine, endColumn);
72
Assert.AreEqual(region.ToString(), c.BodyRegion.ToString());
76
/// The class declaration region needs to extend up to and
77
/// including the colon.
80
public void ClassRegion()
86
DomRegion region = new DomRegion(startLine, startColumn, endLine, endColumn);
87
Assert.AreEqual(region.ToString(), c.Region.ToString());
91
public void MethodBodyRegion()
94
int startColumn = 11; // IronRuby parser includes the as part of the method parameters.
97
DomRegion region = new DomRegion(startLine, startColumn, endLine, endColumn);
98
Assert.AreEqual(region.ToString(), method.BodyRegion.ToString());
102
/// The method region does not include the body.
105
public void MethodRegion()
110
int endColumn = 11; // IronRuby parser includes the as part of the method parameters
111
DomRegion region = new DomRegion(startLine, startColumn, endLine, endColumn);
112
Assert.AreEqual(region.ToString(), method.Region.ToString());
116
public void MethodFoldMarkerInnerText()
118
string textInsideFold = document.GetText(methodFold.StartOffset, methodFold.Length);
119
Assert.AreEqual("\r\n\tend", textInsideFold);
123
public void ClassFoldMarkerInnerText()
125
string textInsideFold = document.GetText(classFold.StartOffset, classFold.Length);
126
Assert.AreEqual("\r\n\r\n\tdef foo\r\n\tend\r\nend", textInsideFold);