~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to tests/UnitTests/Mono.TextEditor.Tests/TextBreakerTests.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// TextBreakerTests.cs
 
3
//  
 
4
// Author:
 
5
//       IBBoard <dev@ibboard.co.uk>
 
6
// 
 
7
// Copyright (c) 2011 IBBoard
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
using System;
 
27
using NUnit.Core;
 
28
using Mono.TextEditor;
 
29
using Mono.TextEditor.Utils;
 
30
using NUnit.Framework;
 
31
using NUnit.Framework.SyntaxHelpers;
 
32
using System.Collections.Generic;
 
33
 
 
34
namespace Mono.TextEditor.Tests
 
35
{
 
36
        [TestFixture()]
 
37
        public class TextBreakerTests
 
38
        {
 
39
                [Test()]
 
40
                public void TestTextBreakerWithSingleWord ()
 
41
                {
 
42
                        List<ISegment> segments = BreakAllLines ("Word");
 
43
                        Assert.That (segments.Count, Is.EqualTo (1));
 
44
                        Assert.That (segments [0].Offset, Is.EqualTo (0));
 
45
                        Assert.That (segments [0].Length, Is.EqualTo (4));
 
46
                }
 
47
 
 
48
                [Test()]
 
49
                public void TestTextBreakerWithSingleWordWrappedInSpaces ()
 
50
                {
 
51
                        List<ISegment> segments = BreakAllLines (" Word ");
 
52
                        Assert.That (segments.Count, Is.EqualTo (3));
 
53
                        Assert.That (segments [0].Offset, Is.EqualTo (0));
 
54
                        Assert.That (segments [0].Length, Is.EqualTo (1));
 
55
                        Assert.That (segments [1].Offset, Is.EqualTo (1));
 
56
                        Assert.That (segments [1].Length, Is.EqualTo (4));
 
57
                        Assert.That (segments [2].Offset, Is.EqualTo (5));
 
58
                        Assert.That (segments [2].Length, Is.EqualTo (1));
 
59
                }
 
60
 
 
61
                [Test()]
 
62
                public void TestTextBreakerWithMultipleLines ()
 
63
                {
 
64
                        List<ISegment> segments = BreakAllLines ("SomeText\nTwo Words");
 
65
                        Assert.That (segments.Count, Is.EqualTo (4));
 
66
                        Assert.That (segments [0].Offset, Is.EqualTo (0));
 
67
                        Assert.That (segments [0].Length, Is.EqualTo (8));
 
68
                        Assert.That (segments [1].Offset, Is.EqualTo (9));
 
69
                        Assert.That (segments [1].Length, Is.EqualTo (3));
 
70
                        Assert.That (segments [2].Offset, Is.EqualTo (12));
 
71
                        Assert.That (segments [2].Length, Is.EqualTo (1));
 
72
                        Assert.That (segments [3].Offset, Is.EqualTo (13));
 
73
                        Assert.That (segments [3].Length, Is.EqualTo (5));
 
74
                }
 
75
 
 
76
                [Test()]
 
77
                public void Bug666274_CheckLeftHandSideWordBreaking ()
 
78
                {
 
79
                        List<ISegment> segments = BreakAllLines ("                      //Set points in panel");
 
80
                        Assert.That(segments.Count, Is.EqualTo(12));
 
81
                }
 
82
 
 
83
                [Test()]
 
84
                public void Bug666274_CheckRightHandSideWordBreaking ()
 
85
                {
 
86
                        List<ISegment> segments = BreakAllLines (@"                     if (WarFoundryCore.CurrentArmy != null)
 
87
                        {
 
88
                                lblTotalPoints.Text = Translation.GetTranslation(""statusPanelPoints"", ""{0}pts of {1} pts"", WarFoundryCore.CurrentArmy.Points, WarFoundryCore.CurrentArmy.MaxPoints);
 
89
                        }
 
90
                        else
 
91
                        {
 
92
                                lblTotalPoints.Text = """";
 
93
                        }");
 
94
                        Assert.That (segments.Count, Is.EqualTo (97));
 
95
                }
 
96
 
 
97
                public TextEditor CreateEditor (string editorText)
 
98
                {
 
99
                        return new TextEditor (new Document (editorText));
 
100
                }
 
101
 
 
102
                public List<ISegment> BreakAllLines (String editorText)
 
103
                {
 
104
                        return BreakAllLines (CreateEditor (editorText));
 
105
                }
 
106
 
 
107
                public List<ISegment> BreakAllLines (TextEditor editor)
 
108
                {
 
109
                        return TextBreaker.BreakLinesIntoWords (editor, 1, editor.LineCount);
 
110
                }
 
111
 
 
112
                [TestFixtureSetUp] 
 
113
                public void SetUp ()
 
114
                {
 
115
                        Gtk.Application.Init ();
 
116
                }
 
117
        }
 
118
}
 
119