14 changed files with 20 additions and 160 deletions
@ -1,69 +0,0 @@ |
|||||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
||||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.IO; |
|
||||||
using System.Text; |
|
||||||
|
|
||||||
using ICSharpCode.Scripting; |
|
||||||
|
|
||||||
namespace ICSharpCode.PythonBinding |
|
||||||
{ |
|
||||||
public class PythonOutputStream : Stream |
|
||||||
{ |
|
||||||
IScriptingConsoleTextEditor textEditor; |
|
||||||
|
|
||||||
public PythonOutputStream(IScriptingConsoleTextEditor textEditor) |
|
||||||
{ |
|
||||||
this.textEditor = textEditor; |
|
||||||
} |
|
||||||
|
|
||||||
public override bool CanRead { |
|
||||||
get { return false; } |
|
||||||
} |
|
||||||
|
|
||||||
public override bool CanSeek { |
|
||||||
get { return false; } |
|
||||||
} |
|
||||||
|
|
||||||
public override bool CanWrite { |
|
||||||
get { return true; } |
|
||||||
} |
|
||||||
|
|
||||||
public override long Length { |
|
||||||
get { return 0; } |
|
||||||
} |
|
||||||
|
|
||||||
public override long Position { |
|
||||||
get { return 0; } |
|
||||||
set { } |
|
||||||
} |
|
||||||
|
|
||||||
public override void Flush() |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
public override long Seek(long offset, SeekOrigin origin) |
|
||||||
{ |
|
||||||
return 0; |
|
||||||
} |
|
||||||
|
|
||||||
public override void SetLength(long value) |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
public override int Read(byte[] buffer, int offset, int count) |
|
||||||
{ |
|
||||||
return 0; |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Assumes the bytes are UTF8 and writes them to the text editor.
|
|
||||||
/// </summary>
|
|
||||||
public override void Write(byte[] buffer, int offset, int count) |
|
||||||
{ |
|
||||||
string text = UTF8Encoding.UTF8.GetString(buffer, offset, count); |
|
||||||
textEditor.Write(text); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,66 +0,0 @@ |
|||||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
||||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.IO; |
|
||||||
using System.Text; |
|
||||||
|
|
||||||
using ICSharpCode.RubyBinding; |
|
||||||
using ICSharpCode.Scripting.Tests.Utils; |
|
||||||
using NUnit.Framework; |
|
||||||
using RubyBinding.Tests.Utils; |
|
||||||
|
|
||||||
namespace RubyBinding.Tests.Console |
|
||||||
{ |
|
||||||
[TestFixture] |
|
||||||
public class RubyOutputStreamTestFixture |
|
||||||
{ |
|
||||||
RubyOutputStream stream; |
|
||||||
MockConsoleTextEditor textEditor; |
|
||||||
|
|
||||||
[TestFixtureSetUp] |
|
||||||
public void SetUpFixture() |
|
||||||
{ |
|
||||||
textEditor = new MockConsoleTextEditor(); |
|
||||||
stream = new RubyOutputStream(textEditor); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void CanReadIsFalse() |
|
||||||
{ |
|
||||||
Assert.IsFalse(stream.CanRead); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void CanSeekIsFalse() |
|
||||||
{ |
|
||||||
Assert.IsFalse(stream.CanSeek); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void CanWriteIsTrue() |
|
||||||
{ |
|
||||||
Assert.IsTrue(stream.CanWrite); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void WriteAddsTextToTextEditor() |
|
||||||
{ |
|
||||||
textEditor.Text = String.Empty; |
|
||||||
byte[] bytes = UTF8Encoding.UTF8.GetBytes("test"); |
|
||||||
stream.Write(bytes, 0, bytes.Length); |
|
||||||
|
|
||||||
Assert.AreEqual("test", textEditor.Text); |
|
||||||
} |
|
||||||
|
|
||||||
[Test] |
|
||||||
public void OffsetAndLengthUsedInWriteMethod() |
|
||||||
{ |
|
||||||
textEditor.Text = String.Empty; |
|
||||||
byte[] bytes = UTF8Encoding.UTF8.GetBytes("0output1"); |
|
||||||
stream.Write(bytes, 1, bytes.Length - 2); |
|
||||||
|
|
||||||
Assert.AreEqual("output", textEditor.Text); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue