diff --git a/Merlin/External/Languages/IronRuby/mspec/ironruby-tags/library/zlib/gzipfile/close_tags.txt b/Merlin/External/Languages/IronRuby/mspec/ironruby-tags/library/zlib/gzipfile/close_tags.txt deleted file mode 100644 index fad0199e72..0000000000 --- a/Merlin/External/Languages/IronRuby/mspec/ironruby-tags/library/zlib/gzipfile/close_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails:Zlib::GzipFile#close finishes the stream and closes the io diff --git a/Merlin/External/Languages/IronRuby/mspec/ironruby-tags/library/zlib/gzipfile/closed_tags.txt b/Merlin/External/Languages/IronRuby/mspec/ironruby-tags/library/zlib/gzipfile/closed_tags.txt deleted file mode 100644 index fc729795c8..0000000000 --- a/Merlin/External/Languages/IronRuby/mspec/ironruby-tags/library/zlib/gzipfile/closed_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails:Zlib::GzipFile#closed? returns the closed status diff --git a/Merlin/External/Languages/IronRuby/mspec/ironruby-tags/library/zlib/gzipfile/comment_tags.txt b/Merlin/External/Languages/IronRuby/mspec/ironruby-tags/library/zlib/gzipfile/comment_tags.txt deleted file mode 100644 index 959b877e28..0000000000 --- a/Merlin/External/Languages/IronRuby/mspec/ironruby-tags/library/zlib/gzipfile/comment_tags.txt +++ /dev/null @@ -1,2 +0,0 @@ -fails:Zlib::GzipFile#comment returns the name -fails:Zlib::GzipFile#comment raises an error on a closed stream diff --git a/Merlin/External/Languages/IronRuby/mspec/ironruby-tags/library/zlib/gzipfile/orig_name_tags.txt b/Merlin/External/Languages/IronRuby/mspec/ironruby-tags/library/zlib/gzipfile/orig_name_tags.txt deleted file mode 100644 index a40e8ad619..0000000000 --- a/Merlin/External/Languages/IronRuby/mspec/ironruby-tags/library/zlib/gzipfile/orig_name_tags.txt +++ /dev/null @@ -1,2 +0,0 @@ -fails:Zlib::GzipFile#orig_name returns the name -fails:Zlib::GzipFile#orig_name raises an error on a closed stream diff --git a/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/close_spec.rb b/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/close_spec.rb index a93617c308..26fc758577 100644 --- a/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/close_spec.rb +++ b/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/close_spec.rb @@ -3,20 +3,33 @@ require 'zlib' describe 'Zlib::GzipFile#close' do - it 'finishes the stream and closes the io' do - io = StringIO.new - Zlib::GzipWriter.wrap io do |gzio| - gzio.close - - gzio.closed?.should == true - - lambda { gzio.orig_name }.should \ - raise_error(Zlib::GzipFile::Error, 'closed gzip stream') - lambda { gzio.comment }.should \ - raise_error(Zlib::GzipFile::Error, 'closed gzip stream') - end + before(:each) do + @io = StringIO.new + @gzip_writer = Zlib::GzipWriter.new @io + end + + it 'closes the GzipFile' do + @gzip_writer.close + @gzip_writer.closed?.should be_true + end + + it 'closes the IO object' do + @gzip_writer.close + @io.closed?.should be_true + end + + it 'returns the associated IO object' do + @gzip_writer.close.should eql(@io) + end + + it 'raises Zlib::GzipFile::Error if called multiple times' do + @gzip_writer.close + lambda { @gzip_writer.close }.should raise_error(Zlib::GzipFile::Error) + end - io.string[10..-1].should == "\003\000\000\000\000\000\000\000\000\000" + it 'raises Zlib::GzipFile::Error if called after Zlib#finish' do + @gzip_writer.finish + lambda { @gzip_writer.close }.should raise_error(Zlib::GzipFile::Error) end end diff --git a/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/comment_spec.rb b/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/comment_spec.rb index cf094b86c5..8994c1e259 100644 --- a/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/comment_spec.rb +++ b/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/comment_spec.rb @@ -5,23 +5,42 @@ describe 'Zlib::GzipFile#comment' do before :each do @io = StringIO.new + @gzip_writer = Zlib::GzipWriter.new @io end + it 'is nil by default' do + @gzip_writer.comment.should be_nil + end + it 'returns the name' do - Zlib::GzipWriter.wrap @io do |gzio| - gzio.comment = 'name' + @gzip_writer.comment = 'comment' + @gzip_writer.comment.should == 'comment' + end +end - gzio.comment.should == 'name' - end +describe 'Zlib::GzipFile#comment=' do + before :each do + @io = StringIO.new + @gzip_writer = Zlib::GzipWriter.new @io end + it 'returns the argument' do + c = 'comment' + (@gzip_writer.comment = c).should equal(c) + end + + it 'raises TypeError if argument is nil' do + lambda { @gzip_writer.comment = nil }.should raise_error(TypeError) + end + + it 'raises TypeError if argument is not a String' do + m = mock("comment").should_receive(:to_s).any_number_of_times.and_return("comment") + lambda { @gzip_writer.comment = m }.should raise_error(TypeError) + end + it 'raises an error on a closed stream' do - Zlib::GzipWriter.wrap @io do |gzio| - gzio.close - - lambda { gzio.comment }.should \ - raise_error(Zlib::GzipFile::Error, 'closed gzip stream') - end + @gzip_writer.close + lambda { @gzip_writer.comment = 'comment' }.should raise_error(Zlib::GzipFile::Error) end end diff --git a/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/finish_spec.rb b/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/finish_spec.rb index 0ec1016caa..b8441c0b57 100644 --- a/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/finish_spec.rb +++ b/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/finish_spec.rb @@ -1 +1,29 @@ require File.dirname(__FILE__) + '/../../../spec_helper' +require 'stringio' +require 'zlib' + +describe 'Zlib::GzipFile#finish' do + before(:each) do + @io = StringIO.new + @gzip_writer = Zlib::GzipWriter.new @io + end + + it 'closes the GzipFile' do + @gzip_writer.finish + @gzip_writer.closed?.should be_true + end + + it 'does not close the IO object' do + @gzip_writer.finish + @io.closed?.should be_false + end + + it 'returns the associated IO object' do + @gzip_writer.finish.should eql(@io) + end + + it 'raises Zlib::GzipFile::Error if called multiple times' do + @gzip_writer.finish + lambda { @gzip_writer.finish }.should raise_error(Zlib::GzipFile::Error) + end +end diff --git a/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/orig_name_spec.rb b/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/orig_name_spec.rb index 8e52ab3d51..a780819375 100644 --- a/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/orig_name_spec.rb +++ b/Merlin/External/Languages/IronRuby/mspec/rubyspec/library/zlib/gzipfile/orig_name_spec.rb @@ -5,23 +5,42 @@ describe 'Zlib::GzipFile#orig_name' do before :each do @io = StringIO.new + @gzip_writer = Zlib::GzipWriter.new @io end + it 'is nil by default' do + @gzip_writer.orig_name.should be_nil + end + it 'returns the name' do - Zlib::GzipWriter.wrap @io do |gzio| - gzio.orig_name = 'name' + @gzip_writer.orig_name = 'name' + @gzip_writer.orig_name.should == 'name' + end +end - gzio.orig_name.should == 'name' - end +describe 'Zlib::GzipFile#orig_name=' do + before :each do + @io = StringIO.new + @gzip_writer = Zlib::GzipWriter.new @io end + it 'returns the argument' do + n = 'name' + (@gzip_writer.orig_name = n).should equal(n) + end + + it 'raises TypeError if argument is nil' do + lambda { @gzip_writer.orig_name = nil }.should raise_error(TypeError) + end + + it 'raises TypeError if argument is not a String' do + m = mock("name").should_receive(:to_s).any_number_of_times.and_return("name") + lambda { @gzip_writer.orig_name = m }.should raise_error(TypeError) + end + it 'raises an error on a closed stream' do - Zlib::GzipWriter.wrap @io do |gzio| - gzio.close - - lambda { gzio.orig_name }.should \ - raise_error(Zlib::GzipFile::Error, 'closed gzip stream') - end + @gzip_writer.close + lambda { @gzip_writer.orig_name = 'name' }.should raise_error(Zlib::GzipFile::Error) end end diff --git a/Merlin/External/Languages/IronRuby/mspec/rubyspec/spec_helper.rb b/Merlin/External/Languages/IronRuby/mspec/rubyspec/spec_helper.rb index 970e1a97e7..e7fdae43ba 100644 --- a/Merlin/External/Languages/IronRuby/mspec/rubyspec/spec_helper.rb +++ b/Merlin/External/Languages/IronRuby/mspec/rubyspec/spec_helper.rb @@ -12,6 +12,10 @@ require 'mspec/matchers/equal_element' require 'mspec/matchers/equal_utf16' require 'mspec/matchers/match_yaml' + def debugger + require 'mscorlib' + System::Diagnostics::Debugger.break if System::Diagnostics::Debugger.launch + end # Code to setup HOME directory correctly on Windows # This duplicates Ruby 1.9 semantics for defining HOME diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs index 2cf40172cf..04584566a4 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs @@ -4344,9 +4344,9 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia ); module.DefineLibraryMethod("gsub", 0x51, + new System.Func(IronRuby.Builtins.MutableStringOps.ReplaceAll), new System.Func, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex, System.Object>(IronRuby.Builtins.MutableStringOps.BlockReplaceAll), - new System.Func, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, System.Object>(IronRuby.Builtins.MutableStringOps.BlockReplaceAll), - new System.Func(IronRuby.Builtins.MutableStringOps.ReplaceAll) + new System.Func, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, System.Object>(IronRuby.Builtins.MutableStringOps.BlockReplaceAll) ); module.DefineLibraryMethod("gsub!", 0x51, @@ -4507,9 +4507,9 @@ public sealed class BuiltinsLibraryInitializer : IronRuby.Builtins.LibraryInitia ); module.DefineLibraryMethod("sub", 0x51, + new System.Func(IronRuby.Builtins.MutableStringOps.ReplaceFirst), new System.Func, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.RubyRegex, System.Object>(IronRuby.Builtins.MutableStringOps.BlockReplaceFirst), - new System.Func, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, System.Object>(IronRuby.Builtins.MutableStringOps.BlockReplaceFirst), - new System.Func(IronRuby.Builtins.MutableStringOps.ReplaceFirst) + new System.Func, IronRuby.Runtime.RubyScope, IronRuby.Runtime.BlockParam, IronRuby.Builtins.MutableString, IronRuby.Builtins.MutableString, System.Object>(IronRuby.Builtins.MutableStringOps.BlockReplaceFirst) ); module.DefineLibraryMethod("sub!", 0x51, @@ -6881,6 +6881,18 @@ public sealed class ZlibLibraryInitializer : IronRuby.Builtins.LibraryInitialize new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GZipFile.IsClosed) ); + module.DefineLibraryMethod("comment", 0x11, + new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GZipFile.Comment) + ); + + module.DefineLibraryMethod("orig_name", 0x11, + new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GZipFile.OriginalName) + ); + + module.DefineLibraryMethod("original_name", 0x11, + new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GZipFile.OriginalName) + ); + } private static void LoadZlib__GzipFile_Class(IronRuby.Builtins.RubyModule/*!*/ module) { @@ -6897,25 +6909,17 @@ public sealed class ZlibLibraryInitializer : IronRuby.Builtins.LibraryInitialize private static void LoadZlib__GzipReader_Instance(IronRuby.Builtins.RubyModule/*!*/ module) { module.DefineLibraryMethod("close", 0x11, - new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GZipReader.Close) - ); - - module.DefineLibraryMethod("comment", 0x11, - new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GZipReader.Comment) + new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GZipReader.Close) ); module.DefineLibraryMethod("finish", 0x11, - new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GZipReader.Close) + new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GZipReader.Finish) ); module.DefineLibraryMethod("open", 0x12, new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GZipReader.Open) ); - module.DefineLibraryMethod("original_name", 0x11, - new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GZipReader.OriginalName) - ); - module.DefineLibraryMethod("read", 0x11, new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GZipReader.Read) ); @@ -6941,11 +6945,15 @@ public sealed class ZlibLibraryInitializer : IronRuby.Builtins.LibraryInitialize ); module.DefineLibraryMethod("close", 0x11, - new System.Action(IronRuby.StandardLibrary.Zlib.Zlib.GzipWriter.Close) + new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GzipWriter.Close) + ); + + module.DefineLibraryMethod("comment=", 0x11, + new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GzipWriter.Comment) ); module.DefineLibraryMethod("finish", 0x11, - new System.Action(IronRuby.StandardLibrary.Zlib.Zlib.GzipWriter.Close) + new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GzipWriter.Finish) ); module.DefineLibraryMethod("flush", 0x11, @@ -6953,6 +6961,10 @@ public sealed class ZlibLibraryInitializer : IronRuby.Builtins.LibraryInitialize new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GzipWriter.Flush) ); + module.DefineLibraryMethod("orig_name=", 0x11, + new System.Func(IronRuby.StandardLibrary.Zlib.Zlib.GzipWriter.OriginalName) + ); + module.DefineLibraryMethod("write", 0x11, new System.Func, IronRuby.Runtime.RubyContext, IronRuby.StandardLibrary.Zlib.Zlib.GzipWriter, IronRuby.Builtins.MutableString, System.Int32>(IronRuby.StandardLibrary.Zlib.Zlib.GzipWriter.Write) ); diff --git a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Zlib/zlib.cs b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Zlib/zlib.cs index 766bff523c..88c6951a4d 100644 --- a/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Zlib/zlib.cs +++ b/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Zlib/zlib.cs @@ -585,6 +585,8 @@ public class GZipFile { protected int _outPos; protected int _inPos; protected bool _isClosed; + protected MutableString/*!*/ _originalName; + protected MutableString/*!*/ _comment; public GZipFile(IOWrapper/*!*/ ioWrapper) { Debug.Assert(ioWrapper != null); @@ -634,8 +636,12 @@ public Error(string message) } } - internal static void Close(UnaryOpStorage/*!*/ closeStorage, GZipFile/*!*/ self) { - if (self._ioWrapper.CanBeClosed) { + internal static void Close(UnaryOpStorage/*!*/ closeStorage, GZipFile/*!*/ self, bool closeIO) { + if (self._isClosed) { + throw new Error("closed gzip stream"); + } + + if (closeIO && self._ioWrapper.CanBeClosed) { var site = closeStorage.GetCallSite("close"); site.Target(site, self._ioWrapper.UnderlyingObject); } @@ -649,11 +655,29 @@ public Error(string message) return self._isClosed; } - // comment() + [RubyMethod("comment")] + public static MutableString/*!*/ Comment(GZipFile/*!*/ self) { + if (self._isClosed) { + throw new Error("closed gzip stream"); + } + + return self._comment; + } + // crc() // level() // mtime() - // orig_name() + + [RubyMethod("orig_name")] + [RubyMethod("original_name")] + public static MutableString/*!*/ OriginalName(GZipFile/*!*/ self) { + if (self._isClosed) { + throw new Error("closed gzip stream"); + } + + return self._originalName; + } + // os_code() // sync() // sync = flag @@ -670,8 +694,6 @@ public class GZipReader : GZipFile { protected MutableString _xtraField; protected MutableString/*!*/ _contents; - protected MutableString/*!*/ _originalName; - protected MutableString/*!*/ _comment; protected ushort _headerCrc; [RubyMethod("xtra_field")] @@ -679,16 +701,6 @@ public class GZipReader : GZipFile { return self._xtraField; } - [RubyMethod("original_name")] - public static MutableString/*!*/ OriginalName(GZipReader/*!*/ self) { - return self._originalName; - } - - [RubyMethod("comment")] - public static MutableString/*!*/ Comment(GZipReader/*!*/ self) { - return self._comment; - } - [RubyConstant("OSES")] public static string[] OSES = { "FAT filesystem", @@ -836,10 +848,15 @@ private GZipReader(IOWrapper/*!*/ ioWrapper, BinaryReader/*!*/ reader) } [RubyMethod("close")] + public static object/*!*/ Close(UnaryOpStorage/*!*/ closeStorage, RubyContext/*!*/ context, GZipReader/*!*/ self) { + GZipFile.Close(closeStorage, self, true); + return self._ioWrapper.UnderlyingObject; + } + [RubyMethod("finish")] - public static GZipReader/*!*/ Close(UnaryOpStorage/*!*/ closeStorage, GZipReader/*!*/ self) { - GZipFile.Close(closeStorage, self); - return self; + public static object/*!*/ Finish(UnaryOpStorage/*!*/ closeStorage, RubyContext/*!*/ context, GZipReader/*!*/ self) { + GZipFile.Close(closeStorage, self, false); + return self._ioWrapper.UnderlyingObject; } } @@ -1087,14 +1104,33 @@ private GzipWriter(RespondToStorage/*!*/ respondToStorage, RubyContext/*!*/ cont } [RubyMethod("close")] - [RubyMethod("finish")] - public static void Close(UnaryOpStorage/*!*/ closeStorage, GzipWriter/*!*/ self) { + public static object/*!*/ Close(UnaryOpStorage/*!*/ closeStorage, RubyContext/*!*/ context, GzipWriter/*!*/ self) { + if (self._isClosed) { + throw new Error("closed gzip stream"); + } self._gzipStream.Close(); self._ioWrapper.Flush(); - GZipFile.Close(closeStorage, self); + GZipFile.Close(closeStorage, self, true); + return self._ioWrapper.UnderlyingObject; + } + + [RubyMethod("finish")] + public static object/*!*/ Finish(UnaryOpStorage/*!*/ closeStorage, RubyContext/*!*/ context, GzipWriter/*!*/ self) { + self._gzipStream.Close(); + self._ioWrapper.Flush(closeStorage, context); + GZipFile.Close(closeStorage, self, false); + return self._ioWrapper.UnderlyingObject; } - // comment=(p1) + [RubyMethod("comment=")] + public static MutableString/*!*/ Comment(GzipWriter/*!*/ self, [NotNull]MutableString/*!*/ comment) { + if (self._isClosed) { + throw new Error("closed gzip stream"); + } + self._comment = comment; + + return comment; + } [RubyMethod("flush")] public static GzipWriter Flush(UnaryOpStorage/*!*/ flushStorage, RubyContext/*!*/ context, GzipWriter/*!*/ self, object flush) { @@ -1123,7 +1159,18 @@ private GzipWriter(RespondToStorage/*!*/ respondToStorage, RubyContext/*!*/ cont } // mtime=(p1) - // orig_name=(p1) + + [RubyMethod("orig_name=")] + public static MutableString/*!*/ OriginalName(GzipWriter/*!*/ self, [NotNull]MutableString/*!*/ originalName) { + if (self._isClosed) { + throw new Error("closed gzip stream"); + } + + self._originalName = originalName; + + return originalName; + } + // pos() // print(...) // printf(...)