~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/XmlEditor/Test/Editor/ElementEndAddedAfterGreaterThanCharTypedTestFixture.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
 
 
6
using ICSharpCode.AvalonEdit.Document;
 
7
using ICSharpCode.NRefactory;
 
8
using ICSharpCode.SharpDevelop.Editor.AvalonEdit;
 
9
using ICSharpCode.XmlEditor;
 
10
using NUnit.Framework;
 
11
using XmlEditor.Tests.Utils;
 
12
 
 
13
namespace XmlEditor.Tests.Editor
 
14
{
 
15
        [TestFixture]
 
16
        public class ElementEndAddedAfterGreaterThanCharTypedTestFixture
 
17
        {
 
18
                XmlFormattingStrategy formattingStrategy;
 
19
                MockTextEditor textEditor;
 
20
                MockTextEditorOptions options;
 
21
                AvalonEditDocumentAdapter document;
 
22
                TextDocument textDocument;
 
23
                
 
24
                [SetUp]
 
25
                public void Init()
 
26
                {
 
27
                        formattingStrategy = new XmlFormattingStrategy();
 
28
                        
 
29
                        options = new MockTextEditorOptions();
 
30
                        textEditor = new MockTextEditor();
 
31
                        textEditor.Options = options;
 
32
                        
 
33
                        textDocument = new TextDocument();
 
34
                        document = new AvalonEditDocumentAdapter(textDocument, null);
 
35
                        textEditor.SetDocument(document);
 
36
                        
 
37
                        document.Text = 
 
38
                                "<root>\r\n" +
 
39
                                "\t<child>\r\n" +
 
40
                                "</root>\r\n";
 
41
                        
 
42
                        // Just typed the '>' character of the <child> element
 
43
                        textEditor.Caret.Offset = 16; 
 
44
                        formattingStrategy.FormatLine(textEditor, '>');
 
45
                }
 
46
                
 
47
                [Test]
 
48
                public void ChildEndElementAddedAfterGreaterThanCharTyped()
 
49
                {
 
50
                        string expectedText = 
 
51
                                "<root>\r\n" +
 
52
                                "\t<child></child>\r\n" +
 
53
                                "</root>\r\n";
 
54
                        
 
55
                        Assert.AreEqual(expectedText, document.Text);
 
56
                }
 
57
                
 
58
                [Test]
 
59
                public void IndentCanBeUndoneInOneStep()
 
60
                {
 
61
                        string expectedText =
 
62
                                "<root>\r\n" +
 
63
                                "\t<child>\r\n" +
 
64
                                "</root>\r\n";
 
65
                        
 
66
                        textDocument.UndoStack.Undo();
 
67
                        
 
68
                        Assert.AreEqual(expectedText, textDocument.Text);
 
69
                }
 
70
                
 
71
                [Test]
 
72
                public void CursorIsJustBeforeEndElementTagAfterLinesFormatted()
 
73
                {
 
74
                        int newCaretOffset = 16;
 
75
                        Assert.AreEqual(newCaretOffset, textEditor.Caret.Offset);
 
76
                }
 
77
        }
 
78
}