[Ironruby-core] Linebreak issue with clr strings manipulated by Ruby code

Aldinei Sampaio aldinei.sampaio at gmail.com
Thu Mar 3 18:11:59 EST 2011


Hi, sorry again, but is anyone seeing this message?

I coudnt get any response about this, either here or in the Codeplex
issue tracker.

2011/2/25 Aldinei Sampaio <aldinei.sampaio at gmail.com>:
> Hi, guys. Sorry if I am posting this in the wrong place, but I need
> some kind of direction here.
>
> I isolated my problem in the following UnitTest in Visual Basic:
>
> <TestMethod()>
> Public Sub LineBreakProblem()
>    Const SCRIPT = "print System::String.Format('Line1{0}Line2',
> System::Environment.NewLine)"
>
>    Dim engine = IronRuby.Ruby.CreateEngine()
>    Dim stream = New IO.MemoryStream
>    Dim writer = New IO.StreamWriter(stream)
>    engine.Runtime.IO.SetOutput(stream, writer)
>    Dim source = engine.CreateScriptSourceFromString(SCRIPT, "Script",
> Microsoft.Scripting.SourceCodeKind.File)
>    source.Execute()
>
>    writer.Flush()
>    stream.Position = 0
>    Dim actual = (New IO.StreamReader(stream)).ReadToEnd()
>
>    Dim expected = String.Format("Line1{0}Line2", Environment.NewLine)
>
>    Assert.AreEqual(expected, actual)
> End Sub
>
>
> As you can see, i am running this Ruby code:
>
> print System::String.Format('Line1{0}Line2', System::Environment.NewLine)
>
> And then I am using the engine.Runtime.IO.SetOutput to get back the
> result generated by the "print" statement. System.Environment.NewLine
> returns the char combination CR + LF.
>
> The "expected" variable will contain: "Line1" + CR + LF + "Line2".
> The "actual" variable receive the value "Line1" + CR + LF + CR + LF + "Line2"
>
> Seems that all the linebreaks are doubled when using the CLR string
> with the "print" statement.
>
> Any suggestion that you can give me to resolve or work around this
> problem will be much appreciated.
>


More information about the Ironruby-core mailing list