void test_fetch_bytes_out_of_bounds() { CharArray* c = String::create(state, "xyzzy")->data(); Fixnum* neg = Fixnum::from(-1); Fixnum* zero = Fixnum::from(0); Fixnum* one = Fixnum::from(1); Fixnum* size = c->size(state); TS_ASSERT_THROWS_ASSERT(c->fetch_bytes(state, neg, zero), const RubyException &e, TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception))); TS_ASSERT_THROWS_ASSERT(c->fetch_bytes(state, zero, neg), const RubyException &e, TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception))); TS_ASSERT_THROWS_ASSERT(c->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"); CharArray* c = s->data(); CharArray* ca = c->fetch_bytes(state, Fixnum::from(1), Fixnum::from(3)); TS_ASSERT_SAME_DATA(ca->raw_bytes(), "yzz", 3); }