void test_fetch_bytes_out_of_bounds() { ByteArray* b = String::create(state, "xyzzy")->data(); Integer* neg = Fixnum::from(-1); Integer* zero = Fixnum::from(0); Integer* one = Fixnum::from(1); Integer* size = b->size(state); Integer* size1 = Fixnum::from(b->size(state)->to_native()+1); TS_ASSERT_THROWS_ASSERT(b->fetch_bytes(state, neg, zero), const RubyException &e, TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception))); TS_ASSERT_THROWS_ASSERT(b->fetch_bytes(state, zero, neg), const RubyException &e, TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception))); TS_ASSERT_THROWS_ASSERT(b->fetch_bytes(state, zero, size1), const RubyException &e, TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception))); TS_ASSERT_THROWS_ASSERT(b->fetch_bytes(state, one, size), const RubyException &e, TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception))); }
void test_fetch_bytes() { String* s = String::create(state, "xyzzy"); ByteArray* b = s->data(); ByteArray* ba = b->fetch_bytes(state, Fixnum::from(1), Fixnum::from(3)); TS_ASSERT_SAME_DATA(ba->bytes, "yzz", 3); }
void test_fetch_bytes() { ByteArray* b = new_bytearray("xyzzy"); ByteArray* ba = b->fetch_bytes(state, Fixnum::from(1), Fixnum::from(3)); TS_ASSERT_SAME_DATA(ba->raw_bytes(), "yzz", 3); }