~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Scripting/Test/Console/ScriptingConsoleReadTests.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.Threading;
 
6
using System.Windows.Input;
 
7
 
 
8
using ICSharpCode.Scripting;
 
9
using ICSharpCode.Scripting.Tests.Utils;
 
10
using NUnit.Framework;
 
11
 
 
12
namespace ICSharpCode.Scripting.Tests.Console
 
13
{
 
14
        /// <summary>
 
15
        /// Tests the ScriptingConsole ReadLine method.
 
16
        /// </summary>
 
17
        [TestFixture]
 
18
        public class ScriptingConsoleReadTests : ScriptingConsoleTestsBase
 
19
        {       
 
20
                [Test]
 
21
                public void ReadLine_AutoIndentIsTwo_TwoSpacesWrittenToConsoleTextEditor()
 
22
                {
 
23
                        CreateConsole();
 
24
                        FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
 
25
                        FakeConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
 
26
                        
 
27
                        int indent = 2;
 
28
                        TestableScriptingConsole.ReadLine(indent);
 
29
                        
 
30
                        string expectedText = "  ";
 
31
                        Assert.AreEqual(expectedText, FakeConsoleTextEditor.TextPassedToAppend);
 
32
                }
 
33
                
 
34
                [Test]
 
35
                public void ReadLine_AutoIndentIsZero_NoTextWrittenToConsoleTextEditor()
 
36
                {
 
37
                        CreateConsole();
 
38
                        FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
 
39
                        FakeConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
 
40
                        
 
41
                        FakeConsoleTextEditor.IsAppendCalled = false;
 
42
                        
 
43
                        TestableScriptingConsole.ReadLine(0);
 
44
                        
 
45
                        Assert.IsFalse(FakeConsoleTextEditor.IsAppendCalled);
 
46
                }
 
47
                
 
48
                [Test]
 
49
                public void ProcessPreviewKeyDown_TextEditorPreviewKeyDownEventFiresWithLetterA_ReturnsFalseForLetterThatShouldBeHandledByTextEditorItself()
 
50
                {
 
51
                        CreateConsole();
 
52
                        bool result = FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
 
53
                        Assert.IsFalse(result);
 
54
                }
 
55
                
 
56
                [Test]
 
57
                public void ProcessPreviewKeyDown_TextEditorPreviewKeyDownEventFiresWithEnterKey_ReturnsFalseForLetterThatShouldBeHandledByTextEditorItself()
 
58
                {
 
59
                        CreateConsole();
 
60
                        bool result = FakeConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
 
61
                        Assert.IsFalse(result);
 
62
                }
 
63
                
 
64
                [Test]
 
65
                public void ReadLine_NoLinesAvailable_ReturnsNull()
 
66
                {
 
67
                        CreateConsole();
 
68
                        string line = TestableScriptingConsole.ReadLine(0);
 
69
                        
 
70
                        Assert.IsNull(line);
 
71
                }
 
72
                
 
73
                [Test]
 
74
                public void ReadLine_OneLineWaitingAndAutoIndentIsTwo_TwoSpacesAddedToLineText()
 
75
                {
 
76
                        CreateConsole();
 
77
                        FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
 
78
                        FakeConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
 
79
                        
 
80
                        int indent = 2;
 
81
                        string line = TestableScriptingConsole.ReadLine(indent);
 
82
                        
 
83
                        string expectedLine = "  A";
 
84
                        Assert.AreEqual(expectedLine, line);
 
85
                }
 
86
                
 
87
                [Test]
 
88
                public void FireLineReceivedEvent_LineReceivedEventHandlerRegistered_CallsEventHandler()
 
89
                {
 
90
                        CreateConsole();
 
91
                        
 
92
                        bool fired = false;
 
93
                        TestableScriptingConsole.LineReceived += delegate { 
 
94
                                fired = true;
 
95
                        };
 
96
                        
 
97
                        TestableScriptingConsole.CallBaseFireLineReceivedEvent();
 
98
                        
 
99
                        Assert.IsTrue(fired);
 
100
                }
 
101
                
 
102
                [Test]
 
103
                public void ReadFirstUnreadLine_OneLineUnread_ReturnsLine()
 
104
                {
 
105
                        CreateConsole();
 
106
                        FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
 
107
                        FakeConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
 
108
                        
 
109
                        string line = TestableScriptingConsole.ReadFirstUnreadLine();
 
110
                        
 
111
                        string expectedline = "A";
 
112
                        Assert.AreEqual(expectedline, line);
 
113
                }
 
114
                
 
115
                [Test]
 
116
                public void ReadFirstUnreadLine_OneLineUnreadReadTwoLines_ReturnsNull()
 
117
                {
 
118
                        CreateConsole();
 
119
                        FakeConsoleTextEditor.RaisePreviewKeyDownEvent(Key.A);
 
120
                        FakeConsoleTextEditor.RaisePreviewKeyDownEventForDialogKey(Key.Enter);
 
121
                        
 
122
                        TestableScriptingConsole.ReadFirstUnreadLine();
 
123
                        string line = TestableScriptingConsole.ReadFirstUnreadLine();
 
124
                        
 
125
                        Assert.IsNull(line);
 
126
                }
 
127
        }
 
128
}