~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Ruby/RubyBinding/Test/Parsing/ParseClassWithNewLineBeforeMethodTestFixture.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
3
 
 
4
using System;
 
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;
 
13
 
 
14
namespace RubyBinding.Tests.Parsing
 
15
{
 
16
        [TestFixture]
 
17
        public class ParseClassWithNewLineBeforeMethodTestFixture
 
18
        {
 
19
                ICompilationUnit compilationUnit;
 
20
                IClass c;
 
21
                IMethod method;
 
22
                FoldingSection methodFold = null;
 
23
                FoldingSection classFold = null;
 
24
                TextDocument document;
 
25
                
 
26
                [TestFixtureSetUp]
 
27
                public void SetUpFixture()
 
28
                {
 
29
                        string ruby = "class Test\r\n" +
 
30
                                                        "\r\n" +
 
31
                                                        "\tdef foo\r\n" +
 
32
                                                        "\tend\r\n" +
 
33
                                                        "end";
 
34
                        
 
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];
 
42
                                }
 
43
                                
 
44
                                TextArea textArea = new TextArea();
 
45
                                document = new TextDocument();
 
46
                                textArea.Document = document;
 
47
                                textArea.Document.Text = ruby;
 
48
                                
 
49
                                // Get folds.
 
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);
 
54
                                
 
55
                                if (folds.Count > 0) {
 
56
                                        classFold = folds[0];
 
57
                                }
 
58
                                if (folds.Count > 1) {
 
59
                                        methodFold = folds[1];
 
60
                                }
 
61
                        }
 
62
                }
 
63
                
 
64
                [Test]
 
65
                public void ClassBodyRegion()
 
66
                {
 
67
                        int startLine = 1;
 
68
                        int startColumn = 11;
 
69
                        int endLine = 5;
 
70
                        int endColumn = 4;
 
71
                        DomRegion region = new DomRegion(startLine, startColumn, endLine, endColumn);
 
72
                        Assert.AreEqual(region.ToString(), c.BodyRegion.ToString());
 
73
                }
 
74
                
 
75
                /// <summary>
 
76
                /// The class declaration region needs to extend up to and
 
77
                /// including the colon.
 
78
                /// </summary>
 
79
                [Test]
 
80
                public void ClassRegion()
 
81
                {
 
82
                        int startLine = 1;
 
83
                        int startColumn = 1;
 
84
                        int endLine = 5;
 
85
                        int endColumn = 4;
 
86
                        DomRegion region = new DomRegion(startLine, startColumn, endLine, endColumn);
 
87
                        Assert.AreEqual(region.ToString(), c.Region.ToString());
 
88
                }               
 
89
                                
 
90
                [Test]
 
91
                public void MethodBodyRegion()
 
92
                {
 
93
                        int startLine = 3;
 
94
                        int startColumn = 11; // IronRuby parser includes the as part of the method parameters.
 
95
                        int endLine = 4;
 
96
                        int endColumn = 5;
 
97
                        DomRegion region = new DomRegion(startLine, startColumn, endLine, endColumn);
 
98
                        Assert.AreEqual(region.ToString(), method.BodyRegion.ToString());
 
99
                }
 
100
                
 
101
                /// <summary>
 
102
                /// The method region does not include the body.
 
103
                /// </summary>
 
104
                [Test]
 
105
                public void MethodRegion()
 
106
                {
 
107
                        int startLine = 3;
 
108
                        int startColumn = 2;
 
109
                        int endLine = 3;
 
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());
 
113
                }
 
114
                
 
115
                [Test]
 
116
                public void MethodFoldMarkerInnerText()
 
117
                {
 
118
                        string textInsideFold = document.GetText(methodFold.StartOffset, methodFold.Length);
 
119
                        Assert.AreEqual("\r\n\tend", textInsideFold);
 
120
                }
 
121
                
 
122
                [Test]
 
123
                public void ClassFoldMarkerInnerText()
 
124
                {
 
125
                        string textInsideFold = document.GetText(classFold.StartOffset, classFold.Length);
 
126
                        Assert.AreEqual("\r\n\r\n\tdef foo\r\n\tend\r\nend", textInsideFold);
 
127
                }
 
128
        }
 
129
}