void test_set_byte() { CharArray* c = String::create(state, "xyz")->data(); c->set_byte(state, Fixnum::from(0), Fixnum::from('1')); TS_ASSERT_EQUALS(c->get_byte(state, Fixnum::from(0)), Fixnum::from('1')); c->set_byte(state, Fixnum::from(2), Fixnum::from('2')); TS_ASSERT_EQUALS(c->get_byte(state, Fixnum::from(2)), Fixnum::from('2')); }
void test_get_byte_index_out_of_bounds() { CharArray* c = String::create(state, "xyz")->data(); native_int sz = c->size(state)->to_native(); TS_ASSERT_THROWS_ASSERT(c->get_byte(state, Fixnum::from(sz)), const RubyException &e, TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception))); TS_ASSERT_THROWS_ASSERT(c->get_byte(state, Fixnum::from(sz+1)), const RubyException &e, TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception))); TS_ASSERT_THROWS_ASSERT(c->get_byte(state, Fixnum::from(-1)), const RubyException &e, TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception))); }