~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleEnterKeyTests.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.Windows.Input;
 
6
using ICSharpCode.Scripting;
 
7
using NUnit.Framework;
 
8
using ICSharpCode.Scripting.Tests.Utils;
 
9
 
 
10
namespace ICSharpCode.Scripting.Tests.Console
 
11
{
 
12
        /// <summary>
 
13
        /// Tests that pressing the enter key in the middle of a typed in line in the console
 
14
        /// leaves the line alone and moves the cursor to the next line. By default the text editor
 
15
        /// will break the line and move the last part to the second line.
 
16
        /// </summary>
 
17
        [TestFixture]
 
18
        public class ScriptingConsoleEnterKeyTests : ScriptingConsoleTestsBase
 
19
        {
 
20
                string prompt = ">>> ";
 
21
 
 
22
                [SetUp]
 
23
                public void Init()
 
24
                {
 
25
                        base.CreateConsole();
 
26
                        TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt);
 
27
                }
 
28
                
 
29
                public void EnterKeyDoesNotBreakUpExistingLine()
 
30
                {
 
31
                        FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
 
32
                        FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B);
 
33
                        FakeConsoleTextEditor.SelectionStart = 1 + prompt.Length;
 
34
                        FakeConsoleTextEditor.Column = 1 + prompt.Length;
 
35
                        FakeConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
 
36
                        
 
37
                        Assert.AreEqual(">>> AB\r\n", FakeConsoleTextEditor.Text);
 
38
                }
 
39
                
 
40
                [Test]
 
41
                public void PreviousLineIsReadOnlyAfterEnterPressed()
 
42
                {
 
43
                        FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
 
44
                        FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.B);
 
45
                        FakeConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
 
46
                        TestableScriptingConsole.Write(prompt, ScriptingStyle.Prompt);
 
47
                        
 
48
                        // Move up a line with cursor.
 
49
                        FakeConsoleTextEditor.Line = 0;
 
50
                        FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.C);
 
51
                        
 
52
                        string expectedText = 
 
53
                                ">>> AB\r\n" +
 
54
                                ">>> ";
 
55
                        Assert.AreEqual(expectedText, FakeConsoleTextEditor.Text);
 
56
                }
 
57
        }
 
58
}