~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Scripting/Test/Console/SendLineToScriptingConsoleCommandTests.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 ICSharpCode.Scripting;
 
6
using ICSharpCode.Scripting.Tests.Utils;
 
7
using NUnit.Framework;
 
8
 
 
9
namespace ICSharpCode.Scripting.Tests.Console
 
10
{
 
11
        [TestFixture]
 
12
        public class SendLineToScriptingConsoleCommandTests : SendToScriptingConsoleCommandTestsBase
 
13
        {
 
14
                SendLineToScriptingConsoleCommand sendLineToConsoleCommand;
 
15
                
 
16
                [Test]
 
17
                public void Run_SingleLineInTextEditor_FirstLineSentToPythonConsole()
 
18
                {
 
19
                        CreateSendLineToConsoleCommand();
 
20
                        AddSingleLineToTextEditor("print 'hello'");
 
21
                        sendLineToConsoleCommand.Run();
 
22
                        
 
23
                        string text = fakeConsole.TextPassedToSendLine;
 
24
                        
 
25
                        string expectedText = "print 'hello'";
 
26
                        Assert.AreEqual(expectedText, text);
 
27
                }
 
28
                
 
29
                void CreateSendLineToConsoleCommand()
 
30
                {
 
31
                        base.CreateFakeWorkbench();
 
32
                        sendLineToConsoleCommand = new SendLineToScriptingConsoleCommand(workbench);
 
33
                }
 
34
                
 
35
                void AddSingleLineToTextEditor(string line)
 
36
                {
 
37
                        fakeTextEditor.Document.Text = line;
 
38
                        fakeTextEditor.Caret.Line = 1;
 
39
 
 
40
                        SetTextToReturnFromTextEditorGetLine(line);
 
41
                }
 
42
                
 
43
                void SetTextToReturnFromTextEditorGetLine(string line)
 
44
                {
 
45
                        FakeDocumentLine documentLine = new FakeDocumentLine();
 
46
                        documentLine.Text = line;
 
47
                        fakeTextEditor.FakeDocument.DocumentLineToReturnFromGetLine = documentLine;                     
 
48
                }
 
49
                
 
50
                [Test]
 
51
                public void Run_TwoLinesInTextEditorCursorOnFirstLine_FirstLineSentToPythonConsole()
 
52
                {
 
53
                        CreateSendLineToConsoleCommand();
 
54
                        
 
55
                        fakeTextEditor.Document.Text = 
 
56
                                "print 'hello'\r\n" +
 
57
                                "print 'world'\r\n";
 
58
                        
 
59
                        fakeTextEditor.Caret.Line = 1;
 
60
                        
 
61
                        SetTextToReturnFromTextEditorGetLine("print 'hello'");
 
62
                        
 
63
                        sendLineToConsoleCommand.Run();
 
64
                        string text = fakeConsole.TextPassedToSendLine;
 
65
                        
 
66
                        string expectedText = "print 'hello'";
 
67
                        Assert.AreEqual(expectedText, text);
 
68
                }
 
69
                
 
70
                [Test]
 
71
                public void Run_SingleLineInTextEditor_ScriptingConsolePadBroughtToFront()
 
72
                {
 
73
                        CreateSendLineToConsoleCommand();
 
74
                        AddSingleLineToTextEditor("print 'hello'");
 
75
                        
 
76
                        sendLineToConsoleCommand.Run();
 
77
                        
 
78
                        bool broughtToFront = workbench.FakeScriptingConsolePad.BringToFrontCalled;
 
79
                        Assert.IsTrue(broughtToFront);
 
80
                }
 
81
        }
 
82
}