Skip to content

Commit

Permalink
Add closed?
Browse files Browse the repository at this point in the history
  • Loading branch information
kojix2 committed Sep 24, 2024
1 parent 782496c commit efd1a9c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
16 changes: 16 additions & 0 deletions ext/bio/bigwig/bigwigext.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ bigwig_close(VALUE self)
return Qnil;
}

static VALUE
bigwig_is_closed(VALUE self)
{
bigWigFile_t *bw = get_bigWigFile(self);

if (bw)
{
return Qfalse;
}
else
{
return Qtrue;
}
}

static VALUE
bw_get_header(VALUE self)
{
Expand Down Expand Up @@ -738,6 +753,7 @@ void Init_bigwigext()

rb_define_private_method(rb_BigWig, "initialize_raw", bigwig_init, 2);
rb_define_method(rb_BigWig, "close", bigwig_close, 0);
rb_define_method(rb_BigWig, "closed?", bigwig_is_closed, 0);
rb_define_method(rb_BigWig, "header", bw_get_header, 0);
rb_define_method(rb_BigWig, "chroms", bw_get_chroms, -1);
rb_define_private_method(rb_BigWig, "stats_raw", bw_get_stats, 6);
Expand Down
18 changes: 17 additions & 1 deletion test/bigwig_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,24 @@ def test_open_with_block
end
end

def test_closed?
bw = Bio::BigWig.new(bwfile)
assert_equal Bio::BigWig, bw.class
assert_equal false, bw.closed?
assert_nil bw.close
assert_equal true, bw.closed?
end

def test_closed_with_block
f = Bio::BigWig.open(bwfile) do |bw|
assert_equal Bio::BigWig, bw.class
assert_equal false, bw.closed?
end
assert_equal true, f.closed?
end

def test_open_remote
skip "Skipping remote test" unless ENV['RUN_REMOTE_TESTS'] == '1'
skip "Skipping remote test" unless ENV["RUN_REMOTE_TESTS"] == "1"

Bio::BigWig.open(bwurl) do |bw|
assert_equal Bio::BigWig, bw.class
Expand Down

0 comments on commit efd1a9c

Please sign in to comment.