Skip to content

Commit

Permalink
jruby: Add StringIO::VERSION
Browse files Browse the repository at this point in the history
Fixes GH-57
  • Loading branch information
kou committed Aug 10, 2023
1 parent 2b5e2a5 commit c4e0800
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
3 changes: 3 additions & 0 deletions ext/java/org/jruby/ext/stringio/StringIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public static RubyClass createStringIOClass(final Ruby runtime) {
RubyClass stringIOClass = runtime.defineClass(
"StringIO", runtime.getObject(), StringIO::new);

RubyString version = RubyString.newString(runtime, "3.0.8");
stringIOClass.defineConstant("VERSION", version);

stringIOClass.defineAnnotatedMethods(StringIO.class);
stringIOClass.includeModule(runtime.getEnumerable());

Expand Down
19 changes: 9 additions & 10 deletions rakelib/version.rake
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
class << (helper = Bundler::GemHelper.instance)
SOURCE_PATH = "ext/stringio/stringio.c"
C_SOURCE_PATH = "ext/stringio/stringio.c"
JAVA_SOURCE_PATH = "ext/java/org/jruby/ext/stringio/StringIO.java"
def update_source_version
path = SOURCE_PATH
File.open(path, "r+b") do |f|
d = f.read
if d.sub!(/^#define\s+STRINGIO_VERSION\s+\K".*"/) {version.to_s.dump}
f.rewind
f.truncate(0)
f.print(d)
end
end
c_source = File.read(C_SOURCE_PATH)
c_source.sub!(/^#define\s+STRINGIO_VERSION\s+\K".*"/) {version.to_s.dump}
File.write(C_SOURCE_PATH, c_source)

java_source = File.read(JAVA_SOURCE_PATH)
java_source.sub!(/version = RubyString\.newString\(runtime, \K".*"/) {version.to_s.dump}
File.write(JAVA_SOURCE_PATH, java_source)
end

def commit_bump
Expand Down
4 changes: 4 additions & 0 deletions test/stringio/test_stringio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def open_file(content)

include TestEOF::Seek

def test_version
assert_kind_of(String, StringIO::VERSION)
end

def test_initialize
assert_kind_of StringIO, StringIO.new
assert_kind_of StringIO, StringIO.new('str')
Expand Down

0 comments on commit c4e0800

Please sign in to comment.